Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1127669pxk; Fri, 2 Oct 2020 01:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr4XjK8gVMBCebThleBCpt+wkgUvEjOAi3TwN7YjVL4N9cuYwvh914WyIcsHCom3FBrnES X-Received: by 2002:a17:906:f2cd:: with SMTP id gz13mr1149950ejb.19.1601627420088; Fri, 02 Oct 2020 01:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601627420; cv=none; d=google.com; s=arc-20160816; b=fXueXtN8GF1hNT1gCdrV7fWPvtMiTEEWonfTuuB+hNnWRE7wPaFuYXkFjnS3wfPFHF PUGtT5cik9GMZxC1sG+TrV38ZHXg+T+kI7ReN40qTqU4ngfDlH5xOg4bVEBOoiqTArRj Z3Y3EJYbetucr+TNywXbaCSmgULtkVmX/HR8ltivcL9W5RBs+lhRYT4uWFDQAneOwD3+ WQhBTfcLpAm2x/Ywy2y41P8VA/+EZiGbwf26fV4bsW/4q4R6vhv1GTqfNMatuGMaj0ek wu7u2XG6xIY5xtnzmTlpRk1hxgNsqDjevLWzeLqFPnX5RyVAf/rmd7+Mr5gxS2odAybi F6Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QFmotsCR5+/z8Ca0u8OffmpdOvDM+GimNzKjjFhI9J8=; b=F3Q+NFtm/ubyHnESm5rhE9xBaWQmUq1l+XjFiIEwXPgLUknJGzRq/SRGmf37xqefOz MOxMTJQuTd+0bjr8T/zpMisk2J/mvjKWQQsFxVsNEWZzYMMrTmxnL8fLk00RcPXX6z1h oQ9hW9pCdmeKnnNprYZhJWye4WhAVrYEjbDTiXlyK2aJwKsUbY/lN0DkPX5cEAJBMKCg UjGxD+mk/8+mFwsVvSkAk/CgdsP11Kn2MqOt/KNS8/j76k+OQx2PIfXq3FPvtqgFMMIF IPWYwXYM3C7dtv29zQfsJYxRhkthg3QnUVxSBCQRsoElDuea+GW/AQG1mRuuMv81YVbH FFuw== 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 b1si661759ejb.290.2020.10.02.01.29.58; Fri, 02 Oct 2020 01:30:20 -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 S2387734AbgJBI2c (ORCPT + 99 others); Fri, 2 Oct 2020 04:28:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:50082 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387699AbgJBI2W (ORCPT ); Fri, 2 Oct 2020 04:28:22 -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 B9D48AF1A; Fri, 2 Oct 2020 08:28:20 +0000 (UTC) From: Coly Li To: davem@davemloft.net, 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 , stable@vger.kernel.org Subject: [PATCH v10 4/7] tcp: use sendpage_ok() to detect misused .sendpage Date: Fri, 2 Oct 2020 16:27:31 +0800 Message-Id: <20201002082734.13925-5-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201002082734.13925-1-colyli@suse.de> References: <20201002082734.13925-1-colyli@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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..2135ee7c806d 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