All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCHv6 03/13] uprobes/x86: Do not leak trampoline vma mapping on optimization failure
Date: Fri,  3 Jul 2026 13:49:07 +0200	[thread overview]
Message-ID: <20260703114917.238144-4-jolsa@kernel.org> (raw)
In-Reply-To: <20260703114917.238144-1-jolsa@kernel.org>

In case the optimization fails, we leak new-ly created trampoline
vma mapping (in case we just created it), let's unmap it.

Fixes: ba2bfc97b462 ("uprobes/x86: Add support to optimize uprobes")
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/kernel/uprobes.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index d2933cf77cd3..5730d41eb5f2 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -677,11 +677,14 @@ static unsigned long find_nearest_trampoline(unsigned long vaddr)
 	return high_tramp;
 }
 
-static struct vm_area_struct *get_uprobe_trampoline(struct mm_struct *mm, unsigned long vaddr)
+static struct vm_area_struct *get_uprobe_trampoline(struct mm_struct *mm, unsigned long vaddr,
+						    bool *new_mapping)
 {
 	VMA_ITERATOR(vmi, mm, 0);
 	struct vm_area_struct *vma;
 
+	*new_mapping = false;
+
 	if (vaddr > TASK_SIZE || vaddr < PAGE_SIZE)
 		return ERR_PTR(-EINVAL);
 
@@ -696,6 +699,7 @@ static struct vm_area_struct *get_uprobe_trampoline(struct mm_struct *mm, unsign
 	if (IS_ERR_VALUE(vaddr))
 		return ERR_PTR(vaddr);
 
+	*new_mapping = true;
 	return _install_special_mapping(mm, vaddr, PAGE_SIZE,
 				VM_READ|VM_EXEC|VM_MAYEXEC|VM_MAYREAD|VM_DONTCOPY|VM_IO,
 				&tramp_mapping);
@@ -1053,6 +1057,7 @@ static int __arch_uprobe_optimize(struct arch_uprobe *auprobe, struct mm_struct
 {
 	struct pt_regs *regs = task_pt_regs(current);
 	struct vm_area_struct *vma, *tramp;
+	bool new_mapping;
 	int ret;
 
 	if (!user_64bit_mode(regs))
@@ -1060,10 +1065,13 @@ static int __arch_uprobe_optimize(struct arch_uprobe *auprobe, struct mm_struct
 	vma = find_vma(mm, vaddr);
 	if (!vma)
 		return -EINVAL;
-	tramp = get_uprobe_trampoline(mm, vaddr);
+	tramp = get_uprobe_trampoline(mm, vaddr, &new_mapping);
 	if (IS_ERR(tramp))
 		return PTR_ERR(tramp);
-	return WARN_ON_ONCE(swbp_optimize(auprobe, vma, vaddr, tramp->vm_start));
+	ret = swbp_optimize(auprobe, vma, vaddr, tramp->vm_start);
+	if (WARN_ON_ONCE(ret) && new_mapping)
+		WARN_ON_ONCE(do_munmap(mm, tramp->vm_start, PAGE_SIZE, NULL));
+	return ret;
 }
 
 void arch_uprobe_optimize(struct arch_uprobe *auprobe, unsigned long vaddr)
-- 
2.54.0


  parent reply	other threads:[~2026-07-03 11:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 11:49 [PATCHv6 00/13] uprobes/x86: Fix red zone issue for optimized uprobes Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 01/13] uprobes/x86: Use proper mm_struct in __in_uprobe_trampoline Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 02/13] uprobes/x86: Remove struct uprobe_trampoline object Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` Jiri Olsa [this message]
2026-07-03 12:32   ` [PATCHv6 03/13] uprobes/x86: Do not leak trampoline vma mapping on optimization failure bot+bpf-ci
2026-07-03 12:45   ` Peter Zijlstra
2026-07-03 14:11     ` Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 04/13] uprobes/x86: Allow to copy uprobe trampolines on fork Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 05/13] uprobes/x86: Move optimized uprobe from nop5 to nop10 Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 06/13] libbpf: Change has_nop_combo to work on top of nop10 Jiri Olsa
2026-07-03 12:00   ` sashiko-bot
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  8:58     ` Ingo Molnar
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 07/13] libbpf: Detect uprobe syscall with new error Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  8:57     ` Ingo Molnar
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 08/13] selftests/bpf: Emit nop,nop10 instructions combo for x86_64 arch Jiri Olsa
2026-07-03 12:03   ` sashiko-bot
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 09/13] selftests/bpf: Change uprobe syscall tests to use nop10 Jiri Olsa
2026-07-03 12:00   ` sashiko-bot
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 10/13] selftests/bpf: Change uprobe/usdt trigger bench code " Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 11/13] selftests/bpf: Add reattach tests for uprobe syscall Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa
2026-07-03 11:49 ` [PATCHv6 12/13] selftests/bpf: Add tests for uprobe nop10 red zone clobbering Jiri Olsa
2026-07-03 14:35   ` [tip: perf/core] " tip-bot2 for Andrii Nakryiko
2026-07-04  9:00   ` tip-bot2 for Andrii Nakryiko
2026-07-03 11:49 ` [PATCHv6 13/13] selftests/bpf: Add tests for forked/cloned optimized uprobes Jiri Olsa
2026-07-03 14:34   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2026-07-04  9:00   ` tip-bot2 for Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260703114917.238144-4-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.