[PATCH v10 9/9] selftests/landlock: Add tests for invalid use of quiet flag

Mickaël Salaün mic at digikod.net
Mon Jun 8 22:41:57 UTC 2026


On Mon, Jun 01, 2026 at 01:00:43AM +0100, Tingmao Wang wrote:
> Make sure that these calls return EINVAL.
> 
> Signed-off-by: Tingmao Wang <m at maowtm.org>
> ---
> 
> Changes in v4:
> - New patch
> 
>  tools/testing/selftests/landlock/base_test.c | 57 ++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c
> index 84e91fcaa1b2..af9ad822a444 100644
> --- a/tools/testing/selftests/landlock/base_test.c
> +++ b/tools/testing/selftests/landlock/base_test.c
> @@ -526,4 +526,61 @@ TEST(cred_transfer)
>  	EXPECT_EQ(EACCES, errno);
>  }
>  
> +TEST(useless_quiet_rule)
> +{
> +	struct landlock_ruleset_attr ruleset_attr = {
> +		.handled_access_fs = LANDLOCK_ACCESS_FS_READ_DIR,
> +		.quiet_access_fs = 0,

The other .quiet_* fields should also be tested.

> +	};
> +	struct landlock_path_beneath_attr path_beneath_attr = {
> +		.allowed_access = LANDLOCK_ACCESS_FS_READ_DIR,
> +	};
> +	int ruleset_fd, root_fd;
> +
> +	drop_caps(_metadata);
> +	ruleset_fd =
> +		landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> +	ASSERT_LE(0, ruleset_fd);
> +
> +	root_fd = open("/", O_PATH | O_CLOEXEC);
> +	ASSERT_LE(0, root_fd);
> +	path_beneath_attr.parent_fd = root_fd;
> +	ASSERT_EQ(-1, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> +					&path_beneath_attr,
> +					LANDLOCK_ADD_RULE_QUIET));
> +	ASSERT_EQ(EINVAL, errno);
> +
> +	/* Check that the rule had not been added. */
> +	ASSERT_EQ(0, close(root_fd));
> +	enforce_ruleset(_metadata, ruleset_fd);
> +	ASSERT_EQ(0, close(ruleset_fd));
> +
> +	ASSERT_EQ(-1, open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC));
> +	ASSERT_EQ(EACCES, errno);
> +}
> +
> +TEST(invalid_quiet_bits_1)
> +{
> +	struct landlock_ruleset_attr ruleset_attr = {
> +		.handled_access_fs = LANDLOCK_ACCESS_FS_READ_DIR,
> +		.quiet_access_fs = LANDLOCK_ACCESS_FS_WRITE_FILE,

ditto

> +	};
> +
> +	ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr,
> +					      sizeof(ruleset_attr), 0));
> +	ASSERT_EQ(EINVAL, errno);
> +}
> +
> +TEST(invalid_quiet_bits_2)
> +{
> +	struct landlock_ruleset_attr ruleset_attr = {
> +		.handled_access_fs = LANDLOCK_ACCESS_FS_READ_DIR,
> +		.quiet_access_fs = 1ULL << 63,

ditto

> +	};
> +
> +	ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr,
> +					      sizeof(ruleset_attr), 0));
> +	ASSERT_EQ(EINVAL, errno);
> +}
> +
>  TEST_HARNESS_MAIN
> -- 
> 2.54.0
> 



More information about the Linux-security-module-archive mailing list