From: Vladimir Kondratiev <Vladimir.Kondratiev@mobileye.com>
To: 袁晓峰 <yuanxiaofeng@eswincomputing.com>
Cc: "Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Oleg Nesterov" <oleg@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Guo Ren" <guoren@kernel.org>,
"Pekka Enberg" <penberg@kernel.org>,
"Patrick Stählin" <me@packi.ch>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
"Palmer Dabbelt" <palmerdabbelt@google.com>,
Sashiko <sashiko-bot@kernel.org>,
"Nam Cao" <namcao@linutronix.de>
Subject: Re: [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence
Date: Wed, 18 Nov 2026 17:43:06 +0200 [thread overview]
Message-ID: <400aae15-aa35-4e49-afa9-427c0fe60309@mobileye.com> (raw)
In-Reply-To: <178ccbf1.a40.1a1ee49cebb.Coremail.yuanxiaofeng@eswincomputing.com>
On 11/18/26 12:52, 袁晓峰 wrote:
> Hi Vladimir, Nam, Masami,
> Vladimir, your forward scan also covers uprobes
> and does not suffer from the lone-lr false rejection that our window-based check had,
> so your approach is the better base; I would rather continue the fix on top of
> your series than push ours.
I discovered fundamental flaw in this simple forward scan approach. For
example it can't detect a literal inside the code. In the next version I
implemented a Control Flow Graph analysis.
> 1) Window size
>
> Spec 13.3 defines the constrained LR/SC loop as the LR/SC sequence plus
> the code to retry it, at most 16 instructions in total. That leaves at
> most 14 instructions between the lr and the sc (fewer once the retry
> branch is counted). RISCV_LRSC_MAX_BODY=16 is larger than that; could we
> align the bound with the spec? We had an off-by-one round on this with Nam
> in our series.
Thanks for this. I misread the spec in a way there's at max 16
instructions between LR and SC, this is wrong. Spec says, reduced quote:
---cut---
The loop comprises only an LR/SC sequence and code to retry the sequence
in the case of failure, and must comprise at most 16 instructions placed
sequentially in memory.
An LR/SC sequence begins with an LR instruction and ends with an SC
instruction. [...]
The code to retry a failing LR/SC sequence can contain backwards jumps
and/or branches to repeat the LR/SC sequence [...]
---cut---
There's 16 instructions limit for the
- LR
- dynamic code between LR/SC
- SC
- code to retry
I will update my defines. I can't analyze "code to retry" and don't know
where is the LR instruction, effectively maintaining 64-byte window to
scan for the SC. Assumption is only valid constrained LR/SC loops are
used, unconstrained LR/SC loops not supported.
> Three smaller things:
>
> - KUNIT_EXPECT_LT(ret, 0) also accepts -EILSEQ (or any other negative
> error), so it can pass even when the LR/SC rejection did not happen.
> -EINVAL would pin the specific reason.
Good point.
> - There is no allow-direction boundary, so a window that is too wide
> would still pass. A case just outside the (spec-correct) window,
> expected to be accepted, would pin the bound from both sides.
This is because I can't find LR; this is correct for both kprobes and
uprobes. For uprobes - because I have no symbolic information; for
kprobes - if one put global label inside the function, scan from the
nearest symbol won't work anymore. But assuming every SC belongs to
valid constrained LR/SC loop, I don't need it. This code will not detect
badly formed LR/SC loop.
> - The max-length case is lr + 16 nops + sc, which is neither a loop nor
> within the 16-instruction spec bound. A real loop (lr + 13 instructions
> + sc + retry branch) would test what the spec actually constrains.
Yes, will fix
One more note, I have unanswered question, it can alter part of the
riscv_insn_is_lrsc_body that deals with branches:
https://lore.kernel.org/all/a971d355-a7bd-41a8-83ba-a250e77f78f1@mobileye.com/
Thanks, Vladimir
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Vladimir Kondratiev <Vladimir.Kondratiev@mobileye.com>
To: 袁晓峰 <yuanxiaofeng@eswincomputing.com>
Cc: "Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Oleg Nesterov" <oleg@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Guo Ren" <guoren@kernel.org>,
"Pekka Enberg" <penberg@kernel.org>,
"Patrick Stählin" <me@packi.ch>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
"Palmer Dabbelt" <palmerdabbelt@google.com>,
Sashiko <sashiko-bot@kernel.org>,
"Nam Cao" <namcao@linutronix.de>
Subject: Re: [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence
Date: Wed, 18 Nov 2026 17:43:06 +0200 [thread overview]
Message-ID: <400aae15-aa35-4e49-afa9-427c0fe60309@mobileye.com> (raw)
In-Reply-To: <178ccbf1.a40.1a1ee49cebb.Coremail.yuanxiaofeng@eswincomputing.com>
On 11/18/26 12:52, 袁晓峰 wrote:
> Hi Vladimir, Nam, Masami,
> Vladimir, your forward scan also covers uprobes
> and does not suffer from the lone-lr false rejection that our window-based check had,
> so your approach is the better base; I would rather continue the fix on top of
> your series than push ours.
I discovered fundamental flaw in this simple forward scan approach. For
example it can't detect a literal inside the code. In the next version I
implemented a Control Flow Graph analysis.
> 1) Window size
>
> Spec 13.3 defines the constrained LR/SC loop as the LR/SC sequence plus
> the code to retry it, at most 16 instructions in total. That leaves at
> most 14 instructions between the lr and the sc (fewer once the retry
> branch is counted). RISCV_LRSC_MAX_BODY=16 is larger than that; could we
> align the bound with the spec? We had an off-by-one round on this with Nam
> in our series.
Thanks for this. I misread the spec in a way there's at max 16
instructions between LR and SC, this is wrong. Spec says, reduced quote:
---cut---
The loop comprises only an LR/SC sequence and code to retry the sequence
in the case of failure, and must comprise at most 16 instructions placed
sequentially in memory.
An LR/SC sequence begins with an LR instruction and ends with an SC
instruction. [...]
The code to retry a failing LR/SC sequence can contain backwards jumps
and/or branches to repeat the LR/SC sequence [...]
---cut---
There's 16 instructions limit for the
- LR
- dynamic code between LR/SC
- SC
- code to retry
I will update my defines. I can't analyze "code to retry" and don't know
where is the LR instruction, effectively maintaining 64-byte window to
scan for the SC. Assumption is only valid constrained LR/SC loops are
used, unconstrained LR/SC loops not supported.
> Three smaller things:
>
> - KUNIT_EXPECT_LT(ret, 0) also accepts -EILSEQ (or any other negative
> error), so it can pass even when the LR/SC rejection did not happen.
> -EINVAL would pin the specific reason.
Good point.
> - There is no allow-direction boundary, so a window that is too wide
> would still pass. A case just outside the (spec-correct) window,
> expected to be accepted, would pin the bound from both sides.
This is because I can't find LR; this is correct for both kprobes and
uprobes. For uprobes - because I have no symbolic information; for
kprobes - if one put global label inside the function, scan from the
nearest symbol won't work anymore. But assuming every SC belongs to
valid constrained LR/SC loop, I don't need it. This code will not detect
badly formed LR/SC loop.
> - The max-length case is lr + 16 nops + sc, which is neither a loop nor
> within the 16-instruction spec bound. A real loop (lr + 13 instructions
> + sc + retry branch) would test what the spec actually constrains.
Yes, will fix
One more note, I have unanswered question, it can alter part of the
riscv_insn_is_lrsc_body that deals with branches:
https://lore.kernel.org/all/a971d355-a7bd-41a8-83ba-a250e77f78f1@mobileye.com/
Thanks, Vladimir
next prev parent reply other threads:[~2026-11-18 15:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 12:37 [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence Vladimir Kondratiev
2026-11-15 12:37 ` Vladimir Kondratiev
2026-11-15 12:37 ` [PATCH v4 1/3] riscv: kprobes: fix out-of-bounds read in riscv_probe_decode_insn Vladimir Kondratiev
2026-11-15 12:37 ` Vladimir Kondratiev
2026-11-15 12:37 ` [PATCH v4 2/3] riscv: probes: reject probes inside an LR/SC sequence Vladimir Kondratiev
2026-11-15 12:37 ` Vladimir Kondratiev
2026-11-15 13:01 ` sashiko-bot
2026-11-15 18:37 ` kernel test robot
2026-11-15 18:37 ` kernel test robot
2026-11-15 20:12 ` kernel test robot
2026-11-15 20:12 ` kernel test robot
2026-11-15 12:37 ` [PATCH v4 3/3] riscv: kprobes: add KUnit test for LR/SC sequence rejection Vladimir Kondratiev
2026-11-15 12:37 ` Vladimir Kondratiev
2026-11-18 10:52 ` [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence 袁晓峰
2026-11-18 10:52 ` 袁晓峰
2026-11-18 15:43 ` Vladimir Kondratiev [this message]
2026-11-18 15:43 ` 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=400aae15-aa35-4e49-afa9-427c0fe60309@mobileye.com \
--to=vladimir.kondratiev@mobileye.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=me@packi.ch \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=oleg@redhat.com \
--cc=palmer@dabbelt.com \
--cc=palmerdabbelt@google.com \
--cc=penberg@kernel.org \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=yuanxiaofeng@eswincomputing.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 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.