Skip to contentSkip to conversation

LSM testing suite

PATCH In review Andrea Cervesato 3 participants 11 messages Jun 2, 2025 – Jun 3, 2025

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 7f475f6b6419ee14125dada3ddd7d9ea06eb6b48..9ff098b273b9298b4d0ddcd43fb6aefdddf44f0c 100644
@@ -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
#2 lore raw

PATCH v5 2/7 Add lsm_get_self_attr01 test

In reply to Andrea Cervesato

From: 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
index e7bc7b27b604e0f0f69b6bad99955662c6c58a91..f141baa8110aa4e701a808f72a19f2bad46da2d6 100644
@@ -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
new file mode 100644
index 0000000000000000000000000000000000000000..49f4a9263349ce633b8decb8fff1dd1d2111cf49
@@ -0,0 +1 @@
+lsm_get_self_attr01
testcases/kernel/syscalls/lsm/Makefile new file +7 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8cf1b9024d8bdebe72408c90fef4b8b84ce9dc4b
@@ -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
#3 lore raw

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
#4 lore raw

PATCH v5 3/7 Add lsm_get_self_attr02 test

In reply to Andrea Cervesato

From: 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
index f141baa8110aa4e701a808f72a19f2bad46da2d6..2c69e2cc93d2bea73a4849cbb406d3f87ba41d15 100644
@@ -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
index 49f4a9263349ce633b8decb8fff1dd1d2111cf49..9f7c9b00b026a377f1b36f483ac2c1a0adba6249 100644
@@ -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
#5 lore raw

PATCH v5 4/7 Add lsm_get_self_attr03 test

In reply to Andrea Cervesato

From: 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
index 2c69e2cc93d2bea73a4849cbb406d3f87ba41d15..ac3c46ee9f8ae84cbbef18ef0c18bf224dd46964 100644
@@ -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
index 9f7c9b00b026a377f1b36f483ac2c1a0adba6249..19956fdf8b9952b4850c3a20826e29ec67ea3560 100644
@@ -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
#7 lore raw

PATCH v5 5/7 Add lsm_list_modules01 test

In reply to Andrea Cervesato

From: 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
index ac3c46ee9f8ae84cbbef18ef0c18bf224dd46964..01129a0bfb0f56098a83176caeb3098e7ddc810d 100644
@@ -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
index 19956fdf8b9952b4850c3a20826e29ec67ea3560..501d332549a84cceb9741346bdb8b83eb02467c5 100644
@@ -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
#8 lore raw

PATCH v5 6/7 Add lsm_list_modules02 test

In reply to Andrea Cervesato

From: 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
index 01129a0bfb0f56098a83176caeb3098e7ddc810d..43b05d7b2ecc18bc2770c9d6c2f142537bde3252 100644
@@ -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
index 501d332549a84cceb9741346bdb8b83eb02467c5..766f81fd1c74a10001862f142c02ba251e666ef2 100644
@@ -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
#9 lore raw

PATCH v5 7/7 Add lsm_set_self_attr01 test

In reply to Andrea Cervesato

From: 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
index 43b05d7b2ecc18bc2770c9d6c2f142537bde3252..fc336f7c76770b526c7d08bfd7b232487c1c4bda 100644
@@ -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
index 766f81fd1c74a10001862f142c02ba251e666ef2..467f07cec5443393d231bbb98880b7183635dd9d 100644
@@ -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