Re: [PATCH -next -v2 8/8] selftests/lsm: add lockdown securityfs test
From: Nicolas Bouchinet
Date: Tue Nov 24 2026 - 10:35:54 EST
On Tue, 10 Nov 2026 21:28:18 +0800, Cai Xinchen <caixinchen1@xxxxxxxxxx> wrote:
> diff --git a/tools/testing/selftests/lsm/common.c b/tools/testing/selftests/lsm/common.c
> index 927dce4f04cb2..e7d5cdb101375 100644
> --- a/tools/testing/selftests/lsm/common.c
> +++ b/tools/testing/selftests/lsm/common.c
> @@ -50,23 +51,39 @@ int read_proc_attr(const char *attr, char *value, size_t size)
> [ ... skip 26 lines ... ]
> + int err = errno;
>
> - if (red <= 0 || red == size)
> + close(fd);
> + errno = err;
> return -1;
Here you change the return value of read_sysfs_lsms function, leading to
hypothetical test failure, take the
lsm_list_modules_test.c:correct_lsm_list_modules test as an example, in a scenario
where the size parameter is not sufficient for the read string, your
function will return 0, thus passing the test (obviously, it is
currently at `_SC_PAGESIZE` and should not fail). The previous
read_sysfs_lsms function returned -1.
Nitpick, in this scenario, you also read one less character than the
previous function.
>
> diff --git a/tools/testing/selftests/lsm/lockdown_test.c b/tools/testing/selftests/lsm/lockdown_test.c
> new file mode 100644
> index 0000000000000..fed050551cff2
> --- /dev/null
> +++ b/tools/testing/selftests/lsm/lockdown_test.c
> @@ -0,0 +1,230 @@
> [ ... skip 206 lines ... ]
> + }
> + if (geteuid() != 0)
> + SKIP(return, "requires root");
> + if (status_writable())
> + SKIP(return, "cannot open %s for writing: %s",
> + LOCKDOWN_PATH, strerror(errno));
Could you synthesize those checks in a FIXTURE_SETUP ?
> [ ... skip 10 lines ... ]
> + ASSERT_EQ(0, write_status(next));
> +
> + ASSERT_EQ(0, read_file(LOCKDOWN_PATH, after, sizeof(after)));
> + ASSERT_EQ(0, get_active_level(after, level, sizeof(level)));
> + ASSERT_STREQ(next, level);
> +}
Since this testsuite is not included by default, because, as specified in
the Makefile, it will change the machine state, you might move the
upgrade test before the same_level and no_downgrade tests. Hence those
two will never be at a none state.
--
Nicolas Bouchinet <nicolas.bouchinet@xxxxxxxxxxxxxxxxx>