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=unavailable 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 388E3C433DF for ; Mon, 12 Oct 2020 13:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA3E52225F for ; Mon, 12 Oct 2020 13:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510165; bh=iO7A3UDABTT4fqsjuY546SAsDNwvLoYNDp0TNT7BO5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IG+8tKw7TkDsmVQwbbsoOnP63J1CCDw1PdZXvW8dcZvXfY5OxknGc8nsnXrJBL63e wMhdefyh8YSYJeh2+Y3OxONDbnxCJoYYXp8ErAip6n7m3Y9hRRFbeYuTJSNcY21guy 0KGs1i9LV2W8xx9IHQj+W8mpqsu8lpsx3o6pEcFU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731338AbgJLNmm (ORCPT ); Mon, 12 Oct 2020 09:42:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:46218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731083AbgJLNlh (ORCPT ); Mon, 12 Oct 2020 09:41:37 -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 D247F221FE; Mon, 12 Oct 2020 13:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510092; bh=iO7A3UDABTT4fqsjuY546SAsDNwvLoYNDp0TNT7BO5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SRCXPKr+jZjqycN8vHDui4EghZsUpr3rRpEjxOEC5daIcmrNF5KdhejIXzjq9GJOE hUUgqbesk1RxhWaOzjthdjrZA0Pe72czX/4JcAJGRicUCFpE6/PgiGuHGGX2p23K99 Z2oJcWSF/tI+tHiX47b1WmnA/HDwUkPyU53qZ5Yw= 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.4 36/85] tcp: use sendpage_ok() to detect misused .sendpage Date: Mon, 12 Oct 2020 15:26:59 +0200 Message-Id: <20201012132634.594653424@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132632.846779148@linuxfoundation.org> References: <20201012132632.846779148@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 @@ -971,7 +971,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