[LTP] [PATCH v6 15/16] Add listmount03 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Oct 8 17:00:10 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that listmount() raises EPERM when mount point is not accessible.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/listmount/.gitignore | 1 +
testcases/kernel/syscalls/listmount/listmount03.c | 62 +++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index f8ae25344..7e6d7aacf 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -733,6 +733,7 @@ listen01 listen01
listmount01 listmount01
listmount02 listmount02
+listmount03 listmount03
listxattr01 listxattr01
listxattr02 listxattr02
diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
index 30bbf9f02..e4273f319 100644
--- a/testcases/kernel/syscalls/listmount/.gitignore
+++ b/testcases/kernel/syscalls/listmount/.gitignore
@@ -1,2 +1,3 @@
listmount01
listmount02
+listmount03
diff --git a/testcases/kernel/syscalls/listmount/listmount03.c b/testcases/kernel/syscalls/listmount/listmount03.c
new file mode 100644
index 000000000..befe0edaf
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount03.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that listmount() raises EPERM when mount point is not accessible.
+ */
+
+#define _GNU_SOURCE
+
+#include <pwd.h>
+#include "listmount.h"
+#include "lapi/stat.h"
+
+#define LISTSIZE 32
+
+static uint64_t root_id;
+static gid_t nobody_gid;
+static uid_t nobody_uid;
+
+static void run(void)
+{
+ if (SAFE_FORK())
+ return;
+
+ uint64_t list[LISTSIZE];
+
+ SAFE_SETEGID(nobody_gid);
+ SAFE_SETEUID(nobody_uid);
+
+ TST_EXP_FAIL(listmount(root_id, 0, list, LISTSIZE, 0), EPERM);
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+ struct passwd *pw;
+
+ pw = SAFE_GETPWNAM("nobody");
+ nobody_gid = pw->pw_gid;
+ nobody_uid = pw->pw_uid;
+
+ SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx);
+ root_id = sx.data.stx_mnt_id;
+
+ SAFE_CHROOT(tst_tmpdir_path());
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .forks_child = 1,
+ .min_kver = "6.8",
+};
+
--
2.43.0
More information about the ltp
mailing list