Skip to contentSkip to conversation

Fix race condition in wait with thread groups

PATCH New Dave McCracken 1 participant 1 message Nov 6, 2001 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix race condition in wait with thread groups

There is code in sys_wait4() that makes a task wait for the children of all members of the thread group. This code has a race condition when more than one task in a thread group calls wait. Once it has picked a zomebie task to return it drops the tasklist lock before it calls release_task(). This allows another task to select the same zombie to clean up.

My fix for this race condition is to set the zombie task's state to a different value before the tasklist lock is released. This means no other waiting task will select it. There could be other ways of marking a task as already selected for cleanup, but this seemed the simplest.

The patch is appended below. It applies cleanly to 2.4.14

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

-------------------------

kernel/exit.c +3 -0
@@ -534,6 +534,9 @@
 				}
 				goto end_wait4;
 			case TASK_ZOMBIE:
+				/* Make sure no other waiter picks this task up */
+				p->state = TASK_DEAD;
+
 				current->times.tms_cutime += p->times.tms_utime + p->times.tms_cutime;
 				current->times.tms_cstime += p->times.tms_stime + p->times.tms_cstime;
 				read_unlock(&tasklist_lock);
include/linux/sched.h +1 -0
@@ -88,6 +88,7 @@
 #define TASK_UNINTERRUPTIBLE	2
 #define TASK_ZOMBIE		4
 #define TASK_STOPPED		8
+#define TASK_DEAD		16
 
 #define __set_task_state(tsk, state_value)		\
 	do { (tsk)->state = (state_value); } while (0)