-
Notifications
You must be signed in to change notification settings - Fork 641
restore: do mount proc in usernsd on certain conditions #2600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: criu-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1445,19 +1445,41 @@ static int __legacy_mount_proc(void) | |
return fd; | ||
} | ||
|
||
static int mount_proc(void) | ||
static int userns_mount_proc(void *arg, int pid, int fd) | ||
{ | ||
int fd, ret; | ||
int ret; | ||
|
||
if (root_ns_mask == 0) | ||
fd = ret = open("/proc", O_DIRECTORY); | ||
ret = open("/proc", O_DIRECTORY); | ||
else { | ||
if (kdat.has_fsopen) | ||
fd = ret = mount_detached_fs("proc"); | ||
ret = mount_detached_fs("proc"); | ||
else | ||
fd = ret = __legacy_mount_proc(); | ||
ret = __legacy_mount_proc(); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
static int mount_proc(void) | ||
{ | ||
int fd, ret; | ||
|
||
/* | ||
* In most cases, self-mounting procfs in the containerized process will work. | ||
* But in the case where the process only has its isolated user namespace | ||
* but shares the mount namespace and pid namespace with the host, | ||
* it won't work due to the lack of privilege to do the proc-mount job. | ||
* A Userns call is needed to deal with such scenerios. | ||
* | ||
* See linux/fs/fsopen.c and linux/fs/proc/root.c for more info. | ||
* */ | ||
|
||
if ((root_ns_mask & CLONE_NEWUSER) && !(root_ns_mask & CLONE_NEWNS) && !(root_ns_mask & CLONE_NEWPID)) | ||
fd = ret = userns_call(userns_mount_proc, UNS_FDOUT, NULL, sizeof(NULL), -1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will it be mounted in the target pid namespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No i don't think it will be mounted and it's gonna be rejected. I fixed this now. The corner case is only when the user namespace is isolated while keeping both mount namespace and pid namespace be shared with host. If either of two namespaces are isolated, the proc fs will be mounted successfully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a target workload is restored in just separate userns and pid namespaces, userns_mount_proc will fail, because the current process doesn't have CAP_SYS_ADMIN in the current mount namespace. The only way to workaround that is to mount proc from usernsd, and the userns mount callback has to enter the target pid namespace before mounting proc. |
||
else | ||
fd = ret = userns_mount_proc(NULL, -1, -1); | ||
|
||
if (fd >= 0) { | ||
ret = set_proc_fd(fd); | ||
close(fd); | ||
|
Uh oh!
There was an error while loading. Please reload this page.