Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3082101pxa; Tue, 18 Aug 2020 06:16:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAsg991401TULjFXLt1X93uDxLPpy9cieWc4MVysuKvT5UkcI4p7LUWL97Fuzl6iPQ8mAP X-Received: by 2002:a17:906:ad99:: with SMTP id la25mr19189936ejb.63.1597756575570; Tue, 18 Aug 2020 06:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597756575; cv=none; d=google.com; s=arc-20160816; b=m0wqu93/lamW+F38/DftcZW3InjB5JX9cY2SFMrKOsQmqIo2qRjY36l0hqhSe+ng84 AoXny3V23Kr19Xj2677rUjW0TyUQ41QvQ1gfBKSsu0s/G2GT0xlqHc6EYaAqccNKL9yR WyYkCtNuoslOE5kklSfJIbOV/ODi+nPzC5gCAaILLwSb4APoD19HRwKSCMc1GTOlDd5K xOAhIyg7TfBxK7VFfxoZ1k7evUaCeifGOpopBhP8Iuqb2/PHPjIaQXP5h/UAJ3E+BxGc FMNy07z0PHI9nGXPkW8jdJe95dkYViJgqra7Cwi/al8Dx0HYpUmVrXLva/e3f/cvABdU OkXg== 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=0nsVQx51QNCIBn5XowjtD9itDxo+XOytIptUHsXXc+M=; b=tVHTfWgdScMmIqMadpRYX9V1V7yt1eb7B2ozzeY6kxmsuMYczP03DA9mfYApMvXb7z NfwDvVWUWqp9KUu9E58mttfCO6iq/d6MvJXrMADL77605WeCL6EepGZgJ4jeGdVfGQBg QMGHgREhcmcwiltEvZQBeJ5NTQZMa7kUX8IOaz8r/v/7kX/fszwCToNFpVmkVGo3Dadu E40nHaCbZ7BlRUstxS/TxLZ7NqviC0g74vylou9A7fvFC8Qlvn9GjwjJqGqnjk3KpKKl odkoV7NhZlTkwT3Ksgyl6z3YUhKota0IzaHu0/zcc1VDpA/7x0pgricZ7E6KpQ5Abooo G+Sw== 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 m23si13305685edq.564.2020.08.18.06.15.50; Tue, 18 Aug 2020 06:16:15 -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 S1726713AbgHRNNR (ORCPT + 99 others); Tue, 18 Aug 2020 09:13:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:33284 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbgHRNNN (ORCPT ); Tue, 18 Aug 2020 09:13:13 -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 DC6E4B15D; Tue, 18 Aug 2020 13:13:36 +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 , Chaitanya Kulkarni , Christoph Hellwig , Hannes Reinecke , Jan Kara , Jens Axboe , Mikhail Skorzhinskii , Philipp Reisner , Sagi Grimberg , Vlastimil Babka , stable@vger.kernel.org Subject: [PATCH v7 1/6] net: introduce helper sendpage_ok() in include/linux/net.h Date: Tue, 18 Aug 2020 21:12:22 +0800 Message-Id: <20200818131227.37020-2-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200818131227.37020-1-colyli@suse.de> References: <20200818131227.37020-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 The original problem was from nvme-over-tcp code, who mistakenly uses kernel_sendpage() to send pages allocated by __get_free_pages() without __GFP_COMP flag. Such pages don't have refcount (page_count is 0) on tail pages, sending them by kernel_sendpage() may trigger a kernel panic from a corrupted kernel heap, because these pages are incorrectly freed in network stack as page_count 0 pages. This patch introduces a helper sendpage_ok(), it returns true if the checking page, - is not slab page: PageSlab(page) is false. - has page refcount: page_count(page) is not zero All drivers who want to send page to remote end by kernel_sendpage() may use this helper to check whether the page is OK. If the helper does not return true, the driver should try other non sendpage method (e.g. sock_no_sendpage()) to handle the page. Signed-off-by: Coly Li Cc: Chaitanya Kulkarni Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Jan Kara Cc: Jens Axboe Cc: Mikhail Skorzhinskii Cc: Philipp Reisner Cc: Sagi Grimberg Cc: Vlastimil Babka Cc: stable@vger.kernel.org --- include/linux/net.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/net.h b/include/linux/net.h index d48ff1180879..05db8690f67e 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -286,6 +287,21 @@ do { \ #define net_get_random_once_wait(buf, nbytes) \ get_random_once_wait((buf), (nbytes)) +/* + * E.g. XFS meta- & log-data is in slab pages, or bcache meta + * data pages, or other high order pages allocated by + * __get_free_pages() without __GFP_COMP, which have a page_count + * of 0 and/or have PageSlab() set. We cannot use send_page for + * those, as that does get_page(); put_page(); and would cause + * either a VM_BUG directly, or __page_cache_release a page that + * would actually still be referenced by someone, leading to some + * obscure delayed Oops somewhere else. + */ +static inline bool sendpage_ok(struct page *page) +{ + return !PageSlab(page) && page_count(page) >= 1; +} + int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t len); int kernel_sendmsg_locked(struct sock *sk, struct msghdr *msg, -- 2.26.2