Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1174094pxk; Fri, 25 Sep 2020 08:03:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNXCoLUg8iweBv+SDhx+xtcFwx51TiXlk1CRxTjhd7V4D7BSDd2Hyrc6BmU0zEtnmvQTOL X-Received: by 2002:a17:907:2506:: with SMTP id y6mr2978946ejl.265.1601046211995; Fri, 25 Sep 2020 08:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601046211; cv=none; d=google.com; s=arc-20160816; b=SEn/YOSyXpULh6J/jVBpsruvcxVf1kcfXLjGgueg3BVhasdpQwwNcU2hxbzxGRqUfL ypXrX8CTgptMuwm2cMbJtqjPZY7NFF/gMRyBsUrz0jTqsEehsua6gwuFPFWTp5z8kfHT 3QFAGyRsapoZSstwSbbAooj+f+YYPipHLFgmhuJ8sSxCrg/ILWfiEg7KYFgZsXd5cEL7 dLOwz3/Vq47rxKAFRk+IR9FASD5Hu5vGO7XjYQUhCJc683hAryTdckKS0FilVvE0+2tQ ibrFzgtjkgsgAqynuPpBuDYGcHOWh6/9lelry25E2inzIays4EgObHQ31gTHL6qeqUxX p0tQ== 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=0nsVQx51QNCIBn5XowjtD9itDxo+XOytIptUHsXXc+M=; b=vCEbwEz8ECCcg+bnnT+Z/QIv3gK3mRr5KzG3wvngRF/lFEchYdhX0M2334rFOSR7Nu KJL/BGPytaybpSOVbErWk9lAJJr7SUcqCMHclR+ahjy24Em31rMZXmTD7gZ4O71lnZul A4a0pLMaN7FaTMwdjNrPGKWkhMHdaWo+PmaXX/ZtnJcT3NQrvR/P801KSqo4IHNyYEB6 5khzZYK74iQ6pSOu53/ZNymRkBHz7mk45rj8JnZJvgDmbatiynjcfpds3ypt3CYHNtYV qkFUqZp/nwc+syDEwqaEQgFf1fX7N1LxQ/fMLJQCQU/satdDT5I0hcA2ZCCqnO5j7c5X i0ww== 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 n6si1949685ejx.165.2020.09.25.08.03.08; Fri, 25 Sep 2020 08:03:31 -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 S1729356AbgIYPBs (ORCPT + 99 others); Fri, 25 Sep 2020 11:01:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:34016 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728693AbgIYPBs (ORCPT ); Fri, 25 Sep 2020 11:01: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 A0E5AACA3; Fri, 25 Sep 2020 15:01:45 +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 v8 1/7] net: introduce helper sendpage_ok() in include/linux/net.h Date: Fri, 25 Sep 2020 23:01:13 +0800 Message-Id: <20200925150119.112016-2-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 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