From: sashiko-bot@kernel.org
To: "Andi Kleen" <ak@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFC v1 10/19] ptwrite uprobes: Minimal memory references and fault handling
Date: Mon, 31 Aug 2026 19:59:35 +0000 [thread overview]
Message-ID: <20260831195936.451161F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831150651.1134594-11-ak@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Premature publication of `ptw->nblocks` without memory barriers exposes uninitialized memory to concurrent page fault handlers.
- [Medium] Rolling back `ptw->nblocks` on error allows in-place reuse of array slots without an RCU grace period, causing torn reads in concurrent fault handlers.
--
commit 925690411c45029e0f0a323ac69035b5e1cc8c87
Author: Andi Kleen <ak@kernel.org>
ptwrite uprobes: Minimal memory references and fault handling
Add support for memory references. Currently this is only simple cases,
no indirect memory references or strings. This requires fault handling
using the fault notifier hook added earlier.
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index df652c56414b5..90e702a4a8e99 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
[ ... ]
> @@ -1689,13 +1852,22 @@ int arch_uprobe_install_ptwrite(struct arch_uprobe *auprobe,
> return -ENOMEM;
>
> block_off = ptw->cursor;
> - if (block_off > PAGE_SIZE ||
> - ptw_a->stub_len > PAGE_SIZE - block_off)
> + if (block_off > PAGE_SIZE || ptw_a->stub_len > PAGE_SIZE - block_off)
> + return -ENOMEM;
> + if (ptw->nblocks >= ARRAY_SIZE(ptw->index))
> return -ENOMEM;
> stub_addr = ptw->vaddr + block_off;
> if (!ptwrite_rel32(stub_addr + ptw_a->jmp_off + 4,
> vaddr + 5, &rel))
> return -ERANGE;
> + site_delta = (s64)vaddr - (s64)ptw->vaddr;
> + if (site_delta < INT_MIN || site_delta > INT_MAX)
> + return -ERANGE;
> +
> + ptw->index[ptw->nblocks].off = block_off;
> + ptw->index[ptw->nblocks].len = ptw_a->stub_len;
> + ptw->index[ptw->nblocks].ft_off = ptw_a->ft_off;
> + ptw->nblocks++;
>
> kaddr = kmap_local_page(ptw->page);
> memcpy(kaddr + block_off, ptw_a->stub, ptw_a->stub_len);
[Severity: Medium]
Does this code expose uninitialized memory to concurrent page fault handlers?
Since ptw->nblocks is incremented before memcpy() initializes the stub
block memory, a concurrent lockless reader in uprobe_ptwrite_handle_fault()
might observe the incremented nblocks and read the uninitialized fault table
while memcpy() is actively writing to it.
> @@ -1704,9 +1876,13 @@ int arch_uprobe_install_ptwrite(struct arch_uprobe *auprobe,
> kunmap_local(kaddr);
>
> ret = ptwrite_text_poke(auprobe, vma, vaddr, stub_addr);
> - if (!ret)
> - ptw->cursor = block_off + ptw_a->stub_len;
> - return ret;
> + if (ret)
> + /* Publish rollback before readers use the reduced block count. */
> + smp_store_release(&ptw->nblocks, ptw->nblocks - 1);
> + return ret;
> + }
[Severity: Medium]
Can this rollback of ptw->nblocks cause use-after-free or torn reads for
concurrent readers?
If ptwrite_text_poke() fails, ptw->nblocks is rolled back. However, a
lockless reader executing uprobe_ptwrite_handle_fault() under rcu_read_lock()
might have already read the old ptw->nblocks and be actively iterating over
this slot. A subsequent probe installation could then immediately reuse this
array slot and block_off memory without waiting for a synchronize_rcu()
grace period, causing the lockless reader to observe torn data.
> + ptw->cursor = block_off + ptw_a->stub_len;
> + return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831150651.1134594-1-ak@kernel.org?part=10
next prev parent reply other threads:[~2026-08-31 19:59 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 15:04 [RFC] ptwrite uprobes Andi Kleen
2026-08-31 15:04 ` [RFC v1 01/19] uprobes: guard trace cleanup against error pointers Andi Kleen
2026-08-31 18:15 ` sashiko-bot
2026-09-01 0:49 ` Masami Hiramatsu
2026-08-31 15:04 ` [RFC v1 02/19] uprobes: Correctly reject anonymous VMAs for breakpoint installation Andi Kleen
2026-08-31 18:29 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 03/19] uprobes: Print warning for missing breakpoint install Andi Kleen
2026-08-31 18:42 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 04/19] ptwrite uprobes: Add infrastructure for ptwrite uprobes Andi Kleen
2026-08-31 18:55 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 05/19] ptwrite uprobes: Add minimal low level support for x86 Andi Kleen
2026-08-31 19:11 ` sashiko-bot
2026-09-02 16:35 ` Lorenzo Stoakes (ARM)
2026-08-31 15:04 ` [RFC v1 06/19] ptwrite uprobes: Add a sample module to exercise interface Andi Kleen
2026-08-31 19:19 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 07/19] ptwrite uprobes: Add support to tracing infrastructure Andi Kleen
2026-08-31 19:31 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 08/19] ptwrite uprobes / x86: Add a user fault notifier chain Andi Kleen
2026-08-31 19:38 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 09/19] ptwrite uprobes: Factor file-backed instruction reads Andi Kleen
2026-08-31 19:45 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 10/19] ptwrite uprobes: Minimal memory references and fault handling Andi Kleen
2026-08-31 19:59 ` sashiko-bot [this message]
2026-08-31 15:04 ` [RFC v1 11/19] ptwrite uprobes: Add multinop support Andi Kleen
2026-08-31 20:09 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 12/19] ptwrite uprobes: Add pacing to the probes Andi Kleen
2026-08-31 20:19 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 13/19] ptwrite uprobes: Support instruction puning Andi Kleen
2026-08-31 20:39 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 14/19] ptwrite uprobes: Use atomic patching for multinop sites Andi Kleen
2026-08-31 21:08 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 15/19] ptwrite uprobes: Add a tutorial and overview documentation Andi Kleen
2026-08-31 21:10 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 16/19] ptwrite uprobes / perf tools pt: Improve FUP error handling for ptwrite Andi Kleen
2026-08-31 21:19 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 17/19] ptwrite uprobes / perf tools probe: Add support of ptwrite probes Andi Kleen
2026-08-31 21:32 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 18/19] ptwrite uprobes / perf tools script: Add ptwrite uprobes decoder Andi Kleen
2026-08-31 21:39 ` sashiko-bot
2026-08-31 15:04 ` [RFC v1 19/19] ptwrite uprobes: Add self tests Andi Kleen
2026-08-31 21:47 ` sashiko-bot
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=20260831195936.451161F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ak@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.