Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1127211pxk; Fri, 2 Oct 2020 01:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNIT/mSDu1JCLxaZ0E/G1+jOd1kXnsx86+jea4TsmlREXt3wpoi38Vm9LFzr1iXtAxMNiq X-Received: by 2002:a17:906:850:: with SMTP id f16mr1084950ejd.447.1601627371953; Fri, 02 Oct 2020 01:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601627371; cv=none; d=google.com; s=arc-20160816; b=SlG1/0ViGq3UhtPpiCSfkgb5sH/D54bf/dKSSjfErzYK9knIKVIh6LeZCVvh9GxbRc ZeKUg9yEKSQ65NL93xDmzFJqz71dxRepiSUhH8rBcRTPyt+SA1zJRkkLGaUPNkynuJUF v8e4QYdGOfsTa+nosGgHJkdNux0tPRrKUaSuQScdqoWlwZneBmTOYv7NYo0get2P0kRE PpgDs/SNC4/YHPKT48e3WGCWZWPZ0YwGijsHQa9LPW4vDacqtMJrEPrAI10T021JNWQa 4nRuEWBm8mQ4b8LiuWUjzMhTnGBIluNcwpWDHOVwTFKjDRoSAbF6FOyQJHJOTT0JQKbm ZWbQ== 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=PLQwKwevBasGwaIUn3WpJoJm3qLc/YVZREIrKpLSBlQqZlsOZ4ROlpqcTX1/mY1VD6 91nw0A4x1P6G689aT6JOoKTzQvWQHv2PNuC8kHmSmaDmg9+meJ4uIuIpxd7oKmkw8dBV 9QBebAbvkWkj32kOKus25Li6STiOk4fNdNBd3ghKT5PpXgilc7He9hKyWlYjkzQFk8aN EvpfXfRre6+LuHg9qGBzM5IYLaNV/pN9AV43Mg5wMhwYMh+/27HCmQNH28SGvvHij8XU gEruUN6NDX3/Jj008sJ5HvYoeq/+hXlW/jyFpSPBn5D7VZbUrJztGw07o10Mrzmyr3Z2 v6gg== 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 p61si516445edd.188.2020.10.02.01.29.09; Fri, 02 Oct 2020 01:29: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 S2387629AbgJBI2D (ORCPT + 99 others); Fri, 2 Oct 2020 04:28:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:49394 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgJBI2C (ORCPT ); Fri, 2 Oct 2020 04:28:02 -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 AC64DAF1A; Fri, 2 Oct 2020 08:27:59 +0000 (UTC) From: Coly Li To: davem@davemloft.net, 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 v10 1/7] net: introduce helper sendpage_ok() in include/linux/net.h Date: Fri, 2 Oct 2020 16:27:28 +0800 Message-Id: <20201002082734.13925-2-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201002082734.13925-1-colyli@suse.de> References: <20201002082734.13925-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