Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp244491pxk; Thu, 1 Oct 2020 00:58:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVfJrfCFEcMlrjG9M7ne/FSFq5dTsffvpCFO1APV7meEdzvSeDfY7QCG+LxNlpKhQCwR8g X-Received: by 2002:a17:906:f119:: with SMTP id gv25mr5455709ejb.373.1601539100469; Thu, 01 Oct 2020 00:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601539100; cv=none; d=google.com; s=arc-20160816; b=0gXGfqrBmr/poJNmWDzbZ4N6Bw4wI5kMkwzevjqWJVYhUufbFUVRfk0PUOWnp30mLo vZ33szBBCWYN3CdiOp9zIHFzV3rte+cJFbEhy9gDiRg3emg/mBSnggknc5YBRJ0VKQ6c Zk+LuBxziCBXr3Gfq1q0VjD7V8cw36LRTTvK+5xiXTvA06kqeKHd2+mxuMHP7BJAujr/ 0WQO/GHOdXD5me16KBKClJju/nG52b9lz8hOvvxjzF85C+1XjyJBk2NePyz1lSITcNG+ 1Mx2XjDglrmJTcVTKLq8tOH3o5aUjSXYCHxpytWlTIqbExTgg2p/HsZ54rqZK7Mt52pR AxsA== 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=kAyH25uGybhJBy0idJMvxsSK0HDGJixB12FCl9IYRlE=; b=nxUw1/6CjU4EPcZzMSYRNezEja8uAjHHkmo0D00FUpnldfiuDF4sW630GxFklhMDBZ JLyMhAgmuc9uyii5u92yUM5w1xg+ekj6E2P8uQTH1Ywn8RNYG5C/VwhwQGNOY6fFGv/M osZA5CDn3kYLlzEC1kboXVQ2qLwpuw213XD0f7kB7UYMm8GhMOqZVPSjRmgRpeQGQJ2t Id6u+/5jJA2j+yKb7F3tYkzGswhn+6hPBD3G7kggSEdoHZkFJNlhFMMvHEWekjIYmzNl 76krsN/T9w4F7LauYvu04I8Qg+c8LhNu7y8r5VjZrSrrfzsW6Yd/dcYi9lnwOwNQhBmR Wldg== 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 r21si2925610ejs.399.2020.10.01.00.57.57; Thu, 01 Oct 2020 00:58:20 -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 S1731602AbgJAHys (ORCPT + 99 others); Thu, 1 Oct 2020 03:54:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:44188 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730534AbgJAHyo (ORCPT ); Thu, 1 Oct 2020 03:54:44 -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 A7F5EAC83; Thu, 1 Oct 2020 07:54:41 +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 v9 1/7] net: introduce helper sendpage_ok() in include/linux/net.h Date: Thu, 1 Oct 2020 15:54:02 +0800 Message-Id: <20201001075408.25508-2-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 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..ae713c851342 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