Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 54DC2442FB7; Tue, 21 Jul 2026 20:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667576; cv=none; b=DKfQRzAKi+pwP8EUaotkYsPpBq3uaY793fSdbu6RBT0xMIgmufOVXp+ZRyNkq+E0pVdhza83F8DiBITDkcIyz5EqW8xuBlcPDRAMlTMtzV+cTV31HgO7cy92jCGxGLdcdpQShNPB9MOzOzVbxJNcyQfqX99FCTTgiAYMTiwwQCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667576; c=relaxed/simple; bh=1vn3gsCp0lqGFlJZl59H2ElwVxl7vIcNn5z/RAT70wY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g1p8tl6cLQKldJohM99wZo4GiIiN7q9ekPtSwOIVqXpo8s/GUrxrLMoJe6ybmq9DvxPAFmX3a7jJTNaPj2zfmgVX63JSP3aVRcTS2bxiY+UMkeIImyKS2mzNvOyHDUlT5RwJE3fzqif1BeSqHlkqhP/+4W7Ha7RW34gnUB2nCYw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zep4cBTb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zep4cBTb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8CDB1F000E9; Tue, 21 Jul 2026 20:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784667575; bh=DKJEVlk5lej99uJL9WBI8NpOcEwdSIIo4IFFig9AJew=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zep4cBTb3LAtA3pKf1sBu6ycLhb/WtiWGVsQpxzzKKRpka/yJxx5Hj7R7/IIRb7FQ NOEe0z0keJcPKWb2CbBxa4qjb05VyuU8+/KHKudzC2T7bzwUFI4nzXTjcGBSZQFRPF XIMeA3rd0lnuNCYI0og/ErHmphuHvIe6D08WuuIw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Martin Kaiser , "Masami Hiramatsu (Google)" , Paul Walmsley Subject: [PATCH 6.6 1114/1266] riscv: probes: save original sp in rethook trampoline Date: Tue, 21 Jul 2026 17:25:51 +0200 Message-ID: <20260721152506.731814409@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Kaiser commit bc7b086a45521a986a49045907f017e3e46c763e upstream. Reading a word from the stack in a kretprobe crashes a risc-v kernel. $ cd /sys/kernel/tracing/ $ echo 'r n_tty_write $stack0' > dynamic_events $ echo 1 > events/kprobes/enable Unable to handle kernel paging request at virtual address 0000000200000128 ... [] regs_get_kernel_stack_nth+0x26/0x38 [] process_fetch_insn+0x3ee/0x760 [] kretprobe_trace_func+0x116/0x1f0 [] kretprobe_dispatcher+0x4a/0x58 [] kretprobe_rethook_handler+0x5e/0x90 [] rethook_trampoline_handler+0x70/0x108 [] arch_rethook_trampoline_callback+0x12/0x1c [] arch_rethook_trampoline+0x48/0x94 [] tty_write+0x1a/0x30 In regs_get_kernel_stack_nth, regs->sp contains an arbitrary value. arch_rethook_trampoline saves the registers from the probed function in a struct pt_regs. sp is not saved. Instead, sp is decremented for arch_rethook_trampoline's local stack. Fix this crash and save the original sp along with the other registers. Use a0 as a temporary register, it is overwritten anyway. Cc: stable@vger.kernel.org Fixes: c22b0bcb1dd02 ("riscv: Add kprobes supported") Signed-off-by: Martin Kaiser Acked-by: Masami Hiramatsu (Google) Link: https://patch.msgid.link/20260630194010.1824039-1-martin@kaiser.cx [pjw@kernel.org: added Fixes tag; cc'ed stable] Signed-off-by: Paul Walmsley Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kernel/probes/rethook_trampoline.S | 3 +++ 1 file changed, 3 insertions(+) --- a/arch/riscv/kernel/probes/rethook_trampoline.S +++ b/arch/riscv/kernel/probes/rethook_trampoline.S @@ -41,6 +41,9 @@ REG_S x29, PT_T4(sp) REG_S x30, PT_T5(sp) REG_S x31, PT_T6(sp) + /* save original sp */ + addi a0, sp, PT_SIZE_ON_STACK + REG_S a0, PT_SP(sp) .endm .macro restore_all_base_regs