From nobody Wed Jun 17 06:02:51 2026 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 A8F7035AC32; Mon, 27 Apr 2026 16:15:40 +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=1777306540; cv=none; b=tw4qCbGMemAlWaIM8vuYkn1tpJr/RN3Z5dlZ2/gCPmKXDuMDwp3On+3kX4KJVntNQT3vQeDLLokBznjq348dpDWL6Z2Yhz52nQ9U4yZBIW/vuloGfbKQgM3exi1JOj7SssHnkaQtCHnfN2ffyud1YpKmzYUhTViXFaMEP2dLDFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306540; c=relaxed/simple; bh=J8ZpFzOkrsE8Rd7KjjR9PYZ6e8XG2Q66HZDH5fx2iCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y6kWHx1V01Ov+ZL5xdpKbOEP+vl6L6hnQWYgL/g/D6JweI6eob+wB/8/ZAFoNzwb212KTU+Y9amV4a+mqhWFEmcRkzFlF85gebRjESBCCYMj0XUJNmStySumtWDSDgjILRDOkh9aVbiJzzEkgib7EIAH4NZRP25tvANlgT6tJVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hBI5jAAL; 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="hBI5jAAL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33F4EC2BCB7; Mon, 27 Apr 2026 16:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777306540; bh=J8ZpFzOkrsE8Rd7KjjR9PYZ6e8XG2Q66HZDH5fx2iCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hBI5jAALSlMPavCbUQXjYh5nzq/fVLi2HxP6f07Qa+sg05+vgr4bqMZfagyaLZFuy iGhDAPhR6WR+/awmWaEOZnhCFIutZRIIbvbdydLWvQd3sAruK3wgF8E+CkM/XxILyL KXbeA9PtUGG/nA6CgktXyHVAs83r1p26r7pGmuOFg1m1tkYN6wvN0B54MRh/gPC84V Vzp/oKm21F9CgZ0W96n+mKD7RcnsxaHHvAYigsh7zc6TWKpm+URwGWvbYYz3H/jEfM aU5wcTyO/d3mXfev7pkFzrWyWXeUn689nLRPSXfktUo9Om/h/paF7JEmleaF9PWgYT sVZtH9LVHfySg== From: Tycho Andersen To: Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , "Tycho Andersen (AMD)" Subject: [PATCH v1 1/4] crypto/ccp: Do not initialize SNP for SEV ioctls Date: Mon, 27 Apr 2026 10:15:04 -0600 Message-ID: <20260427161507.32686-2-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427161507.32686-1-tycho@kernel.org> References: <20260427161507.32686-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" Sashiko notes: > if SEV initialization fails and KVM is actively running normal VMs, could= a > userspace process trigger this code path via /dev/sev ioctls (e.g., > SEV_PDH_GEN) and zero out MSR_VM_HSAVE_PA globally? Would the next VMRUN > execution for an active VM trigger a general protection fault and crash t= he > host? sev_move_to_init_state() is called for ioctls requiring only SEV firmware: SEV_PEK_GEN, SEV_PDH_GEN, SEV_PEK_CSR, SEV_PEK_CERT_IMPORT, and SEV_PDH_CERT_EXPORT. After the firmware command, it does SEV_SHUTDOWN on the SEV firmware. Since these commands do not require SNP to be initialized, skip it by calling __sev_platform_init_locked() which only initializes the SEV firmware. This way SNP is not Initialized at all, and HSAVE_PA is not cleared. The previous code saved any SEV initialization firmware error to init_args.error and then threw it away and hardcoded the return value of INVALID_PLATFORM_STATE regardless of the real firmware error. This patch changes it to surface the underlying error, which is hopefully both more useful and doesn't cause any problems. Note that it is still safe to call __sev_firmware_shutdown() directly: it calls __sev_snp_shutdown_locked(), which skips SNP shutdown if SNP was not initialized. Fixes: ceac7fb89e8d ("crypto: ccp - Ensure implicit SEV/SNP init and shutdo= wn in ioctls") Reported-by: Sashiko Assisted-by: Gemini:gemini-3.1-pro-preview Link: https://sashiko.dev/#/patchset/20260324161301.1353976-1-tycho%40kerne= l.org Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index d1e9e0ac63b6..6891b90bbb88 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1716,14 +1716,11 @@ static int sev_get_platform_state(int *state, int *= error) =20 static int sev_move_to_init_state(struct sev_issue_cmd *argp, bool *shutdo= wn_required) { - struct sev_platform_init_args init_args =3D {0}; int rc; =20 - rc =3D _sev_platform_init_locked(&init_args); - if (rc) { - argp->error =3D SEV_RET_INVALID_PLATFORM_STATE; + rc =3D __sev_platform_init_locked(&argp->error); + if (rc) return rc; - } =20 *shutdown_required =3D true; =20 --=20 2.53.0 From nobody Wed Jun 17 06:02:51 2026 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 35B1E355F49; Mon, 27 Apr 2026 16:15:42 +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=1777306542; cv=none; b=Vur99VucRRt8LmRlbZFtC8Ilk/OR1pminK1S4pogQsZGTp2OZhfi1e+dTFY3wvWFtSZ5rG0GwintnqZCylsQ9EWTKKWb15zfuOvzch+sKYyS14Dncilx+82Wib3615M292g5g5fDYSrrHg1z3cuL8PSkovRO/Zwzs8HuxyxXUkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306542; c=relaxed/simple; bh=kFNV6IvwRebNmrJadqN5N4ec/NhPbNyKzVZb/1MxaUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h9JY4xikpqgMUwC+cV0UFGxQOX8YkcHr9GqxCosZj9A2NdZW0blmCSxhN7Fq9C1lzCjh8Wli9SYz3Vu2IBZl0MepbptGp+P4BgAyGiU8Kkki8y8YlxqI/Ih41nm3iiADF17UGT4tX2tAQeKqGeTCKo5t4UIrYdHRa1ClDVHqbh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fxOQLuei; 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="fxOQLuei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9593C2BCB5; Mon, 27 Apr 2026 16:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777306542; bh=kFNV6IvwRebNmrJadqN5N4ec/NhPbNyKzVZb/1MxaUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fxOQLuei/EJYGbsbItGRY8LBU+KkHm9/1hfR7UIVDhvIqULQl5Bm0hTUYAObXWfZ3 5LgqxWnVpx7E90wh1Au8JEEpm035YI2koVERz5hdvCF9RLbhm+Zj1ya1tO2QdH/enk 1QAo4TBgyQ0pOrThmDl4uykKsp3+8yi3DZD2OkMD4bB1LJR6FR+WcWZp3BszI5pVWh UjC5Z6BjWc+VgeFBqUFbcq6h8neXyz8+IYoocvEXwdAQUz1vsDk7IefW63l452hp/E fzNRxUiKGM78dd5sqAK1JEcidOiSp7FEH9iNWdGfzm7veRqpHhUPMGLFdBYJpY7VM5 DxafetOOSjeVA== From: Tycho Andersen To: Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , "Tycho Andersen (AMD)" Subject: [PATCH v1 2/4] crypto/ccp: Do not initialize SNP for ioctl(SNP_COMMIT) Date: Mon, 27 Apr 2026 10:15:05 -0600 Message-ID: <20260427161507.32686-3-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427161507.32686-1-tycho@kernel.org> References: <20260427161507.32686-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" Sashiko notes: > if SEV initialization fails and KVM is actively running normal VMs, could= a > userspace process trigger this code path via /dev/sev ioctls (e.g., > SEV_PDH_GEN) and zero out MSR_VM_HSAVE_PA globally? Would the next VMRUN > execution for an active VM trigger a general protection fault and crash t= he > host? The SNP_COMMIT command does not require the firmware to be in any particular state. Skip initializing it if it was previously uninitialized. The SEV-SNP firmware specification doc 56860 does not mention SNP_COMMIT in Table 5 as a command that is allowed in the UNINIT state, but it is in fact allowed and a future documentation update will reflect that. Fixes: ceac7fb89e8d ("crypto: ccp - Ensure implicit SEV/SNP init and shutdo= wn in ioctls") Reported-by: Sashiko Assisted-by: Gemini:gemini-3.1-pro-preview Link: https://sashiko.dev/#/patchset/20260324161301.1353976-1-tycho%40kerne= l.org Signed-off-by: Tycho Andersen (AMD) Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 6891b90bbb88..572f06368d4b 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2437,24 +2437,13 @@ static int sev_ioctl_do_snp_platform_status(struct = sev_issue_cmd *argp) =20 static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp) { - struct sev_device *sev =3D psp_master->sev_data; struct sev_data_snp_commit buf; - bool shutdown_required =3D false; - int ret, error; - - if (!sev->snp_initialized) { - ret =3D snp_move_to_init_state(argp, &shutdown_required); - if (ret) - return ret; - } + int ret; =20 buf.len =3D sizeof(buf); =20 ret =3D __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error); =20 - if (shutdown_required) - __sev_snp_shutdown_locked(&error, false); - return ret; } =20 --=20 2.53.0 From nobody Wed Jun 17 06:02:51 2026 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 154AC34FF76; Mon, 27 Apr 2026 16:15:43 +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=1777306544; cv=none; b=EyLiuvHBXh+iJdx2i1N7Lsr898An5eqAd8/443tyY37cWSIOfU4RsCBxTmZtYVpz/9Ihd2vLhmJN6LLEoVlKh/pOmqwEC9A4XB5LO32L/4cTXNQlCETXtfabFAPJUAcj/pJmkAUuTINsYUMaqMQE+4HjRBWPVpYEt/7BFQhWDJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306544; c=relaxed/simple; bh=k+ixcJknwre6q34CCiMJgH6/hhzle1sP7nNkFejXdIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Le9VLN8IXcoEJ/OeJkYypoBDYE57QrRnJ4mPuBJTj2cd30ePXGVVvj75/RxLpACU7dpPA4cEyLqsheZtJh4EDTqVOTEWs2OShQCmytH6QOOKhnG5OTSrh7r1P20QtyIlfk6ID24Z+kK0D6s2virjGLfO08EPcFxjoH/FXsclcpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L8RaBZ45; 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="L8RaBZ45" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6911CC19425; Mon, 27 Apr 2026 16:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777306543; bh=k+ixcJknwre6q34CCiMJgH6/hhzle1sP7nNkFejXdIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8RaBZ45vGuJIwmxBP/QaEd1eueqdRRieonal3/6gLibdHDxQWen7k6ceyawFdVMO EbrsdyYi/2qh+s1TwFO3LOtA53hE/aneQ3WzUM1xPWdQhVDclXd+oaNBRf4kfdfIQa yXw83ebV2n1YrEKGJOFfk+0y3p7sZy7ZXpZT7rMT0gpM4oTIasp9Wsnnsv8cqtgnUq Svd+PQT4o3E/HsXNCnNR1gD5OVlcSLkwVNTrjDCUkjgCumUnzvcD+Kun9qj+RdC7Vx pu/qYsgX1mVYF8Ei1WEbNru2Ua38GI67CkzZWT2eCDBqNy63q6mvtenJLyaGin51kw Y9Cf2YPAgrg4Q== From: Tycho Andersen To: Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , "Tycho Andersen (AMD)" Subject: [PATCH v1 3/4] crypto/ccp: Do not initialize SNP for ioctl(SNP_VLEK_LOAD) Date: Mon, 27 Apr 2026 10:15:06 -0600 Message-ID: <20260427161507.32686-4-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427161507.32686-1-tycho@kernel.org> References: <20260427161507.32686-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" Sashiko notes: > if SEV initialization fails and KVM is actively running normal VMs, could= a > userspace process trigger this code path via /dev/sev ioctls (e.g., > SEV_PDH_GEN) and zero out MSR_VM_HSAVE_PA globally? Would the next VMRUN > execution for an active VM trigger a general protection fault and crash t= he > host? The SEV firmware docs for SNP_VLEK_LOAD note: > On SNP_SHUTDOWN, the VLEK is deleted. That is, the initialization/shutdown wrapper here is pointless, because the firmware immediately throws away the key anyway. Instead, refuse to do anything if SNP has not been previously initialized. Fixes: ceac7fb89e8d ("crypto: ccp - Ensure implicit SEV/SNP init and shutdo= wn in ioctls") Reported-by: Sashiko Assisted-by: Gemini:gemini-3.1-pro-preview Link: https://sashiko.dev/#/patchset/20260324161301.1353976-1-tycho%40kerne= l.org Signed-off-by: Tycho Andersen (AMD) --- drivers/crypto/ccp/sev-dev.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 572f06368d4b..e8c3ac6d989a 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2481,9 +2481,8 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issu= e_cmd *argp, bool writable) { struct sev_device *sev =3D psp_master->sev_data; struct sev_user_data_snp_vlek_load input; - bool shutdown_required =3D false; - int ret, error; void *blob; + int ret; =20 if (!argp->data) return -EINVAL; @@ -2497,6 +2496,9 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_issu= e_cmd *argp, bool writable) if (input.len !=3D sizeof(input) || input.vlek_wrapped_version !=3D 0) return -EINVAL; =20 + if (!sev->snp_initialized) + return -EINVAL; + blob =3D psp_copy_user_blob(input.vlek_wrapped_address, sizeof(struct sev_user_data_snp_wrapped_vlek_hashstick)); if (IS_ERR(blob)) @@ -2504,18 +2506,7 @@ static int sev_ioctl_do_snp_vlek_load(struct sev_iss= ue_cmd *argp, bool writable) =20 input.vlek_wrapped_address =3D __psp_pa(blob); =20 - if (!sev->snp_initialized) { - ret =3D snp_move_to_init_state(argp, &shutdown_required); - if (ret) - goto cleanup; - } - ret =3D __sev_do_cmd_locked(SEV_CMD_SNP_VLEK_LOAD, &input, &argp->error); - - if (shutdown_required) - __sev_snp_shutdown_locked(&error, false); - -cleanup: kfree(blob); =20 return ret; --=20 2.53.0 From nobody Wed Jun 17 06:02:51 2026 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 91F233D646C; Mon, 27 Apr 2026 16:15:45 +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=1777306545; cv=none; b=BA6lXoQOMd+dxvYoXE9l5NtEEiONyeXKB5yau8Yz+upxuudD0CGde1gvStH78wGbG7xaUAwZnD8zcqpJtTLP8pdfCoyo/f9g7TMKKVJ2NbEoXpTWF4ayQT3GhR6aB3Hq9OgVI3yHIJ9VDhxsRgLB6KwvKwn20obmN+bja/jDjuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306545; c=relaxed/simple; bh=3jamtsGYAbH++td68bEeRovzkP04ihwgbfd/GpwYtQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AvR650u1Mtgu5PkBlZPP6WPKh03VswghIoio0Bp0MayYT9omfQ9z4SQqw0azrxryA9hb90367aff5p5oSfN4tOxjvStduiybu3Q42t2toHJju5dv1MoyNhyhRBP56hHsaNJWa6C5AME9s32ArNmRpnrx6+Ihe9kbedrC/O1Lg4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FzSy2Cdv; 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="FzSy2Cdv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08E4DC2BCB7; Mon, 27 Apr 2026 16:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777306545; bh=3jamtsGYAbH++td68bEeRovzkP04ihwgbfd/GpwYtQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzSy2CdvNvnm7lfZO4ezO6oX1XZZ4jq6zbYmev5cMBoVk3XM+IEmRkWuL4BB63rD6 LDww26458PVKbNG4OqxtSLC1pWnVkz/N8Nn9Q93eJ6IwOeS4tTRUPr9C+L+T4qzhyM JM3pwIC6qykKxmTCyaOvy+fTZg0Hh9xUbVXtUqXzOFVWWKvMUUYOWlUH6+ItrHNX56 m6GyhSu1ZUhXpsar25XRyF/p1Qkx86MWzaMph5ifHGymSM1JAbt7J1v+pNlz8xl/rv BUaK20OiLPJ6oIsledonorniqWTiZc4mZxXRXnhGgfX5+cEUA6C/HSnFZoYJI9n7I2 VGYl/GA1H9wnA== From: Tycho Andersen To: Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , "Tycho Andersen (AMD)" Subject: [PATCH v1 4/4] crypto/ccp: Do not initialize SNP for ioctl(SNP_CONFIG) Date: Mon, 27 Apr 2026 10:15:07 -0600 Message-ID: <20260427161507.32686-5-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427161507.32686-1-tycho@kernel.org> References: <20260427161507.32686-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" Sashiko notes: > if SEV initialization fails and KVM is actively running normal VMs, could= a > userspace process trigger this code path via /dev/sev ioctls (e.g., > SEV_PDH_GEN) and zero out MSR_VM_HSAVE_PA globally? Would the next VMRUN > execution for an active VM trigger a general protection fault and crash t= he > host? Refuse to re-try initialization if SNP is not already initialized for SNP_CONFIG. This is technically an ABI break: before if SNP initialization failed it could be transparently retriggered by this ioctl, and if no VMs were running, everything worked fine. Hopefully this is enough of a corner case that nobody will notice, but someone does, there are a few options: * do something like symbol_get() for kvm and refuse to initialize if KVM is loaded * check each cpu's HSAVE_PA for non-zero data before re-initializing * once initialization has failed, continue to refuse to initialize until the ccp module is unloaded Fixes: ceac7fb89e8d ("crypto: ccp - Ensure implicit SEV/SNP init and shutdo= wn in ioctls") Reported-by: Sashiko Assisted-by: Gemini:gemini-3.1-pro-preview Link: https://sashiko.dev/#/patchset/20260324161301.1353976-1-tycho%40kerne= l.org Signed-off-by: Tycho Andersen (AMD) --- drivers/crypto/ccp/sev-dev.c | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e8c3ac6d989a..5b113908a4f9 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1727,21 +1727,6 @@ static int sev_move_to_init_state(struct sev_issue_c= md *argp, bool *shutdown_req return 0; } =20 -static int snp_move_to_init_state(struct sev_issue_cmd *argp, bool *shutdo= wn_required) -{ - int error, rc; - - rc =3D __sev_snp_init_locked(&error, 0); - if (rc) { - argp->error =3D SEV_RET_INVALID_PLATFORM_STATE; - return rc; - } - - *shutdown_required =3D true; - - return 0; -} - static int sev_ioctl_do_reset(struct sev_issue_cmd *argp, bool writable) { int state, rc; @@ -2451,8 +2436,6 @@ static int sev_ioctl_do_snp_set_config(struct sev_iss= ue_cmd *argp, bool writable { struct sev_device *sev =3D psp_master->sev_data; struct sev_user_data_snp_config config; - bool shutdown_required =3D false; - int ret, error; =20 if (!argp->data) return -EINVAL; @@ -2460,21 +2443,13 @@ static int sev_ioctl_do_snp_set_config(struct sev_i= ssue_cmd *argp, bool writable if (!writable) return -EPERM; =20 + if (!sev->snp_initialized) + return -EINVAL; + if (copy_from_user(&config, (void __user *)argp->data, sizeof(config))) return -EFAULT; =20 - if (!sev->snp_initialized) { - ret =3D snp_move_to_init_state(argp, &shutdown_required); - if (ret) - return ret; - } - - ret =3D __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); - - if (shutdown_required) - __sev_snp_shutdown_locked(&error, false); - - return ret; + return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error); } =20 static int sev_ioctl_do_snp_vlek_load(struct sev_issue_cmd *argp, bool wri= table) --=20 2.53.0