ptrace: PTRACE_GETFDPIC: fix the unsafe usage of child->mm
authorOleg Nesterov <[email protected]>
Wed, 26 May 2010 21:42:53 +0000 (14:42 -0700)
committerLinus Torvalds <[email protected]>
Thu, 27 May 2010 16:12:44 +0000 (09:12 -0700)
Now that Mike Frysinger unified the FDPIC ptrace code, we can fix the
unsafe usage of child->mm in ptrace_request(PTRACE_GETFDPIC).

We have the reference to task_struct, and ptrace_check_attach() verified
the tracee is stopped.  But nothing can protect from SIGKILL after that,
we must not assume child->mm != NULL.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Mike Frysinger <[email protected]>
Acked-by: David Howells <[email protected]>
Cc: Paul Mundt <[email protected]>
Cc: Greg Ungerer <[email protected]>
Acked-by: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/ptrace.c

index 4b4f72084d1ba21b79ef01a41f0c50439840a6dc..74a3d693c196810f9eed784a2825ea50a7f9db83 100644 (file)
@@ -596,18 +596,24 @@ int ptrace_request(struct task_struct *child, long request,
 
 #ifdef CONFIG_BINFMT_ELF_FDPIC
        case PTRACE_GETFDPIC: {
+               struct mm_struct *mm = get_task_mm(child);
                unsigned long tmp = 0;
 
+               ret = -ESRCH;
+               if (!mm)
+                       break;
+
                switch (addr) {
                case PTRACE_GETFDPIC_EXEC:
-                       tmp = child->mm->context.exec_fdpic_loadmap;
+                       tmp = mm->context.exec_fdpic_loadmap;
                        break;
                case PTRACE_GETFDPIC_INTERP:
-                       tmp = child->mm->context.interp_fdpic_loadmap;
+                       tmp = mm->context.interp_fdpic_loadmap;
                        break;
                default:
                        break;
                }
+               mmput(mm);
 
                ret = put_user(tmp, (unsigned long __user *) data);
                break;