From: sashiko-bot@kernel.org
To: "David Windsor" <dwindsor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 2/2] selftests/bpf: add tests for bpf_init_inode_xattr kfunc
Date: Sun, 03 May 2026 22:12:01 +0000 [thread overview]
Message-ID: <20260503221201.DFD1BC2BCB4@smtp.kernel.org> (raw)
In-Reply-To: <20260503211835.16103-3-dwindsor@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The test will fail spuriously if the target test file already exists.
- [Medium] Uninitialized stack memory is read if `getxattr` returns a smaller length than expected.
- [Low] The test fails instead of gracefully skipping on filesystems that do not support xattrs.
--
commit 96e5b274b42a271a01409d6e21dc11302496f1d3
Author: David Windsor <dwindsor@gmail.com>
selftests/bpf: add tests for bpf_init_inode_xattr kfunc
This commit tests BPF atomic inode xattr labeling via the
inode_init_security LSM hook.
> diff --git a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
> index 43a26ec69a8e..26daef116ee2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
[ ... ]
> @@ -268,6 +269,51 @@ static void test_fsverity(void)
> remove(testfile);
> }
>
> +static void test_init_inode_xattr(void)
> +{
> + struct test_init_inode_xattr *skel = NULL;
> + int fd = -1, err;
> + char value_out[32];
> + const char *testfile_new = "/tmp/test_progs_fs_kfuncs_new";
[ ... ]
> + /* Create a new file — this triggers inode_init_security */
> + fd = open(testfile_new, O_CREAT | O_RDWR, 0644);
Could this cause spuriously failing tests if the file already exists from a
previous, aborted run?
If the file exists, no new inode is created, so the inode_init_security
hook won't be triggered, leaving init_result at -1.
Should we unlink the file before opening it, or use the O_EXCL flag to ensure
we're creating a new inode?
> + if (!ASSERT_GE(fd, 0, "create_file"))
> + goto out;
> +
> + ASSERT_EQ(skel->data->init_result, 0, "init_result");
> +
> + /* The initxattrs callback prepends "security." to the name */
> + err = getxattr(testfile_new, "security.bpf.test_label", value_out,
> + sizeof(value_out));
> + if (err < 0 && errno == ENODATA) {
Will this fail the test instead of gracefully skipping it on filesystems
that don't support extended attributes?
If the filesystem lacks xattr support (like some tmpfs configs), getxattr
will return -EOPNOTSUPP.
Could we broaden the check to include EOPNOTSUPP?
> + printf("%s:SKIP:filesystem did not apply LSM xattrs\n",
> + __func__);
> + test__skip();
> + goto out;
> + }
> + if (!ASSERT_GE(err, 0, "getxattr"))
> + goto out;
> +
> + ASSERT_EQ(err, (int)sizeof(skel->data->xattr_value), "xattr_size");
> + ASSERT_EQ(strncmp(value_out, "test_value",
> + sizeof("test_value")), 0, "xattr_value");
Could this lead to an uninitialized stack memory read?
If getxattr returns a smaller size than expected, the size assertion will
fail, but execution will continue to strncmp since there is no goto out.
Because value_out is uninitialized, strncmp may read garbage data and
trigger KMSAN errors.
Would it be better to wrap the size assertion with if (!ASSERT_EQ(...))
goto out, or zero-initialize value_out?
> +
> +out:
> + close(fd);
> + test_init_inode_xattr__destroy(skel);
> + remove(testfile_new);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260503211835.16103-1-dwindsor@gmail.com?part=2
next prev parent reply other threads:[~2026-05-03 22:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 21:18 [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling David Windsor
2026-05-03 21:18 ` [PATCH v2 1/2] " David Windsor
2026-05-03 21:59 ` sashiko-bot
2026-05-04 20:14 ` Paul Moore
2026-05-04 21:40 ` Song Liu
2026-05-04 22:42 ` Paul Moore
2026-05-04 23:09 ` Song Liu
2026-05-05 1:07 ` David Windsor
2026-05-05 2:02 ` Paul Moore
2026-05-05 2:05 ` Paul Moore
2026-05-05 9:00 ` Song Liu
2026-05-05 13:49 ` Paul Moore
2026-05-10 21:22 ` bot+bpf-ci
2026-05-03 21:18 ` [PATCH v2 2/2] selftests/bpf: add tests for bpf_init_inode_xattr kfunc David Windsor
2026-05-03 21:52 ` bot+bpf-ci
2026-05-03 22:12 ` sashiko-bot [this message]
2026-05-10 21:10 ` bot+bpf-ci
[not found] ` <b6170cc360f0db18ceb0857f97dfaf84d129a6de55836fef2b0b604805cf5039@mail.kernel.org>
2026-05-03 22:16 ` [PATCH v2 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling David Windsor
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=20260503221201.DFD1BC2BCB4@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwindsor@gmail.com \
--cc=sashiko@lists.linux.dev \
/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