Re: [PATCH v2] rseq: fix using an uninitialized stack variable in rseq_exit_user_update
From: Mark Rutland
Date: Tue Jun 02 2026 - 06:11:55 EST
On Tue, Jun 02, 2026 at 11:08:54AM +0800, Qing Wang wrote:
> There is an bug which is an uninitialized stack variable use in
> `rseq_exit_user_update()` reported by syzbot:
>
> BUG: KMSAN: kernel-infoleak in rseq_set_ids_get_csaddr include/linux/rseq_entry.h:502 [inline]
>
> The local variable:
> ```c
> struct rseq_ids ids = {
> .cpu_id = task_cpu(t),
> .mm_cid = task_mm_cid(t),
> .node_id = cpu_to_node(ids.cpu_id),
> };
> ```
> According to the C standard, the evaluation order of expressions in an
> initializer list is indeterminately sequenced. The compiler (Clang, in this
> KMSAN build) evaluates `cpu_to_node(ids.cpu_id)` *before* `ids.cpu_id` is
> initialized with `task_cpu(t)`.
>
> This is fixed by moving the assignment of ids.node_id outside the structure
> initialization.
>
> Reported-by: syzbot+185a631927096f9da2fc@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=185a631927096f9da2fc
> Fixes: 82f572449cfe ("rseq: Implement read only ABI enforcement for optimized RSEQ V2 mode")
> Signed-off-by: Qing Wang <wangqing7171@xxxxxxxxx>
FWIW, this looks sane to me, so:
Acked-by: Mark Rutland <mark.rutland@xxxxxxx>
Mark.
> ---
> include/linux/rseq_entry.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/rseq_entry.h b/include/linux/rseq_entry.h
> index 63bc72086e75..ed9da6e41a2a 100644
> --- a/include/linux/rseq_entry.h
> +++ b/include/linux/rseq_entry.h
> @@ -635,10 +635,11 @@ static __always_inline bool rseq_exit_user_update(struct pt_regs *regs, struct t
> return true;
> }
>
> + int cpu = task_cpu(t);
> struct rseq_ids ids = {
> - .cpu_id = task_cpu(t),
> + .cpu_id = cpu,
> .mm_cid = task_mm_cid(t),
> - .node_id = cpu_to_node(ids.cpu_id),
> + .node_id = cpu_to_node(cpu),
> };
>
> return rseq_update_usr(t, regs, &ids);
> --
> 2.34.1
>