Commit e0129ef91ed758c06b6557c36124acfb2e1c7305
Committed by
Linus Torvalds
1 parent
9c1a125921
Exists in
master
and in
39 other branches
ptrace: PTRACE_GETFDPIC: fix the unsafe usage of child->mm
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 <oleg@redhat.com> Acked-by: Mike Frysinger <vapier.adi@gmail.com> Acked-by: David Howells <dhowells@redhat.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Greg Ungerer <gerg@snapgear.com> Acked-by: Roland McGrath <roland@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 8 additions and 2 deletions Side-by-side Diff
kernel/ptrace.c
... | ... | @@ -596,18 +596,24 @@ |
596 | 596 | |
597 | 597 | #ifdef CONFIG_BINFMT_ELF_FDPIC |
598 | 598 | case PTRACE_GETFDPIC: { |
599 | + struct mm_struct *mm = get_task_mm(child); | |
599 | 600 | unsigned long tmp = 0; |
600 | 601 | |
602 | + ret = -ESRCH; | |
603 | + if (!mm) | |
604 | + break; | |
605 | + | |
601 | 606 | switch (addr) { |
602 | 607 | case PTRACE_GETFDPIC_EXEC: |
603 | - tmp = child->mm->context.exec_fdpic_loadmap; | |
608 | + tmp = mm->context.exec_fdpic_loadmap; | |
604 | 609 | break; |
605 | 610 | case PTRACE_GETFDPIC_INTERP: |
606 | - tmp = child->mm->context.interp_fdpic_loadmap; | |
611 | + tmp = mm->context.interp_fdpic_loadmap; | |
607 | 612 | break; |
608 | 613 | default: |
609 | 614 | break; |
610 | 615 | } |
616 | + mmput(mm); | |
611 | 617 | |
612 | 618 | ret = put_user(tmp, (unsigned long __user *) data); |
613 | 619 | break; |