From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 62E6E348894; Tue, 11 Nov 2025 01:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762825324; cv=none; b=fn0tQ7g1Af+umpcUxA81plhAP1d4MBTpApKCcyzrYjeYZa4P73N22RsId+KY0zzdxskIwUHm8frHB2Gd9IoODsgrC4FK5jZ++W8QaK89yAl+orhDu7Bn4eENaHXX7hbRE/ECSmXifHD5LnYkk9M9xC5PLREIcqu3wlkFih0VIKk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762825324; c=relaxed/simple; bh=flV0s+vc0KIYUJOvIky4GSf7VDWasQBJsuakD+PeMYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iyb2ZPyLUVBwvwvIN8TRUFxIrcXn7wmz151VBa8ecHi2mwP5jhhlClIsXzkav7hhyM4kQujS3HzioN+3F7ZfBbEDnb0hEqR2Nne5IZOEpNKYvz3nWx7pmgskasAn0bTP3xbfwFkEjz58/yctJ5P4GVuK+AIvobwFxgVgly+oh3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YXrIMe0h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YXrIMe0h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC315C4CEF5; Tue, 11 Nov 2025 01:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1762825324; bh=flV0s+vc0KIYUJOvIky4GSf7VDWasQBJsuakD+PeMYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YXrIMe0hN8LszHKFdCPtlMVWN2k8t0wgDpOiV7a5ShDO7dNngaJkFZtkY1SRUp/sF y3J9FabEJj8jszGnr8tCLwulVxym9IFaeYjMjfLhA92ukoD2ohmvCFGBOsIJ6+rkGz o3693bqFv20fIllHog38tzsgOyMNC+M+Y5J4H1XM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiakai Xu , Chunyan Zhang , Paul Walmsley , Sasha Levin Subject: [PATCH 6.17 752/849] riscv: stacktrace: Disable KASAN checks for non-current tasks Date: Tue, 11 Nov 2025 09:45:22 +0900 Message-ID: <20251111004554.613480498@linuxfoundation.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251111004536.460310036@linuxfoundation.org> References: <20251111004536.460310036@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chunyan Zhang [ Upstream commit 060ea84a484e852b52b938f234bf9b5503a6c910 ] Unwinding the stack of a task other than current, KASAN would report "BUG: KASAN: out-of-bounds in walk_stackframe+0x41c/0x460" There is a same issue on x86 and has been resolved by the commit 84936118bdf3 ("x86/unwind: Disable KASAN checks for non-current tasks") The solution could be applied to RISC-V too. This patch also can solve the issue: https://seclists.org/oss-sec/2025/q4/23 Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly") Co-developed-by: Jiakai Xu Signed-off-by: Jiakai Xu Signed-off-by: Chunyan Zhang Link: https://lore.kernel.org/r/20251022072608.743484-1-zhangchunyan@iscas.ac.cn [pjw@kernel.org: clean up checkpatch issues] Signed-off-by: Paul Walmsley Signed-off-by: Sasha Levin --- arch/riscv/kernel/stacktrace.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 3fe9e6edef8f1..b41b6255751cb 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -16,6 +16,22 @@ #ifdef CONFIG_FRAME_POINTER +/* + * This disables KASAN checking when reading a value from another task's stack, + * since the other task could be running on another CPU and could have poisoned + * the stack in the meantime. + */ +#define READ_ONCE_TASK_STACK(task, x) \ +({ \ + unsigned long val; \ + unsigned long addr = x; \ + if ((task) == current) \ + val = READ_ONCE(addr); \ + else \ + val = READ_ONCE_NOCHECK(addr); \ + val; \ +}) + extern asmlinkage void handle_exception(void); extern unsigned long ret_from_exception_end; @@ -69,8 +85,9 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, fp = frame->ra; pc = regs->ra; } else { - fp = frame->fp; - pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra, + fp = READ_ONCE_TASK_STACK(task, frame->fp); + pc = READ_ONCE_TASK_STACK(task, frame->ra); + pc = ftrace_graph_ret_addr(current, &graph_idx, pc, &frame->ra); if (pc >= (unsigned long)handle_exception && pc < (unsigned long)&ret_from_exception_end) { -- 2.51.0