From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Zhao Gongyi <zhaogongyi@bytedance.com>
Cc: peterz@infradead.org, tglx@kernel.org, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/unwind/orc: Read the CS slot without KASAN checking
Date: Wed, 2 Dec 2026 14:54:57 -0800 [thread overview]
Message-ID: <axChL0Zz1JvUSIGf@jpoimboe> (raw)
In-Reply-To: <20261130125820.37165-1-zhaogongyi@bytedance.com>
On Mon, Nov 30, 2026 at 08:58:20PM +0800, Zhao Gongyi wrote:
> The end-of-stack check in unwind_next_frame() calls user_mode(), leaving
> the recovered CS read instrumented by KASAN. Commit e504e74cc3a2
> ("x86/unwind/orc: Disable KASAN checking in the ORC unwinder, part 2")
> converted other recovered register reads to READ_ONCE_NOCHECK(), but
> left this read unchanged. Best-effort unwinding can visit poisoned slots
> within a valid stack range.
>
> Reading /proc/<pid>/stack has reported a two-byte stack-out-of-bounds
> read at this check:
>
> BUG: KASAN: stack-out-of-bounds in user_mode [inline]
> unwind_next_frame
> arch_stack_walk
> stack_trace_save_tsk
> proc_pid_stack
>
> Read the CS slot with READ_ONCE_NOCHECK() as well. Use the word-sized csx
> member to satisfy the macro's size requirement, and test its low two bits
> to preserve the x86-64 user_mode() predicate. The existing stack range
> checks remain in place.
>
> Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder")
> Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>
> Link: https://syzkaller.appspot.com/bug?extid=d081d4f4ee906c359975
> ---
> Testing:
> - Built baseline and patched unwind_orc.o on d430c96a291a with GCC 12.2,
> KASAN_GENERIC, KASAN_STACK and UNWINDER_ORC; no compiler diagnostics.
> Disassembly confirmed the nocheck CS read, NULL check and low-bit test.
> - Built and booted baseline and patched kernels on 8bf5d77a8edacc under
> x86-64 QEMU/KVM with identical embedded configs and KASAN stack
> instrumentation. Five sampled proc-stack dump symbol sequences matched
> between the two kernels.
> - In a 300-second QEMU/KVM run per kernel with the same workload (48
> churn threads, 12 readers), the baseline logged a two-byte KASAN
> stack-out-of-bounds read in unwind_next_frame() via proc_pid_stack();
> the patched kernel logged no KASAN report during that run.
> - The target task and the ORC entry that produced the recovered regs
> pointer were not captured, so why the read hit a redzone is not
> diagnosed here.
>
> arch/x86/kernel/unwind_orc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
> index 6407bc9..8469a25 100644
> --- a/arch/x86/kernel/unwind_orc.c
> +++ b/arch/x86/kernel/unwind_orc.c
> @@ -494,8 +494,8 @@ bool unwind_next_frame(struct unwind_state *state)
> /* Don't let modules unload while we're reading their ORC data. */
> guard(rcu)();
>
> - /* End-of-stack check for user tasks: */
> - if (state->regs && user_mode(state->regs))
> + /* End-of-stack check, following the other ORC stack access rules. */
> + if (state->regs && (READ_ONCE_NOCHECK(state->regs->csx) & 3))
The fix itself is fine, but the comment is worse, please leave the
original comment intact.
--
Josh
next prev parent reply other threads:[~2026-12-02 22:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:58 Zhao Gongyi
2026-12-02 22:54 ` Josh Poimboeuf [this message]
2026-12-03 3:39 ` Zhao Gongyi
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=axChL0Zz1JvUSIGf@jpoimboe \
--to=jpoimboe@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=zhaogongyi@bytedance.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
all inboxes | Powered by JetHome®