[PATCH v2 5/8] uprobes/x86: Leave sealed trampolines in place on optimisation failure
Chris Down
chris at chrisdown.name
Tue Nov 3 07:18:33 PST 2026
If swbp_optimize() fails, __arch_uprobe_optimize() unmaps the
trampoline it has just created. The next patch seals all special
mappings when CONFIG_MSEAL_SYSTEM_MAPPINGS is enabled, which includes
uprobe trampolines, and then this do_munmap() would fail with -EPERM
and warn a second time.
Nothing is really leaked if we leave the trampoline mapped in that
case, since get_uprobe_trampoline() reuses any existing trampoline
which is in reach of the probe. So let's just leave it in place when
it's sealed.
Signed-off-by: Chris Down <chris at chrisdown.name>
---
arch/x86/kernel/uprobes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 0f60c0d076b6..fb895bfc09e0 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -1183,7 +1183,7 @@ static int __arch_uprobe_optimize(struct arch_uprobe *auprobe, struct mm_struct
if (IS_ERR(tramp))
return PTR_ERR(tramp);
ret = swbp_optimize(auprobe, vma, vaddr, tramp->vm_start);
- if (WARN_ON_ONCE(ret) && new_mapping)
+ if (WARN_ON_ONCE(ret) && new_mapping && !vma_test(tramp, VMA_SEALED_BIT))
WARN_ON_ONCE(do_munmap(mm, tramp->vm_start, PAGE_SIZE, NULL));
return ret;
}
--
2.54.0
More information about the linux-riscv
mailing list