Re: [PATCH] Fix signal race during process exit

From: Jeremy Kerr
Date: Wed Jun 02 2004 - 03:19:25 EST


> Andrew Morton <akpm@xxxxxxxx> wrote:
> > yes?
>
> no. It needs tasklist_lock as well, to keep the other CPU (which is doing
> wait4) at bay.

almost:

> + tsk->it_virt_incr = 0;
> + tsk->it_prof_value = 0;

If we're using this approach, we also need to deal with the send_sig() calls
in do_process_times():

if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
/* Send SIGXCPU every second.. */
if (!(psecs % HZ))
send_sig(SIGXCPU, p, 1);
/* and SIGKILL when we go over max.. */
if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_max)
send_sig(SIGKILL, p, 1);
}

by setting rlim_cur to RLIM_INFINITY.



Fix a race identified by Jeremy Kerr <jeremy@xxxxxxxxxxxxxxxxxxxxxx>: if
update_process_times() decides to deliver a signal due to process timer
expiry, it can race with __exit_sighand()'s freeing of task->sighand.

Fix that by clearing the per-process timer state in exit_notify(), while under
local_irq_disable() and under tasklist_lock. tasklist_lock provides exclusion
wrt release_task()'s freeing of task->sighand and local_irq_disable() provides
exclusion wrt update_process_times()'s inspection of the per-process timer
state.

Signed-off-by: Andrew Morton <akpm@xxxxxxxx>
Signed-off-by: Jeremy Kerr <jk@xxxxxxxxxx>


diff -urN --exclude '.*.sw[op]' linux-2.6.7-rc2-bk2.orig/kernel/exit.c
linux-2.6.7-rc2-bk2/kernel/exit.c
--- linux-2.6.7-rc2-bk2.orig/kernel/exit.c 2004-06-02 11:29:13.000000000 +1000
+++ linux-2.6.7-rc2-bk2/kernel/exit.c 2004-06-02 18:02:05.000000000 +1000
@@ -736,6 +736,14 @@
tsk->state = state;
tsk->flags |= PF_DEAD;

+ /*
+ * Clear these here so that update_process_times() won't try to deliver
+ * itimer, profile or rlimit signals to this task while it is in late exit.
+ */
+ tsk->it_virt_incr = 0;
+ tsk->it_prof_value = 0;
+ tsk->rlim[RLIMIT_CPU].rlim_cur = RLIM_INFINITY;
+
/*
* In the preemption case it must be impossible for the task
* to get runnable again, so use "_raw_" unlock to keep



Jeremy







-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/