Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Theodore Ts'o" <tytso@mit.edu>,
	"Ext4 Developers List" <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 04/27] ext4: add KUnit tests for fs/ext4/xattr.c
Date: Thu, 12 Nov 2026 04:26:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-210335@kernel.org> (raw)
In-Reply-To: <20261112040638.1576836-5-tytso@mit.edu>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ext4: uninitialized e_name in test_xattr_check_inode()
  bypasses value checks
- [Low] ext4: stack frame size warning in
  test_xattr_credits_usage_expand_and_delete()
- [Low] ext4: missing i_size_ordered_init() in init_mock_inode_slot()
--

commit b81033fe08ff323ec6a5c24275644912bdfe1108
Author: Theodore Ts'o <tytso@mit.edu>

ext4: add KUnit tests for fs/ext4/xattr.c

This commit adds a KUnit test suite in fs/ext4/xattr-test.c to exercise
extended attribute operations in fs/ext4/xattr.c using static stubs and
exports.

> diff --git a/fs/ext4/xattr-test.c b/fs/ext4/xattr-test.c
> new file mode 100644
> index 0000000000000..35be150353a20
> --- /dev/null
> +++ b/fs/ext4/xattr-test.c

[ ... ]

> +static void init_mock_inode_slot(struct xattr_test_ctx *ctx,
> +				 struct mock_inode_slot *slot,
> +				 unsigned long ino)
> +{
> +	struct inode *inode = &slot->ei.vfs_inode;
> +	struct ext4_inode *raw_inode;
> +
> +	memset(slot, 0, sizeof(*slot));
> +	slot->allocated = true;
> +
> +	inode->i_sb = &ctx->sb;
> +	inode->i_ino = ino;
> +	inode->i_mode = S_IFREG | 0644;
> +	inode->i_blkbits = TEST_BLK_BITS;
> +	inode->i_mapping = &inode->i_data;
> +	set_nlink(inode, 1);
> +	atomic_set(&inode->i_count, 1);
> +
> +	spin_lock_init(&inode->i_lock);
> +	init_rwsem(&inode->i_rwsem);

[Severity: Low]
Should init_mock_inode_slot() also call i_size_ordered_init(inode)?

On 32-bit SMP builds with CONFIG_DEBUG_LOCK_ALLOC=y, struct inode embeds
i_size_seqcount, so calling i_size_write() or i_size_read() on the mock
EA inodes triggers a lockdep warning for an uninitialized key and
disables lockdep.

[ ... ]

> +static void test_xattr_check_inode(struct kunit *test)
> +{
> +	const struct xattr_check_param *p = test->param_value;
> +	struct xattr_test_ctx *ctx = test->priv;
> +	struct inode *inode = &ctx->primary.ei.vfs_inode;
> +	struct ext4_inode *raw_inode = (struct ext4_inode *)ctx->primary.raw_buf;
> +	struct ext4_xattr_ibody_header *hdr = IHDR(inode, raw_inode);
> +	struct ext4_xattr_entry *e1, *e2;
> +	void *end = ITAIL(inode, raw_inode);
> +	size_t total_size = (char *)end - (char *)IFIRST(hdr);
> +	int ret;
> +
> +	memset(hdr, 0, (char *)end - (char *)hdr);
> +	hdr->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
> +	e1 = IFIRST(hdr);
> +
> +	switch (p->id) {

[ ... ]

> +	case CHECK_NONZERO_OFFS_WITH_INUM:
> +		e1->e_name_len = 1;
> +		e1->e_value_inum = cpu_to_le32(20);
> +		e1->e_value_offs = cpu_to_le16(total_size - 4);
> +		break;
> +	case CHECK_VALUE_SIZE_GT_TOTAL:
> +		e1->e_name_len = 1;
> +		e1->e_value_size = cpu_to_le32(total_size + 4);
> +		e1->e_value_offs = cpu_to_le16(total_size - 4);
> +		break;
> +	case CHECK_VALUE_OFFS_OVERLAPS_ENTRY:
> +		e1->e_name_len = 1;
> +		e1->e_value_size = cpu_to_le32(4);
> +		/* Offset points inside e1 + 4-byte terminator */
> +		e1->e_value_offs = cpu_to_le16(EXT4_XATTR_LEN(1));
> +		break;
> +	case CHECK_VALUE_END_EXCEEDS_TOTAL:
> +		e1->e_name_len = 1;
> +		e1->e_value_size = cpu_to_le32(8);
> +		e1->e_value_offs = cpu_to_le16(total_size - 4);
> +		break;
> +	}

[Severity: Medium]
Do these four cases reach the value checks in check_xattrs()?

Because hdr is zeroed with memset() and e1->e_name[0] is left as NUL
while e1->e_name_len is 1, check_xattrs() rejects all four cases in the
entry-name loop before reaching the value-validation loop:

fs/ext4/xattr.c:check_xattrs() {
    ...
	while (!IS_LAST_ENTRY(e)) {
		...
		if (strnlen(e->e_name, e->e_name_len) != e->e_name_len) {
			err_str = "bad e_name length";
			goto errout;
		}
		e = next;
	}

	/* Check the values */
	while (!IS_LAST_ENTRY(entry)) {
    ...
}

In addition, check_xattrs() only inspects e_value_offs when
entry->e_value_inum == 0, so CHECK_NONZERO_OFFS_WITH_INUM does not test a
check that check_xattrs() performs; even with e1->e_name[0] set, it would
fail on the missing EXT4_FEATURE_INCOMPAT_EA_INODE feature or zero
e_value_size instead.

[ ... ]

> +static void test_xattr_credits_usage_expand_and_delete(struct kunit *test)
> +{
> +	struct xattr_test_ctx *ctx = test->priv;
> +	struct inode *inode = &ctx->primary.ei.vfs_inode;
> +	struct ext4_inode *raw = (struct ext4_inode *)ctx->primary.raw_buf;
> +	journal_t fake_journal = {
> +		.j_revoke_records_per_block = 64,
> +	};

[Severity: Low]
Can placing fake_journal on the stack exceed CONFIG_FRAME_WARN?

journal_t (struct journal_s) is ~1.3 KB on 64-bit builds and over 2.2 KB
when lock debugging is enabled, which triggers -Wframe-larger-than=
warnings on 32-bit builds or 64-bit debug configurations.  Moving
fake_journal into struct xattr_test_ctx or allocating it with
kunit_kzalloc() would avoid the large stack frame.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112040638.1576836-1-tytso@mit.edu?part=4

  reply	other threads:[~2026-11-12  4:26 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:06 [PATCH 00/27] ext4: add lots of KUnit tests! Theodore Ts'o
2026-11-12  4:06 ` [PATCH 01/27] ext4: add KUinit tests for fs/ext4/extents_status.c Theodore Ts'o
2026-11-12  4:18   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 02/27] ext4: add KUnit tests for fs/ext4/extents.c Theodore Ts'o
2026-11-12  4:28   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 03/27] ext4: add KUnit tests for ext4_ext_split() leaf and index splitting Theodore Ts'o
2026-11-12  4:15   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 04/27] ext4: add KUnit tests for fs/ext4/xattr.c Theodore Ts'o
2026-11-12  4:26   ` sashiko-bot [this message]
2026-11-12  4:06 ` [PATCH 05/27] ext4: add KUnit tests for fs/ext4/namei.c Theodore Ts'o
2026-11-12  4:21   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 06/27] ext4: expand KUnit tests for fs/ext4/mballoc.c Theodore Ts'o
2026-11-12  4:26   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 07/27] ext4: add KUnit tests for fs/ext4/inline.c Theodore Ts'o
2026-11-12  4:29   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 08/27] ext4: zero s_fc_replay_state in ext4_fc_replay_cleanup() Theodore Ts'o
2026-11-12  4:16   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 09/27] ext4: add KUnit tests for fs/ext4/fast_commit.c Theodore Ts'o
2026-11-12  4:28   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 10/27] ext4: expand KUnit tests for fs/ext4/inode.c Theodore Ts'o
2026-11-12  4:36   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 11/27] ext4: add KUnit tests for fs/ext4/ialloc.c Theodore Ts'o
2026-11-12  4:25   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 12/27] ext4: add KUnit tests for fs/ext4/balloc.c Theodore Ts'o
2026-11-12  4:16   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 13/27] ext4: add KUnit tests for fs/ext4/orphan.c Theodore Ts'o
2026-11-12  4:18   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 14/27] ext4: add KUnit tests for fs/ext4/block_validity.c Theodore Ts'o
2026-11-12  4:21   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 15/27] ext4: check multi-block overlap on left traversal in add_system_zone() Theodore Ts'o
2026-11-12  4:10   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 16/27] ext4: enable full feature coverage in fs/ext4/.kunitconfig Theodore Ts'o
2026-11-12  4:24   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 17/27] ext4: add KUnit tests for fs/ext4/super.c Theodore Ts'o
2026-11-12  4:27   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 18/27] ext4: add KUnit tests for fs/ext4/sysfs.c Theodore Ts'o
2026-11-12  4:32   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 19/27] ext4: add KUnit tests for fs/ext4/ioctl.c Theodore Ts'o
2026-11-12  4:35   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 20/27] ext4: add KUnit tests for fs/ext4/resize.c Theodore Ts'o
2026-11-12  4:34   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 21/27] ext4: add KUnit tests for fs/ext4/migrate.c Theodore Ts'o
2026-11-12  4:37   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 22/27] ext4: add KUnit tests for fs/ext4/indirect.c Theodore Ts'o
2026-11-12  4:46   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 23/27] ext4: expand KUnit tests in fs/ext4/extents-test.c for file range operations Theodore Ts'o
2026-11-12  4:34   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 24/27] ext4: add KUnit tests for fs/ext4/fsmap.c Theodore Ts'o
2026-11-12  4:30   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 25/27] ext4: add KUnit tests for fs/ext4/move_extent.c Theodore Ts'o
2026-11-12  4:36   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 26/27] ext4: add KUnit tests for fs/ext4/mmp.c Theodore Ts'o
2026-11-12  4:29   ` sashiko-bot
2026-11-12  4:06 ` [PATCH 27/27] ext4: add KUnit tests for fs/ext4/dir.c Theodore Ts'o
2026-11-12  4:41   ` 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-210335@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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