Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3057268rwe; Mon, 29 Aug 2022 05:15:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ncPpTfgdMQX4GBqIEToN1Gi3aAPNXakPbxdV4lUuw1yihSBPgoy/W5odvXyvCuSRImBGS X-Received: by 2002:a17:90b:4d07:b0:1ef:521c:f051 with SMTP id mw7-20020a17090b4d0700b001ef521cf051mr18464839pjb.164.1661775327774; Mon, 29 Aug 2022 05:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775327; cv=none; d=google.com; s=arc-20160816; b=MBHsM5zG9Bp0vQkllYN9Qn2SftClPONrzlVtVeludajMGqNoBaw1bZmI04id0P1Wyx 0+0cK4ScnoG7kippWIVzU+vc1rZlryOqKBFjrusOmxNzTmBGmNG6XYhQ/2ppqkv4bo2R yQQLSE/KRdyLiy/aBL1GQaR0hfcJihC2wRQDFaD4IKDvvRZXKSQHAjwE7xV4R5IQ6QZa nv/RtLHVaKYDEohUXKZcCK4wIKnn7hKcxeujfX/MkWrFKp+mohAmqgdsQB7eeheqrSIK 0QhRfXDBaHHiNsR+b1sGFWYQqGGPNNSxNqkQVpOGXp0OKzcl9T719ZY/PKLYqAaHQ/Km +qSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=++2341LNtLTpaEdgUE+uCFZkF6jhfP3odvS98fGhHyY=; b=eaXbSHaJJtgQna0z6LhwgZwyoW67ChXIXWhbmXP2d/CxCoyXW5h1mrPf5CWqvENa8R a3wz5x5T4VU7xXPKhi0cbYEDIsV3oL4fPBgFaUFZMscMbg/JOxgFkPLynLRXuoqI72cf q14OVivx8frDWYbFmnxE+XzJuFqCNLuSzYBi63wUIasQX6Ox3FpPl3NDRcwmAkSf/c1V fs8wn94lQGDjCq8DLxdqoedovnC1ZFt+P0+ytRZ7cTlc7CY7uHsHuyWdn+u00v0mGDF2 Y77fcbbGmdumZI9es31uVRptGkNMnOTwFKNi3dE/JD6AUzP9cxdcUQ5c2RZdJ/jDBhbl y4Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Duvo/fRt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a63d954000000b0042b30fbdd76si9333418pgj.779.2022.08.29.05.15.16; Mon, 29 Aug 2022 05:15:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Duvo/fRt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233028AbiH2LtN (ORCPT + 99 others); Mon, 29 Aug 2022 07:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233145AbiH2Lsp (ORCPT ); Mon, 29 Aug 2022 07:48:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F5D7B7B4; Mon, 29 Aug 2022 04:32:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4E68EB80F9E; Mon, 29 Aug 2022 11:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A004BC433D6; Mon, 29 Aug 2022 11:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771799; bh=1nf+LBF2sKGwkTpTN8P40gOXyki1/W9fa4kqIVgEXNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Duvo/fRt7/5+4bXaF+mtIyfjhq6maTISK9WiK6wfGnNUyBj87OngR3N60yi9DyXvG BVJc45lvVeOI7PBsxYZ5lACxKUYkuQ8B192+C+kguFC5EJlQf/R/puZ4ZWLnySWWwW ipiKNPzipSAG1pEea/6rZr5FYQm+HrtI8lNyUMqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeremi Piotrowski , watnuss@gmx.de, Michael Roth , Borislav Petkov Subject: [PATCH 5.19 101/158] x86/boot: Dont propagate uninitialized boot_params->cc_blob_address Date: Mon, 29 Aug 2022 12:59:11 +0200 Message-Id: <20220829105813.324012491@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Roth commit 4b1c742407571eff58b6de9881889f7ca7c4b4dc upstream. In some cases, bootloaders will leave boot_params->cc_blob_address uninitialized rather than zeroing it out. This field is only meant to be set by the boot/compressed kernel in order to pass information to the uncompressed kernel when SEV-SNP support is enabled. Therefore, there are no cases where the bootloader-provided values should be treated as anything other than garbage. Otherwise, the uncompressed kernel may attempt to access this bogus address, leading to a crash during early boot. Normally, sanitize_boot_params() would be used to clear out such fields but that happens too late: sev_enable() may have already initialized it to a valid value that should not be zeroed out. Instead, have sev_enable() zero it out unconditionally beforehand. Also ensure this happens for !CONFIG_AMD_MEM_ENCRYPT as well by also including this handling in the sev_enable() stub function. [ bp: Massage commit message and comments. ] Fixes: b190a043c49a ("x86/sev: Add SEV-SNP feature detection/setup") Reported-by: Jeremi Piotrowski Reported-by: watnuss@gmx.de Signed-off-by: Michael Roth Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=216387 Link: https://lore.kernel.org/r/20220823160734.89036-1-michael.roth@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/boot/compressed/misc.h | 12 +++++++++++- arch/x86/boot/compressed/sev.c | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 4910bf230d7b..62208ec04ca4 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -132,7 +132,17 @@ void snp_set_page_private(unsigned long paddr); void snp_set_page_shared(unsigned long paddr); void sev_prep_identity_maps(unsigned long top_level_pgt); #else -static inline void sev_enable(struct boot_params *bp) { } +static inline void sev_enable(struct boot_params *bp) +{ + /* + * bp->cc_blob_address should only be set by boot/compressed kernel. + * Initialize it to 0 unconditionally (thus here in this stub too) to + * ensure that uninitialized values from buggy bootloaders aren't + * propagated. + */ + if (bp) + bp->cc_blob_address = 0; +} static inline void sev_es_shutdown_ghcb(void) { } static inline bool sev_es_check_ghcb_fault(unsigned long address) { diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 52f989f6acc2..c93930d5ccbd 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -276,6 +276,14 @@ void sev_enable(struct boot_params *bp) struct msr m; bool snp; + /* + * bp->cc_blob_address should only be set by boot/compressed kernel. + * Initialize it to 0 to ensure that uninitialized values from + * buggy bootloaders aren't propagated. + */ + if (bp) + bp->cc_blob_address = 0; + /* * Setup/preliminary detection of SNP. This will be sanity-checked * against CPUID/MSR values later. -- 2.37.2