Skip to content

Commit ed8d5b0

Browse files
oleg-nesterovakpm00
authored andcommitted
Revert "uprobes: use vm_special_mapping close() functionality"
This reverts commit 08e28de. A malicious application can munmap() its "[uprobes]" vma and in this case xol_mapping.close == uprobe_clear_state() will free the memory which can be used by another thread, or the same thread when it hits the uprobe bp afterwards. Link: https://lkml.kernel.org/r/20240911131320.GA3448@redhat.com Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 242d12c commit ed8d5b0

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

include/linux/uprobes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
126126
extern void uprobe_notify_resume(struct pt_regs *regs);
127127
extern bool uprobe_deny_signal(void);
128128
extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
129+
extern void uprobe_clear_state(struct mm_struct *mm);
129130
extern int arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
130131
extern int arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
131132
extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);

kernel/events/uprobes.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,22 +1482,6 @@ void * __weak arch_uprobe_trampoline(unsigned long *psize)
14821482
return &insn;
14831483
}
14841484

1485-
/*
1486-
* uprobe_clear_state - Free the area allocated for slots.
1487-
*/
1488-
static void uprobe_clear_state(const struct vm_special_mapping *sm, struct vm_area_struct *vma)
1489-
{
1490-
struct xol_area *area = container_of(vma->vm_private_data, struct xol_area, xol_mapping);
1491-
1492-
mutex_lock(&delayed_uprobe_lock);
1493-
delayed_uprobe_remove(NULL, vma->vm_mm);
1494-
mutex_unlock(&delayed_uprobe_lock);
1495-
1496-
put_page(area->pages[0]);
1497-
kfree(area->bitmap);
1498-
kfree(area);
1499-
}
1500-
15011485
static struct xol_area *__create_xol_area(unsigned long vaddr)
15021486
{
15031487
struct mm_struct *mm = current->mm;
@@ -1516,7 +1500,6 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
15161500

15171501
area->xol_mapping.name = "[uprobes]";
15181502
area->xol_mapping.fault = NULL;
1519-
area->xol_mapping.close = uprobe_clear_state;
15201503
area->xol_mapping.pages = area->pages;
15211504
area->pages[0] = alloc_page(GFP_HIGHUSER);
15221505
if (!area->pages[0])
@@ -1562,6 +1545,25 @@ static struct xol_area *get_xol_area(void)
15621545
return area;
15631546
}
15641547

1548+
/*
1549+
* uprobe_clear_state - Free the area allocated for slots.
1550+
*/
1551+
void uprobe_clear_state(struct mm_struct *mm)
1552+
{
1553+
struct xol_area *area = mm->uprobes_state.xol_area;
1554+
1555+
mutex_lock(&delayed_uprobe_lock);
1556+
delayed_uprobe_remove(NULL, mm);
1557+
mutex_unlock(&delayed_uprobe_lock);
1558+
1559+
if (!area)
1560+
return;
1561+
1562+
put_page(area->pages[0]);
1563+
kfree(area->bitmap);
1564+
kfree(area);
1565+
}
1566+
15651567
void uprobe_start_dup_mmap(void)
15661568
{
15671569
percpu_down_read(&dup_mmap_sem);

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ static inline void __mmput(struct mm_struct *mm)
13381338
{
13391339
VM_BUG_ON(atomic_read(&mm->mm_users));
13401340

1341+
uprobe_clear_state(mm);
13411342
exit_aio(mm);
13421343
ksm_exit(mm);
13431344
khugepaged_exit(mm); /* must run before exit_mmap */

0 commit comments

Comments
 (0)