Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/3] riscv: probes: reject probes inside an LR/SC sequence
Date: Sun, 29 Nov 2026 11:23:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-239541@kernel.org> (raw)
In-Reply-To: <20261129-probes-in-lrsc-v6-2-f97e90cf07cf@mobileye.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] riscv: probes: uprobe_in_lrsc_body() accepts probe when first
  page read fails
--

commit f31772122cc1adbb7329eb88b2f9554c8eb7d103
Author: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>

riscv: probes: reject probes inside an LR/SC sequence

This commit adds forward control-flow analysis to reject kprobes and
uprobes placed inside a constrained LR/SC atomic sequence.

> diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c
> index eb177d0ce8ab0..d97a102621665 100644
> --- a/arch/riscv/kernel/probes/uprobes.c
> +++ b/arch/riscv/kernel/probes/uprobes.c
> @@ -28,6 +28,34 @@ unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
>  	return instruction_pointer(regs);
>  }
>  
> +/*
> + * Is the instruction at addr inside a constrained LR/SC sequence? Only the
> + * probed instruction was copied, so read the text that follows it from the
> + * task. The caller holds mmap_lock, as uprobe_write_opcode() requires too.
> + * Text that cannot be read ends the scan early, which accepts the probe.
> + */
> +static bool uprobe_in_lrsc_body(struct mm_struct *mm, unsigned long addr)
> +{
> +	u16 buf[RISCV_LRSC_SCAN_BYTES / sizeof(u16)];
> +	struct vm_area_struct *vma;
> +	struct page *page;
> +	size_t got = 0;
> +	int len;
> +
> +	while (got < sizeof(buf)) {
> +		len = min_t(size_t, sizeof(buf) - got,
> +			    PAGE_SIZE - offset_in_page(addr + got));
> +		page = get_user_page_vma_remote(mm, addr + got, FOLL_FORCE, &vma);
> +		if (IS_ERR(page))
> +			break;
> +		uprobe_copy_from_page(page, addr + got, (void *)buf + got, len);
> +		put_page(page);
> +		got += len;
> +	}
> +
> +	return riscv_probe_in_lrsc_body(buf, got);
> +}
> +
>  int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
>  			     unsigned long addr)
>  {
> @@ -53,6 +81,9 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
>  		return -EINVAL;
>  	}
>  
> +	if (uprobe_in_lrsc_body(mm, addr))
> +		return -EINVAL;
> +
>  	return 0;
>  }

[Severity: Medium]
Can uprobe_in_lrsc_body() accept a probe inside an LR/SC sequence when
get_user_page_vma_remote() fails on the first page?

If the first page fault fails (for example with -EINTR when a fatal signal
is pending during uprobe_mmap(), or -ENOMEM), the loop breaks with got == 0
and riscv_probe_in_lrsc_body(buf, 0) returns false without inspecting even
the instruction already copied into auprobe->insn.
arch_uprobe_analyze_insn() then returns 0, causing prepare_uprobe() to set
UPROBE_COPY_INSN on uprobe->flags permanently.  Later installs of the same
uprobe in other tasks or VMAs see UPROBE_COPY_INSN set, skip
prepare_uprobe(), and plant the breakpoint inside the LR/SC sequence or on
an SC instruction, livelocking the traced process.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-probes-in-lrsc-v6-0-f97e90cf07cf@mobileye.com?part=2

  reply	other threads:[~2026-11-29 11:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 11:09 [PATCH v6 0/3] riscv: probes: check for LR/SC sequence Vladimir Kondratiev
2026-11-29 11:09 ` [PATCH v6 1/3] riscv: kprobes: fix out-of-bounds read in riscv_probe_decode_insn Vladimir Kondratiev
2026-11-29 11:09 ` [PATCH v6 2/3] riscv: probes: reject probes inside an LR/SC sequence Vladimir Kondratiev
2026-11-29 11:23   ` sashiko-bot [this message]
2026-11-29 11:09 ` [PATCH v6 3/3] riscv: kprobes: add KUnit test for LR/SC sequence rejection Vladimir Kondratiev

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=sashiko-outbox-239541@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vladimir.kondratiev@mobileye.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox