From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293047; b=un2hwwVPM1RuSyUIyajcyRt8qVNSd41ZqVmIHPTO55hHBqgdZFRtRKEPBOvj1TViqWNo 9eVwWptioCmitET7U0CjDWaCin+ZgOfL/QiEfZG634nW2eGxnHsRPXcmDWoOHAO5bQbmg VsxO9QHOP8mLA2eX0YtFAt1W9+vhWPUAum3LdAZ7Chkbba7VI40uf6aFVOlcocwS1LFvz CZ9QT4K7TQvhgTNK3Z4Hei7hC4IeKY5g57nasNhClWcahVzcOi7SAw1nOkl9rxnALvzFV 5U5XA4rCY+/oVA0IEEfFGxxWpIouscMcHeXF86yfJp56X049JqfjbckcU6+ObiCVN8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293047; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=32hg0DMe8L/N82Fq93h6dgOAzgiRT2qRFhiVOTQB70c=; b=f80sNqz48f8O9HzPzuux/UEaKFaKa802m7+WWRcPS7/DFaqMxryKlPsFQmtXQ2+QVU6P sDBozGjI0QxY515rObIzBgznTPnUBZgL5tWy39/uFpGTMU8xD78kezCAhMvaDESCJOpG9 zpuN5QcR6jzKMcNiAmqOtTc/t5OwZmQJfBPK+WI274skxKv54ghneTWRVgVFqD831WI/X Zas6OyY+D+SrHHKBlHwJhqLZAgSY/DBxjpun0UXLmc8ytsP+IS4HQoPbrnbzED5rnkfmN dlvo3HPqlO1qqV/bOMoYwRSdznnXm8UHIN4mX5x0r+Uj24S7rvsZS3R6Sdhunz6u6yw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BwVfLNLo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A368606A680 for ; Thu, 3 Dec 2026 10:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BwVfLNLo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 093AD1F00893; Thu, 3 Dec 2026 10:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796293047; bh=32hg0DMe8L/N82Fq93h6dgOAzgiRT2qRFhiVOTQB70c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BwVfLNLohfRaK7uJuiEvbrGuIUu1iVwYqOWMObmYrem0qzvlbQbEROnKoIT77yJCC /lUfshGhGB6DmMzTszLfo9WB048QdQQ6VSN9WJhMlFEsFBtg+m1GFOKSd6ied4whks 4Fi9tsjlqYmAA4JlQ/lOHbB4BnfMyeVaw8S5Dar6coOsWcuAFs15t4+dgSzYmSTmNB aR5GMubQSyzJXH8uiTIBbSX0tOz6NzxI7XmcTTcSxWRQTu7JRLxIdZZ75whH30Le+J K/gZXiSI8qcBj6HN1TxjphAoMcTPYpjcC3SrFFLqMGG+i8RdlRyV0SdRCEFia/MNiX 0itzd3nF7uMTQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] ext4: test that ext4_readpage_inline() keeps uptodate buffers Reply-To: sashiko-reviews@lists.linux.dev To: "Florian Schmaus" Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: <20261203-ext4-inline-readpage-v1-2-1dd69e69f53b@geekplace.eu> References: <20261203-ext4-inline-readpage-v1-0-1dd69e69f53b@geekplace.eu> <20261203-ext4-inline-readpage-v1-2-1dd69e69f53b@geekplace.eu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 10:17:26 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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(stru= ct kunit *test) > kunmap_local(kaddr); > folio_put(folio); > =20 > + /* > + * 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 =3D __filemap_get_folio(&inode->i_data, 2, > + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, > + GFP_KERNEL); > + KUNIT_ASSERT_FALSE(test, IS_ERR(folio)); > + kaddr =3D kmap_local_folio(folio, 0); > + memset(kaddr, 0xff, PAGE_SIZE); > + memset(kaddr + TEST_BLOCK_SIZE, 0xab, TEST_BLOCK_SIZE); > + kunmap_local(kaddr); > + head =3D create_empty_buffers(folio, TEST_BLOCK_SIZE, 0); > + set_buffer_uptodate(head->b_this_page); > + > + ret =3D 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 =3D 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 =3D head; > + do { > + KUNIT_EXPECT_TRUE(test, buffer_uptodate(bh)); > + bh =3D bh->b_this_page; > + } while (bh !=3D 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 =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-ext4-inlin= e-readpage-v1-0-1dd69e69f53b@geekplace.eu?part=3D2