Skip to contentSkip to conversation

check_process_timers: fix possible lockup

PATCH In review Oleg Nesterov 2 participants 2 messages Jun 15, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 check_process_timers: fix possible lockup

If the local timer interrupt happens just after do_exit() sets PF_EXITING (and before it clears ->it_xxx_expires) run_posix_cpu_timers() will call check_process_timers() with tasklist_lock + ->siglock held and

	check_process_timers:

		t = tsk;
		do {
			....

			do {
				t = next_thread(t);
			} while (unlikely(t->flags & PF_EXITING));
		} while (t != tsk);

the outer loop will never stop.

Actually, the window is bigger. Another process can attach the timer after ->it_xxx_expires was cleared (see the patch 2/3) and the 'if (PF_EXITING)' check in arm_timer() is racy (see the patch 3/3).

kernel/posix-cpu-timers.c renamed from kernel/posix-cpu-timers.c~1_CPT +4 -5
@@ -1173,6 +1173,9 @@ static void check_process_timers(struct 
 		}
 		t = tsk;
 		do {
+			if (unlikely(t->flags & PF_EXITING))
+				continue;
+
 			ticks = cputime_add(cputime_add(t->utime, t->stime),
 					    prof_left);
 			if (!cputime_eq(prof_expires, cputime_zero) &&
@@ -1193,11 +1196,7 @@ static void check_process_timers(struct 
 					      t->it_sched_expires > sched)) {
 				t->it_sched_expires = sched;
 			}
-
-			do {
-				t = next_thread(t);
-			} while (unlikely(t->flags & PF_EXITING));
-		} while (t != tsk);
+		} while ((t = next_thread(t)) != tsk);
 	}
 }
 
#1 lore raw
Quoted 15 lines · Oleg Nesterov

If the local timer interrupt happens just after do_exit() sets PF_EXITING (and before it clears ->it_xxx_expires) run_posix_cpu_timers() will call check_process_timers() with tasklist_lock + ->siglock held and

	check_process_timers:

		t = tsk;
		do {
			....

			do {
				t = next_thread(t);
			} while (unlikely(t->flags & PF_EXITING));
		} while (t != tsk);
Quoted 1 line

the outer loop will never stop.

I believe we've hit the same issue here in the -RT tree.

Quoted 20 lines

Actually, the window is bigger. Another process can attach the timer after ->it_xxx_expires was cleared (see the patch 2/3) and the 'if (PF_EXITING)' check in arm_timer() is racy (see the patch 3/3).

kernel/posix-cpu-timers.c renamed from kernel/posix-cpu-timers.c~1_CPT +3 -0
@@ -1173,6 +1173,9 @@ static void check_process_timers(struct 
 		}
 		t = tsk;
 		do {
+			if (unlikely(t->flags & PF_EXITING))
+				continue;
+
 			ticks = cputime_add(cputime_add(t->utime, t->stime),
 					    prof_left);
 			if (!cputime_eq(prof_expires, cputime_zero) &&
@@ -1193,11 +1196,7 @@ static void check_process_timers(struct 
 					      t->it_sched_expires > sched)) {

kernel/posix-cpu-timers.c static void check_process_timers(struct · line 1201

Quoted 10 lines
kernel/posix-cpu-timers.c renamed from kernel/posix-cpu-timers.c~1_CPT +1 -5
 				t->it_sched_expires = sched;
 			}
-
-			do {
-				t = next_thread(t);
-			} while (unlikely(t->flags & PF_EXITING));
-		} while (t != tsk);
+		} while ((t = next_thread(t)) != tsk);
 	}
 }

This looks equivalent to the fix in -RT.

thanks
-john