On Mon, Jun 29, 2026 at 08:13:33PM -0400, David Windsor wrote:
> Uprobe CALL emulation updates the normal user stack, but not the CET user
> shadow stack. The subsequent RET then sees a stale shadow stack entry and
> raises #CP.
> 
> Update the relative CALL emulation and XOL CALL fixup paths to keep the
> shadow stack in sync.
> 
> Fixes: 488af8ea7131 ("x86/shstk: Wire in shadow stack interface")
> Signed-off-by: David Windsor <[email protected]>

hi, lgtm

Tested-by: Jiri Olsa <[email protected]>
Acked-by: Jiri Olsa <[email protected]>

jirka


> ---
> 
> v2:
>  - propagate error from shshk_update_last_frame() rather than returning
>    -ERESTART in default_post_xol_op(). (Oleg)
> 
> v1: https://lore.kernel.org/all/[email protected]/
> 
>  arch/x86/kernel/uprobes.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index ebb1baf1eb1d..d74bb54543b6 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
> @@ -1246,9 +1246,15 @@ static int default_post_xol_op(struct arch_uprobe 
> *auprobe, struct pt_regs *regs
>               long correction = utask->vaddr - utask->xol_vaddr;
>               regs->ip += correction;
>       } else if (auprobe->defparam.fixups & UPROBE_FIX_CALL) {
> +             unsigned long retaddr = utask->vaddr + auprobe->defparam.ilen;
> +             int err;
> +
>               regs->sp += sizeof_long(regs); /* Pop incorrect return address 
> */
> -             if (emulate_push_stack(regs, utask->vaddr + 
> auprobe->defparam.ilen))
> +             if (emulate_push_stack(regs, retaddr))
>                       return -ERESTART;
> +             err = shstk_update_last_frame(retaddr);
> +             if (err)
> +                     return err;
>       }
>       /* popf; tell the caller to not touch TF */
>       if (auprobe->defparam.fixups & UPROBE_FIX_SETF)
> @@ -1338,6 +1344,10 @@ static bool branch_emulate_op(struct arch_uprobe 
> *auprobe, struct pt_regs *regs)
>                */
>               if (emulate_push_stack(regs, new_ip))
>                       return false;
> +             if (shstk_push(new_ip) == -EFAULT) {
> +                     regs->sp += sizeof_long(regs);
> +                     return false;
> +             }
>       } else if (!check_jmp_cond(auprobe, regs)) {
>               offs = 0;
>       }
> -- 
> 2.53.0
> 

Reply via email to