From: Nick Alcock Date: Thu, 10 Oct 2013 23:32:25 +0000 (+0100) Subject: dtrace: armour ustack() against kernel threads, !task->mm, and corrupt usersp. X-Git-Tag: v4.1.12-111.0.20170907_2225~3^2~3^2~119 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1e6c9a5bcbfde68912704174860aecf32c902a40;p=users%2Fjedix%2Flinux-maple.git dtrace: armour ustack() against kernel threads, !task->mm, and corrupt usersp. Kernel threads have no userspace stack, by definition: we should not assume they do. Further, tasks with no mm (whether because they are kernel threads or for any other reason) should not be ustack()ed, nor tasks in which find_vma() cannot find the vma corresponding to the usersp. (Possible causes for this might be a task which just smashed its own userspace sp or a task which is in the middle of exiting or exec()ing.) Orabug: 17591351 Signed-off-by: Nick Alcock --- diff --git a/dtrace/dtrace_isa.c b/dtrace/dtrace_isa.c index 189d170581697..732d652e8539e 100644 --- a/dtrace/dtrace_isa.c +++ b/dtrace/dtrace_isa.c @@ -284,8 +284,17 @@ void dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, { struct task_struct *p = current; unsigned long *sp = (unsigned long *)this_cpu_read(old_rsp); - unsigned long *bos = (unsigned long *)p->mm->start_stack; - struct vm_area_struct *stack_vma = find_vma(p->mm, p->thread.usersp); + unsigned long *bos; + struct vm_area_struct *stack_vma; + + if ((p->mm == NULL) || (p->flags & PF_KTHREAD)) + return; + + bos = (unsigned long *)p->mm->start_stack; + stack_vma = find_vma(p->mm, p->thread.usersp); + + if (stack_vma == NULL) + return; *pcstack++ = (uint64_t)p->pid; pcstack_limit--;