From: Jiri Olsa <olsajiri@gmail.com>
To: bot+bpf-ci@kernel.org
Cc: mhiramat@kernel.org, rostedt@goodmis.org, jpoimboe@kernel.org,
peterz@infradead.org, bpf@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, x86@kernel.org, yhs@fb.com,
songliubraving@fb.com, andrii@kernel.org, ast@kernel.org,
daniel@iogearbox.net, martin.lau@kernel.org, eddyz87@gmail.com,
yonghong.song@linux.dev, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCHv2 2/4] x86/fgraph,bpf: Fix stack ORC unwind from kprobe_multi return probe
Date: Tue, 4 Nov 2025 10:27:20 +0100 [thread overview]
Message-ID: <aQnG-D8O8Jco9_4X@krava> (raw)
In-Reply-To: <bb44afd60873d171a8482032e466d2827018486ecd13b4047df74632d2df4950@mail.kernel.org>
On Mon, Nov 03, 2025 at 11:47:37PM +0000, bot+bpf-ci@kernel.org wrote:
> > diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h
> > index 93156ac4f..b08c95872 100644
> > --- a/arch/x86/include/asm/ftrace.h
> > +++ b/arch/x86/include/asm/ftrace.h
> > @@ -56,6 +56,11 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs)
> > return &arch_ftrace_regs(fregs)->regs;
> > }
> >
> > +#define arch_ftrace_partial_regs(regs) do { \
> > + regs->flags &= ~X86_EFLAGS_FIXED; \
> > + regs->cs = __KERNEL_CS; \
> > +} while (0)
> > +
>
> Can arch_ftrace_partial_regs read uninitialized regs->flags?
>
> In return_to_handler, the ftrace_regs structure is allocated on the
> stack but only a few fields are initialized (RAX, RDX, RBP, RSP).
> The EFLAGS/flags field is never written before
> arch_ftrace_partial_regs reads it:
>
> arch/x86/kernel/ftrace_64.S return_to_handler:
> subq $(FRAME_SIZE), %rsp # Allocate ftrace_regs on stack
> movq %rax, RAX(%rsp)
> movq %rdx, RDX(%rsp)
> movq %rbp, RBP(%rsp)
> movq %rsp, RSP(%rsp)
> # No initialization of EFLAGS field
>
> Then ftrace_partial_regs()->arch_ftrace_partial_regs() executes:
> regs->flags &= ~X86_EFLAGS_FIXED;
>
> This reads the uninitialized flags field. Stack allocations contain
> garbage, so regs->flags will have whatever data was previously on
> the stack. The &= operation produces undefined results when operating
> on uninitialized memory.
>
> For comparison, ftrace_regs_caller explicitly initializes EFLAGS:
> movq MCOUNT_REG_SIZE(%rsp), %rcx
> movq %rcx, EFLAGS(%rsp)
>
> Should return_to_handler initialize regs->flags to 0 (or another
> appropriate value) before arch_ftrace_partial_regs modifies it?
yes, that was in the initial version [1] but Stephen did not like that,
so I moved the flags init to later where it needs to take into account
other callers (that have meaningful flags) and just zeros the X86_EFLAGS_FIXED,
so we go through !perf_hw_regs leg in perf_callchain_kernel
jirka
[1] https://lore.kernel.org/bpf/aObSyt3qOnS_BMcy@krava/
next prev parent reply other threads:[~2025-11-04 9:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 22:09 [PATCHv2 0/4] x86/fgraph,bpf: Fix ORC stack unwind from return probe Jiri Olsa
2025-11-03 22:09 ` [PATCHv2 1/4] Revert "perf/x86: Always store regs->ip in perf_callchain_kernel()" Jiri Olsa
2025-11-06 12:27 ` Peter Zijlstra
2025-11-03 22:09 ` [PATCHv2 2/4] x86/fgraph,bpf: Fix stack ORC unwind from kprobe_multi return probe Jiri Olsa
2025-11-03 23:47 ` bot+bpf-ci
2025-11-04 9:27 ` Jiri Olsa [this message]
2025-11-06 12:29 ` Peter Zijlstra
2025-11-07 22:22 ` Alexei Starovoitov
2025-11-03 22:09 ` [PATCHv2 3/4] selftests/bpf: Add stacktrace ips test for kprobe_multi/kretprobe_multi Jiri Olsa
2025-11-03 22:09 ` [PATCHv2 4/4] selftests/bpf: Add stacktrace ips test for raw_tp Jiri Olsa
2025-11-03 23:47 ` bot+bpf-ci
2025-11-04 8:35 ` Jiri Olsa
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=aQnG-D8O8Jco9_4X@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=jpoimboe@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=x86@kernel.org \
--cc=yhs@fb.com \
--cc=yonghong.song@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.