Skip to contentSkip to conversation

exit signals: use of uninitialized field notify_count

PATCH In review Steve VanDeBogart 3 participants 6 messages Aug 26, 2008 – Aug 28, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exit signals: use of uninitialized field notify_count

task->signal->notify_count is only initialized if task->signal->group_exit_task is not NULL. Reorder a conditional so that uninitialised memory is not used. Found by Valgrind.

---

kernel/exit.c +2 -2
Index: linux/kernel/exit.c
===================================================================
@@ -883,8 +883,8 @@
 
 	/* mt-exec, de_thread() is waiting for us */
 	if (thread_group_leader(tsk) &&
-	    tsk->signal->notify_count < 0 &&
-	    tsk->signal->group_exit_task)
+	    tsk->signal->group_exit_task &&
+	    tsk->signal->notify_count < 0)
 		wake_up_process(tsk->signal->group_exit_task);
 
 	write_unlock_irq(&tasklist_lock);
#1 lore raw
Quoted 5 lines · Steve VanDeBogart

task->signal->notify_count is only initialized if task->signal->group_exit_task is not NULL. Reorder a conditional so that uninitialised memory is not used. Found by Valgrind.

Applied the commit below to tip/core/urgent, thanks. Roland/Oleg, do you concur with the fix?

nice find btw. - are you running Valgrind on UML?

Ingo

#2 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 5 lines · Steve VanDeBogart

task->signal->notify_count is only initialized if task->signal->group_exit_task is not NULL. Reorder a conditional so that uninitialised memory is not used. Found by Valgrind.

Applied the commit below to tip/core/urgent, thanks. Roland/Oleg, do you concur with the fix?

Inho, very nice cleanup.

Minor comment. As Roland pointed out, it makes sense to initialize the whole signal_struct explicitely, perhaps copy_signal() should just use zalloc. In that case we don't need to check ->group_exit_task at all, the same for __exit_signal().

Thanks Steve! and what do you think about the above?

Oleg.

#3 lore raw
Quoted 6 lines · Oleg Nesterov
Quoted 5 lines · Steve VanDeBogart
Quoted 4 lines

task->signal->notify_count is only initialized if task->signal->group_exit_task is not NULL. Reorder a conditional so that uninitialised memory is not used. Found by Valgrind.

Quoted 6 lines

Minor comment. As Roland pointed out, it makes sense to initialize the whole signal_struct explicitely, perhaps copy_signal() should just use zalloc. In that case we don't need to check ->group_exit_task at all, the same for __exit_signal().

Thanks Steve! and what do you think about the above?

It looks like that would work. Seems that
sig->count == 0 && sig->group_exit_task != NULL can never be true. If it does work, a lot of initialization in copy_signal() can be removed and it would reduce the chances that a similar problem would be reintroduced. I would submit a patch, but I'm not sure how to trigger those code paths in order to test it.

--
Steve

#4 lore raw
Quoted 7 lines · Steve VanDeBogart

It looks like that would work. Seems that
sig->count == 0 && sig->group_exit_task != NULL can never be true. If it does work, a lot of initialization in copy_signal() can be removed and it would reduce the chances that a similar problem would be reintroduced. I would submit a patch, but I'm not sure how to trigger those code paths in order to test it.

I'd suggest to make 2 patches. The first one adds "->notify_count = 0" to copy_signal() and removes "->group_exit_task != NULL" checks. The second one changes copy_signal() to use zalloc.

BTW, I forgot to mention that you can kill the "thread_group_leader()" check in exit_notify() too.

Oleg.

#5 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Steve VanDeBogart

task->signal->notify_count is only initialized if task->signal->group_exit_task is not NULL. Reorder a conditional so that uninitialised memory is not used. Found by Valgrind.

Quoted 6 lines
Quoted 1 line

Applied the commit below to tip/core/urgent, thanks. Roland/Oleg, do you concur with the fix?

nice find btw. - are you running Valgrind on UML?

Thanks. Yes, I am running Valgrind on UML. I revisited the previous patches that allowed it and tried to remove any unnecessary changes. The patches and a recipe on how to make it work can be found on the
UML wiki: http://uml.jfdi.org/uml/Wiki.jsp?page=ValgrindingUML

I'll stir up trouble by posting the kernel patches on lkml after a little more cleanup.

--
Steve