From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7AC1C433E7 for ; Mon, 12 Oct 2020 13:54:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A57F02076E for ; Mon, 12 Oct 2020 13:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510879; bh=EFJRoblRIop2zVy4Y8mHcgY2ymAkUouoA+3yDkJrn7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=XP3TMrWjcFB3WnI3wtk/OWm2wf9khdB/Qtggnqc5YdYTPYloKeYD3MVbXFTsGP0F9 OMjmysaHdNxNECg5sffP7XLoCq0MgUH3WtYgvgAtwLB829LcjRmAKkenPmFtDN9W/r 1lkL0UUi/mZFDADUWPpPUhwnmrqnI6LJKwL8b5WM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390043AbgJLNyi (ORCPT ); Mon, 12 Oct 2020 09:54:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:48360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389708AbgJLNpv (ORCPT ); Mon, 12 Oct 2020 09:45:51 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E91DD2227F; Mon, 12 Oct 2020 13:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510280; bh=EFJRoblRIop2zVy4Y8mHcgY2ymAkUouoA+3yDkJrn7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IK95PYGE5IlvN3wiWgQqwz4YfQeu4DDMIzcxjYNtV0zniWtBk9g6x78TnwXJXiSOI 9vduIdunCj6mErvjQGlViSnvK7qftXiTbRATAMfaas7SFDCrNcRpiD1AYqv9sir0f4 MGz92PKj4CFaFuVc8p0qqrw3/GtXsb0oicfSwyTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Coly Li , Vasily Averin , "David S. Miller" Subject: [PATCH 5.8 032/124] tcp: use sendpage_ok() to detect misused .sendpage Date: Mon, 12 Oct 2020 15:30:36 +0200 Message-Id: <20201012133148.403480821@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012133146.834528783@linuxfoundation.org> References: <20201012133146.834528783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li commit cf83a17edeeb36195596d2dae060a7c381db35f1 upstream. commit a10674bf2406 ("tcp: detecting the misuse of .sendpage for Slab objects") adds the checks for Slab pages, but the pages don't have page_count are still missing from the check. Network layer's sendpage method is not designed to send page_count 0 pages neither, therefore both PageSlab() and page_count() should be both checked for the sending page. This is exactly what sendpage_ok() does. This patch uses sendpage_ok() in do_tcp_sendpages() to detect misused .sendpage, to make the code more robust. Fixes: a10674bf2406 ("tcp: detecting the misuse of .sendpage for Slab objects") Suggested-by: Eric Dumazet Signed-off-by: Coly Li Cc: Vasily Averin Cc: David S. Miller Cc: stable@vger.kernel.org Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -970,7 +970,8 @@ ssize_t do_tcp_sendpages(struct sock *sk long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); if (IS_ENABLED(CONFIG_DEBUG_VM) && - WARN_ONCE(PageSlab(page), "page must not be a Slab one")) + WARN_ONCE(!sendpage_ok(page), + "page must not be a Slab one and have page_count > 0")) return -EINVAL; /* Wait for a connection to finish. One exception is TCP Fast Open