nsjconf->iface_vs_gw = "0.0.0.0";
nsjconf->iface_vs_ma = "";
nsjconf->orig_uid = getuid();
+ nsjconf->orig_euid = geteuid();
nsjconf->num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
nsjconf->seccomp_fprog.filter = NULL;
nsjconf->seccomp_fprog.len = 0;
*/
if (!nsjconf->clone_newns) {
if (nsjconf->chroot.empty()) {
- PLOG_E(
- "--chroot was not specified, and it's required when not using "
- "CLONE_NEWNS");
- return false;
+ return true;
}
if (chroot(nsjconf->chroot.c_str()) == -1) {
PLOG_E("chroot('%s')", nsjconf->chroot.c_str());
return true;
}
-static bool setGroups(pid_t pid) {
+static bool setGroups(nsjconf_t* nsjconf, pid_t pid) {
/*
* No need to write 'deny' to /proc/pid/setgroups if our euid==0, as writing to
* uid_map/gid_map will succeed anyway
*/
- if (geteuid() == 0) {
+ if (!nsjconf->clone_newuser || nsjconf->orig_euid == 0) {
return true;
}
}
bool initNsFromParent(nsjconf_t* nsjconf, pid_t pid) {
- if (!setGroups(pid)) {
+ if (!setGroups(nsjconf, pid)) {
return false;
}
if (!nsjconf->clone_newuser) {
}
bool initNsFromChild(nsjconf_t* nsjconf) {
- /*
- * Best effort because of /proc/self/setgroups
- */
- LOG_D("setgroups(0, NULL)");
- const gid_t* group_list = NULL;
- if (setgroups(0, group_list) == -1) {
- PLOG_D("setgroups(NULL) failed");
+ if (!nsjconf->clone_newuser && nsjconf->orig_euid != 0) {
+ return true;
}
/*
return false;
}
+ /*
+ * Best effort because of /proc/self/setgroups
+ */
+ LOG_D("setgroups(0, NULL)");
+ const gid_t* group_list = NULL;
+ if (setgroups(0, group_list) == -1) {
+ PLOG_D("setgroups(NULL) failed");
+ }
+
if (!setResGid(nsjconf->gids[0].inside_id)) {
PLOG_E("setresgid(%u)", nsjconf->gids[0].inside_id);
return false;