Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: arzuagapozosergio@gmail.com
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v5] ext4: bound xattr journal credits to transaction limit
Date: Wed, 25 Nov 2026 05:39:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-232619@kernel.org> (raw)
In-Reply-To: <20261125051909.61227-1-arzuagapozosergio@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ext4: ea_inode refcount leak in ext4_xattr_block_set() when
  new_bh == bs->bh
- [Low] selftests/ext4: flat main() and manual TAP plan in
  ext4_xattr_journal_credits
--

commit 772b6f10e7b839b9e96f3998c77f31c8ed924efa
Author: Ryuji Hiroshi <arzuagapozosergio@gmail.com>

ext4: bound xattr journal credits to transaction limit

This commit drops obsolete ea_inode removal credits from
__ext4_xattr_set_credits(), bounds xattr credit estimates against the
JBD2 transaction limit, drops the provisional ea_inode reference when
reusing a cached xattr block, and adds an ext4 selftest.

Link: https://syzbot.org/bug?extid=25d45c0bd716f2b794a7

> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 5c310747b9650..0a955a6e0912d 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c

[ ... ]

> @@ -2109,6 +2090,18 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
>  								   new_bh);
>  				if (error)
>  					goto cleanup_dquot;
> +				if (ea_inode &&
> +				    !(bs->bh && s->base == bs->bh->b_data)) {
> +					/* The reused block already holds this reference. */
> +					error = ext4_xattr_inode_dec_ref(handle,
> +									 ea_inode);
> +					if (error)
> +						ext4_warning_inode(ea_inode,
> +								   "dec ref error=%d",
> +								   error);
> +					ext4_put_ea_inode(ea_inode);
> +					ea_inode = NULL;
> +				}
>  			}
>  			mb_cache_entry_touch(ea_block_cache, ce);
>  			mb_cache_entry_put(ea_block_cache, ce);

[Severity: High]
Does this leak an on-disk reference on ea_inode when a cloned xattr block
matches bs->bh itself in ea_block_cache (new_bh == bs->bh)?

ext4_xattr_value_same() returns 0 whenever s->here->e_value_inum is set, so
overwriting an existing ea_inode-backed attribute with the same value still
enters ext4_xattr_block_set(), where ext4_xattr_inode_lookup_create() finds
the existing ea_inode and increments its on-disk refcount.  When bs->bh is
shared (h_refcount > 1) or its mb_cache entry is busy, clone_block clears
s->here->e_value_inum in s->base so ext4_xattr_set_entry() does not drop the
existing reference, then writes the same ea_inode->i_ino back into s->base
and ext4_xattr_block_cache_find() returns new_bh == bs->bh:

fs/ext4/xattr.c:ext4_xattr_block_set() {
    ...
		if (new_bh) {
			/* We found an identical block in the cache. */
			if (new_bh == bs->bh)
				ea_bdebug(new_bh, "keeping");
			else {
    ...
}

Because the new_bh == bs->bh branch skips the else block and bs->bh == new_bh
also skips ext4_xattr_release_block(), the provisional reference on ea_inode
is never decremented, leaving the ea_inode and its data blocks permanently
allocated on disk.  Moving this ea_inode drop after the if (new_bh == bs->bh)
/ else block (still inside if (new_bh)) would cover both cases.

> diff --git a/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c
> new file mode 100644
> index 0000000000000..85dd28d62bcf3
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c
> @@ -0,0 +1,243 @@

[ ... ]

> +static void report_setup_error(const char *what, unsigned int skip_count)
> +{
> +	int saved_errno = errno;
> +	unsigned int i;
> +
> +	ksft_test_result_error("setup %s: %s\n", what,
> +			       strerror(saved_errno));
> +	for (i = 0; i < skip_count; i++)
> +		ksft_test_result_skip("setup failed\n");
> +}

[ ... ]

> +int main(int argc, char **argv)
> +{
> +	char path[4096], shared_a[4096], shared_b[4096];
> +	char *value = NULL, *expected = NULL, *readback = NULL;
> +	char target_new[64];
> +	static const char small_value[] = "small-xattr";
> +	char small_value_readback[sizeof(small_value)];
> +	char target_old = 0x11;
> +	int fd, path_len, shared_len;
> +	bool created = false, replaced = false, shared_ready = false;
> +	bool shared_replaced = false;
> +	int ret;

[Severity: Low]
Could this test use kselftest_harness.h (FIXTURE(), FIXTURE_SETUP(),
FIXTURE_TEARDOWN(), and TEST_F() with ASSERT_*/EXPECT_*) instead of a flat
main() that chains checks with boolean flags and pads the TAP plan via
report_setup_error()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125051909.61227-1-arzuagapozosergio@gmail.com?part=1

  reply	other threads:[~2026-11-25  5:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  7:53 [PATCH] ext4: bound xattr journal credits to transaction limit arzuagapozosergio
2026-11-22  8:09 ` sashiko-bot
2026-11-22  8:49 ` [PATCH v2] " arzuagapozosergio
2026-11-22  9:09   ` sashiko-bot
2026-11-22  9:37   ` [PATCH v3] " arzuagapozosergio
2026-11-22  9:53     ` sashiko-bot
2026-11-24 12:38     ` Jan Kara
2026-11-25  4:51     ` [PATCH v4] " arzuagapozosergio
2026-11-25  5:09       ` sashiko-bot
2026-11-25  5:19       ` [PATCH v5] " arzuagapozosergio
2026-11-25  5:39         ` sashiko-bot [this message]
2026-11-25  6:01         ` [PATCH v6] " arzuagapozosergio
2026-11-25  6:23           ` sashiko-bot
2026-11-25  6:30           ` [PATCH v7] " arzuagapozosergio

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-232619@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arzuagapozosergio@gmail.com \
    --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