From: sashiko-bot@kernel.org
To: arzuagapozosergio@gmail.com
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: bound xattr journal credits to transaction limit
Date: Sun, 22 Nov 2026 08:09:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-227808@kernel.org> (raw)
In-Reply-To: <20261122075355.81772-1-arzuagapozosergio@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] ext4: ext4_xattr_set_credits() bound check omits default
revoke block credits
- [Medium] ext4: __ext4_xattr_set_credits() overcharges for deferred
ea_inode eviction
- [Medium] selftests: ext4: helper binary listed in TEST_GEN_PROGS
breaks make run_tests
- [Low] selftests: ext4: missing kselftest helpers, fd close, and mount
skip handling
- [Low] ext4: redundant xattr block reads and lookups during credit
calculation
--
commit c2bfcf812ed8b979038bd6d5afa72dc0e3e9494f
Author: Ryuji Hiroshi <182191995+root465-lipcripto@users.noreply.github.com>
ext4: bound xattr journal credits to transaction limit
This commit looks up existing xattr entries to charge journal credits for
the actual old ea_inode value size instead of XATTR_SIZE_MAX, rejects
estimates exceeding JBD2's maximum transaction credits, 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..a904ea1dc05bc 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -949,7 +949,7 @@ static void ext4_xattr_inode_free_quota(struct inode *parent,
>
> int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
> struct buffer_head *block_bh, size_t value_len,
> - bool is_create)
> + bool is_create, size_t old_ea_value_len)
> {
> int credits;
> int blocks;
> @@ -998,14 +998,15 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
> /* Blocks themselves. */
> credits += blocks;
>
> - if (!is_create) {
> + if (!is_create && old_ea_value_len) {
> /* Dereference ea_inode holding old xattr value.
> * Old ea_inode, inode map, block bitmap, group descriptor.
> */
> credits += 4;
>
> /* Data blocks for old ea_inode. */
> - blocks = XATTR_SIZE_MAX >> sb->s_blocksize_bits;
> + blocks = (old_ea_value_len + sb->s_blocksize - 1) >>
> + sb->s_blocksize_bits;
>
> /* Indirection block or one level of extent tree for old
> * ea_inode.
[Severity: Medium]
Does the setxattr transaction actually free the old ea_inode's data blocks
here?
ext4_xattr_set_entry() only calls ext4_xattr_inode_dec_ref() (which
dirties old_ea_inode and adds it to the orphan list when ref_count reaches
0, using 2 credits) and then releases the reference via
ext4_put_ea_inode(). Because ext4_put_ea_inode() defers the final iput()
and ext4_evict_inode() truncation to sbi->s_ea_inode_work in a separate
transaction, charging 2 * blocks credits for old_ea_value_len here causes
in-place replacements of large ea_inode xattrs on small-journal
filesystems to fail with -ENOSPC.
[ ... ]
> @@ -2415,6 +2393,38 @@ 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 value size. */
> + if (ext4_handle_valid(handle)) {
> + struct ext4_xattr_entry *entry = NULL;
> + size_t old_ea_value_len = 0;
> + 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_value_len = le32_to_cpu(entry->e_value_size);
> +
> + struct buffer_head *bh = ext4_xattr_get_block(inode);
> +
> + if (IS_ERR(bh)) {
> + error = PTR_ERR(bh);
> + goto cleanup;
> + }
> + credits = __ext4_xattr_set_credits(inode->i_sb, inode, bh,
> + value_len,
> + flags & XATTR_CREATE,
> + old_ea_value_len);
> + brelse(bh);
> + if (jbd2_handle_buffer_credits(handle) < credits) {
> + error = -ENOSPC;
> + goto cleanup;
> + }
> + WARN_ON_ONCE(!(current->flags & PF_MEMALLOC_NOFS));
> + }
[Severity: Low]
When is.s.not_found is true, ext4_xattr_block_find() has already read and
validated EXT4_I(inode)->i_file_acl into bs.bh, so calling
ext4_xattr_get_block() again here (and below in ext4_xattr_set_credits())
repeats the buffer read and block validation while bs.bh is already held.
In addition, bh is declared after statements here, and
ext4_xattr_set_credits() unconditionally reads and searches the inode and
xattr block even when !ext4_has_feature_ea_inode(inode->i_sb) or is_create
is true.
[ ... ]
> @@ -2500,28 +2510,76 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
> return error;
> }
>
> -int ext4_xattr_set_credits(struct inode *inode, size_t value_len,
> +int ext4_xattr_set_credits(struct inode *inode, int name_index,
> + const char *name, size_t value_len,
> bool is_create, int *credits)
> {
[ ... ]
> + {
> + struct buffer_head *bh = ext4_xattr_get_block(inode);
> +
> + if (IS_ERR(bh)) {
> + err = PTR_ERR(bh);
> + goto out;
> + }
> *credits = __ext4_xattr_set_credits(inode->i_sb, inode, bh,
> - value_len, is_create);
> + value_len, is_create,
> + old_ea_value_len);
> brelse(bh);
> - err = 0;
> }
> + max_credits = jbd2_journal_get_max_transaction_buffers(journal);
> + err = *credits > max_credits ? -ENOSPC : 0;
[Severity: Medium]
Can *credits still trigger the WARN_ON(1) in start_this_handle() when
*credits is equal to max_credits?
Every caller of ext4_xattr_set_credits() passes *credits to
ext4_journal_start(), which passes
ext4_trans_default_revoke_credits(inode->i_sb) as revoke_records to
jbd2__journal_start():
fs/jbd2/transaction.c:jbd2__journal_start() {
...
nblocks += DIV_ROUND_UP(revoke_records,
journal->j_revoke_records_per_block);
handle = new_handle(nblocks);
...
}
start_this_handle() then checks handle->h_total_credits (which includes at
least 1 revoke descriptor block) against
jbd2_max_user_trans_buffers(journal). On the 1 KiB-block, 1 MiB-journal
filesystem from the test (max_credits = 334), replacing a 61-block
(62464-byte) ea_inode xattr with a 64-block (65296-byte) value yields
*credits = 334, passing this check and requesting 335 credits in
start_this_handle().
> diff --git a/tools/testing/selftests/filesystems/ext4/Makefile b/tools/testing/selftests/filesystems/ext4/Makefile
> new file mode 100644
> index 0000000000000..b271567c0a46d
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/Makefile
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +TEST_GEN_PROGS := ext4_xattr_journal_credits
> +TEST_PROGS := ext4_xattr_journal_credits.sh
> +
> +include ../../lib.mk
[Severity: Medium]
Won't listing ext4_xattr_journal_credits in TEST_GEN_PROGS cause make
run_tests to fail?
lib.mk executes every binary in TEST_GEN_PROGS directly as a standalone
test with no arguments, which hits the argc != 2 check in
ext4_xattr_journal_credits.c and exits with status 2. Helper binaries
invoked by TEST_PROGS scripts belong in TEST_GEN_PROGS_EXTENDED.
> 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..13f4f6673408b
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.c
> @@ -0,0 +1,89 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define _GNU_SOURCE
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/xattr.h>
> +#include <unistd.h>
> +
> +#define LARGE_VALUE_SIZE 65296
> +
> +static int fail(const char *what)
> +{
> + fprintf(stderr, "FAIL: %s: %s\n", what, strerror(errno));
> + return 1;
> +}
> +
> +int main(int argc, char **argv)
> +{
> + char path[4096];
> + char *value, *readback;
> + int path_len;
> + static const char large_name[] = "security.ima";
> + static const char small_name[] = "user.ext4-credit-test";
> + static const char small_value[] = "small-xattr";
> + char small_readback[sizeof(small_value)];
> +
> + if (argc != 2) {
> + fprintf(stderr, "Usage: %s MOUNTPOINT\n", argv[0]);
> + return 2;
> + }
> + path_len = snprintf(path, sizeof(path), "%s/credit-test", argv[1]);
> + if (path_len < 0 || (size_t)path_len >= sizeof(path)) {
> + fprintf(stderr, "Mount path is too long\n");
> + return 2;
> + }
> +
> + if (creat(path, 0600) < 0)
> + return fail("create test file");
> +
> + value = malloc(LARGE_VALUE_SIZE);
> + readback = malloc(LARGE_VALUE_SIZE);
> + if (!value || !readback)
> + return fail("allocate xattr buffers");
[Severity: Low]
Could this test use the kselftest.h or kselftest_harness.h reporting
helpers instead of custom fprintf()/puts() and raw return codes?
Also, using "security.ima" for large_name fails when
CONFIG_EXT4_FS_SECURITY is disabled or when IMA/EVM validates the
attribute format (whereas a user.* attribute avoids both), creat() leaks
its returned file descriptor, and the error paths after malloc() do not
free value or readback.
> diff --git a/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.sh b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.sh
> new file mode 100755
> index 0000000000000..837329fbd859b
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/ext4/ext4_xattr_journal_credits.sh
> @@ -0,0 +1,41 @@
[ ... ]
> +truncate -s 32M "$test_dir/fs.img" || exit 1
> +mkfs.ext4 -q -F -b 1024 -O ea_inode -J size=1 "$test_dir/fs.img" || exit 1
> +mkdir "$test_dir/mnt" || exit 1
> +mount -t ext4 -o loop "$test_dir/fs.img" "$test_dir/mnt" || exit 1
[Severity: Low]
Should a mount failure here call skip instead of exiting with 1 so kernels
built without CONFIG_EXT4_FS or CONFIG_BLK_DEV_LOOP skip the test rather
than failing?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122075355.81772-1-arzuagapozosergio@gmail.com?part=1
next prev parent reply other threads:[~2026-11-22 8:09 UTC|newest]
Thread overview: 3+ 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 [this message]
2026-11-22 8:49 ` [PATCH v2] " 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-227808@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