Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1310276pxa; Sat, 15 Aug 2020 15:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8xpSiV3Clq/WJxminQOsZU56YRVF45NhK/l81oZrw/zzKLuHFWNzxzqoKUQpWc/EEwtIY X-Received: by 2002:a17:907:724b:: with SMTP id ds11mr8424804ejc.481.1597530283893; Sat, 15 Aug 2020 15:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597530283; cv=none; d=google.com; s=arc-20160816; b=brc+KlPJfukVmi6hDG2pFkhQUZPK6fSNTv17KIaQ9WFR1yfsxAVnF02rdxV+t3S4Yu TM0ZeCXdL1q8czJksKKrg5N5Wpvg02+8HhJg1w0y899aY7gMsY0sF8QUIQNqmh0NPSR7 uK8q39c4YGhTiaKXV9DUaYN3gr1j28pyyC/SGyxFAeH6WfQcYkvDdgJ12PYT43zBxper 486C4og9G3dKTwltSvLYPi/H5aLC+qqwhgRuID4R1BmG/SaoA09gA4PetrssEN8rYvls fNdADaVi5YTU4SzBb6OYokUTXUToiCMCIgJTYazWwoWukcYX2Qf2VJiRXhye2eqJorP2 PmsQ== 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 :message-id:date:subject:cc:to:from; bh=NbabXFzOFFYeHW6fNOU84jrKuozteOPhoNS3sy5KkhE=; b=P0lvxBTVHXf0ixKpqA8F0Z9yQlh8nGUlA6F641Y3fQhI7LEYKXEL/CloAodG5MUM4K rjuVtJlj4fT6g62dX+vHxieL8T+UMbTQZlJw+UwCn7hJYcaG5Gk6msataUe73jKl+kgU fYbFLMlss/ofvw6/Hr6d1Sc11sVccKFKFpQbtqVGZSEFSBFyFJogixVGl3hA8KiJ0h1W F94HQm/xoBSwkfdrqzj/BBJu4poO6Tz16Cb9qV7qPoX1zq1OQ3Ra4xN6UVhPkxjJHCgN znlWhcoRjMCCyjPP6Jm7a9conTfXfamIV2wo/Wc3NFWk//Zy06oxAC0O4XIq7knNh9lH 59eQ== 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 a18si7014348ejr.184.2020.08.15.15.24.21; Sat, 15 Aug 2020 15:24:43 -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 S1728938AbgHOWXs (ORCPT + 99 others); Sat, 15 Aug 2020 18:23:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:37792 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726541AbgHOWXo (ORCPT ); Sat, 15 Aug 2020 18:23: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 77BA5AE63; Sat, 15 Aug 2020 07:48:41 +0000 (UTC) From: Coly Li To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: netdev@vger.kernel.org, stable@vger.kernel.org, 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 Subject: [PATCH 1/3] net: introduce helper sendpage_ok() in include/linux/net.h Date: Sat, 15 Aug 2020 15:48:02 +0800 Message-Id: <20200815074804.46995-1-colyli@suse.de> X-Mailer: git-send-email 2.26.2 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/net.h b/include/linux/net.h index d48ff1180879..97e8f1a8a427 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -286,6 +286,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