From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C005424652 for ; Wed, 5 Aug 2026 10:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785927433; cv=none; b=ctfXTKJZWK6UhpxOdi08M0AJYUT024uYeXc4+sRR/LphgU8zrAkM6ZT/TYyW97KlOeA0VsnfVe2IGIcyCzr8PMfVE6tTFAGLfmeRbthe+afArD5HAfb3rE4os1WEK+ZcKD/ToZmSpm6ZxwepWutT8IcVSw47YpAZX4dM+/KIg4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785927433; c=relaxed/simple; bh=YKw0ICIeRAp6klAi8HX6G8q1ows2MNJoFw+X3vXTcv0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=fgYCAiAwlML7SHU20hJ5KENSitPGlTlDLuXsU27l4C/5XEEVtYo8PrJuNrZ9pw/PsziPJwN0pu5BOdvR+HURuDvHim+qBOotC1YtSJlAft6VyOzHMruV1yZAULgqVHkkFd79y5C6bjrRsIXFIIJepmkMnmXcc1IFRU0+aOhqzXQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VKIJZzOg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MYVbG8L2; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VKIJZzOg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MYVbG8L2" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1785927429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=71fRqqtXUfO+bJD5KP+00ZcULR5gj5K2KGfVM/BikIM=; b=VKIJZzOg9WLmmsZzjEHjB05iOonmZ5dAuWlOaJtIh5Szvkq5tuQlX6hhRZ+DAEdIEOk5Yx GRwif/FtnVz6nHms7qtAfwWs8JfpEEgb3N7lvwoZdpWMXJoVnQSsrrV8KIDBySR5RSxogV SyUHeQpKaxK03xJVJtEldW37sEGXLa/Hre7q21pm/jff7yxddGgijV3l1XWmVPZuW89oka l+IzkrFI2e4Ow6bzoEQ+d/uNRm3T5AHbi1OglzyomLTPGipvZcTxJlz2pF04PPj2cPWZvQ kDn421dCoXOLZjn18RSPcJjTPeFAGkGL0Kcx15nxejXv03eSJsx3dH0EkFKnzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1785927429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=71fRqqtXUfO+bJD5KP+00ZcULR5gj5K2KGfVM/BikIM=; b=MYVbG8L2L5AnSpVAOWIlJO79Nwv09fVLBDBb1zO5HD84ZoSXQI+hq9Ag0BcMSkzTCV3a/G hPDc3ZR6OXaTPlBg== To: Jiakai Xu , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Albert Ou , Alexandre Ghiti , Chunyan Zhang , Jiakai Xu , Matthew Bystrin , Palmer Dabbelt , Paul Walmsley , Rui Qi , Samuel Holland Subject: Re: [PATCH v5] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe() In-Reply-To: <20260705063656.237676-1-xujiakai2025@iscas.ac.cn> References: <20260705063656.237676-1-xujiakai2025@iscas.ac.cn> Date: Wed, 05 Aug 2026 12:57:08 +0200 Message-ID: <87y0ek96nv.fsf@yellow.woof> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Jiakai Xu writes: > The fp_is_valid() function uses ALIGN(sp, THREAD_SIZE) as the upper > bound for the frame pointer check. This bound is calculated relative > to the current sp and shifts upward when sp itself exceeds the valid > stack region, allowing the unwinder to read past the end of the > allocated task stack and triggering KASAN stack-out-of-bounds. > > Fix this by using absolute stack boundaries determined once before > the unwind loop: > > - When sp is on the task stack, use the task's pt_regs as the upper > bound. > - When sp is on the overflow_stack (CONFIG_VMAP_STACK=y), use the > overflow_stack's top as the boundary. > - When sp is on the IRQ stack (CONFIG_IRQ_STACKS=y), use the IRQ > stack's top as the boundary. > - When sp is not on any known stack, warn and return. > - For remote tasks (task != current), if sp is not on the task > stack, warn and return since we cannot reliably determine the > correct boundary from a different CPU's stacks. > > Make the DECLARE_PER_CPU(overflow_stack) unconditional in > asm/stacktrace.h so that stacktrace.c can use > IS_ENABLED(CONFIG_VMAP_STACK) instead of #ifdef, in line with the > kernel coding style which discourages the use of #ifdef in .c files > (https://docs.kernel.org/process/coding-style.html). This is safe > because the DEFINE_PER_CPU (memory allocation) in traps.c remains > guarded by CONFIG_VMAP_STACK; the reference in stacktrace.c is only > compiled when IS_ENABLED(CONFIG_VMAP_STACK) evaluates to true. > > Fixes: a2a4d4a6a0bf ("riscv: stacktrace: fixed walk_stackframe()") > Signed-off-by: Jiakai Xu > Assisted-by: YuanSheng:DeepSeek-V3.2 Reviewed-by: Nam Cao