Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Florian Schmaus" <flo@geekplace.eu>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH 2/2] ext4: test that ext4_readpage_inline() keeps uptodate buffers
Date: Thu, 03 Dec 2026 10:17:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-247559@kernel.org> (raw)
In-Reply-To: <20261203-ext4-inline-readpage-v1-2-1dd69e69f53b@geekplace.eu>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ext4: buffer_head use-after-free after folio unlock in inline
  KUnit test
--

commit a38c8e059b87a8ba55ddb0f7f8b0994abdfe6412
Author: Florian Schmaus <flo@geekplace.eu>

ext4: test that ext4_readpage_inline() keeps uptodate buffers

This commit adds a KUnit test case to test_readpage_inline_link_and_iomap()
checking that ext4_readpage_inline() preserves uptodate buffers, zeroes the
remaining buffers, and marks all buffers uptodate on a partially uptodate
folio past index 0.

> diff --git a/fs/ext4/inline-test.c b/fs/ext4/inline-test.c
> index b3d7c51ad216b..1558454d9d8bf 100644
> --- a/fs/ext4/inline-test.c
> +++ b/fs/ext4/inline-test.c

[ ... ]

> @@ -960,6 +961,41 @@ static void test_readpage_inline_link_and_iomap(struct kunit *test)
>  	kunmap_local(kaddr);
>  	folio_put(folio);
>  
> +	/*
> +	 * 3b. ext4_readpage_inline on folio->index > 0 with only some buffers
> +	 * uptodate: keeps their data, zeroes the other buffers and marks all
> +	 * of them uptodate. Buffered writes after a delalloc conversion
> +	 * leave such a folio behind until writeback destroys the inline data.
> +	 */
> +	folio = __filemap_get_folio(&inode->i_data, 2,
> +				    FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
> +				    GFP_KERNEL);
> +	KUNIT_ASSERT_FALSE(test, IS_ERR(folio));
> +	kaddr = kmap_local_folio(folio, 0);
> +	memset(kaddr, 0xff, PAGE_SIZE);
> +	memset(kaddr + TEST_BLOCK_SIZE, 0xab, TEST_BLOCK_SIZE);
> +	kunmap_local(kaddr);
> +	head = create_empty_buffers(folio, TEST_BLOCK_SIZE, 0);
> +	set_buffer_uptodate(head->b_this_page);
> +
> +	ret = ext4_readpage_inline(inode, folio);
> +	KUNIT_EXPECT_EQ(test, ret, 0);
> +	KUNIT_EXPECT_TRUE(test, folio_test_uptodate(folio));
> +	KUNIT_EXPECT_FALSE(test, folio_test_locked(folio));
> +	kaddr = kmap_local_folio(folio, 0);
> +	KUNIT_EXPECT_NULL(test, memchr_inv(kaddr, 0, TEST_BLOCK_SIZE));
> +	KUNIT_EXPECT_NULL(test, memchr_inv(kaddr + TEST_BLOCK_SIZE, 0xab,
> +					   TEST_BLOCK_SIZE));
> +	KUNIT_EXPECT_NULL(test, memchr_inv(kaddr + 2 * TEST_BLOCK_SIZE, 0,
> +					   PAGE_SIZE - 2 * TEST_BLOCK_SIZE));
> +	kunmap_local(kaddr);
> +	bh = head;
> +	do {
> +		KUNIT_EXPECT_TRUE(test, buffer_uptodate(bh));
> +		bh = bh->b_this_page;
> +	} while (bh != head);

[Severity: Low]
Can walking head after ext4_readpage_inline() trigger a buffer_head
use-after-free?

ext4_readpage_inline() unlocks folio before returning.  Because folio is
clean, unmapped, and on the LRU, and none of its buffers are dirty or
pinned, memory reclaim can strip the buffer ring before the loop runs:

CPU0                                    CPU1 (reclaim)
test_readpage_inline_link_and_iomap()
  head = create_empty_buffers(folio, ...)
  ext4_readpage_inline(inode, folio)
    folio_unlock(folio)
                                        shrink_folio_list()
                                          folio_trylock(folio)
                                          filemap_release_folio(...)
                                            test_release_folio(...)
                                              try_to_free_buffers(folio)
                                                free_buffer_head(...)
  bh = head
  buffer_uptodate(bh)  <-- use-after-free

Holding a folio reference until folio_put() keeps the folio alive, but
try_to_free_buffers() requires folio_lock(folio), mapping->i_private_lock,
or a busy buffer to prevent freeing the attached buffer_heads.  Pinning
head with get_bh(head) before ext4_readpage_inline() and releasing it with
put_bh(head) after the loop would keep the buffer ring alive while the test
checks it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ext4-inline-readpage-v1-0-1dd69e69f53b@geekplace.eu?part=2

  reply	other threads:[~2026-12-03 10:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:06 [PATCH 0/2] ext4: fix data loss when reading during inline data conversion Florian Schmaus
2026-12-03 10:06 ` [PATCH 1/2] ext4: don't zero uptodate buffers in ext4_readpage_inline() Florian Schmaus
2026-12-03 10:06 ` [PATCH 2/2] ext4: test that ext4_readpage_inline() keeps uptodate buffers Florian Schmaus
2026-12-03 10:17   ` sashiko-bot [this message]
2026-12-03 10:30 ` [PATCH 0/2] ext4: fix data loss when reading during inline data conversion sashiko-bot

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=sashiko-outbox-247559@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=flo@geekplace.eu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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