From: Qu Wenruo <wqu@suse.com>
To: listout@listout.xyz, David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org
Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>,
Chris Mason <mason@kernel.org>,
clm@fb.com, david@kernel.org, jgg@ziepe.ca, jhubbard@nvidia.com,
peterx@redhat.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com,
Brahmajit Das <bdas@suse.de>
Subject: Re: [PATCH v4 1/2] btrfs: don't dereference a missing folio private on writeback error
Date: Fri, 4 Dec 2026 18:24:11 +1030 [thread overview]
Message-ID: <772f3bd2-24de-443d-b0c0-d79d1fcc2b90@suse.com> (raw)
In-Reply-To: <20261204063235.1033893-2-listout@listout.xyz>
在 2026/12/4 17:02, listout@listout.xyz 写道:
> From: Brahmajit Das <bdas@suse.de>
>
> extent_writepage() rejects a dirty folio without folio::private with
> -EUCLEAN, then jumps to the common exit path, which calls
> btrfs_folio_end_lock_bitmap(). For the bs < folio size case, that
> function dereferences the folio private:
>
> btrfs_folio_end_lock_bitmap()
> bfs = folio_get_private(folio); /* NULL */
> ...
> if (atomic_read(&bfs->nr_locked) == 0) /* NULL dereference */
>
> so the error path meant to catch such a folio crashes instead.
>
> No subpage lock can be held on a folio without private, so just set the
> mapping error and unlock the folio directly.
>
> Note: this was only build tested.
>
> This patch was written with the help of an AI coding assistant (Claude).
Again, the last 2 paragraphs will be drop at merge time.
>
> Fixes: 7ca3e84980ef ("btrfs: reject out-of-band dirty folios during writeback")
> Signed-off-by: Brahmajit Das <bdas@suse.de>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/extent_io.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index b2739838c646..9dded5c670de 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -2070,8 +2070,15 @@ static int extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ctrl
> "root %lld ino %llu folio %llu is marked dirty without notifying the fs",
> btrfs_root_id(inode->root),
> btrfs_ino(inode), folio_pos(folio));
> - ret = -EUCLEAN;
> - goto done;
> + /*
> + * Don't go through btrfs_folio_end_lock_bitmap(), which
> + * dereferences the missing folio private for the
> + * bs < folio size case. No subpage lock can be held on a
> + * folio without private, so a plain unlock is enough.
> + */
> + mapping_set_error(folio->mapping, -EUCLEAN);
> + folio_unlock(folio);
> + return -EUCLEAN;
> }
>
> ret = set_folio_extent_mapped(folio);
next prev parent reply other threads:[~2026-12-04 7:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <6ab2d179.e8212013.2d060.0001.GAE@google.com>
2026-12-03 13:30 ` [PATCH v3 0/3] btrfs: fix dirtying of folios that lost their private Brahmajit Das
2026-12-03 13:30 ` [PATCH v3 1/3] btrfs: don't dereference a missing folio private on writeback error Brahmajit Das
2026-12-03 13:30 ` [PATCH v3 2/3] btrfs: sync the uptodate bitmap when attaching a data folio state Brahmajit Das
2026-12-03 20:36 ` Qu Wenruo
2026-12-04 13:31 ` sashiko-bot
2026-12-03 13:30 ` [PATCH v3 3/3] btrfs: re-attach folio private when a released folio gets dirtied Brahmajit Das
2026-12-03 20:36 ` Qu Wenruo
2026-12-04 6:36 ` Brahmajit Das
2026-12-04 13:31 ` sashiko-bot
2026-12-04 6:32 ` [PATCH v4 0/2] btrfs: fix dirtying of folios that lost their private listout
2026-12-04 6:32 ` [PATCH v4 1/2] btrfs: don't dereference a missing folio private on writeback error listout
2026-12-04 7:54 ` Qu Wenruo [this message]
2026-12-04 6:32 ` [PATCH v4 2/2] btrfs: re-attach folio private when a released folio gets dirtied listout
2026-12-04 7:52 ` Qu Wenruo
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=772f3bd2-24de-443d-b0c0-d79d1fcc2b90@suse.com \
--to=wqu@suse.com \
--cc=bdas@suse.de \
--cc=clm@fb.com \
--cc=david@kernel.org \
--cc=dsterba@suse.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=listout@listout.xyz \
--cc=mason@kernel.org \
--cc=peterx@redhat.com \
--cc=quwenruo.btrfs@gmx.com \
--cc=syzbot+d6f123d4060990f0f3ff@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