diff options
author | Ryusuke Konishi <konishi.ryusuke@gmail.com> | 2023-06-12 11:14:56 +0900 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-06-28 10:14:19 +0200 |
commit | 1ae24bbbb33f13ff84369ce4634b915fbd059d23 (patch) | |
tree | dd360071fb2b95897d55460e80326ea4d5ffaf43 | |
parent | 467a830573419afe42b341a90f03cf8b93f61daf (diff) | |
download | linux-stable-1ae24bbbb33f13ff84369ce4634b915fbd059d23.tar.gz linux-stable-1ae24bbbb33f13ff84369ce4634b915fbd059d23.tar.bz2 linux-stable-1ae24bbbb33f13ff84369ce4634b915fbd059d23.zip |
nilfs2: prevent general protection fault in nilfs_clear_dirty_page()
commit 782e53d0c14420858dbf0f8f797973c150d3b6d7 upstream.
In a syzbot stress test that deliberately causes file system errors on
nilfs2 with a corrupted disk image, it has been reported that
nilfs_clear_dirty_page() called from nilfs_clear_dirty_pages() can cause a
general protection fault.
In nilfs_clear_dirty_pages(), when looking up dirty pages from the page
cache and calling nilfs_clear_dirty_page() for each dirty page/folio
retrieved, the back reference from the argument page to "mapping" may have
been changed to NULL (and possibly others). It is necessary to check this
after locking the page/folio.
So, fix this issue by not calling nilfs_clear_dirty_page() on a page/folio
after locking it in nilfs_clear_dirty_pages() if the back reference
"mapping" from the page/folio is different from the "mapping" that held
the page/folio just before.
Link: https://lkml.kernel.org/r/20230612021456.3682-1-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+53369d11851d8f26735c@syzkaller.appspotmail.com
Closes: https://lkml.kernel.org/r/000000000000da4f6b05eb9bf593@google.com
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/nilfs2/page.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 884c2452e60d..d67b711f9c0d 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -382,7 +382,15 @@ void nilfs_clear_dirty_pages(struct address_space *mapping, bool silent) struct page *page = pvec.pages[i]; lock_page(page); - nilfs_clear_dirty_page(page, silent); + + /* + * This page may have been removed from the address + * space by truncation or invalidation when the lock + * was acquired. Skip processing in that case. + */ + if (likely(page->mapping == mapping)) + nilfs_clear_dirty_page(page, silent); + unlock_page(page); } pagevec_release(&pvec); |