PATCH? fix unshare(NEWPID) && vfork()
Subsystems (3)
Hello.
Colin reports that vfork() doesn't work after unshare(PIDNS). The reason is trivial, copy_process() does:
/* * If the new process will be in a different pid namespace * don't allow the creation of threads. */ if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && (task_active_pid_ns(current) != current->nsproxy->pid_ns)) return ERR_PTR(-EINVAL);
and CLONE_VM obviously nacks vfork(). So perhaps we can relax this check to CLONE_THREAD? Or should we really nack CLONE_VM by security reasons?
OTOH. Perhaps we should also deny CLONE_PARENT in this case?
In short. So far I am thinking about the patch below but I got lost and totally confused. Will try to think more tomorrow, but I would like to see the fix from someone who still understands this all.
Oleg.
kernel/fork.c +3 -10
@@ -1172,14 +1172,6 @@ static struct task_struct *copy_process( current->signal->flags & SIGNAL_UNKILLABLE)return ERR_PTR (-EINVAL ); -/* -* If the new process will be in a different pid namespace -* don't allow the creation of threads. -*/ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && - (task_active_pid_ns (current) != current->nsproxy->pid_ns)) -return ERR_PTR (-EINVAL ); - retval =security_task_create (clone_flags);if (retval) goto fork_out;
@@ -1578,8 +1570,9 @@ long do_fork(unsigned long clone_flags,* Do some preliminary argument and permissions checking before we * actually start allocating stuff */ -if (clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) { -if (clone_flags & (CLONE_THREAD |CLONE_PARENT )) +if ((clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) || + (task_active_pid_ns (current) != current->nsproxy->pid_ns)) { +if (clone_flags & (CLONE_THREAD |CLONE_PARENT |CLONE_NEWPID ))return -EINVAL ; }
Quoted 12 lines · Oleg Nesterov
Colin reports that
vfork()doesn't work after unshare(PIDNS). The reason is trivial,copy_process()does:/* * If the new process will be in a different pid namespace * don't allow the creation of threads. */ if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && (task_active_pid_ns(current) != current->nsproxy->pid_ns)) return ERR_PTR(-EINVAL);
Quoted 5 lines
and
CLONE_VMobviously nacksvfork(). So perhaps we can relax this check toCLONE_THREAD? Or should we really nackCLONE_VMby security reasons?OTOH. Perhaps we should also deny
CLONE_PARENTin this case?
I agree that we should probably deny CLONE_PARENT, which makes more sense paired with CLONE_NEWPID. I think we should also disallow CLONE_THREAD, which is the thread goup.
And I *think* we can drop CLONE_VM. I suspect that snuck in as a (misguided) attempt at CLONE_THREAD, as implied by the comment.
In fact, if you go look at the history of that CLONE_VM test, it came from
unshare(CLONE_NEWPID)
clone(CLONE_THREAD|CLONE_SIGHAND|CLONE_VM)
and the commit message talks about not setting pid_ns->child_reaper. Which is very much about the PID, not about the shared VM space.
So I think your patch is correct, although I'm not sure why you move the test. The new test you have look complicated as hell, so I think you're actually making things worse by making them unreadable.
Linus
Quoted 3 lines · Linus Torvalds
So I think your patch is correct, although I'm not sure why you move the test.
I didn't really, we have 2 tests, in do_fork() and copy_process(). I think it would be better to do the similar checks in one place.
This is off-topic and needs a separate change anyway, but perhaps we should add the new helper which checks clone_flags. copy_process() is huge.
Quoted 2 lines
The new test you have look complicated as hell, so I think you're actually making things worse by making them unreadable.
Oh I agree. I'll wait for the comments on intent, then try to cleanup it somehow. Unless a better fix comes.
Oleg.
Quoted 17 lines · Oleg Nesterov
Hello.
Colin reports that
vfork()doesn't work after unshare(PIDNS). The reason is trivial,copy_process()does:/* * If the new process will be in a different pid namespace * don't allow the creation of threads. */ if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && (task_active_pid_ns(current) != current->nsproxy->pid_ns)) return ERR_PTR(-EINVAL);and
CLONE_VMobviously nacksvfork(). So perhaps we can relax this check toCLONE_THREAD? Or should we really nackCLONE_VMby security reasons?
Quoted 8 lines
OTOH. Perhaps we should also deny
CLONE_PARENTin this case?In short. So far I am thinking about the patch below but I got lost and totally confused. Will try to think more tomorrow, but I would like to see the fix from someone who still understands this all.
Oleg.
By way of (partial) explanation:
http://marc.info/?l=linux-kernel&m=135545831607095
(tl;dr: I think that CLONE_VM is irrelevant here, but there may be other issues lurking around.)
--Andy
Quoted 31 lines
kernel/fork.c 2013-08-19 19:03:43.848823039 +0200 renamed from kernel/fork.c 2013-08-14 18:34:06.000000000 +0200 +3
-10@@ -1172,14 +1172,6 @@ static struct task_struct *copy_process( current->signal->flags & SIGNAL_UNKILLABLE) return ERR_PTR(-EINVAL); - /* - * If the new process will be in a different pid namespace - * don't allow the creation of threads. - */ - if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && - (task_active_pid_ns(current) != current->nsproxy->pid_ns)) - return ERR_PTR(-EINVAL); - retval = security_task_create(clone_flags); if (retval) goto fork_out;@@ -1578,8 +1570,9 @@ long do_fork(unsigned long clone_flags, * Do some preliminary argument and permissions checking before we * actually start allocating stuff */ - if (clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) { - if (clone_flags & (CLONE_THREAD|CLONE_PARENT)) + if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) || + (task_active_pid_ns(current) != current->nsproxy->pid_ns)) { + if (clone_flags & (CLONE_THREAD | CLONE_PARENT | CLONE_NEWPID)) return -EINVAL; }
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Quoted 26 lines · Andy Lutomirski
Quoted 24 lines · Oleg Nesterov
Hello.
Colin reports that
vfork()doesn't work after unshare(PIDNS). The reason is trivial,copy_process()does:/* * If the new process will be in a different pid namespace * don't allow the creation of threads. */ if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && (task_active_pid_ns(current) != current->nsproxy->pid_ns)) return ERR_PTR(-EINVAL);and
CLONE_VMobviously nacksvfork(). So perhaps we can relax this check toCLONE_THREAD? Or should we really nackCLONE_VMby security reasons?OTOH. Perhaps we should also deny
CLONE_PARENTin this case?In short. So far I am thinking about the patch below but I got lost and totally confused. Will try to think more tomorrow, but I would like to see the fix from someone who still understands this all.
Quoted 5 lines
Quoted 1 line
Oleg.
By way of (partial) explanation:
Thanks... too late for me to even try to read this discussion today.
and I am a bit confused,
Quoted 2 lines
(tl;dr: I think that
CLONE_VMis irrelevant here, but there may be other issues lurking around.)
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
Oleg.
Quoted 35 lines · Oleg Nesterov
Quoted 26 lines · Andy Lutomirski
Quoted 24 lines · Oleg Nesterov
Hello.
Colin reports that
vfork()doesn't work after unshare(PIDNS). The reason is trivial,copy_process()does:/* * If the new process will be in a different pid namespace * don't allow the creation of threads. */ if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) && (task_active_pid_ns(current) != current->nsproxy->pid_ns)) return ERR_PTR(-EINVAL);and
CLONE_VMobviously nacksvfork(). So perhaps we can relax this check toCLONE_THREAD? Or should we really nackCLONE_VMby security reasons?OTOH. Perhaps we should also deny
CLONE_PARENTin this case?In short. So far I am thinking about the patch below but I got lost and totally confused. Will try to think more tomorrow, but I would like to see the fix from someone who still understands this all.
Quoted 5 lines
Quoted 1 line
Oleg.
By way of (partial) explanation:
Thanks... too late for me to even try to read this discussion today.
Quoted 7 lines
and I am a bit confused,
Quoted 2 lines
(tl;dr: I think that
CLONE_VMis irrelevant here, but there may be other issues lurking around.)So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the CLONE_VM check is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.
--Andy
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.
OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in do_fork().
Oleg.
kernel/fork.c +1 -1
@@ -1176,7 +1176,7 @@ static struct task_struct *copy_process(* If the new process will be in a different pid namespace * don't allow the creation of threads. */ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && +if ((clone_flags & (CLONE_THREAD |CLONE_PARENT |CLONE_NEWPID )) && (task_active_pid_ns (current) != current->nsproxy->pid_ns))return ERR_PTR (-EINVAL );
Quoted 7 lines · Oleg Nesterov
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
Quoted 8 lines
Quoted 3 lines
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().
The patch below also needs CLONE_SIGHAND. You can't meaningfully share signal handlers if you can't represent the pid in the siginfo. pids and signals are too interconnected.
Eric
Quoted 13 lines
Oleg.
kernel/fork.c +1
-1@@ -1176,7 +1176,7 @@ static struct task_struct *copy_process(* If the new process will be in a different pid namespace * don't allow the creation of threads. */ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && +if ((clone_flags & (CLONE_THREAD |CLONE_PARENT |CLONE_NEWPID )) && (task_active_pid_ns (current) != current->nsproxy->pid_ns))return ERR_PTR (-EINVAL );
Quoted 14 lines · Eric W. Biederman
Quoted 11 lines · Oleg Nesterov
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.
Quoted 8 lines
Quoted 4 lines
OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().The patch below also needs
CLONE_SIGHAND. You can't meaningfully share signal handlers if you can't represent the pid in the siginfo. pids and signals are too interconnected.
I don't really understand. If we allow to share ->mm (with this patch), why it is bad to share sighand_struct->action[] ? This only shares the pointers to the code which handles a signal.
However I agree it probably makes sense to deny it "just in case", I do not think CLONE_SIGHAND can be useful in this case.
But then we should also deny CLONE_SIGHAND if CLONE_NEWUSER|CLONE_NEWPID (another check in do_fork()). Which makes me think again we should unify these 2 checks.
Oleg.
Quoted 20 lines · Oleg Nesterov
Quoted 19 lines · Eric W. Biederman
Quoted 15 lines · Oleg Nesterov
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().
Quoted 7 lines
Quoted 3 lines
The patch below also needs
CLONE_SIGHAND. You can't meaningfully share signal handlers if you can't represent the pid in the siginfo. pids and signals are too interconnected.I don't really understand. If we allow to share ->mm (with this patch), why it is bad to share sighand_struct->action[] ? This only shares the pointers to the code which handles a signal.
Not the signal queues? I guess it is only CLONE_THREAD that shares the
signal queues between tasks.
The practical problem I am worried about with signals is in __send_signal and the lead up to send signal, pids and uids are stored in the struct siginfo in the namespace of the destination task. If that destination task shares the signal queues we can not possibly store the proper information.
I believe that sharing just the signal handlers between tasks is also a problem because while in principle you could distinguish the signals. In practice it will require at least an extra system call to do so.
Quoted 2 lines
However I agree it probably makes sense to deny it "just in case", I do not think
CLONE_SIGHANDcan be useful in this case.
I agree. The only CLONE_VM case I can imagine being useful is vfork().
Quoted 3 lines
But then we should also deny
CLONE_SIGHANDif CLONE_NEWUSER|CLONE_NEWPID (another check indo_fork()). Which makes me think again we should unify these 2 checks.
I agree CLONE_SIGHAND if CLONE_NEWUSER|CLONE_NEWPID.
As for unifying them. I can see colocating the related checks to keep everything together. I don't know about unifying them.
I know I get a little dizzy when trying to think of all of the possible orderings of unshare and clone that can result in problem cases.
Hmm. Thinking a little more I am half sold on unification. If we just handle the pid namespace by itself. And we handle the user namespace by itself I think things make sense.
So I am thinking something like the diff below. CLONE_SIGHAND as in theory you can figure out which task you are in and sort it out, although I don't expect that to happen in practice.
Eric
kernel/fork.c +16 -7
@@ -1172,12 +1172,21 @@ static struct task_struct *copy_process(unsigned long clone_flags, current->signal->flags & SIGNAL_UNKILLABLE)return ERR_PTR (-EINVAL ); +/* Dissallow unshare(CLONE_NEWPID) ; clone(CLONE_NEWPID). +* That can result in a possibly empty parent pid namespace +* which makes no sense. +*/ +if ((clone_flags &CLONE_NEWPID ) && +task_active_pid_ns (current) != current->nsproxy->pid_ns) +return ERR_PTR (-EINVAL ); +/* * If the new process will be in a different pid namespace -* don't allow the creation of threads. +* don't allow the problematic sharing. */ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && - (task_active_pid_ns (current) != current->nsproxy->pid_ns)) +if ((clone_flags & (CLONE_THREAD |CLONE_SIGHAND |CLONE_PARENT )) && + ((clone_flags &CLONE_NEWPID ) || + (task_active_pid_ns(current) != current->nsproxy->pid_ns))return ERR_PTR (-EINVAL ); retval =security_task_create (clone_flags);
@@ -1578,8 +1587,8 @@ long do_fork(unsigned long clone_flags,* Do some preliminary argument and permissions checking before we * actually start allocating stuff */ -if (clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) { -if (clone_flags & (CLONE_THREAD |CLONE_PARENT )) +if (clone_flags & (CLONE_NEWUSER )) { +if (clone_flags & (CLONE_THREAD |CLONE_PARENT |CLONE_SIGHAND ))return -EINVAL ; }
@@ -1816,12 +1825,12 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)* If unsharing a user namespace must also unshare the thread. */ if (unshare_flags &CLONE_NEWUSER ) - unshare_flags |=CLONE_THREAD |CLONE_FS ; + unshare_flags |=CLONE_THREAD |CLONE_FS |CLONE_SIGHAND ;/* * If unsharing a pid namespace must also unshare the thread. */ if (unshare_flags &CLONE_NEWPID ) - unshare_flags |=CLONE_THREAD ; + unshare_flags |=CLONE_THREAD |CLONE_SIGHAND ;/* * If unsharing a thread from a thread group, must also unshare vm. */
Quoted 8 lines · Eric W. Biederman
Quoted 5 lines · Oleg Nesterov
Quoted 4 lines
The patch below also needs
CLONE_SIGHAND. You can't meaningfully share signal handlers if you can't represent the pid in the siginfo. pids and signals are too interconnected.
Quoted 6 lines
Quoted 3 lines
I don't really understand. If we allow to share ->mm (with this patch), why it is bad to share sighand_struct->action[] ? This only shares the pointers to the code which handles a signal.
Not the signal queues? I guess it is only
CLONE_THREADthat shares the
signal queues between tasks.
Yes, and we should nack CLONE_THREAD anyway.
Quoted 3 lines
I believe that sharing just the signal handlers between tasks is also a problem because while in principle you could distinguish the signals. In practice it will require at least an extra system call to do so.
I still do not think this is a problem. If nothing else they share the code, the fact that they also share the entry point for the signal handler is not relevant, I think. And they share it anyway until the child or parent does sigaction().
But this doesn't matter, we both agree that it would be better to deny CLONE_SIGHAND anyway.
Quoted 3 lines
So I am thinking something like the diff below.
CLONE_SIGHANDas in theory you can figure out which task you are in and sort it out, although I don't expect that to happen in practice.
Well, I do not really mind. And I won't argue if you submit this patch.
But can't we at least move this CLONE_NEWUSER to copy_process? closer to other clone_flags checks.
As for your patch,
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* Dissallow unshare(CLONE_NEWPID) ; clone(CLONE_NEWPID). + * That can result in a possibly empty parent pid namespace + * which makes no sense. + */ + if ((clone_flags & CLONE_NEWPID) && + task_active_pid_ns(current) != current->nsproxy->pid_ns) + return ERR_PTR(-EINVAL);
This looks unneeded... copy_pid_ns() should fail in this case, no?
Review
Quoted 3 lines
(quoted diff) +2
-0+ if ((clone_flags & (CLONE_THREAD|CLONE_SIGHAND|CLONE_PARENT)) && + if (clone_flags & (CLONE_THREAD | CLONE_PARENT | CLONE_SIGHAND))
This doesn't really matter, but CLONE_THREAD can be omitted.
Still. Can't we make a single check? Like the initial patch I sent, but this one moves the check into copy_process() and checks CLONE_* first. Looks a bit simpler. And more understandable to me but this is subjective.
But once again, I won't argue, it's up to you.
Oleg.
kernel/fork.c +6 -14
@@ -1173,12 +1173,13 @@ static struct task_struct *copy_process(return ERR_PTR (-EINVAL );/* -* If the new process will be in a different pid namespace -* don't allow the creation of threads. +* -------------- COMMENT ----------------- */ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && - (task_active_pid_ns (current) != current->nsproxy->pid_ns)) -return ERR_PTR (-EINVAL ); +if (clone_flags & (CLONE_SIGHAND |CLONE_PARENT )) { +if ((clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) || + (task_active_pid_ns (current) != current->nsproxy->pid_ns)) +return -EINVAL ; + } retval =security_task_create (clone_flags);if (retval)
@@ -1575,15 +1576,6 @@ long do_fork(unsigned long clone_flags,long nr;/* -* Do some preliminary argument and permissions checking before we -* actually start allocating stuff -*/ -if (clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) { -if (clone_flags & (CLONE_THREAD |CLONE_PARENT )) -return -EINVAL ; - } - -/* * Determine whether and which event to report to ptracer. When * called from kernel_thread or CLONE_UNTRACED is explicitly * requested, no event is reported; otherwise, report if the event
Quoted 4 lines · Oleg Nesterov
Still. Can't we make a single check? Like the initial patch I sent, but this one moves the check into
copy_process()and checks CLONE_* first. Looks a bit simpler. And more understandable to me but this is subjective.
Seriously. CLONE_NEWPID and task_active_pid_ns() != nsproxy->pid_ns are the same thing in this respect. Let me send the patches for review, I decided to split this change.
Quoted 7 lines
kernel/fork.c +0
-1@@ -1173,12 +1173,13 @@ static struct task_struct *copy_process(return ERR_PTR (-EINVAL );/* -* If the new process will be in a different pid namespace
kernel/fork.c static struct task_struct *copy_process( · line 1181
Quoted 10 lines
kernel/fork.c +5
-4-* don't allow the creation of threads. +* -------------- COMMENT ----------------- */ -if ((clone_flags & (CLONE_VM |CLONE_NEWPID )) && - (task_active_pid_ns (current) != current->nsproxy->pid_ns)) -return ERR_PTR (-EINVAL ); +if (clone_flags & (CLONE_SIGHAND |CLONE_PARENT )) { +if ((clone_flags & (CLONE_NEWUSER |CLONE_NEWPID )) || + (task_active_pid_ns (current) != current->nsproxy->pid_ns)) +return -EINVAL ;
^^^^^^
should be ERR_PTR(-EINVAL)
Oleg.
Quoted 7 lines · Oleg Nesterov
Quoted 6 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
Quoted 8 lines
Quoted 3 lines
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().
I was confused.
Currently (with or without your patch), vfork() followed by unshare(CLONE_NEWUSER) or unshare(CLONE_NEWPID) will unshare the VM. This may be surprising, but at least it will work.
--Andy
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Oleg Nesterov
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.
Quoted 6 lines
Quoted 4 lines
OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().I was confused.
Andy, I do not know how much you were confused, but I bet I am confused much more ;)
Quoted 2 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.
Could you spell please?
We never unshare the VM. CLONE_VM in sys_unshare() paths just means "fail unless ->mm is not shared".
Oleg.
Quoted 24 lines · Oleg Nesterov
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Oleg Nesterov
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.Quoted 6 lines
Quoted 4 lines
OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().I was confused.
Andy, I do not know how much you were confused, but I bet I am confused much more ;)
Quoted 8 lines
Quoted 2 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.Could you spell please?
We never unshare the VM.
CLONE_VMinsys_unshare()paths just means "fail unless ->mm is not shared".
Argh. In that case this is probably buggy, and I am just as confused as you. This stuff is serious spaghetti code.
sys_unshare will see CLONE_NEWPID or CLONE_NEWUSER and set CLONE_THREAD. Then it will see CLONE_THREAD and set CLONE_VM. Then check_unshare_flags will see CLONE_VM and fail if we just called vfork.
Could this be made much more comprehensible by having a single list of shareable things are allowed to be shared across namespaces and enforcing the *same* list in clone and unshare?
--Andy
Quoted 2 lines
Oleg.
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines · Oleg Nesterov
Quoted 3 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.
Quoted 7 lines
Quoted 5 lines
Could you spell please?
We never unshare the VM.
CLONE_VMinsys_unshare()paths just means "fail unless ->mm is not shared".Argh. In that case this is probably buggy,
I don't think so. Just we can't really unshare ->mm or implement unshare(CLONE_THREAD). We simply pretend it works if there is nothing to unshare.
Quoted 2 lines
sys_unsharewill seeCLONE_NEWPIDorCLONE_NEWUSERand setCLONE_THREAD. Then it will seeCLONE_THREADand setCLONE_VM.
This matches copy_process() to some degree... but looks confusing, I agree.
Quoted 3 lines
Could this be made much more comprehensible by having a single list of shareable things are allowed to be shared across namespaces and enforcing the *same* list in clone and unshare?
Not sure...
but at least we can probably simplify this a little bit. Say, we can just kill
if (unshare_flags & CLONE_THREAD) unshare_flags |= CLONE_VM;
Oleg.
Quoted 19 lines · Oleg Nesterov
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines · Oleg Nesterov
Quoted 3 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.Quoted 7 lines
Quoted 5 lines
Could you spell please?
We never unshare the VM.
CLONE_VMinsys_unshare()paths just means "fail unless ->mm is not shared".Argh. In that case this is probably buggy,
I don't think so. Just we can't really unshare ->mm or implement
unshare(CLONE_THREAD). We simply pretend it works if there is nothing to unshare.
Quoted 5 lines
Quoted 2 lines
sys_unsharewill seeCLONE_NEWPIDorCLONE_NEWUSERand setCLONE_THREAD. Then it will seeCLONE_THREADand setCLONE_VM.This matches
copy_process()to some degree... but looks confusing, I agree.
Huh? Doesn't this mean that unshare(CLONE_NEWPID); vfork() will work with your patches, but vfork(); unshare(CLONE_NEWPID) will fail? (I admit I haven't tested it.)
--Andy
Quoted 11 lines · Andy Lutomirski
Quoted 9 lines · Oleg Nesterov
Quoted 8 lines · Andy Lutomirski
Quoted 6 lines · Oleg Nesterov
Quoted 3 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.Could you spell please?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
We never unshare the VM.
CLONE_VMinsys_unshare()paths just means "fail unless ->mm is not shared".Argh. In that case this is probably buggy,
I don't think so. Just we can't really unshare ->mm
this looks confusing, sorry. Afaics it is possible to implement unshare(CLONE_VM), but
Quoted 2 lines
or implement
Quoted 1 line
unshare(CLONE_THREAD).
this is unlikely.
but this doesn't matter,
Quoted 8 lines
We simply pretend it works if there is nothing
Quoted 7 lines
to unshare.
Quoted 2 lines
sys_unsharewill seeCLONE_NEWPIDorCLONE_NEWUSERand setCLONE_THREAD. Then it will seeCLONE_THREADand setCLONE_VM.This matches
copy_process()to some degree... but looks confusing, I agree.
I only mean that copy_process() requires CLONE_VM if CLONE_THREAD. But, unlike unshare(), it fails if CLONE_VM is not set.
Quoted 2 lines
Huh? Doesn't this mean that
unshare(CLONE_NEWPID);vfork()will work with your patches,
I hope,
Quoted 2 lines
but
vfork();unshare(CLONE_NEWPID)will fail? (I
admit I haven't tested it.)
Do you mean that the child does unshare(CLONE_NEWPID) before exec? It should fail with or without this patch.
Oleg.
Quoted 7 lines · Oleg Nesterov
Quoted 5 lines · Andy Lutomirski
Quoted 1 line · Oleg Nesterov
On 08/20, Andy Lutomirski wrote:
Huh? Doesn't this mean that
unshare(CLONE_NEWPID);vfork()will work with your patches,
Quoted 8 lines
I hope,
Quoted 2 lines
but
vfork();unshare(CLONE_NEWPID)will fail? (I
admit I haven't tested it.)Do you mean that the child does
unshare(CLONE_NEWPID)before exec? It should fail with or without this patch.
Exactly. Shouldn't it succeed?
--Andy
Quoted 11 lines · Andy Lutomirski
Quoted 7 lines · Oleg Nesterov
Quoted 3 lines
but
vfork();unshare(CLONE_NEWPID)will fail? (I
admit I haven't tested it.)Do you mean that the child does
unshare(CLONE_NEWPID)before exec? It should fail with or without this patch.Exactly. Shouldn't it succeed?
Ah, I am starting to understand... Sorry, I thought that you were arguing with the patch I sent.
Yes, perhaps you are right... But this is another isssue, and needs another change and another discussion. Afaics, we only need to change the "clone_flags" checks in sys_unshare().
Oleg.
Quoted 37 lines · Andy Lutomirski
Quoted 24 lines · Oleg Nesterov
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Oleg Nesterov
Quoted 9 lines · Andy Lutomirski
Quoted 3 lines · Oleg Nesterov
So do you think this change is fine or not (ignoring the fact it needs cleanups) ?
I think that removing the
CLONE_VMcheck is fine (although there are some other ones that should probably be removed as well), but I'm not sure if that check needs replacing with something else.Quoted 6 lines
Quoted 4 lines
OK, thanks... but I still can't understand.
The patch I sent is equivalent to the new one below. I just tried to unify it with another check in
do_fork().I was confused.
Andy, I do not know how much you were confused, but I bet I am confused much more ;)
Quoted 8 lines
Quoted 2 lines
Currently (with or without your patch),
vfork()followed byunshare(CLONE_NEWUSER)orunshare(CLONE_NEWPID)will unshare the VM.Could you spell please?
We never unshare the VM.
CLONE_VMinsys_unshare()paths just means "fail unless ->mm is not shared".Argh. In that case this is probably buggy, and I am just as confused as you. This stuff is serious spaghetti code.
Quoted 8 lines
sys_unsharewill seeCLONE_NEWPIDorCLONE_NEWUSERand setCLONE_THREAD. Then it will seeCLONE_THREADand setCLONE_VM. Thencheck_unshare_flagswill seeCLONE_VMand fail if we just called vfork.Could this be made much more comprehensible by having a single list of shareable things are allowed to be shared across namespaces and enforcing the *same* list in clone and unshare?
Having a single function would be nice.
Unforutunately the logic is different (unshare attempts to silently add the flags you need to make it work) and clone only unshares what you tell it too.
Even more than that the meaning of half of the bits changes meaning between unshare and clone.
For clone CLONE_VM means don't generate a new VM.
For unshare CLONE_VM means generate a new VM.
As for reorganizing shrug. It is always possible to make things better but clone doesn't look too scary to me.
Eric