[PATCH] Fix atomicity of TIF update in flush_thread() for x86_64
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Sun, 18 Mar 2007 09:26:11 +0000 (01:26 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Sun, 18 Mar 2007 18:35:08 +0000 (11:35 -0700)
Fix atomicity of TIF update in flush_thread() for x86_64

Race :

parent process executing :
sys_ptrace()
 (lock_kernel())
 (ptrace_get_task_struct(pid))
 arch_ptrace()
   ptrace_detach()
     ptrace_disable(child);
       clear_singlestep(child);
         clear_tsk_thread_flag(child, TIF_SINGLESTEP);
         (which clears the TIF_SINGLESTEP flag atomically from a different
  process)
 (put_task_struct(child))
 (unlock_kernel())

And at the same time, in the child process :
sys_execve()
 do_execve()
   search_binary_handler()
     load_elf_binary()
       flush_old_exec()
         flush_thread()
           doing a non-atomic thread flag update

Signed-off-by: Rebecca Schultz <rschultz@google.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86_64/kernel/process.c

index cbbc6adc1a92004c902954f10777528f6b964178..d8d5ccc245c8977eaa1c616b9301df058661d386 100644 (file)
@@ -382,14 +382,17 @@ void exit_thread(void)
 void flush_thread(void)
 {
        struct task_struct *tsk = current;
-       struct thread_info *t = current_thread_info();
 
-       if (t->flags & _TIF_ABI_PENDING) {
-               t->flags ^= (_TIF_ABI_PENDING | _TIF_IA32);
-               if (t->flags & _TIF_IA32)
+       if (test_tsk_thread_flag(tsk, TIF_ABI_PENDING)) {
+               clear_tsk_thread_flag(tsk, TIF_ABI_PENDING);
+               if (test_tsk_thread_flag(tsk, TIF_IA32)) {
+                       clear_tsk_thread_flag(tsk, TIF_IA32);
+               } else {
+                       set_tsk_thread_flag(tsk, TIF_IA32);
                        current_thread_info()->status |= TS_COMPAT;
+               }
        }
-       t->flags &= ~_TIF_DEBUG;
+       clear_tsk_thread_flag(tsk, TIF_DEBUG);
 
        tsk->thread.debugreg0 = 0;
        tsk->thread.debugreg1 = 0;