exec: kill unsafe BUG_ON(sig->count) checks
Subsystems (2)
PATCH 1/5 exec: kill unsafe BUG_ON(sig->count) checks
de_thread:
if (atomic_read(&oldsighand->count) <= 1) BUG_ON(atomic_read(&sig->count) != 1);
This is not safe without the rmb() in between. The results of two correctly ordered __exit_signal()->atomic_dec_and_test()'s could be seen out of order on our CPU.
The same is true for the "thread_group_empty()" case, __unhash_process()'s changes could be seen before atomic_dec_and_test(&sig->count).
On some platforms (including i386) atomic_read() doesn't provide even the compiler barrier, in that case these checks are simply racy.
Remove these BUG_ON()'s. Alternatively, we can do something like
BUG_ON( ({ smp_rmb(); atomic_read(&sig->count) != 1; }) );fs/exec.c renamed from fs/exec.c~1_BUG_ON +0 -3
@@ -784,7 +784,6 @@ static int de_thread(struct task_struct* and we can just re-use it all. */ if (atomic_read (&oldsighand->count) <=1 ) { -BUG_ON (atomic_read (&sig->count) !=1 );signalfd_detach (tsk);exit_itimers (sig);return 0 ;
@@ -929,8 +928,6 @@ no_thread_group:if (leader)release_task (leader); -BUG_ON (atomic_read (&sig->count) !=1 ); -if (atomic_read (&oldsighand->count) ==1 ) {/* * Now that we nuked the rest of the thread group,
Quoted 12 lines · Oleg Nesterov
de_thread:if (atomic_read(&oldsighand->count) <= 1) BUG_ON(atomic_read(&sig->count) != 1);This is not safe without the
rmb()in between. The results of two correctly ordered __exit_signal()->atomic_dec_and_test()'s could be seen out of order on our CPU.The same is true for the "
thread_group_empty()" case, __unhash_process()'s changes could be seen beforeatomic_dec_and_test(&sig->count).
Quoted 6 lines
On some platforms (including i386)
atomic_read()doesn't provide even the compiler barrier, in that case these checks are simply racy.Remove these BUG_ON()'s. Alternatively, we can do something like
BUG_ON( ({ smp_rmb(); atomic_read(&sig->count) != 1; }) );
Good catches!
Quoted 22 lines
Signed-off-by Oleg Nesterov <[email protected]>fs/exec.c renamed from fs/exec.c~1_BUG_ON +0
-3@@ -784,7 +784,6 @@ static int de_thread(struct task_struct* and we can just re-use it all. */ if (atomic_read (&oldsighand->count) <=1 ) { -BUG_ON (atomic_read (&sig->count) !=1 );signalfd_detach (tsk);exit_itimers (sig);return 0 ;@@ -929,8 +928,6 @@ no_thread_group:if (leader)release_task (leader); -BUG_ON (atomic_read (&sig->count) !=1 ); -if (atomic_read (&oldsighand->count) ==1 ) {/* * Now that we nuked the rest of the thread group,
Those BUG_ON's were there because of past bugs and fragility in the de_thread and exit synchronization stuff. There's no real need to leave them (in fixed form) if we are confident of that stuff working right now, or have other assertions to give us that confidence when we change it.
Thanks,
Roland