[PATCH v5 6/8] selftests/landlock: Add capability restriction tests
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Wed Oct 7 10:13:32 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/landlock: uninitialized read of records if audit_count_records() fails
--
commit 0b24b77e1134932d1209607c6e9bc067e8fb747d
Author: Mickaël Salaün <mic at digikod.net>
selftests/landlock: Add capability restriction tests
This commit adds tests to exercise LANDLOCK_PERMISSION_CAPABILITY_USE
enforcement. It covers stacking combinations, non-standard capability
contexts, and audit and trace scenarios.
> diff --git a/tools/testing/selftests/landlock/cap_test.c b/tools/testing/selftests/landlock/cap_test.c
> new file mode 100644
> index 0000000000000..07976854ec5a8
> --- /dev/null
> +++ b/tools/testing/selftests/landlock/cap_test.c
> @@ -0,0 +1,1373 @@
[ ... ]
> +TEST_F(cap_audit, denied)
> +{
> + struct audit_records records;
> + int ruleset_fd;
> + __u64 domain_id;
[ ... ]
> + EXPECT_EQ(0, audit_count_records(self->audit_fd, &records));
> + EXPECT_EQ(0, records.access);
> + EXPECT_EQ(0, records.domain);
[Severity: Low]
Does this code read uninitialized stack memory in TEST_F(cap_audit, denied)
if audit_count_records() fails?
The records structure is declared on the stack without initialization.
If audit_count_records() returns early with an error, for instance if
regcomp() fails with -ENOMEM in tools/testing/selftests/landlock/audit.h,
records.access and records.domain will remain uninitialized.
Because EXPECT_EQ() does not abort test execution upon failure like
ASSERT_EQ() would, the test will continue and evaluate the uninitialized
records.access and records.domain fields.
Consider either zero-initializing the records struct upon declaration,
or replacing EXPECT_EQ with ASSERT_EQ for the audit_count_records() call.
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261007100255.1333386-1-mic@digikod.net?part=6
More information about the Linux-security-module-archive
mailing list