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=1796346912; b=LtqSO57A7jt2Eops29gAf3jilQ155xp5eHkDV4y/wjqdKOdf3YEW9nPS3UM2rIf8p8XA yTRRReBV7Jhvu78h4hFPWn50IWZqAz4+CXSe2MmtulNH5Zwk/dwlPGeGcnuTP0CYIgK/g HAbGiqSxyB2yguMZrnTTVBk8z4n4Tp9zZvhXhhcxHLdKYUEDWPuTTc5rOvsNP0/DoUHNa KdKf5ejWhbhmFjByeDr8G7p2tB1wl+v1ZDYQZkqUuwvjB9IctudPTnUr/Cgqq6xeNaZpk Rmix/eqI4EPnMJ7FjrSKHKSOWMyBdb5GI6lfMsoTWDcaQDXF6Oo12Pjfzghxmi9SC6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796346912; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:In-Reply-To: References:Subject:Content-Type:Content-Transfer-Encoding; bh=YzBXaxDOiMOG6bzuAbtnrl9qqF1icBg9sEQKLQyW/C4=; b=xuS57zHOtR5Er+HXYzlUauzjXatCft0Zr2EihJ1nqABqKSHT8Po33HmN6gY0oNv98UrV 5xKZIu0iu6mzI4+RzcPu9i0bycrfo8AY4ElU7823P8uhvsrthFuDcalLQXesB6ugpq0Cn EmmvWhxwqAOJD4ZDzYypaEiVjpEsrO6Ub40nGwElZNqj9yqzRN40oVstlrkvzu6bLq8DB J3nbUKRjFg6XpeCZuV0C9jixgmEhom5JiEDfwyo9ZW/7BF9OhXpAFeTvjqajmQB2ZGUNs TnuSckaZLMg7UW/bWU0SWucjifRXkP1CqCN+dA6h1wPts6LkD4Gcl7gpi0XqrBLr1Ow== 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=dH3+KOTp; 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 A7465606A322 for ; Fri, 4 Dec 2026 01:15:12 +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=dH3+KOTp Received: by smtp.kernel.org (Postfix) with ESMTPSA id B62C61F00897; Fri, 4 Dec 2026 01:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796346912; bh=YzBXaxDOiMOG6bzuAbtnrl9qqF1icBg9sEQKLQyW/C4=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=dH3+KOTp11V6HNV0TQG0LtGGehqGur1Mj2vAifhyABFcn6Ut2Eyaf6IBMO6oVWpXt X//Sy7/i8CdMPBBfvGm1WPN0RrIQqsucrOUmPSvnSvLBz8XhkC9UBE4kdOKMV51P8z u8bDw+gqoLd0Tp+pyX6PoYoc06aaDJKzPEVJos4cYQ9hCTojFJtxrWgUUgCuOGhKfN IiSfRUoiUrXFnBuuQkBkpl4OSprZMAcUtjfi+tHCg9UICRDlHs0H0iKluZbKUSTM3R EAS8fRD1AJ+VOFeKWVbQ8knwPOCmDbr4zuW4Z6dnhCsh/RvmqMLixMWGk8kgGBLqx9 XjOYk2pB2JlcQ== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id D17CFF40066; Thu, 3 Dec 2026 20:15:10 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-01.internal (MEProxy); Thu, 03 Dec 2026 20:15:10 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTFburOgZ/5xuHkpv/Nsu4KJJTKLyXksHZAUDHpzbikAPv1JzHVMGF7vHgs87vits/ AElHc4LvXBVQv1qLY3a41Jgki2C/+TikVJu36bzsSpKEoF/qlRJzy2OsnTvfB9xtVs1biU D0rgpVTMD2pK/Ytn0jsWQloT8owXGOPc7zGsYRrOr/4hRye1FFJRapixDVaf8yambuKbHp nU8khV1CUiWaVxdGR+YAdMxHSBfY1Zd5eV26VwsXFBckU2RLj5KM1q/Ooui6AoHXyeg0zk Lpavd8e3Fsd1ltRX4hTSLWG5wlNeD7Oro21W4y6VeSo0WzihEpF8oXhe9Oeda3unQ6qLt3 Iyzv2dJDZjmSliGAjFVSdGBPymISNL3P/2nqBu686yxPVvQCMU9v9w0gTprVSfR6cmqThX Cyl1mCOnAdHwssSv3q2WJ46dEQfuhB7c20J0LdEHPgv4Q8Fi9CFuyPn+hTGONxRRKMUYlk lMq3AZS8++BTj89hgWD+79XagMZpsxwFwVcIOu47O0+EwLa9qnhGEZ3/JwKUJaiXHkSdKK cOojaCNsglxujWAwxoT6AME7xDqOc8uP+EZsHQQ+TQXctOQf5UaoMFlNIwaV6Rw4diuCYQ ouMvWfsT8nLDOC8qcbjfCNW7AzJdVPWXKzGvoVZJjZx5St2GHprXWOpkvJyw X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id ABC6D700065; Thu, 3 Dec 2026 20:15:10 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface 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 X-ThreadId: AoHIqsiCY7sV Date: Thu, 03 Dec 2026 17:14:49 -0800 From: "Andy Lutomirski" To: "K Prateek Nayak" , "Dave Hansen" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "the arch/x86 maintainers" , "Linux Kernel Mailing List" Cc: "Peter Zijlstra (Intel)" , "Rick P Edgecombe" , "Andrew Cooper" , "Kees Cook" , "Pawan Gupta" Message-Id: <9f3adeab-5fe8-4100-be62-60fd112a807a@app.fastmail.com> In-Reply-To: <20261129222953.9124-5-kprateek.nayak@amd.com> References: <20261129222953.9124-1-kprateek.nayak@amd.com> <20261129222953.9124-5-kprateek.nayak@amd.com> Subject: Re: [RFC PATCH 04/27] x86/cet: Make kernel shadow stack #CP fatal instead of livelocking Content-Type: text/plain Content-Transfer-Encoding: 7bit On Sun, Nov 29, 2026, at 2:29 PM, K Prateek Nayak wrote: > A kernel-mode shadow stack #CP (NEAR-RET or FAR-RET/IRET) ends up in > do_unexpected_cp(), which does WARN_ONCE() and returns to a shadow stack > with mismatch. Returning executes that instruction again and faults > again. After the first WARN this repeats silently forever. For example, > IRET-to-self in sync_core() on a CPU without SERIALIZE just hangs the > machine. > > Nothing can be fixed up at that point. Handle kernel-mode shadow stack > regular stack top vs the shadow stack top for RET, and the RIP in the > IRET/ERETS frame vs the shadow stack LIP for FAR-RET/IRET. Then die(). > A code path that returns somewhere the shadow stack doesn't expect now > shows up as a one-line oops naming both targets, instead of a hang or a > WARN storm. > > static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long > error_code) > { > if ((error_code & CP_EC) != CP_ENDBR) { > @@ -156,36 +229,16 @@ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) > else > do_unexpected_cp(regs, error_code); > } else { > - if (cpu_feature_enabled(X86_FEATURE_IBT)) > + if (cpu_feature_enabled(X86_FEATURE_KERN_SHSTK) && > + (error_code & CP_EC) != CP_ENDBR) > + do_kernel_shstk_cp(regs, error_code); > + else if (cpu_feature_enabled(X86_FEATURE_IBT)) > do_kernel_cp_fault(regs, error_code); > else > do_unexpected_cp(regs, error_code); > } > } When I did all the vmap stack overrun code, I made a point of explicitly analyzing and testing the behavior of the related faults, *including when either the code that faulted or the handler, at any stage including asm, overran the stack*. This needs the same treatment. If we somehow overrun the shadow stack (unlikely but far from impossible, especially if something like the BPF JIT or retpolines mess up outrageously) or if we somehow corrupt SSP. And we need to cover the case where SSP points to non-shstk memory. (Off the top of my head this will end up double-faulting, and we will hit either the IST or the FRED_RSP table, and that needs testing too.) All of these should result in cleanly killing the offending task, printing a log, *and still working correctly if it happens multiple times*, which means we need to be able to escape from #DF context and survive the do_exit experience. Which will be great fun. Maybe this series already handles all of this. Does it?