首页 > 解决方案 > 如何允许子进程创建嵌套的用户命名空间?

问题描述

我使用以下代码在新的用户命名空间中创建子进程:

pid_t child = syscall (SYS_clone, SIGCHLD | CLONE_NEWNS | CLONE_NEWUSER, NULL, NULL, NULL);

在父进程中,我编写uid_mapandgid_map并将当前的 uid 和 pid 映射到自身。

在子进程中,我将调用execvp启动一个新进程,该进程可能会调用unshare带有CLONE_NEWUSER标志,在新用户命名空间中不允许该操作。

我的问题是,是否可以允许对unshare由 启动的进程进行操作execvp

我按照user_namespace和使用手册页中的示例pipe来确保在调用uid_mapandgid_map之前编写。execvp

标签: clinuxkernel

解决方案


我猜你的映射不正确。从man 2 unshare,看起来你正在打这个:

       EPERM  CLONE_NEWUSER was specified in flags, but either  the  effective
              user  ID or the effective group ID of the caller does not have a
              mapping in the parent namespace (see user_namespaces(7)).

推荐阅读