mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
@ 2006-01-29  6:18 Eric W. Biederman
  2006-01-29  8:36 ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Eric W. Biederman @ 2006-01-29  6:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

The weird things we do when we exec from a thread group are just ugly.
Those ugly things do not handle the case of init and I suspect
extending that code to properly support a threaded init would be just
hideous, and impossible to maintain. 

So just in case someone ever threads init return an error for the
unimplemented case.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>


---

 fs/exec.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

408dad0f2b7067b23929866150e73b2b2f12d662
diff --git a/fs/exec.c b/fs/exec.c
index 055378d..c9d8e31 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -600,6 +600,12 @@ static int de_thread(struct task_struct 
 	if (thread_group_empty(current))
 		goto no_thread_group;
 
+	/* A threaded init must exec from it's primary thread.
+	 * As the init task (i.e. child_reaper) may not exit.
+	 */
+	if (!thread_group_leader(current) && (current->tgid == 1))
+		return -EINVAL;
+	
 	/*
 	 * Kill all other threads in the thread group.
 	 * We must hold tasklist_lock to call zap_other_threads.
-- 
1.1.5.g3480


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29  6:18 [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader Eric W. Biederman
@ 2006-01-29  8:36 ` Andrew Morton
  2006-01-29 10:25   ` Eric W. Biederman
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2006-01-29  8:36 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: linux-kernel

ebiederm@xmission.com (Eric W. Biederman) wrote:
>
> The weird things we do when we exec from a thread group are just ugly.
> Those ugly things do not handle the case of init and I suspect
> extending that code to properly support a threaded init would be just
> hideous, and impossible to maintain. 
> 
> So just in case someone ever threads init return an error for the
> unimplemented case.
> 
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
> 
> 
> ---
> 
>  fs/exec.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> 408dad0f2b7067b23929866150e73b2b2f12d662
> diff --git a/fs/exec.c b/fs/exec.c
> index 055378d..c9d8e31 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -600,6 +600,12 @@ static int de_thread(struct task_struct 
>  	if (thread_group_empty(current))
>  		goto no_thread_group;
>  
> +	/* A threaded init must exec from it's primary thread.
> +	 * As the init task (i.e. child_reaper) may not exit.
> +	 */
> +	if (!thread_group_leader(current) && (current->tgid == 1))
> +		return -EINVAL;
> +	
>  	/*
>  	 * Kill all other threads in the thread group.
>  	 * We must hold tasklist_lock to call zap_other_threads.

hmm, this just looks like overhead.  If sometime someone _does_ try to
thread init, what will happen to them?  If it's something nice and nasty,
they'll just whine at us and stop doing that.  Same net effect, no runtime
cost.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29  8:36 ` Andrew Morton
@ 2006-01-29 10:25   ` Eric W. Biederman
  2006-01-29 10:48     ` Andrew Morton
  2006-01-30  9:15     ` Jan Engelhardt
  0 siblings, 2 replies; 10+ messages in thread
From: Eric W. Biederman @ 2006-01-29 10:25 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

Andrew Morton <akpm@osdl.org> writes:

>> 408dad0f2b7067b23929866150e73b2b2f12d662
>> diff --git a/fs/exec.c b/fs/exec.c
>> index 055378d..c9d8e31 100644
>> --- a/fs/exec.c
>> +++ b/fs/exec.c
>> @@ -600,6 +600,12 @@ static int de_thread(struct task_struct 
>>  	if (thread_group_empty(current))
>>  		goto no_thread_group;
>>  
>> +	/* A threaded init must exec from it's primary thread.
>> +	 * As the init task (i.e. child_reaper) may not exit.
>> +	 */
>> +	if (!thread_group_leader(current) && (current->tgid == 1))
>> +		return -EINVAL;
>> +	
>>  	/*
>>  	 * Kill all other threads in the thread group.
>>  	 * We must hold tasklist_lock to call zap_other_threads.
>
> hmm, this just looks like overhead.  If sometime someone _does_ try to
> thread init, what will happen to them?  If it's something nice and nasty,
> they'll just whine at us and stop doing that.  Same net effect, no runtime
> cost.

So threading init will work just fine.  The only case that will blow up
is calling exec from something that is not the thread group leader.
i.e.  If tgid == 1 but pid != 1 the kernel will cause pid == 1 to exit.

I think that will trigger a kernel panic.  It might just ensure that
no more processes are re-parented to init.  And we dereference a
bad pointer we look at child_reaper.  I haven't been brave enough
to try it.

The cost is only paid if you are a threaded task and you call exec.
Normal process never take that path, so we are already off of the
fast path.

The test when all expanded out is only:

if ((current->tgid == current->pid) && (current->tgid == 1))
	return -EINVAL

So it should be relatively cheap.


If process id namespaces become a reality init stops being
terribly special, and becomes something you may have several
of running at any one time.  If one of those inits is compromised
by a hostile user I having the whole system go down so we can
avoid executing a cheap test sounds terribly wrong.  That is
why I really care.

Eric

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29 10:25   ` Eric W. Biederman
@ 2006-01-29 10:48     ` Andrew Morton
  2006-01-29 15:24       ` Pavel Machek
  2006-01-30  9:15     ` Jan Engelhardt
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2006-01-29 10:48 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: linux-kernel

ebiederm@xmission.com (Eric W. Biederman) wrote:
>
>  If process id namespaces become a reality init stops being
>  terribly special, and becomes something you may have several
>  of running at any one time.  If one of those inits is compromised
>  by a hostile user I having the whole system go down so we can
>  avoid executing a cheap test sounds terribly wrong.  That is
>  why I really care.

Wouldn't it be better to do nothing until/unless there's some code in the
kernel or init which actually needs the change?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29 10:48     ` Andrew Morton
@ 2006-01-29 15:24       ` Pavel Machek
  2006-01-29 19:32         ` Andrew Morton
  2006-01-29 21:32         ` Eric W. Biederman
  0 siblings, 2 replies; 10+ messages in thread
From: Pavel Machek @ 2006-01-29 15:24 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Eric W. Biederman, linux-kernel

On Ne 29-01-06 02:48:31, Andrew Morton wrote:
> ebiederm@xmission.com (Eric W. Biederman) wrote:
> >
> >  If process id namespaces become a reality init stops being
> >  terribly special, and becomes something you may have several
> >  of running at any one time.  If one of those inits is compromised
> >  by a hostile user I having the whole system go down so we can
> >  avoid executing a cheap test sounds terribly wrong.  That is
> >  why I really care.
> 
> Wouldn't it be better to do nothing until/unless there's some code in the
> kernel or init which actually needs the change?

It is common to do init=/bin/bash, and I guess people are doing it
with all kinds of wonderful apps....
								Pavel
-- 
Thanks, Sharp!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29 15:24       ` Pavel Machek
@ 2006-01-29 19:32         ` Andrew Morton
  2006-01-29 21:32         ` Eric W. Biederman
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2006-01-29 19:32 UTC (permalink / raw)
  To: Pavel Machek; +Cc: ebiederm, linux-kernel

Pavel Machek <pavel@ucw.cz> wrote:
>
> On Ne 29-01-06 02:48:31, Andrew Morton wrote:
> > ebiederm@xmission.com (Eric W. Biederman) wrote:
> > >
> > >  If process id namespaces become a reality init stops being
> > >  terribly special, and becomes something you may have several
> > >  of running at any one time.  If one of those inits is compromised
> > >  by a hostile user I having the whole system go down so we can
> > >  avoid executing a cheap test sounds terribly wrong.  That is
> > >  why I really care.
> > 
> > Wouldn't it be better to do nothing until/unless there's some code in the
> > kernel or init which actually needs the change?
> 
> It is common to do init=/bin/bash, and I guess people are doing it
> with all kinds of wonderful apps....

err, good point.  And no reports of peculiar things happening with
threading.  Eric's check has the (slight) potential to cause some things to
stop working though.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29 15:24       ` Pavel Machek
  2006-01-29 19:32         ` Andrew Morton
@ 2006-01-29 21:32         ` Eric W. Biederman
  1 sibling, 0 replies; 10+ messages in thread
From: Eric W. Biederman @ 2006-01-29 21:32 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, linux-kernel

Pavel Machek <pavel@ucw.cz> writes:

> On Ne 29-01-06 02:48:31, Andrew Morton wrote:
>> ebiederm@xmission.com (Eric W. Biederman) wrote:
>> >
>> >  If process id namespaces become a reality init stops being
>> >  terribly special, and becomes something you may have several
>> >  of running at any one time.  If one of those inits is compromised
>> >  by a hostile user I having the whole system go down so we can
>> >  avoid executing a cheap test sounds terribly wrong.  That is
>> >  why I really care.
>> 
>> Wouldn't it be better to do nothing until/unless there's some code in the
>> kernel or init which actually needs the change?

Well I think deliberate kernel bugs should at least be accompanied by
a big fat warning in the code, and an explanation of what is happening
and why.

> It is common to do init=/bin/bash, and I guess people are doing it
> with all kinds of wonderful apps....

So it is just a matter of time before someone actually hits this.

I went back through and tested and the actual symptoms are weird.
The thread calling exec just hangs forever, waiting for pid == 1 to
exit.  Anyway I found a simple fix so it is probably better to fix
it than to paper over the problem anyway.

Patch follows in a minute.

Eric




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-29 10:25   ` Eric W. Biederman
  2006-01-29 10:48     ` Andrew Morton
@ 2006-01-30  9:15     ` Jan Engelhardt
  2006-01-30 20:41       ` Eric W. Biederman
  1 sibling, 1 reply; 10+ messages in thread
From: Jan Engelhardt @ 2006-01-30  9:15 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Andrew Morton, linux-kernel

>
>So threading init will work just fine.  The only case that will blow up
>is calling exec from something that is not the thread group leader.
>i.e.  If tgid == 1 but pid != 1 the kernel will cause pid == 1 to exit.

Should not it, at its best, replace the whole thread group by the new 
program and have things carry on?


Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader
  2006-01-30  9:15     ` Jan Engelhardt
@ 2006-01-30 20:41       ` Eric W. Biederman
  0 siblings, 0 replies; 10+ messages in thread
From: Eric W. Biederman @ 2006-01-30 20:41 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Andrew Morton, linux-kernel

Jan Engelhardt <jengelh@linux01.gwdg.de> writes:

>>
>>So threading init will work just fine.  The only case that will blow up
>>is calling exec from something that is not the thread group leader.
>>i.e.  If tgid == 1 but pid != 1 the kernel will cause pid == 1 to exit.
>
> Should not it, at its best, replace the whole thread group by the new 
> program and have things carry on?

You see the bug.

Eric


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] exec: Only allow a threaded init to exec from the  thread_group_leader
       [not found]   ` <5AhYT-4uR-7@gated-at.bofh.it>
@ 2006-01-29 13:36     ` Bodo Eggert
  0 siblings, 0 replies; 10+ messages in thread
From: Bodo Eggert @ 2006-01-29 13:36 UTC (permalink / raw)
  To: Eric W. Biederman, Andrew Morton, linux-kernel

Eric W. Biederman <ebiederm@xmission.com> wrote:

> If process id namespaces become a reality init stops being
> terribly special, and becomes something you may have several
> of running at any one time.  If one of those inits is compromised
> by a hostile user I having the whole system go down so we can
> avoid executing a cheap test sounds terribly wrong.  That is
> why I really care.

There are virtual environments like linux-vserver(.org), where init is
running several times on one system, each with their local/virtual
pid being 1. Killing them does no harm unless it's the real init.
I asume in your system,  the real init will exist under the control
of the administrator, too, so there should be no danger.
-- 
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-01-30 20:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-29  6:18 [PATCH] exec: Only allow a threaded init to exec from the thread_group_leader Eric W. Biederman
2006-01-29  8:36 ` Andrew Morton
2006-01-29 10:25   ` Eric W. Biederman
2006-01-29 10:48     ` Andrew Morton
2006-01-29 15:24       ` Pavel Machek
2006-01-29 19:32         ` Andrew Morton
2006-01-29 21:32         ` Eric W. Biederman
2006-01-30  9:15     ` Jan Engelhardt
2006-01-30 20:41       ` Eric W. Biederman
     [not found] <5AeeD-7xb-7@gated-at.bofh.it>
     [not found] ` <5Aggm-1V6-3@gated-at.bofh.it>
     [not found]   ` <5AhYT-4uR-7@gated-at.bofh.it>
2006-01-29 13:36     ` Bodo Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®