Landlock tests for ABI v6
v3 cover Landlock tests for ABI v6
Landlock released a new feature for IPC scoping in the new ABI. This includes the following new rules which will be tested in this patch-set:
- LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET
- LANDLOCK_SCOPE_SIGNAL
https://docs.kernel.org/userspace-api/landlock.html#ipc-scoping
---
Changes in v3:
- import <stddef.h> for offsetof declaration
- fix build error caused by DOMAIN_CNT in metadata parser. Just use .tst_variants = 3
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- add landlock09 and landlock10 to runtest file
- DOMAIN_LENGTH -> DOMAIN_CNT
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (4):
Add landlock ABI v6 fallback
landlock02: support landlock ABI v6
landlock: add landlock09 test
landlock: add landlock10 test
include/lapi/landlock.h | 23 +++- runtest/syscalls | 2 + testcases/kernel/syscalls/landlock/.gitignore | 2 + testcases/kernel/syscalls/landlock/landlock02.c | 12 +- testcases/kernel/syscalls/landlock/landlock09.c | 131 +++++++++++++++++++++ testcases/kernel/syscalls/landlock/landlock10.c | 108 +++++++++++++++++ .../kernel/syscalls/landlock/landlock_common.h | 11 ++ 7 files changed, 280 insertions(+), 9 deletions(-)
---
base-commit: e3aef569f0d0e7079bdb646965afaf419035eaa5
change-id: 20250325-landlock_unix_socket-592bb00535be
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/4 Add landlock ABI v6 fallback
From: Andrea Cervesato <[email protected]>
The new ABI v6 is defining the following IPC scoped operations:
* LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET
* LANDLOCK_SCOPE_SIGNAL
--- include/lapi/landlock.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
include/lapi/landlock.h +17 -6
@@ -15,15 +15,19 @@#include "lapi/syscalls.h" -struct tst_landlock_ruleset_attr_abi1 -{ +struct tst_landlock_ruleset_attr_abi1 {uint64_t handled_access_fs; }; -struct tst_landlock_ruleset_attr_abi4 -{ +struct tst_landlock_ruleset_attr_abi4 { +uint64_t handled_access_fs; +uint64_t handled_access_net; +}; + +struct tst_landlock_ruleset_attr_abi6 {uint64_t handled_access_fs;uint64_t handled_access_net; +uint64_t scoped; };#ifndef HAVE_STRUCT_LANDLOCK_PATH_BENEATH_ATTR
@@ -43,8 +47,7 @@ struct landlock_path_beneath_attr#endif #ifndef HAVE_STRUCT_LANDLOCK_NET_PORT_ATTR -struct landlock_net_port_attr -{ +struct landlock_net_port_attr {uint64_t allowed_access;uint64_t port; };
@@ -126,6 +129,14 @@ struct landlock_net_port_attr# define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1)#endif +#ifndef LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET +# define LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET (1ULL << 0) +#endif + +#ifndef LANDLOCK_SCOPE_SIGNAL +# define LANDLOCK_SCOPE_SIGNAL (1ULL << 1) +#endif +static inline int safe_landlock_create_ruleset (const char *file,const int lineno,const void *attr,size_t size ,uint32_t flags) {
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/4 landlock02: support landlock ABI v6
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/landlock/landlock02.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/landlock/landlock02.c +9 -3
@@ -20,6 +20,7 @@static struct tst_landlock_ruleset_attr_abi1 *attr_abi1;static struct tst_landlock_ruleset_attr_abi4 *attr_abi4; +static struct tst_landlock_ruleset_attr_abi6 *attr_abi6;static struct landlock_path_beneath_attr *path_beneath_attr;static struct landlock_path_beneath_attr *rule_null;static struct landlock_net_port_attr *net_port_attr;
@@ -144,15 +145,19 @@ static void setup(void) { abi_current =verify_landlock_is_enabled (); - attr_abi1->handled_access_fs = - attr_abi4->handled_access_fs =LANDLOCK_ACCESS_FS_EXECUTE ; + attr_abi1->handled_access_fs =LANDLOCK_ACCESS_FS_EXECUTE ; + attr_abi4->handled_access_fs =LANDLOCK_ACCESS_FS_EXECUTE ; + attr_abi6->handled_access_fs =LANDLOCK_ACCESS_FS_EXECUTE ;if (abi_current <4 ) { ruleset_fd =TST_EXP_FD_SILENT (tst_syscall (__NR_landlock_create_ruleset, attr_abi1,sizeof (struct tst_landlock_ruleset_attr_abi1 ),0 )); - }else { + }else if (abi_current <6 ) { ruleset_fd =TST_EXP_FD_SILENT (tst_syscall (__NR_landlock_create_ruleset, attr_abi4,sizeof (struct tst_landlock_ruleset_attr_abi4 ),0 )); + }else { + ruleset_fd =TST_EXP_FD_SILENT (tst_syscall (__NR_landlock_create_ruleset, + attr_abi6,sizeof (struct tst_landlock_ruleset_attr_abi6 ),0 )); } }
@@ -171,6 +176,7 @@ static struct tst_test test = { .bufs = (struct tst_buffers []) { {&attr_abi1, .size =sizeof (struct tst_landlock_ruleset_attr_abi1 )}, {&attr_abi4, .size =sizeof (struct tst_landlock_ruleset_attr_abi4 )}, + {&attr_abi6, .size =sizeof (struct tst_landlock_ruleset_attr_abi6 )}, {&path_beneath_attr, .size =sizeof (struct landlock_path_beneath_attr )}, {&net_port_attr, .size =sizeof (struct landlock_net_port_attr )}, {},
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 3/4 landlock: add landlock09 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Create landlock09 test in order to verify that sandboxed processes enforced with LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET rule can't connect to any UNIX socket from non-sandboxed processes.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock09.c | 131 +++++++++++++++++++++ .../kernel/syscalls/landlock/landlock_common.h | 11 ++ 4 files changed, 144 insertions(+)
runtest/syscalls +1 -0
@@ -710,6 +710,7 @@ landlock05 landlock05 landlock06 landlock06 landlock07 landlock07 landlock08 landlock08 +landlock09 landlock09 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -7,3 +7,4 @@ landlock05 landlock06 landlock07 landlock08 +landlock09
testcases/kernel/syscalls/landlock/landlock09.c new file +131 -0
131 lines not on this page · raw message
testcases/kernel/syscalls/landlock/landlock_common.h +11 -0
@@ -115,6 +115,17 @@ static inline void apply_landlock_net_layer(SAFE_CLOSE (ruleset_fd); } +static inline void apply_landlock_scoped_layer ( +void *ruleset_attr,size_t attr_size) +{ +int ruleset_fd; + + ruleset_fd =SAFE_LANDLOCK_CREATE_RULESET (ruleset_attr, attr_size,0 ); +enforce_ruleset (ruleset_fd); + +SAFE_CLOSE (ruleset_fd); +} +static inline in_port_t getsocket_port (struct socket_data *socket,const int addr_family) {
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 4/4 landlock: add landlock10 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that landlock's LANDLOCK_SCOPE_SIGNAL rule rejects any signal coming from a process on a different domain, but accept signals from processes in the same domain.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock10.c | 108 ++++++++++++++++++++++++ 3 files changed, 110 insertions(+)
runtest/syscalls +1 -0
@@ -711,6 +711,7 @@ landlock06 landlock06 landlock07 landlock07 landlock08 landlock08 landlock09 landlock09 +landlock10 landlock10 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -8,3 +8,4 @@ landlock06 landlock07 landlock08 landlock09 +landlock10
testcases/kernel/syscalls/landlock/landlock10.c new file +108 -0
108 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp