[PATCH 1/2] uprobes: Add missing read memory barrier in prepare_uprobe()

From: Masami Hiramatsu (Google)

Date: Thu Dec 03 2026 - 04:59:03 EST


From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

prepare_uprobe() uses double-checked locking around UPROBE_COPY_INSN to
serialize concurrent callers (for example, register_for_each_vma() and
uprobe_mmap()). The writer populates uprobe->arch, executes smp_wmb(),
and sets UPROBE_COPY_INSN in uprobe->flags.

However, the lockless fast path at the start of prepare_uprobe() tests
UPROBE_COPY_INSN and returns 0 without a paired read memory barrier. On
weakly-ordered architectures, a concurrent caller taking the fast path
can observe UPROBE_COPY_INSN set while subsequently reading stale or
uninitialized fields from uprobe->arch (for instance, auprobe->bpinsn in
ARM's set_swbp()).

Add the missing smp_rmb() on the fast path of prepare_uprobe() to pair
with the smp_wmb() before set_bit(UPROBE_COPY_INSN, &uprobe->flags).

Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/bug/linux-68084e34-bdf9-4e4a-8740-e4208f044e15
Fixes: 4710f05fd146 ("uprobes: Fix prepare_uprobe() race with itself")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
kernel/events/uprobes.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index c47b1ee266d5..e850865045b2 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1101,8 +1101,17 @@ static int prepare_uprobe(struct uprobe *uprobe, struct file *file,
{
int ret = 0;

- if (test_bit(UPROBE_COPY_INSN, &uprobe->flags))
+ if (test_bit(UPROBE_COPY_INSN, &uprobe->flags)) {
+ /*
+ * Pairs with the smp_wmb() below.
+ *
+ * Guarantees that if we see the UPROBE_COPY_INSN bit set, then
+ * we must also see the stores to &uprobe->arch performed by
+ * prepare_uprobe().
+ */
+ smp_rmb();
return ret;
+ }

/* TODO: move this into _register, until then we abuse this sem. */
down_write(&uprobe->consumer_rwsem);
@@ -1121,7 +1130,8 @@ static int prepare_uprobe(struct uprobe *uprobe, struct file *file,
if (ret)
goto out;

- smp_wmb(); /* pairs with the smp_rmb() in handle_swbp() */
+ /* Pairs with the smp_rmb() in prepare_uprobe() and handle_swbp() */
+ smp_wmb();
set_bit(UPROBE_COPY_INSN, &uprobe->flags);

out: