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 v4] ext4: bound xattr journal credits to transaction limit
Date: Wed, 25 Nov 2026 05:09:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-232602@kernel.org> (raw)
In-Reply-To: <20261125045143.53035-1-arzuagapozosergio@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ext4: double dec_ref of ea_inode in ext4_xattr_block_set()
- [Low] selftests/ext4: flat main() and magic number in
  ext4_xattr_journal_credits
--

commit 4a8d7681896524501769fc05104b7297b7732a84
Author: Ryuji Hiroshi <arzuagapozosergio@gmail.com>

ext4: bound xattr journal credits to transaction limit

This commit removes the journal credit reservation for freeing an old
ea_inode, bounds the xattr credit estimate against the maximum JBD2
transaction buffers, drops the provisional ea_inode reference when reusing
a cached xattr block, and adds an ext4 kselftest.

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

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

[ ... ]

> @@ -2109,6 +2090,17 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
>  								   new_bh);
>  				if (error)
>  					goto cleanup_dquot;
> +				if (ea_inode) {
> +					/* 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 decrement ea_inode's reference count twice when an unshared
bs->bh (h_refcount == 1) is modified in-place and then matches an existing
block in ea_block_cache (new_bh != bs->bh)?

In the in-place modification path, ext4_xattr_set_entry() writes
ea_inode->i_ino into bs->bh->b_data before jumping to inserted: with
ea_inode still non-NULL:

fs/ext4/xattr.c:ext4_xattr_block_set() {
    ...
		if (header(s->base)->h_refcount == cpu_to_le32(1)) {
    ...
			ea_bdebug(bs->bh, "modifying in-place");
			error = ext4_xattr_set_entry(i, s, handle, inode,
					     ea_inode, true /* is_block */);
    ...
			goto inserted;
		}
    ...
	if (bs->bh && bs->bh != new_bh) {
		ext4_xattr_release_block(handle, inode, bs->bh,
					 0 /* extra_credits */);
	}
}

When ext4_xattr_block_cache_find() returns a cached new_bh != bs->bh, this
new block drops ea_inode's reference count once, and
ext4_xattr_release_block() -> ext4_xattr_inode_dec_ref_all() on the
in-place modified bs->bh drops it a second time. If new_bh held the only
other reference to ea_inode, its reference count drops to 0 and ea_inode is
freed on disk while new_bh still references it.

Guarding the decrement here with !(bs->bh && s->base == bs->bh->b_data), or
releasing and clearing ea_inode right after the in-place
ext4_xattr_set_entry() succeeds, would avoid the double decrement.

[ ... ]

> 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..3b4bb726db03e
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c
> @@ -0,0 +1,241 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define _GNU_SOURCE
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/xattr.h>
> +#include <unistd.h>
> +
> +#include "../../kselftest.h"
> +
> +#define LARGE_VALUE_SIZE 65296
> +#define FILLER_VALUE_SIZE 4
> +#define TEST_COUNT 10

[ ... ]

> +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]
This isn't a bug, but could this test use kselftest_harness.h
(FIXTURE()/TEST_F() with ASSERT_*/EXPECT_*) instead of a flat main() with
cascading state booleans and manual skip counts? Also, is there a specific
reason for choosing 65296 for LARGE_VALUE_SIZE that could be documented in
a comment?

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

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

Thread overview: 10+ 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 [this message]
2026-11-25  5:19       ` [PATCH v5] " 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-232602@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