From: Matthew Wilcox <willy@infradead.org>
To: syzbot <syzbot+f2aaf773187f5cae54f3@syzkaller.appspotmail.com>
Cc: linux-block@vger.kernel.org, akpm@linux-foundation.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [mm?] [fs?] KCSAN: data-race in __filemap_add_folio / invalidate_bdev (8)
Date: Mon, 10 Mar 2025 15:28:41 +0000 [thread overview]
Message-ID: <Z88FKeXyaQCeXapp@casper.infradead.org> (raw)
In-Reply-To: <67ceb38a.050a0220.e1a89.04b1.GAE@google.com>
On Mon, Mar 10, 2025 at 02:40:26AM -0700, syzbot wrote:
> Reported-by: syzbot+f2aaf773187f5cae54f3@syzkaller.appspotmail.com
>
> EXT4-fs (loop0): unmounting filesystem 00000000-0000-0000-0000-000000000000.
> ==================================================================
> BUG: KCSAN: data-race in __filemap_add_folio / invalidate_bdev
>
> read-write to 0xffff888100630570 of 8 bytes by task 3291 on cpu 0:
> __filemap_add_folio+0x430/0x6f0 mm/filemap.c:929
This is a write to mapping->nrpages with the i_pages lock held, as it
should be.
> filemap_add_folio+0x9c/0x1b0 mm/filemap.c:981
> page_cache_ra_unbounded+0x1c1/0x350 mm/readahead.c:276
> do_page_cache_ra mm/readahead.c:328 [inline]
> force_page_cache_ra mm/readahead.c:357 [inline]
> page_cache_sync_ra+0x252/0x680 mm/readahead.c:585
> filemap_get_pages+0x2ca/0x11a0 mm/filemap.c:2580
> filemap_read+0x230/0x8c0 mm/filemap.c:2691
> blkdev_read_iter+0x228/0x2d0 block/fops.c:796
> new_sync_read fs/read_write.c:484 [inline]
> vfs_read+0x5cc/0x6f0 fs/read_write.c:565
> ksys_read+0xe8/0x1b0 fs/read_write.c:708
>
> read to 0xffff888100630570 of 8 bytes by task 3306 on cpu 1:
> invalidate_bdev+0x25/0x70 block/bdev.c:99
This is a read of mapping->nrpages with no lock held. So we could
silence this warning by making this a READ_ONCE or data_race().
The problem is that I'm not sure this is the right answer. Obviously
here we only care about zero-vs-non-zero, but what if we race with
0 being incremented to 1? Should there be some locking higher up
that prevents this? Or is this "yes, root can do this and screw
themselves"?
> ext4_put_super+0x571/0x810 fs/ext4/super.c:1356
> generic_shutdown_super+0xe5/0x220 fs/super.c:642
> kill_block_super+0x2a/0x70 fs/super.c:1710
> ext4_kill_sb+0x44/0x80 fs/ext4/super.c:7368
> deactivate_locked_super+0x7d/0x1c0 fs/super.c:473
> deactivate_super+0x9f/0xb0 fs/super.c:506
> cleanup_mnt+0x268/0x2e0 fs/namespace.c:1413
> __cleanup_mnt+0x19/0x20 fs/namespace.c:1420
> task_work_run+0x13a/0x1a0 kernel/task_work.c:227
next prev parent reply other threads:[~2025-03-10 15:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 9:40 [syzbot] [mm?] [fs?] KCSAN: data-race in __filemap_add_folio / invalidate_bdev (8) syzbot
2025-03-10 15:28 ` Matthew Wilcox [this message]
2025-03-10 16:54 ` [PATCH] block: add lock for safe nrpages access in invalidate_bdev() Yuan Tan
2025-03-10 17:11 ` 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=Z88FKeXyaQCeXapp@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=syzbot+f2aaf773187f5cae54f3@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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;
as well as URLs for NNTP newsgroup(s).