Skip to content

Commit cbc91f7

Browse files
srikardIngo Molnar
authored andcommitted
uprobes/core: Decrement uprobe count before the pages are unmapped
Uprobes has a callback (uprobe_munmap()) in the unmap path to maintain the uprobes count. In the exit path this callback gets called in unlink_file_vma(). However by the time unlink_file_vma() is called, the pages would have been unmapped (in unmap_vmas()) and the task->rss_stat counts accounted (in zap_pte_range()). If the exiting process has probepoints, uprobe_munmap() checks if the breakpoint instruction was around before decrementing the probe count. This results in a file backed page being reread by uprobe_munmap() and hence it does not find the breakpoint. This patch fixes this problem by moving the callback to unmap_single_vma(). Since unmap_single_vma() may not unmap the complete vma, add start and end parameters to uprobe_munmap(). This bug became apparent courtesy of commit c3f0327 ("mm: add rss counters consistency check"). Signed-off-by: Srikar Dronamraju <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Jim Keniston <[email protected]> Cc: Linux-mm <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Anton Arapov <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 7396fa8 commit cbc91f7

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

include/linux/uprobes.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
107107
extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
108108
extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
109109
extern int uprobe_mmap(struct vm_area_struct *vma);
110-
extern void uprobe_munmap(struct vm_area_struct *vma);
110+
extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
111111
extern void uprobe_free_utask(struct task_struct *t);
112112
extern void uprobe_copy_process(struct task_struct *t);
113113
extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
@@ -134,7 +134,8 @@ static inline int uprobe_mmap(struct vm_area_struct *vma)
134134
{
135135
return 0;
136136
}
137-
static inline void uprobe_munmap(struct vm_area_struct *vma)
137+
static inline void
138+
uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
138139
{
139140
}
140141
static inline void uprobe_notify_resume(struct pt_regs *regs)

kernel/events/uprobes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ int uprobe_mmap(struct vm_area_struct *vma)
11121112
/*
11131113
* Called in context of a munmap of a vma.
11141114
*/
1115-
void uprobe_munmap(struct vm_area_struct *vma)
1115+
void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
11161116
{
11171117
struct list_head tmp_list;
11181118
struct uprobe *uprobe, *u;
@@ -1138,7 +1138,7 @@ void uprobe_munmap(struct vm_area_struct *vma)
11381138
list_del(&uprobe->pending_list);
11391139
vaddr = vma_address(vma, uprobe->offset);
11401140

1141-
if (vaddr >= vma->vm_start && vaddr < vma->vm_end) {
1141+
if (vaddr >= start && vaddr < end) {
11421142
/*
11431143
* An unregister could have removed the probe before
11441144
* unmap. So check before we decrement the count.

mm/memory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@ static void unmap_single_vma(struct mmu_gather *tlb,
13071307
if (end <= vma->vm_start)
13081308
return;
13091309

1310+
if (vma->vm_file)
1311+
uprobe_munmap(vma, start, end);
1312+
13101313
if (vma->vm_flags & VM_ACCOUNT)
13111314
*nr_accounted += (end - start) >> PAGE_SHIFT;
13121315

mm/mmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ void unlink_file_vma(struct vm_area_struct *vma)
218218
mutex_lock(&mapping->i_mmap_mutex);
219219
__remove_shared_vm_struct(vma, file, mapping);
220220
mutex_unlock(&mapping->i_mmap_mutex);
221-
uprobe_munmap(vma);
222221
}
223222
}
224223

@@ -548,10 +547,11 @@ again: remove_next = 1 + (end > next->vm_end);
548547
mapping = file->f_mapping;
549548
if (!(vma->vm_flags & VM_NONLINEAR)) {
550549
root = &mapping->i_mmap;
551-
uprobe_munmap(vma);
550+
uprobe_munmap(vma, vma->vm_start, vma->vm_end);
552551

553552
if (adjust_next)
554-
uprobe_munmap(next);
553+
uprobe_munmap(next, next->vm_start,
554+
next->vm_end);
555555
}
556556

557557
mutex_lock(&mapping->i_mmap_mutex);
@@ -632,7 +632,7 @@ again: remove_next = 1 + (end > next->vm_end);
632632

633633
if (remove_next) {
634634
if (file) {
635-
uprobe_munmap(next);
635+
uprobe_munmap(next, next->vm_start, next->vm_end);
636636
fput(file);
637637
if (next->vm_flags & VM_EXECUTABLE)
638638
removed_exe_file_vma(mm);

0 commit comments

Comments
 (0)