Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1123911rdb; Tue, 30 Jan 2024 08:32:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+t3CuJ4R3PGiu4CToyqUR45QGAWFMaKI3VG5GHACgn0uqD4IaAqeoNfOlaveuJgqCw+WR X-Received: by 2002:a17:906:dc0a:b0:a30:d35f:d3a5 with SMTP id yy10-20020a170906dc0a00b00a30d35fd3a5mr1723615ejb.21.1706632328572; Tue, 30 Jan 2024 08:32:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706632328; cv=pass; d=google.com; s=arc-20160816; b=Ouj4BfhTzMsJGjynK4DFr2+EM4DhiKIqaUKXtIHx5fNXq1TYU49WvtaZyHrg1e51rX ydKz8zgf4CvU2v6s43isL6DNt55tHziusTYtVL9S83Kf37cB9387cFf8Iszk7m4PF31R rNtlLvmibYqtquE5DJR3j1FPVSz1oL8h9fht6vTXwF4C6pL8xNhNvvpJb5VjvIgsRoY1 tPj5HttkyvXG2ZANOB3tLLfd4Rd1J5qbbdgXuIGI8sJt0G9m2a+qlzhrA0/hIs7uM/HL +wu6HZ+fqHW4SHxqL39HjMZpumi3Z5xxc3wf6grllWtm3Hbh56dLMbZcksj1B+fD+Pyf e2Yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=MOmk/6kxNq3y3+cn0/dKLbhBMWTiBD8mUGvKQP8FJGo=; fh=rVTB9++5xMIecOv+XPWpkq5YZaJRcF05li6wpGIZteI=; b=BFLcbHfl5qs/JlctWD09OLlmho8CH1wuN8ixJogTWWdltrBK51xBSsB6pE9ScVunh7 la6BkGfKYTvtQspghLrMKnukWB6pBsZQyxlh90jLfO57qFaELpB1+OJ4/EtnlkKGmnu1 2tulOp5ZZVEzIxa2tEnDSlkn4+Wj1KCCzjJLhrk3g6Te+DkOBCFA2YE9dc9fOymCgL11 kypS/MxdFe9E3UesNnYX2dcoDlWzZpKHGJq+nMkOLnSBy+5LFEstERmjbC//DUza9LL4 dmKZWdvv+OOQ5oropYsQ0ywuoLF6Msp5tm3KMHkOeQr6+aWN7AwHAzt/Teo006wGxAbd LERA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rzNYnflG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-44943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id os18-20020a170906af7200b00a31867f21a7si4715759ejb.834.2024.01.30.08.32.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 08:32:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rzNYnflG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-44943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 788FD1F27D1A for ; Tue, 30 Jan 2024 16:31:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26C5613B7B0; Tue, 30 Jan 2024 16:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rzNYnflG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8awRw76z" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 103711339B4; Tue, 30 Jan 2024 16:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706631978; cv=none; b=YZPHGOGP5/nSFmv0eKK91OEwyF/RXMDj0VqQC/BkwIh8BGf0Qyep6AoUy1z+cqj2aeGmTL1BaLXg6rai/yRaosLj9NqvLVHqqgZPb2z8C7OKvMy0+PrhYPWOd+xWrc0NUCGnQ2IZytW+hCCOFcG+x/Qbm4ViJlSLkigICQwhcQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706631978; c=relaxed/simple; bh=mlRsWw5KAdMqnIQZyWFpFMWj0vtPPTvVya2YobY5Ez4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=je+fpZBFbUgIwtObZDASmMxKmjduCooFGaol6ALBc8r8GkRqfdTe4yPCRuyUaSt+bivv5yI7vFAeUmESxXECli5tfRN+Id7XWtM75Mjr0DBfRgrnFz6xd1OdLg7EaLGyQvhV3CGcBI5Gb6jOTRHtVPlRsL/EPsendstbs3S21Cg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rzNYnflG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8awRw76z; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Tue, 30 Jan 2024 16:26:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706631974; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MOmk/6kxNq3y3+cn0/dKLbhBMWTiBD8mUGvKQP8FJGo=; b=rzNYnflGJ6N6VQNUYN9QGGF6YKXY2Xrw20zyfIcRcg3QVOjBJ5+kyY0x0WT9aiLPTIWle2 GR3VNQ7iD4iB7WAjSV4+8FH1Gcvv6h8s7V0xSKgYE4pQfjfZB1/Sqyw0v+qPYOrrSakL7r 0YuqKlclssdXpYEdD7Rusgb1PxM2Fv/RURxk2lsrEsmeaKzgYopK6DqX2auqL4PX5X6iwW /O40/oTlhBZ5Ydj6R1/oybDbTixRd93cAvI9GhfbU+xz5oLtaqpwkQWgHGsK7CrKtko8HG P1dHmH+hbrYC3dez6sf5zswob7EwCSVprnOUVck4cLHAMHwQ8J2qZ2pf7n13Bw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706631974; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MOmk/6kxNq3y3+cn0/dKLbhBMWTiBD8mUGvKQP8FJGo=; b=8awRw76z/lQo53M36XJA4/3xh50S3y9xwxddgAAFYyfnXME9eEBgMFCmgArqIarNYX3Hyj JgS2LwOOONo5/JDg== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/sme: Fix memory encryption setting if enabled by default and not overridden Cc: Ard Biesheuvel , "Borislav Petkov (AMD)" , Tom Lendacky , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240126163918.2908990-2-ardb+git@google.com> References: <20240126163918.2908990-2-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170663197391.398.455032611459262025.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/sev branch of tip: Commit-ID: e814b59e6c2b11f5a3d007b2e61f7d550c354c3a Gitweb: https://git.kernel.org/tip/e814b59e6c2b11f5a3d007b2e61f7d550c354c3a Author: Ard Biesheuvel AuthorDate: Fri, 26 Jan 2024 17:39:19 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 29 Jan 2024 17:08:33 +01:00 x86/sme: Fix memory encryption setting if enabled by default and not overridden Commit cbebd68f59f0 ("x86/mm: Fix use of uninitialized buffer in sme_enable()") 'fixed' an issue in sme_enable() detected by static analysis, and broke the common case in the process. cmdline_find_option() will return < 0 on an error, or when the command line argument does not appear at all. In this particular case, the latter is not an error condition, and so the early exit is wrong. Instead, without mem_encrypt= on the command line, the compile time default should be honoured, which could be to enable memory encryption, and this is currently broken. Fix it by setting sme_me_mask to a preliminary value based on the compile time default, and only omitting the command line argument test when cmdline_find_option() returns an error. [ bp: Drop active_by_default while at it. ] Fixes: cbebd68f59f0 ("x86/mm: Fix use of uninitialized buffer in sme_enable()") Signed-off-by: Ard Biesheuvel Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky Link: https://lore.kernel.org/r/20240126163918.2908990-2-ardb+git@google.com --- arch/x86/mm/mem_encrypt_identity.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index d73aeb1..7f72472 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -507,7 +507,6 @@ void __init sme_enable(struct boot_params *bp) const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; - bool active_by_default; unsigned long me_mask; char buffer[16]; bool snp; @@ -593,22 +592,19 @@ void __init sme_enable(struct boot_params *bp) : "p" (sme_cmdline_off)); if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) - active_by_default = true; - else - active_by_default = false; + sme_me_mask = me_mask; cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | ((u64)bp->ext_cmd_line_ptr << 32)); if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) - return; + goto out; if (!strncmp(buffer, cmdline_on, sizeof(buffer))) sme_me_mask = me_mask; else if (!strncmp(buffer, cmdline_off, sizeof(buffer))) sme_me_mask = 0; - else - sme_me_mask = active_by_default ? me_mask : 0; + out: if (sme_me_mask) { physical_mask &= ~sme_me_mask;