[LTP] [PATCH 5/7] Add lsm_list_modules01 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Nov 12 08:15:36 CET 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that lsm_list_modules syscall is raising errors when invalid
data is provided.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/lsm/.gitignore | 1 +
testcases/kernel/syscalls/lsm/lsm_list_modules01.c | 77 ++++++++++++++++++++++
3 files changed, 79 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index e6cff7763649d8b5c7eb9945473052c63b7a48aa..78b70e12b87bbbec88d641b9c11cac2989812ff7 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -759,6 +759,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
diff --git a/testcases/kernel/syscalls/lsm/.gitignore b/testcases/kernel/syscalls/lsm/.gitignore
index 19956fdf8b9952b4850c3a20826e29ec67ea3560..501d332549a84cceb9741346bdb8b83eb02467c5 100644
--- a/testcases/kernel/syscalls/lsm/.gitignore
+++ b/testcases/kernel/syscalls/lsm/.gitignore
@@ -1,3 +1,4 @@
lsm_get_self_attr01
lsm_get_self_attr02
lsm_get_self_attr03
+lsm_list_modules01
diff --git a/testcases/kernel/syscalls/lsm/lsm_list_modules01.c b/testcases/kernel/syscalls/lsm/lsm_list_modules01.c
new file mode 100644
index 0000000000000000000000000000000000000000..6aa401ab19bd3fb303fe28df878c3238bacdd4fb
--- /dev/null
+++ b/testcases/kernel/syscalls/lsm/lsm_list_modules01.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that lsm_list_modules syscall is raising errors when invalid data is
+ * provided.
+ */
+
+#include "lsm_common.h"
+
+#define MAX_LSM_NUM 32
+
+static uint64_t lsm_ids[MAX_LSM_NUM];
+static uint32_t page_size;
+static uint32_t ids_size;
+static uint32_t ids_size_small;
+
+static struct tcase {
+ uint64_t *ids;
+ uint32_t *size;
+ uint32_t flags;
+ int exp_errno;
+ char *msg;
+} tcases[] = {
+ {
+ .size = &ids_size,
+ .exp_errno = EFAULT,
+ .msg = "ids is NULL",
+ },
+ {
+ .ids = lsm_ids,
+ .exp_errno = EFAULT,
+ .msg = "size is NULL",
+ },
+ {
+ .ids = lsm_ids,
+ .size = &ids_size_small,
+ .exp_errno = E2BIG,
+ .msg = "size is too small",
+ },
+ {
+ .ids = lsm_ids,
+ .size = &ids_size,
+ .flags = 1,
+ .exp_errno = EINVAL,
+ .msg = "flags must be zero",
+ },
+};
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+
+ memset(lsm_ids, 0, sizeof(lsm_ids));
+ ids_size = page_size;
+ ids_size_small = 0;
+
+ TST_EXP_FAIL(lsm_list_modules(tc->ids, tc->size, tc->flags),
+ tc->exp_errno,
+ "%s", tc->msg);
+}
+
+static void setup(void)
+{
+ page_size = SAFE_SYSCONF(_SC_PAGESIZE);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "6.8",
+};
--
2.43.0
More information about the ltp
mailing list