• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 listmount() raises EPERM when mount point is not accessible.
10  */
11 
12 #define _GNU_SOURCE
13 
14 #include <pwd.h>
15 #include "listmount.h"
16 #include "lapi/stat.h"
17 
18 #define LISTSIZE 32
19 
20 static uint64_t root_id;
21 static gid_t nobody_gid;
22 static uid_t nobody_uid;
23 
run(void)24 static void run(void)
25 {
26 	if (SAFE_FORK())
27 		return;
28 
29 	uint64_t list[LISTSIZE];
30 
31 	SAFE_SETEGID(nobody_gid);
32 	SAFE_SETEUID(nobody_uid);
33 
34 	TST_EXP_FAIL(listmount(root_id, 0, list, LISTSIZE, 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 };
62 
63