landlock testing suite
v2 cover landlock testing suite
This testing suite is meant to test the following syscalls:
- landlock_create_ruleset
- landlock_add_rule
- landlock_restrict_self
Documentation can be found in kernel manuals and inside the official kernel documentation at
https://www.kernel.org/doc/html/latest/userspace-api/landlock.html
---
Changes in v2:
- remove -lc unused dependency from Makefile
- move SAFE_LANDLOCK_* macros in lapi/landlock.h
- define CAP_MKNOD in the lapi/capability.h
- fix landlock fallback in order to let LTP build properly
- fix landlock01 EINVAL test when "struct landlock_ruleset_attr" size is too small
- fix landlock05 for -i2
- skip exfat from landlock04 filesystems
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (7):
Add landlock01 test
Add landlock02 test
Add landlock03 test
Add CAP_MKNOD fallback in lapi/capability.h
Add landlock04 test
Add landlock05 test
Add landlock06 test
include/lapi/capability.h | 12 +- runtest/syscalls | 7 + testcases/kernel/syscalls/landlock/.gitignore | 7 + testcases/kernel/syscalls/landlock/Makefile | 7 + testcases/kernel/syscalls/landlock/landlock01.c | 92 ++++++ testcases/kernel/syscalls/landlock/landlock02.c | 153 +++++++++ testcases/kernel/syscalls/landlock/landlock03.c | 119 +++++++ testcases/kernel/syscalls/landlock/landlock04.c | 176 +++++++++++ testcases/kernel/syscalls/landlock/landlock05.c | 114 +++++++ testcases/kernel/syscalls/landlock/landlock06.c | 110 +++++++ .../kernel/syscalls/landlock/landlock_common.h | 74 +++++ testcases/kernel/syscalls/landlock/landlock_exec.c | 9 + .../kernel/syscalls/landlock/landlock_tester.h | 350 +++++++++++++++++++++ 13 files changed, 1226 insertions(+), 4 deletions(-)
---
base-commit: a3ebad6faf126347e3cbbd5a112f0853f159a914
change-id: 20240617-landlock-c48a4623a447
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/7 Add landlock01 test
From: Andrea Cervesato <[email protected]>
This test verifies that landlock_create_ruleset syscall fails with the right error codes:
- EINVAL Unknown flags, or unknown access, or too small size
- E2BIG size is too big
- EFAULT attr was not a valid address
- ENOMSG Empty accesses (i.e., attr->handled_access_fs is 0)
--- runtest/syscalls | 2 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/Makefile | 7 ++ testcases/kernel/syscalls/landlock/landlock01.c | 92 ++++++++++++++++++++++ .../kernel/syscalls/landlock/landlock_common.h | 74 +++++++++++++++++ 5 files changed, 176 insertions(+)
runtest/syscalls +2 -0
@@ -684,6 +684,8 @@ kill11 kill11 kill12 kill12 kill13 kill13 +landlock01 landlock01 + lchown01 lchown01 lchown01_16 lchown01_16 lchown02 lchown02
testcases/kernel/syscalls/landlock/.gitignore new file +1 -0
@@ -0,0 +1 @@ +landlock01
testcases/kernel/syscalls/landlock/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/landlock/landlock01.c new file +92 -0
92 lines not on this page · raw message
testcases/kernel/syscalls/landlock/landlock_common.h new file +74 -0
74 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/7 Add landlock02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that landlock_add_rule syscall fails with the right error codes:
- EINVAL flags is not 0, or the rule accesses are inconsistent
- ENOMSG Empty accesses (i.e., rule_attr->allowed_access is 0)
- EBADF ruleset_fd is not a file descriptor for the current thread, or a member of rule_attr is not a file descriptor as expected
- EBADFD ruleset_fd is not a ruleset file descriptor, or a member of rule_attr is not the expected file descriptor type
- EFAULT rule_attr was not a valid address
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock02.c | 153 ++++++++++++++++++++++++ 3 files changed, 155 insertions(+)
runtest/syscalls +1 -0
@@ -685,6 +685,7 @@ kill12 kill12 kill13 kill13 landlock01 landlock01 +landlock02 landlock02 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -1 +1,2 @@ landlock01 +landlock02
testcases/kernel/syscalls/landlock/landlock02.c new file +153 -0
153 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/7 Add landlock03 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that landlock_restrict_self syscall fails with the right error codes:
- EINVAL flags is not 0
- EBADF ruleset_fd is not a file descriptor for the current thread
- EBADFD ruleset_fd is not a ruleset file descriptor
- EPERM ruleset doesn't have CAP_SYS_ADMIN in its namespace
- E2BIG The maximum number of stacked rulesets is reached for the current thread
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock03.c | 119 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+)
runtest/syscalls +1 -0
@@ -686,6 +686,7 @@ kill13 kill13 landlock01 landlock01 landlock02 landlock02 +landlock03 landlock03 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -1,2 +1,3 @@ landlock01 landlock02 +landlock03
testcases/kernel/syscalls/landlock/landlock03.c new file +119 -0
119 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/7 Add CAP_MKNOD fallback in lapi/capability.h
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- include/lapi/capability.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
include/lapi/capability.h +8 -4
@@ -44,14 +44,18 @@# define CAP_SYS_TIME 25#endif -#ifndef CAP_AUDIT_READ -# define CAP_AUDIT_READ 37 -#endif -#ifndef CAP_SYS_RESOURCE # define CAP_SYS_RESOURCE 24#endif +#ifndef CAP_MKNOD +# define CAP_MKNOD 27 +#endif + +#ifndef CAP_AUDIT_READ +# define CAP_AUDIT_READ 37 +#endif +#ifndef CAP_BPF # define CAP_BPF 39#endif
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/7 Add landlock04 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that all landlock rules are working properly. The way we do it is to verify that all disabled syscalls are not working but the one we enabled via specifc landlock rules.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 2 + testcases/kernel/syscalls/landlock/landlock04.c | 176 +++++++++++ testcases/kernel/syscalls/landlock/landlock_exec.c | 9 + .../kernel/syscalls/landlock/landlock_tester.h | 350 +++++++++++++++++++++ 5 files changed, 538 insertions(+)
runtest/syscalls +1 -0
@@ -687,6 +687,7 @@ kill13 kill13 landlock01 landlock01 landlock02 landlock02 landlock03 landlock03 +landlock04 landlock04 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +2 -0
@@ -1,3 +1,5 @@ +landlock_exec landlock01 landlock02 landlock03 +landlock04
testcases/kernel/syscalls/landlock/landlock04.c new file +176 -0
176 lines not on this page · raw message
testcases/kernel/syscalls/landlock/landlock_exec.c new file +9 -0
@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +int main (void ) +{ +return 0 ; +}
testcases/kernel/syscalls/landlock/landlock_tester.h new file +350 -0
350 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/7 Add landlock05 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies LANDLOCK_ACCESS_FS_REFER access in the landlock sandbox. The feature is available since kernel 5.19.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock05.c | 114 ++++++++++++++++++++++++ 3 files changed, 116 insertions(+)
runtest/syscalls +1 -0
@@ -688,6 +688,7 @@ landlock01 landlock01 landlock02 landlock02 landlock03 landlock03 landlock04 landlock04 +landlock05 landlock05 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -3,3 +3,4 @@ landlock01 landlock02 landlock03 landlock04 +landlock05
testcases/kernel/syscalls/landlock/landlock05.c new file +114 -0
114 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 7/7 Add landlock06 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies LANDLOCK_ACCESS_FS_IOCTL_DEV access in the landlock sandbox by creating a pipe and testing that ioctl() can be executed on it. The test is also verifying that some of the I/O operations can be always executed no matter the sandbox rules. This feature is available since kernel 6.10.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock06.c | 110 ++++++++++++++++++++++++ 3 files changed, 112 insertions(+)
runtest/syscalls +1 -0
@@ -689,6 +689,7 @@ landlock02 landlock02 landlock03 landlock03 landlock04 landlock04 landlock05 landlock05 +landlock06 landlock06 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -4,3 +4,4 @@ landlock02 landlock03 landlock04 landlock05 +landlock06
testcases/kernel/syscalls/landlock/landlock06.c new file +110 -0
110 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
please ignore this version because for some reason b4 messed up the patches and some are missing. I think something wrong happened with rebase.
Andrea
Quoted 53 lines · Andrea Cervesato
This testing suite is meant to test the following syscalls:
-
landlock_create_ruleset
-landlock_add_rule
-landlock_restrict_selfDocumentation can be found in kernel manuals and inside the official kernel documentation at
https://www.kernel.org/doc/html/latest/userspace-api/landlock.html
Signed-off-by Andrea Cervesato <[email protected]>---
Changes in v2:
- remove -lc unused dependency fromMakefile
- move SAFE_LANDLOCK_* macros inlapi/landlock.h
- defineCAP_MKNODin thelapi/capability.h
- fix landlock fallback in order to let LTP build properly
- fix landlock01 EINVAL test when "structlandlock_ruleset_attr" size is too small
- fix landlock05 for -i2
- skip exfat from landlock04 filesystems
- Link to v1: https://lore.kernel.org/r/[email protected]---
Andrea Cervesato (7):
Add landlock01 test
Add landlock02 test
Add landlock03 test
AddCAP_MKNODfallback inlapi/capability.hAdd landlock04 test
Add landlock05 test
Add landlock06 testinclude/lapi/capability.h | 12 +- runtest/syscalls | 7 + testcases/kernel/syscalls/landlock/.gitignore | 7 + testcases/kernel/syscalls/landlock/Makefile | 7 + testcases/kernel/syscalls/landlock/landlock01.c | 92 ++++++ testcases/kernel/syscalls/landlock/landlock02.c | 153 +++++++++ testcases/kernel/syscalls/landlock/landlock03.c | 119 +++++++ testcases/kernel/syscalls/landlock/landlock04.c | 176 +++++++++++ testcases/kernel/syscalls/landlock/landlock05.c | 114 +++++++ testcases/kernel/syscalls/landlock/landlock06.c | 110 +++++++ .../kernel/syscalls/landlock/landlock_common.h | 74 +++++ testcases/kernel/syscalls/landlock/landlock_exec.c | 9 + .../kernel/syscalls/landlock/landlock_tester.h | 350 +++++++++++++++++++++ 13 files changed, 1226 insertions(+), 4 deletions(-)---
base-commit:a3ebad6faf126347e3cbbd5a112f0853f159a914
change-id: 20240617-landlock-c48a4623a447Best regards,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp