Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1174248pxk; Fri, 25 Sep 2020 08:03:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoQ9TRYs/hCl/w4+u34WI1OsCm/JbKLxsddkG/0ntmGu8sPTeDqVzID/LshsQgoPgvi+n8 X-Received: by 2002:a17:906:7c82:: with SMTP id w2mr3076480ejo.87.1601046223694; Fri, 25 Sep 2020 08:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601046223; cv=none; d=google.com; s=arc-20160816; b=Hxy/tweeOlIgMDNIl8ktWCFRn67Mh+LvqsLy5dg+SaQV2Sni6yB9PfsL9TFDW9BKRV dFkefN4xpPpBjyuZO9O6SbHWgfUCE0KKu6vJoqH6cSBsaZAn5IbBfeivSceYdc7uq1Lk oPD6qZD372qBTrQRgU/cfCtqf4vsyxZO2ae7eOqCLwMPaO5oix9AWSmwLy1i/Ar2bbPL DCmDcwmRs1oxZ05I0nofY1YZRwC1aV0FRTehl8tdoMJwcqPEHsj5bDonVXqnWL2rGNnt DN6gT4id/YEAprlzWeksNwTu2lYX4o/9jbk42vypgMym1bFgdi5p/8XNp5trcjmVN2Xc jDig== 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=+wZCVzG0Rt/4KjzYL5d+jTEUvhJkWdYcv5VUQxPp4Us=; b=ZuUs4/rOjyrIR4RGT5TDv1N68rquaM/YLSOYJ7g5a1s15VwhVwmkQIp+NfHrQ/Mw0d im2lE1xA/+uwRFkeNtXSg4Pcrtwit2+mMylRiFmnVKImuiISRMinL2wPH4Xjw6KWGjP3 a4+euutFQinEGJbmtzjQ6C7JCkN0CyTfFjYvXNaWNBHhhIC5HyLlD8nVLsJlGtBk5QmD F2PQgAvaAKdLWmsxz0mpX0y4bKOqGIm85ADk/l4358IdYGcy0cRg62hfr/BYIbJhSV4H jRnnYEr5PKEJJlpwuswql5vk0O0W4m2+AWNsiohmxgJ+bRiqnPeLjkhoazE4JqND5y2x XoOg== 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 cx16si2025604edb.575.2020.09.25.08.03.19; Fri, 25 Sep 2020 08:03:43 -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 S1729374AbgIYPBy (ORCPT + 99 others); Fri, 25 Sep 2020 11:01:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:34140 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728693AbgIYPBx (ORCPT ); Fri, 25 Sep 2020 11:01:53 -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 45629AD72; Fri, 25 Sep 2020 15:01:51 +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 , Cong Wang , Christoph Hellwig , "David S . Miller" , Sridhar Samudrala Subject: [PATCH v8 2/7] net: add WARN_ONCE in kernel_sendpage() for improper zero-copy send Date: Fri, 25 Sep 2020 23:01:14 +0800 Message-Id: <20200925150119.112016-3-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200925150119.112016-1-colyli@suse.de> References: <20200925150119.112016-1-colyli@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a page sent into kernel_sendpage() is a slab page or it doesn't have ref_count, this page is improper to send by the zero copy sendpage() method. Otherwise such page might be unexpected released in network code path and causes impredictable panic due to kernel memory management data structure corruption. This path adds a WARN_ON() on the sending page before sends it into the concrete zero-copy sendpage() method, if the page is improper for the zero-copy sendpage() method, a warning message can be observed before the consequential unpredictable kernel panic. This patch does not change existing kernel_sendpage() behavior for the improper page zero-copy send, it just provides hint warning message for following potential panic due the kernel memory heap corruption. Signed-off-by: Coly Li Cc: Cong Wang Cc: Christoph Hellwig Cc: David S. Miller Cc: Sridhar Samudrala --- net/socket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/socket.c b/net/socket.c index 0c0144604f81..771456a1d947 100644 --- a/net/socket.c +++ b/net/socket.c @@ -3638,9 +3638,11 @@ EXPORT_SYMBOL(kernel_getpeername); int kernel_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) { - if (sock->ops->sendpage) + if (sock->ops->sendpage) { + /* Warn in case the improper page to zero-copy send */ + WARN_ONCE(!sendpage_ok(page)); return sock->ops->sendpage(sock, page, offset, size, flags); - + } return sock_no_sendpage(sock, page, offset, size, flags); } EXPORT_SYMBOL(kernel_sendpage); -- 2.26.2