linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: William Kucharski <william.kucharski@oracle.com>
To: Yongqiang Liu <liuyongqiang13@huawei.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	"dhowells@redhat.com" <dhowells@redhat.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"zhangxiaoxu5@huawei.com" <zhangxiaoxu5@huawei.com>,
	"yanaijie@huawei.com" <yanaijie@huawei.com>,
	"vbabka@suse.cz" <vbabka@suse.cz>,
	"wangkefeng.wang@huawei.com" <wangkefeng.wang@huawei.com>
Subject: Re: [PATCH] mm/folio-compact: fix potential NULL pointer in pagecache_get_page
Date: Wed, 27 Jul 2022 11:40:38 +0000	[thread overview]
Message-ID: <B92F20D6-595A-4B7F-95CA-7C681C2AF79D@oracle.com> (raw)
In-Reply-To: <20220727064621.534528-1-liuyongqiang13@huawei.com>

This isn't a NULL pointer dereference; returning &(0->page) is completely legal
as was discussed regarding this exact code back in April:

https://lore.kernel.org/lkml/YmfgqKcMmstgfz+0@casper.infradead.org/

> On Jul 27, 2022, at 12:46 AM, Yongqiang Liu <liuyongqiang13@huawei.com> wrote:
> 
> When __filemap_get_folio() failed and returned NULL, we would
> get a NULL pointer dereference in pagecache_get_page.
> 
> Fixes: 3f0c6a07fee6 ("mm/filemap: Add filemap_get_folio")
> Signed-off-by: Yongqiang Liu <liuyongqiang13@huawei.com>
> Cc: <stable@vger.kernel.org> # 5.16
> ---
> mm/folio-compat.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/folio-compat.c b/mm/folio-compat.c
> index 20bc15b57d93..7b21393480e0 100644
> --- a/mm/folio-compat.c
> +++ b/mm/folio-compat.c
> @@ -124,7 +124,9 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
> struct folio *folio;
> 
> folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
> - if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio))
> + if (!folio)
> + return NULL;
> + if ((fgp_flags & FGP_HEAD) || xa_is_value(folio))
> return &folio->page;
> return folio_file_page(folio, index);
> }
> -- 
> 2.25.1
> 
> 



  reply	other threads:[~2022-07-27 11:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  6:46 Yongqiang Liu
2022-07-27 11:40 ` William Kucharski [this message]
2022-07-28  1:36   ` Yongqiang Liu
2022-07-27 13:29 ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B92F20D6-595A-4B7F-95CA-7C681C2AF79D@oracle.com \
    --to=william.kucharski@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuyongqiang13@huawei.com \
    --cc=vbabka@suse.cz \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    --cc=yanaijie@huawei.com \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox