11 #include <sys/ioctl.h>
12 #include <sys/prctl.h>
15 #define pr_err(fmt, ...) \
17 fprintf(stderr, "%s:%d:" fmt ": %m\n", \
18 __func__, __LINE__, ##__VA_ARGS__); \
23 #define NS_GET_USERNS _IO(NSIO, 0x1)
24 #define NS_GET_PARENT _IO(NSIO, 0x2)
26 #define __stack_aligned__ __attribute__((aligned(16)))
28 char stack[128] __stack_aligned__;
32 static int child(void *args)
34 prctl(PR_SET_PDEATHSIG, SIGKILL);
40 int main(int argc, char *argv[])
42 char *ns_strs[] = {"pid", "user"};
43 char path[] = "/proc/0123456789/ns/pid";
44 struct cr_clone_arg ca;
49 pid = clone(child, ca.stack_ptr, CLONE_NEWUSER | CLONE_NEWPID | SIGCHLD, NULL);
51 return pr_err("clone");
53 for (i = 0; i < 2; i++) {
54 snprintf(path, sizeof(path), "/proc/%d/ns/%s", pid, ns_strs[i]);
55 ns = open(path, O_RDONLY);
57 return pr_err("Unable to open %s", path);
59 pns = ioctl(ns, NS_GET_PARENT);
61 return pr_err("Unable to get a parent pidns");
63 snprintf(path, sizeof(path), "/proc/self/ns/%s", ns_strs[i]);
65 return pr_err("Unable to stat %s", path);
67 return pr_err("Unable to stat the parent pidns");
68 if (st1.st_ino != st2.st_ino)
69 return pr_err("NS_GET_PARENT returned a wrong namespace");
71 if (ioctl(pns, NS_GET_PARENT) >= 0 || errno != EPERM)
72 return pr_err("Don't get EPERM");;