From: Petr Vorel <pvorel@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/2] Implement tst_setup_netns() helper function
Date: Fri, 25 Nov 2022 18:01:31 +0100 [thread overview]
Message-ID: <Y4D066q2R/0S2xFe@pevik> (raw)
In-Reply-To: <20221125153453.19323-1-mdoucha@suse.cz>
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);
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-11-25 17:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-25 15:34 [LTP] [PATCH 1/2] Implement tst_setup_netns() helper function Martin Doucha
2022-11-25 15:34 ` [LTP] [PATCH 2/2] syscalls: Replace namespace setup boilerplate with tst_setup_netns() Martin Doucha
2022-11-25 16:43 ` [LTP] [PATCH 1/2] Implement tst_setup_netns() helper function Petr Vorel
2022-11-25 17:01 ` Petr Vorel [this message]
2022-11-25 17:09 ` Martin Doucha
2022-11-25 17:17 ` Petr Vorel
2022-11-25 17:20 ` Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y4D066q2R/0S2xFe@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
--cc=mdoucha@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox