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