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=1796351192; b=tlVTdh7dp7tyKGEYBslCzJo0Y8qCpva4Aodqc1bObyIUolReqrrKuCzT8ZpDBiYDs6ap 38o1zi+D8Y/xguHNM4rjsTTLrpYr2Oafp+4e5FMyA4oZA01q9oUU0jeJUH771boIzaiT7 YmVjfY3KkdY6z0midICHxqXipZJu8KiPju1zizfNQWd56QFMDceF4mYqImkaXGLjbTfUb BaX4qVE6cnpgk0eKunJs8W3at1SvUBJym1rQiNead7p3x6ltHCyEHoW3WK9GmvZjhEOkf AsyAhtSAwmjLYzkq6zkIaF7QdBXIlMPpqi9kxyUO/7vJviVM7d3WtkAVafBSj7BiF+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796351192; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type:Content-Transfer-Encoding; bh=JaeUvdhMw/mGwvKLRRZSAjevzVLWiUDyVzra72hrQ3k=; b=kpzTm24PCrDNUxdg8zcOYNrelQ99A76s4W9hG9ZuY0ym4IbEuThNEg2HiHTXeIgHkdx9 y+/LEcbqtswbFIZdv53bR4l4YS6cn0MjXPdgOZHnjLcOZ3PGqVjD8t2D8oihbsMK4876f FIB1N25hEB6BzqE8VBA1yaAE84PzrzzhSKIpKWKmKWZ8BVnhTcRACpmObyiJiCoIlMyVr a66gI6bnVe4CgjJuaWFCig8M3yDG3Y0tb0+nQ50e5jdBmb3K1zbHBlwaMXOUFIbJJXmC4 3hqiMNNDzvkAQtqpxguymcBTJZJK8WhFsdhstcMeRD70Vjx1MIXf29P3iaABFVuL+/Q== 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=o2Kmvihe; 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 D95B5606A32D for ; Fri, 4 Dec 2026 02:26:32 +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=o2Kmvihe Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDF1C1F0092C; Fri, 4 Dec 2026 02:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796351192; bh=JaeUvdhMw/mGwvKLRRZSAjevzVLWiUDyVzra72hrQ3k=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=o2Kmvihe11PavSW6bMYDl6vIzlTZfwPGCHDKdGLmtrVHoSUlPUwyw+kCIcwt/I9/m AoC2psw8EcxxbJ3oMg0PIMB9y0BE4491cgISZ4kZsiWLjXEUepL8QLEecVN96SJKzX CCMXNatIm8E9S9TykCAGloV1JtYp2TLG31boLc8q8NZUNknaUdlyH2tbkQvx60i0a3 IwHK/UuikK/Dten1XKA04qJKpe4JMHO6tEO1uOzhmpbEnqvpNb2D1vBDd/4uGd6hxF XHkOSt/zfKvPUAOvwJKkN+qj7szKYPD5WmzVT8Vqo8bAg3ruOrspjVNdQzCH91MjNT RM63ywgEUKDaw== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 0396EF40066; Thu, 3 Dec 2026 21:26:30 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-01.internal (MEProxy); Thu, 03 Dec 2026 21:26:31 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTF4o1exwK3OBjgZg/Zgy4MCImNlpp9mSap4j2JOj0g+gmoyEU5Pu/Ngg5oYjY7C+F hKZwBtiKXU5idr22wzFURYyGd8i+Fj4NLDQPOJlK0KusKo7rZXoyrJ8A33mu3ZIB4ZyA+u EoCt+9lUGD1qyEUEIg+UYGinm2GdI++z3Tiss4KRtStc+Dxzfgs4BiCyMoeVT7zTv0CcTB y3YdVbqYlVHHKef49/fl+BuN9uPbw/HNyxLsQrnaOLMATyY5PaxqOFL6GLkgH15QHDcCsg VCqHp9fHKBXmYIZR/gXCSnv6Ctu2e8JGZ1T8J3Bi36+theA8I1ZwBN65cdlgoVQ55xIWAS YUha+f9DrWhBE++1KAw6DPXujQ5j/GirTnNjpCwpomL4FWrrR1T3B6n4CM7+Wsmun4Dofl X1A3QhOUoWYa/7rbbrwHmPq7ccTV8ae0XtdGuB6ixeBrWguxOWnb/bNi/KMdH8VW1pP4Oe 1U6hATrXBtKd2RfXIUbV0RuCAcE5gPsSMxw/xFgxiYh3H1HeaoJ5LWJ0OmkFM8jwrGDkRZ uabXuAKvKvv85hnr+ebCE199ZtXVqUKBqCsOu655lsuQqZdJAfPbXMv8KIqeOITW7Ymqx+ 3JrxCKxq8ycDl774CahAoT5doRDguPof79y+zA2eBtzCewIocVfQheYqbmNQ X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D5E13700065; Thu, 3 Dec 2026 21:26:30 -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 Date: Thu, 03 Dec 2026 18:26:09 -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: <905695ec-4d07-4243-8455-41b53cb00022@app.fastmail.com> In-Reply-To: <9f3adeab-5fe8-4100-be62-60fd112a807a@app.fastmail.com> References: <20261129222953.9124-1-kprateek.nayak@amd.com> <20261129222953.9124-5-kprateek.nayak@amd.com> <9f3adeab-5fe8-4100-be62-60fd112a807a@app.fastmail.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 Thu, Dec 3, 2026, at 5:14 PM, Andy Lutomirski wrote: > 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? I meant to mention: there should be LKDTM mechanisms to deliberately trigger these sorts of failures.