linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uprobes: Skip breakpoint installation on non executable vmas
@ 2026-08-05 13:19 Sumanth Korikkar
  2026-08-05 15:14 ` Oleg Nesterov
  0 siblings, 1 reply; 11+ messages in thread
From: Sumanth Korikkar @ 2026-08-05 13:19 UTC (permalink / raw)
  To: Masami Hiramatsu, Oleg Nesterov, linux-kernel, linux-trace-kernel
  Cc: Ilya Leoshkevich, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, sumanthk

bpftrace  -e 'usdt:./testprogs/usdt_semaphore_test:tracetest:testprobe {
printf("%s\n", str(arg1) ); exit(); }'

expects a semaphore increment of 1, but semaphore gets double incremented

Test program:
https://github.com/bpftrace/bpftrace/blob/master/tests/testprogs/usdt_semaphore_test.c

Reason: .text mapping and RELRO mapping resolve to the same page aligned
file offset 0
01000000-01001000 r-xp 00000000 5e:01 usdt_semaphore_test (.text)
01001000-01002000 r--p 00000000 5e:01 usdt_semaphore_test (RELRO)
01002000-01003000 rw-p 00001000 5e:01 usdt_semaphore_test (semaphore)

valid_vma() currently accepts both mappings (which contains executable
text and RELRO mapping) during uprobe registration, since both have
VM_MAYEXEC set. This causes register_for_each_vma() to call
install_breakpoint() twice for the same underlying uprobe offset in the
process.  This means, update_ref_ctr() is called twice for the same
process, so a usdt semaphore is incremented from 0 to 2.

Installing a breakpoint for mapping without VM_EXEC and
updating usdt reference counter in that case is not useful.

Skip non VM_EXEC mappings in install_breakpoint(). This fixes semaphore
double increment as shown in the above usecase.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
---
 kernel/events/uprobes.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 6300b216012c..9e0bbc3cf401 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1155,6 +1155,9 @@ static int install_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma,
 	bool first_uprobe;
 	int ret;
 
+	if (!(vma->vm_flags & VM_EXEC))
+		return 0;
+
 	ret = prepare_uprobe(uprobe, vma->vm_file, mm, vaddr);
 	if (ret)
 		return ret;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-08-06 20:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 13:19 [PATCH] uprobes: Skip breakpoint installation on non executable vmas Sumanth Korikkar
2026-08-05 15:14 ` Oleg Nesterov
2026-08-05 17:29   ` Andrii Nakryiko
2026-08-05 18:26     ` Oleg Nesterov
2026-08-05 21:29     ` Sumanth Korikkar
2026-08-05 22:05       ` Sumanth Korikkar
2026-08-05 21:06   ` Sumanth Korikkar
2026-08-06 11:01     ` Oleg Nesterov
2026-08-06 13:34       ` Sumanth Korikkar
2026-08-06 15:35         ` Oleg Nesterov
2026-08-06 20:42           ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).