Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp327700rdb; Thu, 22 Feb 2024 05:14:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVC0WbxjFhesQ3WOx2RlYdHgVolmAUw93KNW3Ezy5sd2MVanLzWoHeFe2Hzui0jhWRp88FSGju+N4uzrDAieTt9HJXz2pchHogABNE3zw== X-Google-Smtp-Source: AGHT+IHh5kW7JDINrVZUN5JiYyZezmQ3POyUF+MUfb+zuVyBoiqLRaYVPb87sE6J8AJJ+4aGjllE X-Received: by 2002:a05:6358:7e0d:b0:178:d40d:3bfa with SMTP id o13-20020a0563587e0d00b00178d40d3bfamr22085891rwm.23.1708607668435; Thu, 22 Feb 2024 05:14:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708607668; cv=pass; d=google.com; s=arc-20160816; b=WaT5tPZLjBEdkBNIT/rCep9KbuhA+gT6Y56vpwAKKYdmAE1qBX1EEOleuTfu1xsvyS S/oSs7/n5oiAaiv+wWghhpC44qoxEECOipN0jU3ScKGx0z8Uqu/PSKqgjVgBLJGL9sxx LP1QSB4binDck/d31S21D2XccWo9pKmt5pIQBzJMu53h/m781yiCnO282s5UIHef1F5Q anFlbqKdKz3qZqvMIaTyBtSGQlhnWFQAQGVH04S22Lh0Icxm07JWFe8OVLYuikmh5jm5 OHY6SA4Nl4yio9ChAMWp/c4ae82/Ej3CwvIVnATyMjoJ/IN4WP9Z7Iu3qPlnif2VpLuK Or/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=4m+venPsQoQRmeDsm/PCUeoA/PWiFLIPENAvU5hSMRs=; fh=OXORlsXUckX+pyxJQOg+QqdF4LdKaF3EeGCuNTKSFYQ=; b=cCwDWDbPvO0+5UoepSziiTlU6mK5hNYN+T6L/Bl1NHMOxoW/0/R0LQBZ5402JYwA87 l9xoa0q1JnvFBArSXrGNJkhN8sqVGJ3TlJ4BaNlTZqyN7YofuRGrXliqN6tTu4KomH8n xF7Wd/cuXkNM05d4rTU/NIDMDgfbl80eHiLDxuyPIP+ZnaJKMgPWIvM5iwxg3d6oL8U7 G1URTnyanTEPAf7pzZELWAfacCMlefWwgojEf2HxuNXUO2+RZbEfQfCM4hGaGgx/hlMj tMwWlUF11rTMkL/RDshIdcM2vL87/2MPVMNRoIujzDE5c9tnaLNysujISsIPsgdDSfJV DXcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-76569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76569-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n29-20020a63721d000000b005dc927ee2fasi10226225pgc.710.2024.02.22.05.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-76569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76569-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2175A285CC0 for ; Thu, 22 Feb 2024 13:14:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC1661350D8; Thu, 22 Feb 2024 13:13:52 +0000 (UTC) Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) (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 6935E3C480; Thu, 22 Feb 2024 13:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708607632; cv=none; b=sthz6P0oPMb3Ox8TxSCGVwknBC9dvwAgDqwD8X2BPLH0mnx03DOm3aa/WPyRVxcQ57Obx7yCKQHPGM5mJHa/DQhD/4qmwCWUVupms29e3I/u/Z2NcBubCz3bual6EGiToFZoy1yzUaA51UPhw94NBlDyGkW2h3h73yx62FQhoC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708607632; c=relaxed/simple; bh=Uy376ED34WIMkkv3zbgADLtj7CtDO3E0JZj2bvWXW3w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=isPsE3PZ2w97Ar1NegwL5khFBLFj0jgvE2M02ALhvGDa0qKvy4Al5qjHQtHVjjYPZ0z1Afwm3MyLqoUBLhwCbBGhe2WDmIVbhed2nGVX3Bcj9E2QrWPB44TSwaAxz3n9p8+och7uWP/kAaMYbOIDTcj0fugGXdIqzEmL4ZAN1R0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4TgY4Y3wljz9xww9; Thu, 22 Feb 2024 20:54:21 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 95B41140ED3; Thu, 22 Feb 2024 21:13:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.45.157.235]) by APP1 (Coremail) with SMTP id LxC2BwDXzhdSSNdlhi4AAw--.34998S3; Thu, 22 Feb 2024 14:13:31 +0100 (CET) From: Petr Tesarik To: Dave Hansen Cc: =?UTF-8?B?UGV0ciBUZXNhxZnDrWs=?= , Petr Tesarik , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Andy Lutomirski , Oleg Nesterov , Peter Zijlstra , Xin Li , Arnd Bergmann , Andrew Morton , Rick Edgecombe , Kees Cook , "Masami Hiramatsu (Google)" , Pengfei Xu , Josh Poimboeuf , Ze Gao , "Kirill A. Shutemov" , Kai Huang , David Woodhouse , Brian Gerst , Jason Gunthorpe , Joerg Roedel , "Mike Rapoport (IBM)" , Tina Zhang , Jacob Pan , "open list:DOCUMENTATION" , open list , Roberto Sassu , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, Petr Tesarik Subject: [RFC 1/5] sbm: x86: fix SBM error entry path Date: Thu, 22 Feb 2024 14:12:26 +0100 Message-Id: <20240222131230.635-2-petrtesarik@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222131230.635-1-petrtesarik@huaweicloud.com> References: <20240222131230.635-1-petrtesarik@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-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WxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUOR6z UUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ From: Petr Tesarik Normal interrupt entry from SBM should be generally treated as entry from kernel mode (no swapgs, no speculation mitigations), but since there is a CPL change, the interrupt handler runs on the trampoline stack, which may get reused if the current task is re-scheduled. Make sure to switch to the SBM exception stack. Signed-off-by: Petr Tesarik --- arch/x86/entry/entry_64.S | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 4ba3eea38102..96830591302d 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1062,14 +1062,20 @@ SYM_CODE_START(error_entry) /* * If sandbox mode was active, adjust the saved CS, * unconditionally switch to kernel CR3 and continue - * as if the interrupt was from kernel space. + * as if the interrupt was from kernel space, but + * switch away from the trampoline stack. */ movq x86_sbm_state + SBM_kernel_cr3, %rcx jrcxz .Lerror_swapgs andb $~3, CS+8(%rsp) movq %rcx, %cr3 - jmp .Lerror_entry_done_lfence + + FENCE_SWAPGS_KERNEL_ENTRY + CALL_DEPTH_ACCOUNT + leaq 8(%rsp), %rdi + /* Put us onto the SBM exception stack. */ + jmp sync_regs #endif .Lerror_swapgs: -- 2.34.1