Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1186896pxk; Fri, 25 Sep 2020 08:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJDsrxO90hvpcHjvbZjDKEiSTKhdIwnfTLoRmrcwx5rE2XH3TYuRe4dg4pWOPNeVcYMqLO X-Received: by 2002:a50:875c:: with SMTP id 28mr1884472edv.20.1601047162827; Fri, 25 Sep 2020 08:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601047162; cv=none; d=google.com; s=arc-20160816; b=UGzPj/eFHanWf7mODXXgg7WE/rpCo05LwhoV4M5ALt59RZmYguXR5kSt0JLdM0CQA0 L/cxe/A7IFiNQx9AX9D+kCbniKUQhJOFLlBH76sDGzo8NsD6lVvj5HY8QWOL6n6KJ2SL TvS3gk+QqQnu+VjZFz3fy5PlM4fiTObICCExOeU2gg5faI5vr7usDR8QI2MuSnRLCQIA mAL+q+xu8M0GK7FwM61+KFqDRLAwU666HB8gbWlgFnBlIPOpOK3LARdGAg8d9wfyJ7G0 BtPK2l4w2KrUyUHoZoLrHVd9c1WiYlu4oNHTnacWfL9eAnBwX78mkbrh3BbbB4Zwx788 nLMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BQ6mez3nHAhL3xrfIz/0X0zLjLwRuhvv7k81BwyAgfQ=; b=rehP4h8yjhpK7WtXu+jbEwQ+RqBwkczkMCdxqLKefoB8phHc9BeUUJgQkJvs5KTOb0 R+IQy3zTl8TccZ3FFp0pFQzgo7SjdSSdk3VtpcVuDOx9hQMaoZ+XuynDESgpxLQ3V7iN lc2We8w+BGJA3F9gJLuqdYXyXKVDY+uuudxhz1Ijf5CIxBhGBjqFIbx91xOMho5EUvGf LMGY8/+gOc8uxBB+Js+LFh0cCEoT/81c16W55NhokjHG1krCqgahD1E8SkxrDk2YCGSR 1mDey8ZuLSIc/5fLwetOP+wIkpxpdbYcplKwVf4eeLR1UmhYs9DBZKdjQYPrqoullAT3 xvfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0I0jvTv7; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g2si2017333ejp.429.2020.09.25.08.18.58; Fri, 25 Sep 2020 08:19:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=0I0jvTv7; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729133AbgIYPR7 (ORCPT + 99 others); Fri, 25 Sep 2020 11:17:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:52162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728818AbgIYPR7 (ORCPT ); Fri, 25 Sep 2020 11:17:59 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B44E920878; Fri, 25 Sep 2020 15:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601047078; bh=Memmat2QMSKm4nwC6E/N+LYsT2VSLAWg4jqrX9rOxRc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0I0jvTv72ihg9+bzMure3BX1lc+87CO5bL9392leVtXnedqMSe5ygE5G4jcX2w1qW xoHSyqw+O8y4wGORU/iFtjKf17BUhMzTBzKdn1CSNW/QQG4RWwA0fbFWc2yeKlC8z5 AE3L4akyOt44u/YxCsUo0F4LAURd4D62LpCDsAXE= Date: Fri, 25 Sep 2020 17:18:12 +0200 From: Greg KH To: Coly Li Cc: 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, linux-kernel@vger.kernel.org, Chaitanya Kulkarni , Christoph Hellwig , Hannes Reinecke , Jan Kara , Jens Axboe , Mikhail Skorzhinskii , Philipp Reisner , Sagi Grimberg , Vlastimil Babka , stable@vger.kernel.org Subject: Re: [PATCH v8 1/7] net: introduce helper sendpage_ok() in include/linux/net.h Message-ID: <20200925151812.GA3182427@kroah.com> References: <20200925150119.112016-1-colyli@suse.de> <20200925150119.112016-2-colyli@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200925150119.112016-2-colyli@suse.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 11:01:13PM +0800, Coly Li wrote: > 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; Do you have one extra ' ' after "return" there? And this feels like a mm thing, why put it in net.h and not mm.h? thanks, greg k-h