Re: [PATCH 1/2] uprobes: Add missing read memory barrier in prepare_uprobe()
From: Oleg Nesterov
Date: Thu Dec 03 2026 - 06:20:01 EST
On 12/03, Masami Hiramatsu (Google) wrote:
>
> --- 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);
Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx>
But I guess we could use test_bit_acquire(UPROBE_COPY_INSN) and
smp_mb__before_atomic() before set_bit(UPROBE_COPY_INSN) ?
Oleg.