fs/proc: Stop trying to report thread stacks
This reverts more of:b76437579d
("procfs: mark thread stack correctly in proc/<pid>/maps") ... which was partially reverted by:65376df582
("proc: revert /proc/<pid>/maps [stack:TID] annotation") Originally, /proc/PID/task/TID/maps was the same as /proc/TID/maps. In current kernels, /proc/PID/maps (or /proc/TID/maps even for threads) shows "[stack]" for VMAs in the mm's stack address range. In contrast, /proc/PID/task/TID/maps uses KSTK_ESP to guess the target thread's stack's VMA. This is racy, probably returns garbage and, on arches with CONFIG_TASK_INFO_IN_THREAD=y, is also crash-prone: KSTK_ESP is not safe to use on tasks that aren't known to be running ordinary process-context kernel code. This patch removes the difference and just shows "[stack]" for VMAs in the mm's stack range. This is IMO much more sensible -- the actual "stack" address really is treated specially by the VM code, and the current thread stack isn't even well-defined for programs that frequently switch stacks on their own. Reported-by: Jann Horn <jann@thejh.net> Signed-off-by: Andy Lutomirski <luto@kernel.org> Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Linux API <linux-api@vger.kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tycho Andersen <tycho.andersen@canonical.com> Link: http://lkml.kernel.org/r/3e678474ec14e0a0ec34c611016753eea2e1b8ba.1475257877.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
0a1eb2d474
commit
b18cb64ead
@@ -266,24 +266,15 @@ static int do_maps_open(struct inode *inode, struct file *file,
|
||||
* /proc/PID/maps that is the stack of the main task.
|
||||
*/
|
||||
static int is_stack(struct proc_maps_private *priv,
|
||||
struct vm_area_struct *vma, int is_pid)
|
||||
struct vm_area_struct *vma)
|
||||
{
|
||||
int stack = 0;
|
||||
|
||||
if (is_pid) {
|
||||
stack = vma->vm_start <= vma->vm_mm->start_stack &&
|
||||
vma->vm_end >= vma->vm_mm->start_stack;
|
||||
} else {
|
||||
struct inode *inode = priv->inode;
|
||||
struct task_struct *task;
|
||||
|
||||
rcu_read_lock();
|
||||
task = pid_task(proc_pid(inode), PIDTYPE_PID);
|
||||
if (task)
|
||||
stack = vma_is_stack_for_task(vma, task);
|
||||
rcu_read_unlock();
|
||||
}
|
||||
return stack;
|
||||
/*
|
||||
* We make no effort to guess what a given thread considers to be
|
||||
* its "stack". It's not even well-defined for programs written
|
||||
* languages like Go.
|
||||
*/
|
||||
return vma->vm_start <= vma->vm_mm->start_stack &&
|
||||
vma->vm_end >= vma->vm_mm->start_stack;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -354,7 +345,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (is_stack(priv, vma, is_pid))
|
||||
if (is_stack(priv, vma))
|
||||
name = "[stack]";
|
||||
}
|
||||
|
||||
@@ -1669,7 +1660,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
|
||||
seq_file_path(m, file, "\n\t= ");
|
||||
} else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
|
||||
seq_puts(m, " heap");
|
||||
} else if (is_stack(proc_priv, vma, is_pid)) {
|
||||
} else if (is_stack(proc_priv, vma)) {
|
||||
seq_puts(m, " stack");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user