1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
4 */
5
6 /*\
7 * [Description]
8 *
9 * Verify that statmount() raises EPERM when mount point is not accessible.
10 */
11
12 #define _GNU_SOURCE
13
14 #include <pwd.h>
15 #include "statmount.h"
16 #include "lapi/stat.h"
17
18 static struct statmount *st_mount;
19 static uint64_t root_id;
20 static gid_t nobody_gid;
21 static uid_t nobody_uid;
22
run(void)23 static void run(void)
24 {
25 if (SAFE_FORK())
26 return;
27
28 SAFE_SETEGID(nobody_gid);
29 SAFE_SETEUID(nobody_uid);
30
31 memset(st_mount, 0, sizeof(struct statmount));
32
33 TST_EXP_FAIL(statmount(root_id, STATMOUNT_SB_BASIC, st_mount,
34 sizeof(struct statmount), 0), EPERM);
35
36 exit(0);
37 }
38
setup(void)39 static void setup(void)
40 {
41 struct ltp_statx sx;
42 struct passwd *pw;
43
44 pw = SAFE_GETPWNAM("nobody");
45 nobody_gid = pw->pw_gid;
46 nobody_uid = pw->pw_uid;
47
48 SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx);
49 root_id = sx.data.stx_mnt_id;
50
51 SAFE_CHROOT(tst_tmpdir_path());
52 }
53
54 static struct tst_test test = {
55 .test_all = run,
56 .setup = setup,
57 .needs_root = 1,
58 .needs_tmpdir = 1,
59 .forks_child = 1,
60 .min_kver = "6.8",
61 .bufs = (struct tst_buffers []) {
62 {&st_mount, .size = sizeof(struct statmount)},
63 {}
64 }
65 };
66