namespace-util: add detach_mount_namespace_userns()
This commit is contained in:
@@ -262,6 +262,21 @@ int detach_mount_namespace_harder(uid_t target_uid, gid_t target_gid) {
|
||||
return detach_mount_namespace();
|
||||
}
|
||||
|
||||
int detach_mount_namespace_userns(int userns_fd) {
|
||||
int r;
|
||||
|
||||
assert(userns_fd >= 0);
|
||||
|
||||
if (setns(userns_fd, CLONE_NEWUSER) < 0)
|
||||
return log_debug_errno(errno, "Failed to join user namespace: %m");
|
||||
|
||||
r = reset_uid_gid();
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to become root in user namespace: %m");
|
||||
|
||||
return detach_mount_namespace();
|
||||
}
|
||||
|
||||
int userns_acquire_empty(void) {
|
||||
_cleanup_(sigkill_waitp) pid_t pid = 0;
|
||||
_cleanup_close_ int userns_fd = -EBADF;
|
||||
|
||||
@@ -35,6 +35,7 @@ int fd_is_ns(int fd, unsigned long nsflag);
|
||||
|
||||
int detach_mount_namespace(void);
|
||||
int detach_mount_namespace_harder(uid_t target_uid, gid_t target_gid);
|
||||
int detach_mount_namespace_userns(int userns_fd);
|
||||
|
||||
static inline bool userns_shift_range_valid(uid_t shift, uid_t range) {
|
||||
/* Checks that the specified userns range makes sense, i.e. contains at least one UID, and the end
|
||||
|
||||
Reference in New Issue
Block a user