From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5D7B333993 for ; Sun, 29 Dec 2024 09:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735464778; cv=none; b=InfLKluKnTKvefAMIS3O+DIaGjNADgxoX59XXVQAGcqSC8NFlcorMx/7BnQT9A7BR/fxEfdb9djtDbUcGSWj6hTmhiIpkNvo5OhkveVKRDBHENddaECZcgqJpHU/ebCiQCBGQiFK4LlsUFwrUN/4vX97OTQz2FUvhRQOskvlGxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735464778; c=relaxed/simple; bh=/P/U9wGV9JVtDBUbI3G/1SZyfdKCsFrRYZ1MPaNwZH8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=Gvx6rJKWnWTLH8ODyq7l3dpX2MuULLzLpsu4q6vLP83IbNIi7P4gGWOV9R2uC7REBYmzovQxey5JZSDWRQ5YcX50UgjbEwKpjEHUZUzET9RdMlQbrsoI/FUUr2oV64foT26rBsG5AVl8FBe9yfS7hzojzDpYEvmr2T2vP3aQmRo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GvhlAuJ1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GvhlAuJ1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A78C4CED1; Sun, 29 Dec 2024 09:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735464777; bh=/P/U9wGV9JVtDBUbI3G/1SZyfdKCsFrRYZ1MPaNwZH8=; h=Date:From:To:Cc:Subject:From; b=GvhlAuJ1zGLlX9SsATK9Pz8a0Nm8LgSdT9RLDRBouTFEd/DXvNnH2xURA7zD8HAad TvsJoPEoJiRPnoRGumidL7UwTXt9Gtsk91J5n/qNRRmCMhqFazfVXuxtweq3QgHKzO ikrEDSokVNltj0ej/3SgfbvtDMun9zx103oJDEd0HaV/75yszrMBdRozSbRgRsiSrq lDSlBEZ/ad2gA5YdGKAMmh6x4AME3m4vQuFxgktgFGORzC2qTMYIK6BWmXQYl4rxzr zBHIim2UfXm/XcVXiAXkPHfYXuWa0SL6PsPqQBtk4OoY7zl5v++sJcM1SylH6278FA 6rMe9EZEVdiIA== Date: Sun, 29 Dec 2024 10:32:52 +0100 From: Ingo Molnar To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , "H. Peter Anvin" , x86@kernel.org Subject: [GIT PULL] x86 fixes Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Linus, Please pull the latest x86/urgent Git tree from: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-urgent-2024-12-29 # HEAD: 27834971f616c5e154423c578fa95e0444444ce1 virt: tdx-guest: Just leak decrypted memory on unrecoverable errors Merge note: I had to rebase the branch today, to get rid of a commit that was already merged upstream (349f0086ba8b), and to get rid of a merge commit as well. I double checked the old tree (10331a93486f in -tip) merges to the same content in your latest tree as the rebased tree (27834971f616). Misc fixes: - Fix a hang in the "kernel IBT no ENDBR" self-test that may trigger on FRED systems, caused by incomplete FRED state cleanup in the #CP fault handler. - Improve TDX (Coco VM) guest unrecoverable error handling to not potentially leak decrypted memory. Thanks, Ingo ------------------> Li RongQing (1): virt: tdx-guest: Just leak decrypted memory on unrecoverable errors Xin Li (Intel) (1): x86/fred: Clear WFE in missing-ENDBRANCH #CPs arch/x86/kernel/cet.c | 30 ++++++++++++++++++++++++++++++ drivers/virt/coco/tdx-guest/tdx-guest.c | 4 +--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c index d2c732a34e5d..303bf74d175b 100644 --- a/arch/x86/kernel/cet.c +++ b/arch/x86/kernel/cet.c @@ -81,6 +81,34 @@ static void do_user_cp_fault(struct pt_regs *regs, unsigned long error_code) static __ro_after_init bool ibt_fatal = true; +/* + * By definition, all missing-ENDBRANCH #CPs are a result of WFE && !ENDBR. + * + * For the kernel IBT no ENDBR selftest where #CPs are deliberately triggered, + * the WFE state of the interrupted context needs to be cleared to let execution + * continue. Otherwise when the CPU resumes from the instruction that just + * caused the previous #CP, another missing-ENDBRANCH #CP is raised and the CPU + * enters a dead loop. + * + * This is not a problem with IDT because it doesn't preserve WFE and IRET doesn't + * set WFE. But FRED provides space on the entry stack (in an expanded CS area) + * to save and restore the WFE state, thus the WFE state is no longer clobbered, + * so software must clear it. + */ +static void ibt_clear_fred_wfe(struct pt_regs *regs) +{ + /* + * No need to do any FRED checks. + * + * For IDT event delivery, the high-order 48 bits of CS are pushed + * as 0s into the stack, and later IRET ignores these bits. + * + * For FRED, a test to check if fred_cs.wfe is set would be dropped + * by compilers. + */ + regs->fred_cs.wfe = 0; +} + static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code) { if ((error_code & CP_EC) != CP_ENDBR) { @@ -90,6 +118,7 @@ static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code) if (unlikely(regs->ip == (unsigned long)&ibt_selftest_noendbr)) { regs->ax = 0; + ibt_clear_fred_wfe(regs); return; } @@ -97,6 +126,7 @@ static void do_kernel_cp_fault(struct pt_regs *regs, unsigned long error_code) if (!ibt_fatal) { printk(KERN_DEFAULT CUT_HERE); __warn(__FILE__, __LINE__, (void *)regs->ip, TAINT_WARN, regs, NULL); + ibt_clear_fred_wfe(regs); return; } BUG(); diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c index d7db6c824e13..224e7dde9cde 100644 --- a/drivers/virt/coco/tdx-guest/tdx-guest.c +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c @@ -124,10 +124,8 @@ static void *alloc_quote_buf(void) if (!addr) return NULL; - if (set_memory_decrypted((unsigned long)addr, count)) { - free_pages_exact(addr, len); + if (set_memory_decrypted((unsigned long)addr, count)) return NULL; - } return addr; }