From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.10 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796355577; b=h3IkbhqoY3a+B2sXW+DN9rOmwM/uKP00NUHENxuKa8+umrzlBJjW4wBsTh7PBE3vcLkV s9Tr4w+EQttbCwkD5Nl3gO1CyPSr3uf1yC8tm5o9vN5SGUIRlx9w1/cnLQbJXJbjPmaXW ucbnp7wMjrR+5iYittx7/qVHgfwxDiDo0fAQebs9uetKnGYzqBpTXBk8gc1282RUZKqLd 7QyLQ29+m2mly5y55jEKWOGbFXZbz1yROUWeqN2v2cskbiLe4c2MlQsWfNj4mmJa7WpJq BGK7LOZQqrVLIu7XOOcMYFyGUikRDeF+0o8fYe0WC0/jg6l7gtv6UPcgGhv61XKYvuA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355577; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To: CC:References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=jGdTMKodMty2jC/yWXfrDUHj45qNyhWeb2Sy/n2VY+Y=; b=OPN4MyTOtkRw1UX0Q2MFH77zqK0diUF9+Y4faOsc5ipzgapOtmgg2qsfveaM1RWUC7yr V4FP6eCobob86VMz2s+094zLk8Qj1/bMipfUR4UYOqQWSUCwTkKg2uGAg9xYzNESbuXxN 9zf+Ybz5xaJT8BIWCagaO/U5lNvoK3tgVOLVisdjW4u2kFCwlX0nzHGayw++iVzY/A0PL UQpASGN+tramULa9EX+GTmCcQJPPBWD2xdUGdOSUqJ2y8bovpU5NXG+EMMfObKkup78XB JXiSIKzFn/G4CHcBie78587HNWNdyCjeIHDxgwWXUigUUPkV8RdvbteiwMlxPBpHNEA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=bQWU2YQy; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.10 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012010.outbound.protection.outlook.com [52.101.43.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EABE606A322 for ; Fri, 4 Dec 2026 03:39:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9EABE606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=bQWU2YQy ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fc9lYrpVcfrodSaCD7vUtLMUMZFz78jWb8TdQLyMp4ogcDXnxdJ8PYW942peihOsb4ZEKcm6HvmJYANTj7UoAjvdx2ElZ9mI1QKY4Hkk/Hf9IiyYXipZrLpKTooXlGxBkpA0DXEA1cd2CtUUpm51poWb+oA/gZ/ESizT+0C4xx7eQ8dKuoxMGV+2/nW4+jKWbFtM3BFLy+NTP5q3w+d9Y9ibtzXXEDmEpy9AkulPjO7pUD+emGHWtdIsrj2fo6Qog1336jYw5bhjjYW5+zWSiqXARXwpF/Qm6G3scKXh9mB+V2/BUz7xhn3UdiVnHmliyqs87izrfJz1v5zjYdQndw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jGdTMKodMty2jC/yWXfrDUHj45qNyhWeb2Sy/n2VY+Y=; b=ys5H3XEZh3DzB++BTV8Xs2gL3rkhcS+6jBlb2r47pBooyryTeBTE4u/Q8WQSpFjR7cPcFqdmI6ZdYZ3t8DDYvrEgqAHzGqRTTw3Xb+6j1XcI2KGGYvMTLBfsrTpyvyM8rgg537Vo+7BID4D81xj9+Cq8DXphkUjkq1tr/g+SYaibO4sr1tQ7m0xrmypYhP5rIR0Tmg1oOM9X+m/vwhz54UZ3G+HyEp/6IMA9Xhc3SjPN9ID/I4VJGXb23OJ/u1JLwnljDhz5QphBPi/oI5dmBVZTshVTCthw8+rRB+scQhHGKx1yFiH7+KucK0faSB2risFiZcySrQeG/fN0pKoYLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jGdTMKodMty2jC/yWXfrDUHj45qNyhWeb2Sy/n2VY+Y=; b=bQWU2YQytF8byG/cRQ+lvO3qCWgOxBlUHuSODlEHvsQqdaJYoEQBtYERfoCjOMdsgCiEEvbXjoCXAaXk64MJLNipRNfg5NjjOQRAXIFdextlgmSRD+xHf3XqGMYJTiYZaQH4sjCycv1OaxBeMw8nFE/cFwIKp+GODOxDRA6ZgJY= Received: from BL1PR13CA0015.namprd13.prod.outlook.com (2603:10b6:208:256::20) by DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Fri, 4 Dec 2026 03:39:28 +0000 Received: from MN1PEPF000793FE.namprd05.prod.outlook.com (2603:10b6:208:256:cafe::5) by BL1PR13CA0015.outlook.office365.com (2603:10b6:208:256::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Fri, 4 Dec 2026 03:39:28 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by MN1PEPF000793FE.mail.protection.outlook.com (10.167.249.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 03:39:28 +0000 Received: from satlexmb10.amd.com (10.181.42.219) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 21:39:28 -0600 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 21:39:27 -0600 Received: from [10.136.42.27] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 21:39:24 -0600 Message-ID: <8de181b8-ac8e-4195-aa80-4bd5252523f1@amd.com> Date: Fri, 4 Dec 2026 09:09:18 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 04/27] x86/cet: Make kernel shadow stack #CP fatal instead of livelocking To: Andy Lutomirski , 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 References: <20261129222953.9124-1-kprateek.nayak@amd.com> <20261129222953.9124-5-kprateek.nayak@amd.com> <9f3adeab-5fe8-4100-be62-60fd112a807a@app.fastmail.com> <905695ec-4d07-4243-8455-41b53cb00022@app.fastmail.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <905695ec-4d07-4243-8455-41b53cb00022@app.fastmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF000793FE:EE_|DM3PR12MB9416:EE_ X-MS-Office365-Filtering-Correlation-Id: c6fbb877-777e-4096-59e1-08df51b8332f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|1800799024|36860700016|376014|7416014|4143699003|11063799006|5023799004|6133799003|261009223027099003|3023799007|13003099007|22082099003|18002099003|261026140227099003|56012099006|261021123027099003|10067099003|261022105027099003|261102123227099003|261028144727099003|261021121427099003|261022075727099003|261026121527099003; X-Microsoft-Antispam-Message-Info: 6sl5p2MH7ua2qFRIAQKV/h/b4j6JB6pvnvnGhdPVvI2bDVnB5gGA9+pkKZvL6EXoV2kXz2H3MOK0LHwIIlzltG+h9bxSFwWQyhuecYQ2haJdOn3lU4tHWHUVwFYd+2/7Fk4hrNw0P5mX7LLrXskRXUbft65Acrh95fj4pe8OFALHUuyYWUrwpNjwmNe+EuVZ1oRmR8oojmd1DoA29VSM4wHG2Nl+hJPM3HcNP+FErFoARI7OPQTgLSpFN+dgpk/ixnVkkZZxjrxF3U6Fvt00gtsa2SXizhYMUbr5ShSYFI3wFgjtXJRO8eN5c42sYyPf9oi70FwFzvnxv+f9gO41kjpIq/yeXAkRZQ1JIBhNLEcVZzl74jg8no1FoDtf/eGUNg5QTHvh6x3/gNs68NaVENAdbVrPJee51zyzQJ2x6eY7zxWgqu35HavGa8TBd5UNbo96yW3woo+NZr8xroShix4VI5l4B/zW6Wkn8KZDz3Jo0Fwl8Y/QNYDuq9moJ4/+ya3PN2SLsb9ITypGhcU/HYk9X2DfWazml6v7FuwxZoBTdRExQPlmfAqmbUXLP1DRgvFGZ1J9T2IpfGItqZovMcFUD9OP6GCLw7mVN7ScjDJxCEP/vVEn77ltYPwSSXd2OtLqaqrV7ispZWsyRjNJe+SCWmI+AN4G8CQ0Tyz75f/+ELn0ZBJuzb+cBHhq5ceWm8agVMn8AdfK+YPEAMdsXw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(23010399003)(1800799024)(36860700016)(376014)(7416014)(4143699003)(11063799006)(5023799004)(6133799003)(261009223027099003)(3023799007)(13003099007)(22082099003)(18002099003)(261026140227099003)(56012099006)(261021123027099003)(10067099003)(261022105027099003)(261102123227099003)(261028144727099003)(261021121427099003)(261022075727099003)(261026121527099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iVI0sIgjFux2gM8DPe0kU4hi5yKw96KEs0Y07PiDEvhX6acmrXMsJcH6P0btilk8IEuKNetmq/JnPrf7wMZnOZJCsvaD0q9b69s5WAsbeKXsFH0L1Rn25Tkpj26qvhrpd8YuTOmk3EW9l2vnO+rVYSrS3zsymMaivN9lajOTEHpse4nOpbGJrHIGvzR/r4lGdicgxfvuIf347pe/wiE11SYD2GnNkiQ/YuJzj2Vt9FaLSA5HnqAxS2uiBpNSNEACbsJ1bTnKWvh3dSfd/J79PabW/Q0/8rJ2HlxSFd6FcXtAsjnfEcQpQvYJqshX/rGrBBA42iJ7Q1AH7TajZ6S5Xurz00MfAvFs6b8Dsb7XauNyuAlFCZMK/I+9cNU5V6+T6BJMGXig0hU+KAGUhQTH838XmqlqcPyjBTObwli/mYJyhUKHC82GWaWn2f1lP3TZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 03:39:28.4020 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6fbb877-777e-4096-59e1-08df51b8332f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF000793FE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9416 Hello Andy, On 12/4/2026 7:56 AM, Andy Lutomirski wrote: > [You don't often get email from luto@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] > > 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. Ack! That should be easy to do by making a bunch of INTRA_FUNCTION_CALL and correcting the rsp while letting the SSP go off the end of the shadow stack page. >> 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.) Yes, you are right. If the SSP points to a mapping with incorrect permission we will get a page fault with SS flag set but since that IDT event cannot push the shadow stack frame either, it'll be upgraded to a double fault. >> 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'm not sure what the right call is for a #CP in kernel mode - that really means someone has messed up the stack / has redirected regs->ip to redirect execution without relying on the CET aware helpers. Since a return address in kernel has been hijacked, I don't think it can be considered safe to allow program to return to the hijacked address and eventually kill the task on exit to usermode right? > I meant to mention: there should be LKDTM mechanisms to deliberately > trigger these sorts of failures. Ack! Triggers for the #DF from incorrect SPP and overrunning the shadow stack can be added - I'll do so in my next iteration or send it on top of Dave's next iteration behind an LKDTM trigger. For #CP in kernel mode, I'm not too sure - I'll love to hear more form the folks who have dealt with security aspects if the fault handler should attempt some form of recovery - we can match the return address on stack to that on the shadow stack but the integrity of the stack at that point is questionable. -- Thanks and Regards, Prateek