LSM testing suite
v5 cover LSM testing suite
Testing the following syscalls which are providing support for the LSM communication added in kernel 6.8:
- lsm_get_self_attr
- lsm_set_self_attr
- lsm_list_modules
Please consider the following documentation as reference:
https://docs.kernel.org/userspace-api/lsm.html
---
Changes in v5:
- check if /sys/kernel/security/lsm exists before reading it
- use next_ctx()
- while(ptr) instead of while(ptr != NULL)
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- fix integer index loop that should be size_t
- correctly cast lsm_ctx pointer to char*
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- lsm_common.h cleanup
- better overall check for supported LSM(s) when using LSM_ATTR_CURRENT
- simplify tests using more common functions
- use the right size for lsm_ctx
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- correctly fallback <linux/lsm.h> include
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (7):
Add fallback definitions of LSM syscalls
Add lsm_get_self_attr01 test
Add lsm_get_self_attr02 test
Add lsm_get_self_attr03 test
Add lsm_list_modules01 test
Add lsm_list_modules02 test
Add lsm_set_self_attr01 test
configure.ac | 3 +- include/lapi/lsm.h | 177 +++++++++++++++++++++ runtest/syscalls | 7 + testcases/kernel/syscalls/lsm/.gitignore | 6 + testcases/kernel/syscalls/lsm/Makefile | 7 + testcases/kernel/syscalls/lsm/lsm_common.h | 96 +++++++++++ .../kernel/syscalls/lsm/lsm_get_self_attr01.c | 92 +++++++++++ .../kernel/syscalls/lsm/lsm_get_self_attr02.c | 45 ++++++ .../kernel/syscalls/lsm/lsm_get_self_attr03.c | 68 ++++++++ testcases/kernel/syscalls/lsm/lsm_list_modules01.c | 75 +++++++++ testcases/kernel/syscalls/lsm/lsm_list_modules02.c | 156 ++++++++++++++++++ .../kernel/syscalls/lsm/lsm_set_self_attr01.c | 110 +++++++++++++ 12 files changed, 841 insertions(+), 1 deletion(-)
---
base-commit: 14d8a5e93874a3fb256932930fd0a15c15f1f503
change-id: 20241105-lsm-5da2f6c2a1e9
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 1/7 Add fallback definitions of LSM syscalls
From: Andrea Cervesato <[email protected]>
Fallback definition for the following syscalls:
- lsm_get_self_attr
- lsm_set_self_attr
- lsm_list_modules
--- configure.ac | 3 +- include/lapi/lsm.h | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-)
configure.ac +2 -1
@@ -69,6 +69,7 @@ AC_CHECK_HEADERS_ONCE([ \ linux/ioprio.h \ linux/keyctl.h \ linux/landlock.h \ + linux/lsm.h \ linux/mempolicy.h \ linux/module.h \ linux/mount.h \
@@ -204,7 +205,7 @@ AC_CHECK_TYPES([struct ipc64_perm],,,[#include <sys/ipcbuf.h>]) AC_CHECK_TYPES([struct loop_config],,,[#include <linux/loop.h>]) AC_CHECK_TYPES([struct landlock_path_beneath_attr],,,[#include <linux/landlock.h>]) AC_CHECK_TYPES([struct landlock_net_port_attr],,,[#include <linux/landlock.h>]) - +AC_CHECK_TYPES([struct lsm_ctx],,,[#include <linux/lsm.h>]) AC_CHECK_TYPES([struct mmsghdr],,,[ #define _GNU_SOURCE #include <sys/types.h>
include/lapi/lsm.h new file +177 -0
177 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 2/7 Add lsm_get_self_attr01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that lsm_get_self_attr syscall is raising errors when invalid data is provided.
--- runtest/syscalls | 2 + testcases/kernel/syscalls/lsm/.gitignore | 1 + testcases/kernel/syscalls/lsm/Makefile | 7 ++ testcases/kernel/syscalls/lsm/lsm_common.h | 96 ++++++++++++++++++++++ .../kernel/syscalls/lsm/lsm_get_self_attr01.c | 92 +++++++++++++++++++++ 5 files changed, 198 insertions(+)
runtest/syscalls +2 -0
@@ -758,6 +758,8 @@ lseek02 lseek02 lseek07 lseek07 lseek11 lseek11 +lsm_get_self_attr01 lsm_get_self_attr01 + lstat01 lstat01 lstat01_64 lstat01_64 lstat02 lstat02
testcases/kernel/syscalls/lsm/.gitignore new file +1 -0
@@ -0,0 +1 @@ +lsm_get_self_attr01
testcases/kernel/syscalls/lsm/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/lsm/lsm_common.h new file +96 -0
96 lines not on this page · raw message
testcases/kernel/syscalls/lsm/lsm_get_self_attr01.c new file +92 -0
92 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 2/7] Add lsm_get_self_attr01 test
testcases/kernel/syscalls/lsm/lsm_common.h line 50
Quoted 9 lines · Andrea Cervesato
testcases/kernel/syscalls/lsm/lsm_common.h new file +9
-0+ +static inline int verify_enabled_lsm (const char *name) +{ +int fd; +char *ptr; +char data[BUFSIZ ]; + +if (access (LSM_SYS_FILE ,F_OK )) +tst_brk (TCONF ,"%s file is not present" ,LSM_SYS_FILE );
@Cyril can you please double check that it's ok? There's the same check in lsm_list_modules02 now, because this function is not needed there.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 3/7 Add lsm_get_self_attr02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that lsm_get_self_attr syscall is acting correctly when ctx is NULL. The syscall can behave in different ways according to the current system status:
- if any LSM is running inside the system, the syscall will pass and it will provide a size as big as the attribute
- if no LSM(s) are running inside the system, the syscall will fail with -1 return code and it will provide EOPNOTSUPP errno
--- runtest/syscalls | 1 + testcases/kernel/syscalls/lsm/.gitignore | 1 + .../kernel/syscalls/lsm/lsm_get_self_attr02.c | 45 ++++++++++++++++++++++ 3 files changed, 47 insertions(+)
runtest/syscalls +1 -0
@@ -759,6 +759,7 @@ lseek07 lseek07 lseek11 lseek11 lsm_get_self_attr01 lsm_get_self_attr01 +lsm_get_self_attr02 lsm_get_self_attr02 lstat01 lstat01 lstat01_64 lstat01_64
testcases/kernel/syscalls/lsm/.gitignore +1 -0
@@ -1 +1,2 @@ lsm_get_self_attr01 +lsm_get_self_attr02
testcases/kernel/syscalls/lsm/lsm_get_self_attr02.c new file +45 -0
45 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 4/7 Add lsm_get_self_attr03 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that LSM_ATTR_CURRENT attribute is correctly recognizing the current, active security context of the process. This is done by checking that /proc/self/attr/current matches with the obtained value.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/lsm/.gitignore | 1 + .../kernel/syscalls/lsm/lsm_get_self_attr03.c | 68 ++++++++++++++++++++++ 3 files changed, 70 insertions(+)
runtest/syscalls +1 -0
@@ -760,6 +760,7 @@ lseek11 lseek11 lsm_get_self_attr01 lsm_get_self_attr01 lsm_get_self_attr02 lsm_get_self_attr02 +lsm_get_self_attr03 lsm_get_self_attr03 lstat01 lstat01 lstat01_64 lstat01_64
testcases/kernel/syscalls/lsm/.gitignore +1 -0
@@ -1,2 +1,3 @@ lsm_get_self_attr01 lsm_get_self_attr02 +lsm_get_self_attr03
testcases/kernel/syscalls/lsm/lsm_get_self_attr03.c new file +68 -0
68 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5 4/7] Add lsm_get_self_attr03 test
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 5/7 Add lsm_list_modules01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that lsm_list_modules syscall is raising errors when invalid data is provided.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/lsm/.gitignore | 1 + testcases/kernel/syscalls/lsm/lsm_list_modules01.c | 75 ++++++++++++++++++++++ 3 files changed, 77 insertions(+)
runtest/syscalls +1 -0
@@ -761,6 +761,7 @@ lseek11 lseek11 lsm_get_self_attr01 lsm_get_self_attr01 lsm_get_self_attr02 lsm_get_self_attr02 lsm_get_self_attr03 lsm_get_self_attr03 +lsm_list_modules01 lsm_list_modules01 lstat01 lstat01 lstat01_64 lstat01_64
testcases/kernel/syscalls/lsm/.gitignore +1 -0
@@ -1,3 +1,4 @@ lsm_get_self_attr01 lsm_get_self_attr02 lsm_get_self_attr03 +lsm_list_modules01
testcases/kernel/syscalls/lsm/lsm_list_modules01.c new file +75 -0
75 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 6/7 Add lsm_list_modules02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that lsm_list_modules syscall is correctly recognizing LSM(s) enabled inside the system.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/lsm/.gitignore | 1 + testcases/kernel/syscalls/lsm/lsm_list_modules02.c | 156 +++++++++++++++++++++ 3 files changed, 158 insertions(+)
runtest/syscalls +1 -0
@@ -762,6 +762,7 @@ lsm_get_self_attr01 lsm_get_self_attr01 lsm_get_self_attr02 lsm_get_self_attr02 lsm_get_self_attr03 lsm_get_self_attr03 lsm_list_modules01 lsm_list_modules01 +lsm_list_modules02 lsm_list_modules02 lstat01 lstat01 lstat01_64 lstat01_64
testcases/kernel/syscalls/lsm/.gitignore +1 -0
@@ -2,3 +2,4 @@ lsm_get_self_attr01 lsm_get_self_attr02 lsm_get_self_attr03 lsm_list_modules01 +lsm_list_modules02
testcases/kernel/syscalls/lsm/lsm_list_modules02.c new file +156 -0
156 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 7/7 Add lsm_set_self_attr01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that lsm_set_self_attr syscall is raising errors when invalid data is provided.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/lsm/.gitignore | 1 + .../kernel/syscalls/lsm/lsm_set_self_attr01.c | 110 +++++++++++++++++++++ 3 files changed, 112 insertions(+)
runtest/syscalls +1 -0
@@ -763,6 +763,7 @@ lsm_get_self_attr02 lsm_get_self_attr02 lsm_get_self_attr03 lsm_get_self_attr03 lsm_list_modules01 lsm_list_modules01 lsm_list_modules02 lsm_list_modules02 +lsm_set_self_attr01 lsm_set_self_attr01 lstat01 lstat01 lstat01_64 lstat01_64
testcases/kernel/syscalls/lsm/.gitignore +1 -0
@@ -3,3 +3,4 @@ lsm_get_self_attr02 lsm_get_self_attr03 lsm_list_modules01 lsm_list_modules02 +lsm_set_self_attr01
testcases/kernel/syscalls/lsm/lsm_set_self_attr01.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
Merged thanks!
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp