* Re: [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
2026-11-16 20:36 [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure Kim Phillips
@ 2026-11-16 21:24 ` Mario Limonciello
2026-11-17 3:34 ` Rijo Thomas
2026-11-23 15:17 ` Serge Hallyn (AMD)
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Mario Limonciello @ 2026-11-16 21:24 UTC (permalink / raw)
To: Kim Phillips, Tom Lendacky, Herbert Xu, David S . Miller, Rijo Thomas
Cc: linux-crypto, linux-kernel, Sashiko, stable
On 11/16/26 14:36, Kim Phillips wrote:
> psp_init() initializes sub-devices sequentially but returns immediately
> on the first failure, leaving earlier sub-devices registered. Its caller
> psp_dev_init() then sets sp->psp_data = NULL, so the later
> psp_dev_destroy() on unbind bails out early and never unregisters them.
>
> Non-devm resources such as the /dev/sev and /dev/dbc character devices
> stay globally visible while their devm-allocated backing structures are
> freed by the driver core, giving a use-after-free if userspace opens the
> orphaned device.
>
> Add reverse-order unwind labels to psp_init() so each sub-device is torn
> down before the error is propagated. Every *_dev_destroy() is already
> NULL-guarded on its own psp->*_data pointer, so skipped or unreached
> sub-devices are no-ops.
>
> sp_init() continues to ignore the psp_dev_init() return value on
> purpose: a PSP failure must not fail the probe, as the CCP can still
> initialize successfully.
>
> Fixes: 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-0de87f0c-0f5a-4dad-8ef1-f49844eb4cce
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kim Phillips <kim.phillips@amd.com>
> ---
> v1: https://lore.kernel.org/linux-crypto/20261021215716.1076732-1-kim.phillips@amd.com/
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
>
> drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index b14ce51065d5..3d9341c2876d 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -207,19 +207,19 @@ static int psp_init(struct psp_device *psp)
> if (!psp_check_tee_support(psp)) {
> ret = tee_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sev;
> }
>
> if (!psp_check_sfs_support(psp)) {
> ret = sfs_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_tee;
> }
>
> if (psp->vdata->platform_access) {
> ret = platform_access_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sfs;
> }
>
> /* dbc must come after platform access as it tests the feature */
> @@ -227,15 +227,28 @@ static int psp_init(struct psp_device *psp)
> psp->capability.dbc_thru_ext) {
> ret = dbc_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_platform_access;
> }
>
> /* HSTI uses platform access on some systems. */
> ret = psp_init_hsti(psp);
> if (ret)
> - return ret;
> + goto e_dbc;
>
> return 0;
> +
> +e_dbc:
> + dbc_dev_destroy(psp);
> +e_platform_access:
> + platform_access_dev_destroy(psp);
> +e_sfs:
> + sfs_dev_destroy(psp);
> +e_tee:
> + tee_dev_destroy(psp);
> +e_sev:
> + sev_dev_destroy(psp);
> +
> + return ret;
> }
>
> int psp_dev_init(struct sp_device *sp)
>
> base-commit: 26ca5f34841f0a86d0883664a1c13be89a01d351
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
2026-11-16 21:24 ` Mario Limonciello
@ 2026-11-17 3:34 ` Rijo Thomas
0 siblings, 0 replies; 6+ messages in thread
From: Rijo Thomas @ 2026-11-17 3:34 UTC (permalink / raw)
To: Mario Limonciello, Kim Phillips, Tom Lendacky, Herbert Xu,
David S . Miller
Cc: linux-crypto, linux-kernel, Sashiko, stable
On 11/17/2026 2:54 AM, Mario Limonciello wrote:
>
>
> On 11/16/26 14:36, Kim Phillips wrote:
>> psp_init() initializes sub-devices sequentially but returns immediately
>> on the first failure, leaving earlier sub-devices registered. Its caller
>> psp_dev_init() then sets sp->psp_data = NULL, so the later
>> psp_dev_destroy() on unbind bails out early and never unregisters them.
>>
>> Non-devm resources such as the /dev/sev and /dev/dbc character devices
>> stay globally visible while their devm-allocated backing structures are
>> freed by the driver core, giving a use-after-free if userspace opens the
>> orphaned device.
>>
>> Add reverse-order unwind labels to psp_init() so each sub-device is torn
>> down before the error is propagated. Every *_dev_destroy() is already
>> NULL-guarded on its own psp->*_data pointer, so skipped or unreached
>> sub-devices are no-ops.
>>
>> sp_init() continues to ignore the psp_dev_init() return value on
>> purpose: a PSP failure must not fail the probe, as the CCP can still
>> initialize successfully.
>>
>> Fixes: 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")
>> Reported-by: Sashiko <sashiko-bot@kernel.org>
>> Closes: https://sashiko.dev/#/bug/linux-0de87f0c-0f5a-4dad-8ef1-f49844eb4cce
>> Cc: Tom Lendacky <thomas.lendacky@amd.com>
>> Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
>> Cc: Mario Limonciello <mario.limonciello@amd.com>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Kim Phillips <kim.phillips@amd.com>
>> ---
>> v1: https://lore.kernel.org/linux-crypto/20261021215716.1076732-1-kim.phillips@amd.com/
>
Looks good to me.
Reviewed-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
>
>>
>> drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++-----
>> 1 file changed, 18 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
>> index b14ce51065d5..3d9341c2876d 100644
>> --- a/drivers/crypto/ccp/psp-dev.c
>> +++ b/drivers/crypto/ccp/psp-dev.c
>> @@ -207,19 +207,19 @@ static int psp_init(struct psp_device *psp)
>> if (!psp_check_tee_support(psp)) {
>> ret = tee_dev_init(psp);
>> if (ret)
>> - return ret;
>> + goto e_sev;
>> }
>> if (!psp_check_sfs_support(psp)) {
>> ret = sfs_dev_init(psp);
>> if (ret)
>> - return ret;
>> + goto e_tee;
>> }
>> if (psp->vdata->platform_access) {
>> ret = platform_access_dev_init(psp);
>> if (ret)
>> - return ret;
>> + goto e_sfs;
>> }
>> /* dbc must come after platform access as it tests the feature */
>> @@ -227,15 +227,28 @@ static int psp_init(struct psp_device *psp)
>> psp->capability.dbc_thru_ext) {
>> ret = dbc_dev_init(psp);
>> if (ret)
>> - return ret;
>> + goto e_platform_access;
>> }
>> /* HSTI uses platform access on some systems. */
>> ret = psp_init_hsti(psp);
>> if (ret)
>> - return ret;
>> + goto e_dbc;
>> return 0;
>> +
>> +e_dbc:
>> + dbc_dev_destroy(psp);
>> +e_platform_access:
>> + platform_access_dev_destroy(psp);
>> +e_sfs:
>> + sfs_dev_destroy(psp);
>> +e_tee:
>> + tee_dev_destroy(psp);
>> +e_sev:
>> + sev_dev_destroy(psp);
>> +
>> + return ret;
>> }
>> int psp_dev_init(struct sp_device *sp)
>>
>> base-commit: 26ca5f34841f0a86d0883664a1c13be89a01d351
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
2026-11-16 20:36 [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure Kim Phillips
2026-11-16 21:24 ` Mario Limonciello
@ 2026-11-23 15:17 ` Serge Hallyn (AMD)
2026-11-24 15:44 ` Tom Lendacky
2026-11-27 5:11 ` Herbert Xu
3 siblings, 0 replies; 6+ messages in thread
From: Serge Hallyn (AMD) @ 2026-11-23 15:17 UTC (permalink / raw)
To: Kim Phillips
Cc: Tom Lendacky, Herbert Xu, David S . Miller, Rijo Thomas,
Mario Limonciello, linux-crypto, linux-kernel, Sashiko, stable
On Mon, Nov 16, 2026 at 02:36:22PM -0600, Kim Phillips wrote:
> psp_init() initializes sub-devices sequentially but returns immediately
> on the first failure, leaving earlier sub-devices registered. Its caller
> psp_dev_init() then sets sp->psp_data = NULL, so the later
> psp_dev_destroy() on unbind bails out early and never unregisters them.
>
> Non-devm resources such as the /dev/sev and /dev/dbc character devices
> stay globally visible while their devm-allocated backing structures are
> freed by the driver core, giving a use-after-free if userspace opens the
> orphaned device.
>
> Add reverse-order unwind labels to psp_init() so each sub-device is torn
> down before the error is propagated. Every *_dev_destroy() is already
> NULL-guarded on its own psp->*_data pointer, so skipped or unreached
> sub-devices are no-ops.
>
> sp_init() continues to ignore the psp_dev_init() return value on
> purpose: a PSP failure must not fail the probe, as the CCP can still
> initialize successfully.
>
> Fixes: 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-0de87f0c-0f5a-4dad-8ef1-f49844eb4cce
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kim Phillips <kim.phillips@amd.com>
All looks good, thanks.
Reviewed-by: Serge Hallyn (AMD) <sergeh@kernel.org>
> ---
> v1: https://lore.kernel.org/linux-crypto/20261021215716.1076732-1-kim.phillips@amd.com/
>
> drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index b14ce51065d5..3d9341c2876d 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -207,19 +207,19 @@ static int psp_init(struct psp_device *psp)
> if (!psp_check_tee_support(psp)) {
> ret = tee_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sev;
> }
>
> if (!psp_check_sfs_support(psp)) {
> ret = sfs_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_tee;
> }
>
> if (psp->vdata->platform_access) {
> ret = platform_access_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sfs;
> }
>
> /* dbc must come after platform access as it tests the feature */
> @@ -227,15 +227,28 @@ static int psp_init(struct psp_device *psp)
> psp->capability.dbc_thru_ext) {
> ret = dbc_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_platform_access;
> }
>
> /* HSTI uses platform access on some systems. */
> ret = psp_init_hsti(psp);
> if (ret)
> - return ret;
> + goto e_dbc;
>
> return 0;
> +
> +e_dbc:
> + dbc_dev_destroy(psp);
> +e_platform_access:
> + platform_access_dev_destroy(psp);
> +e_sfs:
> + sfs_dev_destroy(psp);
> +e_tee:
> + tee_dev_destroy(psp);
> +e_sev:
> + sev_dev_destroy(psp);
> +
> + return ret;
> }
>
> int psp_dev_init(struct sp_device *sp)
>
> base-commit: 26ca5f34841f0a86d0883664a1c13be89a01d351
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
2026-11-16 20:36 [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure Kim Phillips
2026-11-16 21:24 ` Mario Limonciello
2026-11-23 15:17 ` Serge Hallyn (AMD)
@ 2026-11-24 15:44 ` Tom Lendacky
2026-11-27 5:11 ` Herbert Xu
3 siblings, 0 replies; 6+ messages in thread
From: Tom Lendacky @ 2026-11-24 15:44 UTC (permalink / raw)
To: Kim Phillips, Herbert Xu, David S . Miller, Rijo Thomas,
Mario Limonciello
Cc: linux-crypto, linux-kernel, Sashiko, stable
On 11/16/26 14:36, Kim Phillips wrote:
> psp_init() initializes sub-devices sequentially but returns immediately
> on the first failure, leaving earlier sub-devices registered. Its caller
> psp_dev_init() then sets sp->psp_data = NULL, so the later
> psp_dev_destroy() on unbind bails out early and never unregisters them.
>
> Non-devm resources such as the /dev/sev and /dev/dbc character devices
> stay globally visible while their devm-allocated backing structures are
> freed by the driver core, giving a use-after-free if userspace opens the
> orphaned device.
>
> Add reverse-order unwind labels to psp_init() so each sub-device is torn
> down before the error is propagated. Every *_dev_destroy() is already
> NULL-guarded on its own psp->*_data pointer, so skipped or unreached
> sub-devices are no-ops.
>
> sp_init() continues to ignore the psp_dev_init() return value on
> purpose: a PSP failure must not fail the probe, as the CCP can still
> initialize successfully.
Can we look at only disabling just the service that failed. I think
failing all services and the use of a global psp_dead outside of the
individual service should be addressed instead of failing everything. For
example, if the TEE support fails, it doesn't necessarily mean that SEV
support is bad.
What would it take to handle each service on its own and not clear the
sp->psp_data pointer and instead guard each service with its own psp_dead
variable?
Thanks,
Tom
>
> Fixes: 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-0de87f0c-0f5a-4dad-8ef1-f49844eb4cce
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kim Phillips <kim.phillips@amd.com>
> ---
> v1: https://lore.kernel.org/linux-crypto/20261021215716.1076732-1-kim.phillips@amd.com/
>
> drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index b14ce51065d5..3d9341c2876d 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -207,19 +207,19 @@ static int psp_init(struct psp_device *psp)
> if (!psp_check_tee_support(psp)) {
> ret = tee_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sev;
> }
>
> if (!psp_check_sfs_support(psp)) {
> ret = sfs_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_tee;
> }
>
> if (psp->vdata->platform_access) {
> ret = platform_access_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_sfs;
> }
>
> /* dbc must come after platform access as it tests the feature */
> @@ -227,15 +227,28 @@ static int psp_init(struct psp_device *psp)
> psp->capability.dbc_thru_ext) {
> ret = dbc_dev_init(psp);
> if (ret)
> - return ret;
> + goto e_platform_access;
> }
>
> /* HSTI uses platform access on some systems. */
> ret = psp_init_hsti(psp);
> if (ret)
> - return ret;
> + goto e_dbc;
>
> return 0;
> +
> +e_dbc:
> + dbc_dev_destroy(psp);
> +e_platform_access:
> + platform_access_dev_destroy(psp);
> +e_sfs:
> + sfs_dev_destroy(psp);
> +e_tee:
> + tee_dev_destroy(psp);
> +e_sev:
> + sev_dev_destroy(psp);
> +
> + return ret;
> }
>
> int psp_dev_init(struct sp_device *sp)
>
> base-commit: 26ca5f34841f0a86d0883664a1c13be89a01d351
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
2026-11-16 20:36 [PATCH v2] crypto: ccp - unwind PSP sub-devices on partial psp_init() failure Kim Phillips
` (2 preceding siblings ...)
2026-11-24 15:44 ` Tom Lendacky
@ 2026-11-27 5:11 ` Herbert Xu
3 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2026-11-27 5:11 UTC (permalink / raw)
To: Kim Phillips
Cc: Tom Lendacky, David S . Miller, Rijo Thomas, Mario Limonciello,
linux-crypto, linux-kernel, Sashiko, stable
On Mon, Nov 16, 2026 at 02:36:22PM -0600, Kim Phillips wrote:
> psp_init() initializes sub-devices sequentially but returns immediately
> on the first failure, leaving earlier sub-devices registered. Its caller
> psp_dev_init() then sets sp->psp_data = NULL, so the later
> psp_dev_destroy() on unbind bails out early and never unregisters them.
>
> Non-devm resources such as the /dev/sev and /dev/dbc character devices
> stay globally visible while their devm-allocated backing structures are
> freed by the driver core, giving a use-after-free if userspace opens the
> orphaned device.
>
> Add reverse-order unwind labels to psp_init() so each sub-device is torn
> down before the error is propagated. Every *_dev_destroy() is already
> NULL-guarded on its own psp->*_data pointer, so skipped or unreached
> sub-devices are no-ops.
>
> sp_init() continues to ignore the psp_dev_init() return value on
> purpose: a PSP failure must not fail the probe, as the CCP can still
> initialize successfully.
>
> Fixes: 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-0de87f0c-0f5a-4dad-8ef1-f49844eb4cce
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Rijo Thomas <Rijo-john.Thomas@amd.com>
> Cc: Mario Limonciello <mario.limonciello@amd.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kim Phillips <kim.phillips@amd.com>
> ---
> v1: https://lore.kernel.org/linux-crypto/20261021215716.1076732-1-kim.phillips@amd.com/
>
> drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread