Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1127389pxk; Fri, 2 Oct 2020 01:29:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbRKbcQnHQT4r7aM7mlHFSpKoH5LrkbkLXZ1wHLXvhlEMvS5SavGU8HkqZfsyBkV0dadcS X-Received: by 2002:a17:906:1081:: with SMTP id u1mr1095666eju.284.1601627391787; Fri, 02 Oct 2020 01:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601627391; cv=none; d=google.com; s=arc-20160816; b=cHCxWB6v6ByI7WHcZAVvOrH7kV2hKD78XbiEqSIgqEfBjm+c54paNcGq8wjbDvt2s9 B54mjd5mssvtSEcbF9CPfRTwlCtYNcz/8lSrGJhYcSZMUIO57Rw2KXA8S2OnSScBFE82 b0bBuuOyUwdSngINZEwsI9sZqwRqFds8eQlVWN45VcA0qffA8UKA0vV/8lwmHL22y5aH tdioQuMcnnk8fDXsiET6DHR0Bkb4qIqjB00VQ6R4fn6Cz1ZDXp8uyZAiON7BEJZn6GNj 9agoZGcQRwoN6bHr+ZxXkbE8JLvxTktFw5+i0w237/HenN1SmRw8DfXpJz1o45/ZKpqd tegg== 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=prUTcJLq1oJQPP8HuX4bbQYPRkfGVuq1UQonwzNLOq4=; b=L5Smx3lcsrsF2WXzpjIwjk4EknJJI9wcewBY8feUzzh+w5IlyKEBl7vih0r5utFJ+q tdPic7eXw/GTUa/X6B5LFONLvHs8PKssN1Nzo6uBpkcRQ8NjsLHHVEFTSnC8NnRrX7xM GHXheIotYTEzvKFBgZ1my59Xtsk4ggggyXItAiClgXr1m1Rjb97FLUMKZ4LFGhPc4sjp pAs/JSLif+fkmjknB0hwIetdKySUjRr91l7UWH6TrRTG85qhH1/yIpfPGQo727B8MNhI GJXc8GYGux9O8L3CbSwTzznmFt2X0dUcsYgIIo6/0Fm/CvoV/QXzZxhyQKkgQgDTNpPf 48Jg== 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 g16si652850ejf.211.2020.10.02.01.29.23; Fri, 02 Oct 2020 01:29:51 -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 S2387670AbgJBI2K (ORCPT + 99 others); Fri, 2 Oct 2020 04:28:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:49564 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgJBI2H (ORCPT ); Fri, 2 Oct 2020 04:28:07 -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 065B5AF4D; Fri, 2 Oct 2020 08:28:06 +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 , Cong Wang , Christoph Hellwig , Sridhar Samudrala Subject: [PATCH v10 2/7] net: add WARN_ONCE in kernel_sendpage() for improper zero-copy send Date: Fri, 2 Oct 2020 16:27:29 +0800 Message-Id: <20201002082734.13925-3-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 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..58cac2da5f66 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), "improper page for zero-copy send"); 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