All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/4] posix-timers: fix creation race
@ 2007-08-12 17:05 Oleg Nesterov
  2007-08-12 19:05 ` Thomas Gleixner
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2007-08-12 17:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ingo Molnar, Thomas Gleixner, linux-kernel, stable

sys_timer_create() sets ->it_process and unlocks ->siglock, then checks
tmr->it_sigev_notify to define if get_task_struct() is needed.

We already passed ->it_id to the caller, another thread can delete this
timer and free its memory in between.

As a minimal fix, move this code under ->siglock, sys_timer_delete() takes
it too before calling release_posix_timer(). A proper serialization would
be to take ->it_lock, we add a partly initialized timer on posix_timers_id,
not good.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- t/kernel/posix-timers.c~2_CREATE	2007-08-12 17:59:17.000000000 +0400
+++ t/kernel/posix-timers.c	2007-08-12 18:11:33.000000000 +0400
@@ -547,13 +547,12 @@ sys_timer_create(const clockid_t which_c
 				new_timer->it_process = process;
 				list_add(&new_timer->list,
 					 &process->signal->posix_timers);
-				spin_unlock_irqrestore(&process->sighand->siglock, flags);
 				if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
 					get_task_struct(process);
 			} else {
-				spin_unlock_irqrestore(&process->sighand->siglock, flags);
 				process = NULL;
 			}
+			spin_unlock_irqrestore(&process->sighand->siglock, flags);
 		}
 		read_unlock(&tasklist_lock);
 		if (!process) {


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

* Re: [PATCH 2/4] posix-timers: fix creation race
  2007-08-12 17:05 [PATCH 2/4] posix-timers: fix creation race Oleg Nesterov
@ 2007-08-12 19:05 ` Thomas Gleixner
  2007-08-12 19:44   ` Oleg Nesterov
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2007-08-12 19:05 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Ingo Molnar, linux-kernel, stable

On Sun, 2007-08-12 at 21:05 +0400, Oleg Nesterov wrote:
> sys_timer_create() sets ->it_process and unlocks ->siglock, then checks
> tmr->it_sigev_notify to define if get_task_struct() is needed.
> 
> We already passed ->it_id to the caller, another thread can delete this
> timer and free its memory in between.
> 
> As a minimal fix, move this code under ->siglock, sys_timer_delete() takes
> it too before calling release_posix_timer(). A proper serialization would
> be to take ->it_lock, we add a partly initialized timer on posix_timers_id,
> not good.
> 
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

Acked-by: Thomas Gleixner <tglx@linutronix.de>

> --- t/kernel/posix-timers.c~2_CREATE	2007-08-12 17:59:17.000000000 +0400
> +++ t/kernel/posix-timers.c	2007-08-12 18:11:33.000000000 +0400
> @@ -547,13 +547,12 @@ sys_timer_create(const clockid_t which_c
>  				new_timer->it_process = process;
>  				list_add(&new_timer->list,
>  					 &process->signal->posix_timers);
> -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
>  				if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
>  					get_task_struct(process);
>  			} else {
> -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
>  				process = NULL;
>  			}
> +			spin_unlock_irqrestore(&process->sighand->siglock, flags);
>  		}
>  		read_unlock(&tasklist_lock);
>  		if (!process) {
> 


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

* Re: [PATCH 2/4] posix-timers: fix creation race
  2007-08-12 19:05 ` Thomas Gleixner
@ 2007-08-12 19:44   ` Oleg Nesterov
  2007-08-12 19:59     ` Oleg Nesterov
  2007-08-13  7:35     ` Thomas Gleixner
  0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2007-08-12 19:44 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andrew Morton, Ingo Molnar, linux-kernel, stable

On 08/12, Thomas Gleixner wrote:
>
> On Sun, 2007-08-12 at 21:05 +0400, Oleg Nesterov wrote:
> > sys_timer_create() sets ->it_process and unlocks ->siglock, then checks
> > tmr->it_sigev_notify to define if get_task_struct() is needed.
> > 
> > We already passed ->it_id to the caller, another thread can delete this
> > timer and free its memory in between.
> > 
> > As a minimal fix, move this code under ->siglock, sys_timer_delete() takes
> > it too before calling release_posix_timer(). A proper serialization would
> > be to take ->it_lock, we add a partly initialized timer on posix_timers_id,
> > not good.
> > 
> > Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
> 
> Acked-by: Thomas Gleixner <tglx@linutronix.de>

Oooh, thanks, but...

> > --- t/kernel/posix-timers.c~2_CREATE	2007-08-12 17:59:17.000000000 +0400
> > +++ t/kernel/posix-timers.c	2007-08-12 18:11:33.000000000 +0400
> > @@ -547,13 +547,12 @@ sys_timer_create(const clockid_t which_c
> >  				new_timer->it_process = process;
> >  				list_add(&new_timer->list,
> >  					 &process->signal->posix_timers);
> > -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
> >  				if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
> >  					get_task_struct(process);
> >  			} else {
> > -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
> >  				process = NULL;
> >  			}
> > +			spin_unlock_irqrestore(&process->sighand->siglock, flags);

i'll resend this patch tomorrow. We can't do spin_unlock_irqrestore(&process->...)
if we set process = NULL above.

This all needs a cleanup anyway. The PF_EXITING check and related comment are
bogus.

Other patches do not depend on this one.

Oleg.


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

* Re: [PATCH 2/4] posix-timers: fix creation race
  2007-08-12 19:44   ` Oleg Nesterov
@ 2007-08-12 19:59     ` Oleg Nesterov
  2007-08-13  7:35     ` Thomas Gleixner
  1 sibling, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2007-08-12 19:59 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Andrew Morton, Ingo Molnar, linux-kernel, stable

On 08/12, Oleg Nesterov wrote:
>
> > > -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
> > >  				process = NULL;
> > >  			}
> > > +			spin_unlock_irqrestore(&process->sighand->siglock, flags);
> 
> i'll resend this patch tomorrow. We can't do spin_unlock_irqrestore(&process->...)
> if we set process = NULL above.

Another attempt, no cleanups, just a minimal fix for now.


[PATCH 2/4] posix-timers: fix creation race

sys_timer_create() sets ->it_process and unlocks ->siglock, then checks
tmr->it_sigev_notify to define if get_task_struct() is needed.

We already passed ->it_id to the caller, another thread can delete this
timer and free its memory in between.

As a minimal fix, move this code under ->siglock, sys_timer_delete() takes
it too before calling release_posix_timer(). A proper serialization would
be to take ->it_lock, we add a partly initialized timer on posix_timers_id,
not good.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- t/kernel/posix-timers.c~	2007-08-12 23:50:46.000000000 +0400
+++ t/kernel/posix-timers.c	2007-08-12 23:52:07.000000000 +0400
@@ -547,9 +547,9 @@ sys_timer_create(const clockid_t which_c
 				new_timer->it_process = process;
 				list_add(&new_timer->list,
 					 &process->signal->posix_timers);
-				spin_unlock_irqrestore(&process->sighand->siglock, flags);
 				if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
 					get_task_struct(process);
+				spin_unlock_irqrestore(&process->sighand->siglock, flags);
 			} else {
 				spin_unlock_irqrestore(&process->sighand->siglock, flags);
 				process = NULL;


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

* Re: [PATCH 2/4] posix-timers: fix creation race
  2007-08-12 19:44   ` Oleg Nesterov
  2007-08-12 19:59     ` Oleg Nesterov
@ 2007-08-13  7:35     ` Thomas Gleixner
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Gleixner @ 2007-08-13  7:35 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Andrew Morton, Ingo Molnar, linux-kernel, stable

On Sun, 2007-08-12 at 23:44 +0400, Oleg Nesterov wrote:
> > > --- t/kernel/posix-timers.c~2_CREATE	2007-08-12 17:59:17.000000000 +0400
> > > +++ t/kernel/posix-timers.c	2007-08-12 18:11:33.000000000 +0400
> > > @@ -547,13 +547,12 @@ sys_timer_create(const clockid_t which_c
> > >  				new_timer->it_process = process;
> > >  				list_add(&new_timer->list,
> > >  					 &process->signal->posix_timers);
> > > -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
> > >  				if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID))
> > >  					get_task_struct(process);
> > >  			} else {
> > > -				spin_unlock_irqrestore(&process->sighand->siglock, flags);
> > >  				process = NULL;
> > >  			}
> > > +			spin_unlock_irqrestore(&process->sighand->siglock, flags);
> 
> i'll resend this patch tomorrow. We can't do spin_unlock_irqrestore(&process->...)
> if we set process = NULL above.

Doh, half of my brain seems to be still on vacation.

	tglx



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

end of thread, other threads:[~2007-08-13 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-12 17:05 [PATCH 2/4] posix-timers: fix creation race Oleg Nesterov
2007-08-12 19:05 ` Thomas Gleixner
2007-08-12 19:44   ` Oleg Nesterov
2007-08-12 19:59     ` Oleg Nesterov
2007-08-13  7:35     ` Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.