Skip to content

Commit 86c5bf7

Browse files
committed
Merge branch 'mm-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull vmap stack fixes from Ingo Molnar: "This is fallout from CONFIG_HAVE_ARCH_VMAP_STACK=y on x86: stack accesses that used to be just somewhat questionable are now totally buggy. These changes try to do it without breaking the ABI: the fields are left there, they are just reporting zero, or reporting narrower information (the maps file change)" * 'mm-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: mm: Change vm_is_stack_for_task() to vm_is_stack_for_current() fs/proc: Stop trying to report thread stacks fs/proc: Stop reporting eip and esp in /proc/PID/stat mm/numa: Remove duplicated include from mprotect.c
2 parents bfb7bfe + d17af50 commit 86c5bf7

8 files changed

Lines changed: 30 additions & 71 deletions

File tree

Documentation/filesystems/proc.txt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -395,32 +395,6 @@ is not associated with a file:
395395

396396
or if empty, the mapping is anonymous.
397397

398-
The /proc/PID/task/TID/maps is a view of the virtual memory from the viewpoint
399-
of the individual tasks of a process. In this file you will see a mapping marked
400-
as [stack] if that task sees it as a stack. Hence, for the example above, the
401-
task-level map, i.e. /proc/PID/task/TID/maps for thread 1001 will look like this:
402-
403-
08048000-08049000 r-xp 00000000 03:00 8312 /opt/test
404-
08049000-0804a000 rw-p 00001000 03:00 8312 /opt/test
405-
0804a000-0806b000 rw-p 00000000 00:00 0 [heap]
406-
a7cb1000-a7cb2000 ---p 00000000 00:00 0
407-
a7cb2000-a7eb2000 rw-p 00000000 00:00 0
408-
a7eb2000-a7eb3000 ---p 00000000 00:00 0
409-
a7eb3000-a7ed5000 rw-p 00000000 00:00 0 [stack]
410-
a7ed5000-a8008000 r-xp 00000000 03:00 4222 /lib/libc.so.6
411-
a8008000-a800a000 r--p 00133000 03:00 4222 /lib/libc.so.6
412-
a800a000-a800b000 rw-p 00135000 03:00 4222 /lib/libc.so.6
413-
a800b000-a800e000 rw-p 00000000 00:00 0
414-
a800e000-a8022000 r-xp 00000000 03:00 14462 /lib/libpthread.so.0
415-
a8022000-a8023000 r--p 00013000 03:00 14462 /lib/libpthread.so.0
416-
a8023000-a8024000 rw-p 00014000 03:00 14462 /lib/libpthread.so.0
417-
a8024000-a8027000 rw-p 00000000 00:00 0
418-
a8027000-a8043000 r-xp 00000000 03:00 8317 /lib/ld-linux.so.2
419-
a8043000-a8044000 r--p 0001b000 03:00 8317 /lib/ld-linux.so.2
420-
a8044000-a8045000 rw-p 0001c000 03:00 8317 /lib/ld-linux.so.2
421-
aff35000-aff4a000 rw-p 00000000 00:00 0
422-
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
423-
424398
The /proc/PID/smaps is an extension based on maps, showing the memory
425399
consumption for each of the process's mappings. For each of mappings there
426400
is a series of lines such as the following:

fs/proc/array.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
412412
mm = get_task_mm(task);
413413
if (mm) {
414414
vsize = task_vsize(mm);
415-
if (permitted) {
416-
eip = KSTK_EIP(task);
417-
esp = KSTK_ESP(task);
418-
}
415+
/*
416+
* esp and eip are intentionally zeroed out. There is no
417+
* non-racy way to read them without freezing the task.
418+
* Programs that need reliable values can use ptrace(2).
419+
*/
419420
}
420421

421422
get_task_comm(tcomm, task);

fs/proc/task_mmu.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,15 @@ static int do_maps_open(struct inode *inode, struct file *file,
266266
* /proc/PID/maps that is the stack of the main task.
267267
*/
268268
static int is_stack(struct proc_maps_private *priv,
269-
struct vm_area_struct *vma, int is_pid)
269+
struct vm_area_struct *vma)
270270
{
271-
int stack = 0;
272-
273-
if (is_pid) {
274-
stack = vma->vm_start <= vma->vm_mm->start_stack &&
275-
vma->vm_end >= vma->vm_mm->start_stack;
276-
} else {
277-
struct inode *inode = priv->inode;
278-
struct task_struct *task;
279-
280-
rcu_read_lock();
281-
task = pid_task(proc_pid(inode), PIDTYPE_PID);
282-
if (task)
283-
stack = vma_is_stack_for_task(vma, task);
284-
rcu_read_unlock();
285-
}
286-
return stack;
271+
/*
272+
* We make no effort to guess what a given thread considers to be
273+
* its "stack". It's not even well-defined for programs written
274+
* languages like Go.
275+
*/
276+
return vma->vm_start <= vma->vm_mm->start_stack &&
277+
vma->vm_end >= vma->vm_mm->start_stack;
287278
}
288279

289280
static void
@@ -354,7 +345,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
354345
goto done;
355346
}
356347

357-
if (is_stack(priv, vma, is_pid))
348+
if (is_stack(priv, vma))
358349
name = "[stack]";
359350
}
360351

@@ -1669,7 +1660,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
16691660
seq_file_path(m, file, "\n\t= ");
16701661
} else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
16711662
seq_puts(m, " heap");
1672-
} else if (is_stack(proc_priv, vma, is_pid)) {
1663+
} else if (is_stack(proc_priv, vma)) {
16731664
seq_puts(m, " stack");
16741665
}
16751666

fs/proc/task_nommu.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,17 @@ unsigned long task_statm(struct mm_struct *mm,
124124
}
125125

126126
static int is_stack(struct proc_maps_private *priv,
127-
struct vm_area_struct *vma, int is_pid)
127+
struct vm_area_struct *vma)
128128
{
129129
struct mm_struct *mm = vma->vm_mm;
130-
int stack = 0;
131-
132-
if (is_pid) {
133-
stack = vma->vm_start <= mm->start_stack &&
134-
vma->vm_end >= mm->start_stack;
135-
} else {
136-
struct inode *inode = priv->inode;
137-
struct task_struct *task;
138-
139-
rcu_read_lock();
140-
task = pid_task(proc_pid(inode), PIDTYPE_PID);
141-
if (task)
142-
stack = vma_is_stack_for_task(vma, task);
143-
rcu_read_unlock();
144-
}
145-
return stack;
130+
131+
/*
132+
* We make no effort to guess what a given thread considers to be
133+
* its "stack". It's not even well-defined for programs written
134+
* languages like Go.
135+
*/
136+
return vma->vm_start <= mm->start_stack &&
137+
vma->vm_end >= mm->start_stack;
146138
}
147139

148140
/*
@@ -184,7 +176,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
184176
if (file) {
185177
seq_pad(m, ' ');
186178
seq_file_path(m, file, "");
187-
} else if (mm && is_stack(priv, vma, is_pid)) {
179+
} else if (mm && is_stack(priv, vma)) {
188180
seq_pad(m, ' ');
189181
seq_printf(m, "[stack]");
190182
}

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ static inline int stack_guard_page_end(struct vm_area_struct *vma,
13911391
!vma_growsup(vma->vm_next, addr);
13921392
}
13931393

1394-
int vma_is_stack_for_task(struct vm_area_struct *vma, struct task_struct *t);
1394+
int vma_is_stack_for_current(struct vm_area_struct *vma);
13951395

13961396
extern unsigned long move_page_tables(struct vm_area_struct *vma,
13971397
unsigned long old_addr, struct vm_area_struct *new_vma,

mm/mprotect.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/perf_event.h>
2626
#include <linux/pkeys.h>
2727
#include <linux/ksm.h>
28-
#include <linux/pkeys.h>
2928
#include <asm/uaccess.h>
3029
#include <asm/pgtable.h>
3130
#include <asm/cacheflush.h>

mm/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
230230
}
231231

232232
/* Check if the vma is being used as a stack by this task */
233-
int vma_is_stack_for_task(struct vm_area_struct *vma, struct task_struct *t)
233+
int vma_is_stack_for_current(struct vm_area_struct *vma)
234234
{
235+
struct task_struct * __maybe_unused t = current;
236+
235237
return (vma->vm_start <= KSTK_ESP(t) && vma->vm_end >= KSTK_ESP(t));
236238
}
237239

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
35573557
} else if (!vma->vm_file &&
35583558
((vma->vm_start <= vma->vm_mm->start_stack &&
35593559
vma->vm_end >= vma->vm_mm->start_stack) ||
3560-
vma_is_stack_for_task(vma, current))) {
3560+
vma_is_stack_for_current(vma))) {
35613561
rc = current_has_perm(current, PROCESS__EXECSTACK);
35623562
} else if (vma->vm_file && vma->anon_vma) {
35633563
/*

0 commit comments

Comments
 (0)