From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796252100; b=3/OxLrk1tugx71c7SFhgxFsx8+QmDbHhskH/965chhoD4ZijuT9QYOBYVrV2lwTzWN9o EsXZTfVF4zs2+AnNRhrSSwtwjS/w+sOfctMVC7dE9pMnbD2dN8zvAYbddybB2TPMP20xU VbFomMm/jdk4u+oVW1aZJaomj4t0HWOeBc1BMnHmV0emiVKq/joG3Ek9/V95g7dl+fq6u OwJaRLkr1Pgm9KmkDr5FBkU/y3cUWHthcIzZ1a63WL4/l3W3wfm1VcB1R7n4srXz7xMdq TPfqog+G1N4rvq5Yr3gad904fLDt8xx2ECSeHUFZw+ozHeuRnmJehTdQFZesTmqKSIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796252100; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=hhgn6+c5OLT1aBVV9yGo0o0bTWp+0dXh9z4gvZcUQQE=; b=Jvu9xWBoOBbdVAj95WJGCUvQMOePYhkeeHQ3ujF3YUkQ3YcI7dEurJ/Sh79fov1p8Rr8 0IXgTKNkMwLDw+T4d5w4jGvTu1+62q0x/gyBztlGv+85+z6gCUpSMbz8erVO7piOMf7hP wRRqn7++Sd4ndl92slKoZXutyLYBVifZX1DDIYs92WgLyP225LcfF+pQthOBnkFejDUos oNuYrIGQ4pcBKCZHDy4QS62W/lKtwPIVCZwrX8tAWs6eH7VsDf1R76dtqcG1jHzsHa9w5 6vzn1FiBQlJOuwQsQJdp4G6w/LTk1OFcCviDM4EUF/Dg3W2Ji20HqwvibHwDJCPfDAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HgpsJ+SW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52009606A322 for ; Wed, 2 Dec 2026 22:55:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HgpsJ+SW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54D151F00893; Wed, 2 Dec 2026 22:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796252099; bh=hhgn6+c5OLT1aBVV9yGo0o0bTWp+0dXh9z4gvZcUQQE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HgpsJ+SWs9ebI7U7RydphZFN97v1pJLIQdT62oiRPvUkZLxZcbUGI8bb5klcRhFDH ypBW+d5N7Rj+WYHgOEi6I2hWdLzkuxuqA7huWydVZlo9D64C6QurWLplXTrcmVq1nU mY9/VQh8z0Yxx5XdZ4vQKGtfMUtI4/WYlnHR4/PxR2jrJK5a7RvSPa8EDNcAJaT9/d CskMyCTQDuhMRO8U8cnXb8RkKu1Aahyug89u5BntVbog1YjtmUhI5MahCLJaC0hpG9 0eKv+2vre9FlWQ6JsTxe3PRpvgDe7WRPcuQL4GbPdlWJlUK/6vs3t7/ObTQtOgESy9 bCNt6DNV6j6DQ== Date: Wed, 2 Dec 2026 14:54:57 -0800 From: Josh Poimboeuf To: Zhao Gongyi 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 Message-ID: References: <20261130125820.37165-1-zhaogongyi@bytedance.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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//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 > 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