linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Kairui Song <ryncsn@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Subject: Re: [PATCH 13/13] mm: Convert swap_cluster_readahead and swap_vma_readahead to return a folio
Date: Wed, 20 Dec 2023 00:54:17 +0000	[thread overview]
Message-ID: <ZYI7OcVlM1voKfBl@casper.infradead.org> (raw)
In-Reply-To: <CAMgjq7DzN7Zu4JXUj7rcZZd3rWX=fiRS00HVQshvU+4mThH8kw@mail.gmail.com>

On Sat, Dec 16, 2023 at 09:58:03PM +0800, Kairui Song wrote:
> > @@ -888,14 +887,14 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
> >  {
> >         struct mempolicy *mpol;
> >         pgoff_t ilx;
> > -       struct page *page;
> > +       struct folio *folio;
> >
> >         mpol = get_vma_policy(vmf->vma, vmf->address, 0, &ilx);
> > -       page = swap_use_vma_readahead() ?
> > +       folio = swap_use_vma_readahead() ?
> >                 swap_vma_readahead(entry, gfp_mask, mpol, ilx, vmf) :
> >                 swap_cluster_readahead(entry, gfp_mask, mpol, ilx);
> >         mpol_cond_put(mpol);
> > -       return page;
> > +       return folio_file_page(folio, swp_offset(entry));
> 
> Hi Matthew,
> 
> There is a bug here, folio could be NULL, and cause NULL dereference.

Andrew, syzbot has also picked up on this.  Please add this -fix patch?

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 793b5b9e4f96..8a3a8f1ab20a 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -894,6 +894,9 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
 		swap_vma_readahead(entry, gfp_mask, mpol, ilx, vmf) :
 		swap_cluster_readahead(entry, gfp_mask, mpol, ilx);
 	mpol_cond_put(mpol);
+
+	if (!folio)
+		return NULL;
 	return folio_file_page(folio, swp_offset(entry));
 }
 


      reply	other threads:[~2023-12-20  0:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13 21:58 [PATCH 00/13] More swap folio conversions Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 01/13] mm: Return the folio from __read_swap_cache_async() Matthew Wilcox (Oracle)
2023-12-13 23:14   ` Andrew Morton
2023-12-13 21:58 ` [PATCH 02/13] mm: Pass a folio to __swap_writepage() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 03/13] mm: Pass a folio to swap_writepage_fs() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 04/13] mm: Pass a folio to swap_writepage_bdev_sync() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 05/13] mm: Pass a folio to swap_writepage_bdev_async() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 06/13] mm: Pass a folio to swap_readpage_fs() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 07/13] mm: Pass a folio to swap_readpage_bdev_sync() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 08/13] mm: Pass a folio to swap_readpage_bdev_async() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 09/13] mm: Convert swap_page_sector() to swap_folio_sector() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 10/13] mm: Convert swap_readpage() to swap_read_folio() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 11/13] mm: Remove page_swap_info() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 12/13] mm: Return a folio from read_swap_cache_async() Matthew Wilcox (Oracle)
2023-12-13 21:58 ` [PATCH 13/13] mm: Convert swap_cluster_readahead and swap_vma_readahead to return a folio Matthew Wilcox (Oracle)
2023-12-16 13:58   ` Kairui Song
2023-12-20  0:54     ` Matthew Wilcox [this message]

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=ZYI7OcVlM1voKfBl@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=ryncsn@gmail.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