• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
4  */
5 
6 /*
7  * Test ioctl_ns with NS_GET_OWNER_UID request.
8  *
9  * Calls ioctl for a UTS namespace, which isn't a user namespace.
10  * This should make the call fail with EINVAL.
11  *
12  */
13 #define _GNU_SOURCE
14 
15 #include <errno.h>
16 #include "tst_test.h"
17 #include "lapi/ioctl_ns.h"
18 
setup(void)19 static void setup(void)
20 {
21 	int exists = access("/proc/self/ns/uts", F_OK);
22 
23 	if (exists < 0)
24 		tst_res(TCONF, "namespace not available");
25 }
26 
run(void)27 static void run(void)
28 {
29 	int fd, owner_fd;
30 
31 	fd = SAFE_OPEN("/proc/self/ns/uts", O_RDONLY);
32 	uid_t uid;
33 
34 	owner_fd = ioctl(fd, NS_GET_OWNER_UID, &uid);
35 	if (owner_fd == -1) {
36 		if (errno == ENOTTY) {
37 			tst_brk(TCONF,
38 			        "ioctl(NS_GET_OWNER_UID) not implemented");
39 		}
40 
41 		if (errno == EINVAL)
42 			tst_res(TPASS, "NS_GET_OWNER_UID fails, UTS namespace");
43 		else
44 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
45 	} else {
46 		SAFE_CLOSE(fd);
47 		tst_res(TFAIL, "call to ioctl succeded");
48 	}
49 }
50 
51 static struct tst_test test = {
52 	.test_all = run,
53 	.min_kver = "4.11",
54 	.setup = setup
55 };
56