Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp243705pxk; Thu, 1 Oct 2020 00:56:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlMEKDZ/afxbLTjGnSQHgxKI2xTc4qgZg0kLSh6q8A4OFdTF75lTq5+k55VKMB8pahfdBw X-Received: by 2002:aa7:c259:: with SMTP id y25mr4801878edo.249.1601538985538; Thu, 01 Oct 2020 00:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601538985; cv=none; d=google.com; s=arc-20160816; b=tI6fiSFIYEn4iuWbOs0uEwgCpcKiCwocq1CIcwhnC45EUYZ4K2ICVhWhR8IcfLMHPB FRy/f7VdI6XIts9yjajtiN10XIMLthw7IV0n1SULfyKu4lrqkGLcwIKqugzZwjWEejY3 iFRSP7VYvE7v20Z/3sFikKGDd6DSIdJzQz5FpJYNBZoP61VFxeU+NoOViHK2GF2vwI/R oTBKe2DpgJHwYIJ+15GcMdBZoypmPO4HRIZfdyC9qhS8zDv/m8E1MKG7a34rFq0k1AYZ vu49jwTI7O9SDansp+Yx5sLwdKedlT+YhCLump+S1YRNaO7R69HyC9Fo4u1RuIOraO9s rxNA== 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=wgRcgTUQelRySqUqHvE4GI6iq0bbYk3N8k9dERWUjM7a4mw2bH16Ptml6Ty/ZM/RPe VCBvFnZxSi3SLLSKTbWX3zEMM9ZXjI+G3BjUw0sAYUVog69q/M1joZ2DC8EOFMiKeTKw juh+PD2MALnWUCh/hP1vNEuMUA+Q0XWLfJXGOzjuMPeNzMU6AimuDAT6Ge7XAx852viZ 5fgs870LnYixUaxS2lUDda5fT+SGH60DfORXcD0dQmX1/04d1EhqAwKx692cLTKaswF9 qiiszp59cxlgI+BTf4PPM3/2vcJ6WWjXsQ5+aHhej9NrZ0W0Jqxf58Wr4w/wI6KnHGwE 6llQ== 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 k26si3165706eds.483.2020.10.01.00.56.03; Thu, 01 Oct 2020 00:56:25 -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 S1731638AbgJAHyx (ORCPT + 99 others); Thu, 1 Oct 2020 03:54:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:44290 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731566AbgJAHys (ORCPT ); Thu, 1 Oct 2020 03:54:48 -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 73426AC97; Thu, 1 Oct 2020 07:54:46 +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 v9 2/7] net: add WARN_ONCE in kernel_sendpage() for improper zero-copy send Date: Thu, 1 Oct 2020 15:54:03 +0800 Message-Id: <20201001075408.25508-3-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001075408.25508-1-colyli@suse.de> References: <20201001075408.25508-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