小编Had*_*ski的帖子

为什么不允许非特权递归取消共享(CLONE_NEWUSER)?

我使用的是 Ubuntu 17.04。

挂载命名空间的单个非特权取消共享有效。您可以尝试使用 unshare(1) 命令:

$ unshare -m -U /bin/sh
#
Run Code Online (Sandbox Code Playgroud)

但是,不允许在取消共享中取消共享:

$ unshare -m -U /bin/sh
# unshare -m -U /bin/sh
unshare: Operation not permitted
#
Run Code Online (Sandbox Code Playgroud)

这是一个基本上执行相同操作的 C 程序:

#define _GNU_SOURCE
#include <stdio.h>
#include <sched.h>
#include <sys/mount.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    if(unshare(CLONE_NEWUSER|CLONE_NEWNS) == -1) {
        perror("unshare");
        return -1;
    }
    if(unshare(CLONE_NEWUSER|CLONE_NEWNS) == -1) {
        perror("unshare2");
        return -1;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么不允许?我在哪里可以找到有关此内容的文档?我未能在取消共享或克隆手册页以及内核取消共享文档中找到此信息。

是否有系统设置允许这样做?

我想要实现的目标:

第一次取消共享:我想用我自己的版本屏蔽系统上的一些二进制文件。

第二次取消共享:非特权 chroot。

c linux namespaces ubuntu-17.04

5
推荐指数
1
解决办法
4136
查看次数

标签 统计

c ×1

linux ×1

namespaces ×1

ubuntu-17.04 ×1