Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3063058pxa; Tue, 18 Aug 2020 05:49:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1VYYXNloe8l+C9GOBdaVaA/dSADrdkoC9PSUc8X9FX4itlk1lOByY3S5uJyymBFxGC2nS X-Received: by 2002:a05:6402:785:: with SMTP id d5mr20028449edy.370.1597754975039; Tue, 18 Aug 2020 05:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597754975; cv=none; d=google.com; s=arc-20160816; b=vNGGJySEgJx7VtP+4/4MIRg2p3OA9S3PDqPLlmXsS3INIo4aU1VgARVgurc9YJCoZ9 21l8vKLPysvX1pIfbS21pXiv1v3sevUs343yx6LQbAogtyJT+NSpIFN7dxoOtg6+4atm yfYKD//Uuatiqi3MjxhrQq/2vfsUOduYxjjnSCmZaPFBb4732LHaL7ZzJJCjiTN9NkIL DoOw9jG9cfSMq+XOgE04TNc6WKPACqmoDMOHxlXaP+WY30t3xEmCntvZJ+Z+O+sLifBp yUs9KsTKivjdZCuvDtMjIohwuWm5XfaYYHjjIOEA8kn2JWDJWdZZy9d8q7PQEqxjo4V9 Kv9Q== 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=DiXnTC9DpdLmYwFlIjWmqSh4Re0DVvbJoOlFesADieM=; b=y+88O4pViI//ar5DWMVu+L3R71xZrn1k1EQzHWLqb24sER6CgCDoim/uCNHfRSs6AP yyptgCHMvsDWojfqMQRFiKYgy0OyJre/QJjxHtC2/PV5MeTayyJ6NbPf3apjCQDK3WQH a94VIrkMqwFJSWaPTQtXos8zmaMXW8W5X1mvwCm+PVV3kJwOfN69RZeq1pXSCH2QzH4Y Lh3kG0TCdlzj6MB9h+AaNnEvczSfZKo73ajjE/wVi9T8JyIWYOsZmXRrq4WYiDdhAfWg 4MxxcNeBMRr+Jvv1cAyg4u0mLq1+GRSeB3ww9Ep/Ld7IAeQdn3LFH3PlUFgy5zhQg2wi j/ig== 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 y22si14598798ejc.453.2020.08.18.05.49.11; Tue, 18 Aug 2020 05:49:35 -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 S1726819AbgHRMsK (ORCPT + 99 others); Tue, 18 Aug 2020 08:48:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:48392 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbgHRMsE (ORCPT ); Tue, 18 Aug 2020 08:48:04 -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 C8668ADF2; Tue, 18 Aug 2020 12:48:26 +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 v6 1/6] net: introduce helper sendpage_ok() in include/linux/net.h Date: Tue, 18 Aug 2020 20:47:31 +0800 Message-Id: <20200818124736.5790-2-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200818124736.5790-1-colyli@suse.de> References: <20200818124736.5790-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..a807fad31958 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