[LTP] [PATCH 1/2] Implement tst_setup_netns() helper function
Petr Vorel
pvorel@suse.cz
Fri Nov 25 18:01:31 CET 2022
Hi Martin,
> +void tst_setup_netns(void)
> +{
> + int real_uid = getuid();
> + int real_gid = getgid();
> + int nscount = 1;
> +
> + if (!access("/proc/sys/user/max_user_namespaces", F_OK)) {
Out of curiosity, this can happen only on old kernel, which does not support
user namespaces (kernel < 3.8) ? I guess there must be other case,
I suppose you would not bother about 3.8, right?
Also asking that if not readable we don't TCONF (int nscount = 1).
Kind regards,
Petr
> + SAFE_FILE_SCANF("/proc/sys/user/max_user_namespaces", "%d",
> + &nscount);
> + }
> +
> + if (!nscount)
> + tst_brk(TCONF, "User namespaces are disabled");
> +
> + SAFE_UNSHARE(CLONE_NEWUSER);
> + SAFE_UNSHARE(CLONE_NEWNET);
> + SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
> + SAFE_FILE_PRINTF("/proc/self/uid_map", "0 %d 1", real_uid);
> + SAFE_FILE_PRINTF("/proc/self/gid_map", "0 %d 1", real_gid);
> +}
More information about the ltp
mailing list