From: sashiko-bot@kernel.org
To: arzuagapozosergio@gmail.com
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v2] ext4: bound xattr journal credits to transaction limit
Date: Sun, 22 Nov 2026 09:09:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-227843@kernel.org> (raw)
In-Reply-To: <20261122084939.129223-1-arzuagapozosergio@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ext4: missing xattr block lookup in ext4_xattr_set_handle()
credit check
- [Low] ext4: patch changelog and test checklist included in commit
message
- [Low] selftests: ext4: tautological value check in main() after E2BIG
setxattr()
- [Low] selftests: ext4: missing .gitignore and non-standard reporting
in main()
--
commit d21a4fa912d1237c90e910dcdee358a0869f3cfa
Author: Ryuji Hiroshi <arzuagapozosergio@gmail.com>
ext4: bound xattr journal credits to transaction limit
This commit refines ext4 xattr journal credit estimation by charging for
old ea_inode reference drops only when an existing ea_inode attribute is
replaced, bounds the requested credits against the maximum JBD2
transaction buffer limit, and adds an ext4 kselftest.
Link: https://syzbot.org/bug?extid=25d45c0bd716f2b794a7
> Changes in v2:
> - Include the default revoke descriptor blocks in the JBD2 credit limit.
> - Do not charge the current transaction for deferred ea_inode truncation.
> - Correct selftest registration and use kselftest result reporting.
> - Use user.* attributes and skip when required mount support is
> unavailable.
> - Reuse the validated xattr block buffer during the locked credit check.
>
> Tests:
> - make defconfig
> - make -j2 fs/ext4/xattr.o fs/jbd2/transaction.o
> - make -C tools/testing/selftests/filesystems/ext4 clean all
> - sh -n tools/testing/selftests/filesystems/ext4/
> ext4_xattr_journal_credits.sh
> - scripts/checkpatch.pl --strict --no-tree: 0 errors; two environment or
> tree warnings for the Fixes commit lookup and new selftest MAINTAINERS
> coverage.
> - Built and booted the patched x86_64 kernel in a QEMU/KVM guest.
> - The EXT4 selftest passed all 8 cases as guest root on a 1 KiB-block
> ea_inode filesystem with a 1 MiB journal. e2fsck -fn passed after
> the guest unmounted it.
> - The host kselftest runner correctly reported KSFT_SKIP because it cannot
> mount the disposable filesystem without root privileges.
[Severity: Low]
This isn't a bug, but the patch revision changelog ("Changes in v2:") and
the build/checkpatch checklist ("Tests:") belong below the "---" tearline
so they are not recorded in the permanent git commit log.
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 5c310747b9650..0249dc1375386 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
[ ... ]
> @@ -2415,6 +2383,30 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
> error = ext4_xattr_block_find(inode, &i, &bs);
> if (error)
> goto cleanup;
> +
> + /* Check journal credits under write lock using the old ea_inode state. */
> + if (ext4_handle_valid(handle)) {
> + struct ext4_xattr_entry *entry = NULL;
> + bool old_ea_inode = false;
> + int credits;
> +
> + if (!is.s.not_found)
> + entry = is.s.here;
> + else if (!bs.s.not_found)
> + entry = bs.s.here;
> + if (entry && entry->e_value_inum &&
> + !(flags & XATTR_CREATE))
> + old_ea_inode = true;
> + credits = __ext4_xattr_set_credits(inode->i_sb, inode, bs.bh,
> + value_len,
> + flags & XATTR_CREATE,
> + old_ea_inode);
> + if (jbd2_handle_buffer_credits(handle) < credits) {
> + error = -ENOSPC;
> + goto cleanup;
> + }
> + WARN_ON_ONCE(!(current->flags & PF_MEMALLOC_NOFS));
> + }
[Severity: Medium]
Does this underestimate the required credits in ext4_xattr_set_handle()
when the target attribute is found in the inode body?
When !is.s.not_found, ext4_xattr_block_find() is not called, so bs.bh is
NULL even if EXT4_I(inode)->i_file_acl is present (unlike
ext4_xattr_set_credits(), which falls back to ext4_xattr_get_block() when
!bs.bh). Passing bs.bh == NULL to __ext4_xattr_set_credits() omits the
per-ea_inode credits for cloning a shared external xattr block.
If an external xattr block containing ea_inode references was attached
after ext4_xattr_set_credits() dropped xattr_sem, and the new value no
longer fits in the inode body, ext4_xattr_ibody_set() returns -ENOSPC and
falls back to ext4_xattr_block_find() and ext4_xattr_block_set(). Cloning
that shared external xattr block in ext4_xattr_inode_inc_ref_all() can
then run out of handle buffer credits and trigger the WARN_ON_ONCE() in
jbd2_journal_dirty_metadata().
> diff --git a/tools/testing/selftests/filesystems/ext4/Makefile b/tools/testing/selftests/filesystems/ext4/Makefile
> new file mode 100644
> index 0000000000000..90569a1ccef38
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/Makefile
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +TEST_GEN_PROGS_EXTENDED := ext4_xattr_journal_credits
> +TEST_PROGS := ext4_xattr_journal_credits.sh
> +
> +include ../../lib.mk
> 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..92a6a8f7937bc
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c
[ ... ]
> + fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600);
> + if (fd < 0) {
> + failed_test = "create test file";
> + saved_errno = errno;
> + goto out;
> + }
[Severity: Low]
This isn't a bug, but tools/testing/selftests/filesystems/ext4/ is missing
a .gitignore entry for the generated ext4_xattr_journal_credits binary.
Also, in main(), both setup failures (open(), close(), malloc()) and test
failures jump to out: and abort via ksft_exit_fail_msg() rather than using
kselftest_harness.h (FIXTURE / TEST_F) or distinguishing setup errors with
ksft_test_result_error() from test failures with ksft_test_result_fail().
[ ... ]
> + memset(value, 0xa5, LARGE_VALUE_SIZE);
> + value[0] = 2;
> + if (setxattr(path, large_name, value, LARGE_VALUE_SIZE, XATTR_REPLACE) < 0) {
> + failed_test = "replace large ea_inode xattr";
> + saved_errno = errno;
> + goto out;
> + }
> + ksft_test_result_pass("large xattr replacement\n");
> +
> + if (getxattr(path, large_name, readback, LARGE_VALUE_SIZE) !=
> + LARGE_VALUE_SIZE || memcmp(value, readback, LARGE_VALUE_SIZE)) {
> + failed_test = "verify replaced xattr";
> + saved_errno = errno;
> + goto out;
> + }
> + ksft_test_result_pass("replacement readback\n");
> +
> + errno = 0;
> + if (setxattr(path, large_name, value, LARGE_VALUE_SIZE, XATTR_CREATE) !=
> + -1 || errno != EEXIST) {
> + failed_test = "XATTR_CREATE on an existing name should return EEXIST";
> + saved_errno = errno;
> + goto out;
> + }
> + ksft_test_result_pass("XATTR_CREATE semantics\n");
> +
> + errno = 0;
> + if (setxattr(path, large_name, value, OVERSIZED_VALUE_SIZE,
> + XATTR_REPLACE) != -1 || errno != E2BIG) {
> + failed_test = "oversized replacement should return E2BIG";
> + saved_errno = errno;
> + goto out;
> + }
> + if (getxattr(path, large_name, readback, LARGE_VALUE_SIZE) !=
> + LARGE_VALUE_SIZE || memcmp(value, readback, LARGE_VALUE_SIZE)) {
> + failed_test = "oversized replacement changed the old value";
> + saved_errno = errno;
> + goto out;
> + }
> + ksft_test_result_pass("oversized replacement rejected without changing value\n");
[Severity: Low]
Does the oversized replacement check in main() actually test whether the
stored value was preserved?
value is not modified after the preceding XATTR_REPLACE write (and the
trailing bytes between LARGE_VALUE_SIZE and OVERSIZED_VALUE_SIZE are left
uninitialized from malloc()), so value[0..LARGE_VALUE_SIZE - 1] already
matches the attribute on disk and memcmp(value, readback,
LARGE_VALUE_SIZE) would pass even if setxattr() had overwritten the
attribute.
In addition, OVERSIZED_VALUE_SIZE is 65537 (XATTR_SIZE_MAX + 1), which VFS
setxattr_copy() rejects with -E2BIG before reaching ext4_xattr_set() or
ext4_xattr_set_credits(). Also, in the readback checks, if getxattr()
succeeds but memcmp() fails, errno is not set by memcmp(), so saved_errno
captures a stale errno from an earlier syscall.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122084939.129223-1-arzuagapozosergio@gmail.com?part=1
next prev parent reply other threads:[~2026-11-22 9:09 UTC|newest]
Thread overview: 6+ 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 [this message]
2026-11-22 9:37 ` [PATCH v3] " arzuagapozosergio
2026-11-22 9:53 ` 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-227843@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