landlock04: Skip variants unsupported by the running Landlock ABI
PATCH 1/1 landlock04: Skip variants unsupported by the running Landlock ABI
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.
--- testcases/kernel/syscalls/landlock/landlock04.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/landlock/landlock04.c +15 -1
@@ -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 );
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Ivan,
Quoted 1 line · Ivan Hu
landlock04: Skip variants unsupported by the running Landlock ABI
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
AppliedMerged, Thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp