Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3065207pxa; Tue, 18 Aug 2020 05:53:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA7kQG0GWaS+lBvPUDxMuSCJztTGM1Ns2JheJiVoSGzEJDZD8ddiR2e8fBcHikNdafo8tQ X-Received: by 2002:a17:906:7fc9:: with SMTP id r9mr19428942ejs.407.1597755198953; Tue, 18 Aug 2020 05:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597755198; cv=none; d=google.com; s=arc-20160816; b=I1bqS5gKUcLB717C4oheeNv73CDTHo2WTYeLH9OPGXDVYqdo/D/k6wyFQJ6XXZfxXL 7cMh4c2PJMNKtabrnPV3+8pGzDNwtO8Ak4JgKXSEpe7vA6GxkppiAhASj3hhIussUbhq UJUdRw4fefzGnTqgon9zuo4voJ/UBJksdbj5d5wByQTJujssas7oBTHsBRnP1iEKJBKu n0Np5EOCSezqbIpR6Mar95wKmoKTejqDE6F7WVahS4IBcA/4vly4T5odx4F3wIPWa0sn PQk3miiQgP+oN0KlkTFP350L1oXbBdl5JEDPswcr8rXYTjolyvaSpFIpw7KkWeihPEXh C0hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Wyvt44hY+5hH6wb2dkfdbh++ekQU5jdlGFdkN9OgVL8=; b=HMlxKCmiBjWjQaghtd2PSe6ASOfLJ5nN4BXgllOUKAh5FHgA5US2rxSOhrTthaThe8 fQoxELhFPRCVtvmVQExpJGw9ximUiqUJYZ4OGrtVCTTTJnxiLC/pcmg55O8Ub1O2wvde YFgHHYu+3SPGOHjKcdrCLopOOxoAeuZ7AhPMiaeL5fZt9SM/Gv9HcUEM5I0QOYfyu4lq f7/s+c/7lb/EALURPIanCk2eeZXHzQO3LQ0OFaWrsUH/BXnkvn5xA4+hirSRHzxRBuLf 6PH64cprDSmdpKiJSox/GGHDxmFLJb69I0a+kd2kjtn/T9jDdEYaeUZuAKmwfMpcvRHz /xGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si13124418edy.274.2020.08.18.05.52.54; Tue, 18 Aug 2020 05:53:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbgHRMsV (ORCPT + 99 others); Tue, 18 Aug 2020 08:48:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:49524 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbgHRMsS (ORCPT ); Tue, 18 Aug 2020 08:48:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 240E1ADF2; Tue, 18 Aug 2020 12:48:42 +0000 (UTC) From: Coly Li To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, netdev@vger.kernel.org, open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, ceph-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Coly Li , Eric Dumazet , Vasily Averin , "David S . Miller" , stable@vger.kernel.org Subject: [PATCH v6 3/6] tcp: use sendpage_ok() to detect misused .sendpage Date: Tue, 18 Aug 2020 20:47:33 +0800 Message-Id: <20200818124736.5790-4-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200818124736.5790-1-colyli@suse.de> References: <20200818124736.5790-1-colyli@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- net/ipv4/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 31f3b858db81..d96c7549895a 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -970,7 +970,8 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, 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 -- 2.26.2