[PATCH] landlock04: Skip variants unsupported by the running Landlock ABI
Ivan Hu via ltp <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
The LANDLOCK_ACCESS_FS_TRUNCATE access right is only available from Landlock ABI v3 (kernel v6.2, commit b9f5ce27c8f8 "landlock: Support file truncation"). On older kernels (e.g. those exposing ABI v1) setup() passed the variant's access right, including LANDLOCK_ACCESS_FS_TRUNCATE, directly to landlock_add_rule(), which failed with EINVAL and broke the test: landlock04.c: TBROK: landlock_add_rule(8, 1, ..., 0): EINVAL (22) tester_get_all_fs_rules() already masks the rule set according to the running kernel's Landlock ABI. Use it in setup() to detect when a variant requires an unsupported access right and skip it with TCONF instead of breaking. Signed-off-by: Ivan Hu <[email protected]> --- testcases/kernel/syscalls/landlock/landlock04.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/landlock/landlock04.c b/testcases/kernel/syscalls/landlock/landlock04.c index 737fdbf24..86dc19994 100644 --- a/testcases/kernel/syscalls/landlock/landlock04.c +++ b/testcases/kernel/syscalls/landlock/landlock04.c @@ -143,12 +143,26 @@ static void enable_exec_libs(const int ruleset_fd) static void setup(void) { struct tvariant variant = tvariants[tst_variant]; + int supported_rules; verify_landlock_is_enabled(); tst_res(TINFO, "Testing %s", variant.desc); - ruleset_attr->handled_access_fs = tester_get_all_fs_rules(); + supported_rules = tester_get_all_fs_rules(); + + /* Some access rights are only available from a given Landlock ABI + * version (e.g. LANDLOCK_ACCESS_FS_TRUNCATE needs ABI >= 3). Skip the + * variant when the running kernel doesn't support the tested right, + * otherwise landlock_add_rule() fails with EINVAL. + */ + if (variant.access & ~supported_rules) { + tst_brk(TCONF, + "%s is not supported by the current Landlock ABI", + variant.desc); + } + + ruleset_attr->handled_access_fs = supported_rules; ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET( ruleset_attr, sizeof(struct tst_landlock_ruleset_attr_abi1), 0); -- 2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp