crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
PATCH v2 1/1 crypto: ccp - unwind PSP sub-devices on partial psp_init() failure
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.
---
v1: https://lore.kernel.org/linux-crypto/[email protected]/
drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/crypto/ccp/psp-dev.c +18 -5
@@ -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
Signature · 1 line
2.43.0
Quoted 27 lines · Kim Phillips
psp_init()initializes sub-devices sequentially but returns immediately on the first failure, leaving earlier sub-devices registered. Its callerpsp_dev_init()then setssp->psp_data= NULL, so the laterpsp_dev_destroy()on unbind bails out early and never unregisters them.Non-devm resources such as the
/dev/sevand/dev/dbccharacter 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 thepsp_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 <[email protected]>Cc Tom Lendacky <[email protected]>Cc Rijo Thomas <[email protected]>Cc Mario Limonciello <[email protected]>Signed-off-by Kim Phillips <[email protected]>
Quoted 2 lines
---
v1: https://lore.kernel.org/linux-crypto/[email protected]/
Quoted 64 lines
drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)drivers/crypto/ccp/psp-dev.c +18
-5@@ -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
Rijo Thomas
Reviewed-byQuoted 22 lines · Mario Limonciello
Quoted 19 lines · Kim Phillips
psp_init()initializes sub-devices sequentially but returns immediately on the first failure, leaving earlier sub-devices registered. Its callerpsp_dev_init()then setssp->psp_data= NULL, so the laterpsp_dev_destroy()on unbind bails out early and never unregisters them.Non-devm resources such as the
/dev/sevand/dev/dbccharacter 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 thepsp_dev_init()return value on
purpose: a PSP failure must not fail the probe, as the CCP can still initialize successfully.
Quoted 11 lines
Quoted 10 lines
Fixes 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")Reported-by Sashiko <[email protected]>Cc Tom Lendacky <[email protected]>Cc Rijo Thomas <[email protected]>Cc Mario Limonciello <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
v1: https://lore.kernel.org/linux-crypto/[email protected]/
Looks good to me.
Quoted 61 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>Quoted 58 lines
drivers/crypto/ccp/psp-dev.c| 23 ++++++++++++++++++-----1 file changed, 18 insertions(+), 5 deletions(-)drivers/crypto/ccp/psp-dev.c +18
-5@@ -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
Quoted 19 lines · Kim Phillips
psp_init()initializes sub-devices sequentially but returns immediately on the first failure, leaving earlier sub-devices registered. Its callerpsp_dev_init()then setssp->psp_data= NULL, so the laterpsp_dev_destroy()on unbind bails out early and never unregisters them.Non-devm resources such as the
/dev/sevand/dev/dbccharacter 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 thepsp_dev_init()return value on
purpose: a PSP failure must not fail the probe, as the CCP can still initialize successfully.
Quoted 8 lines
Fixes 33960acccfbd ("crypto: ccp - add TEE support for Raven Ridge")Reported-by Sashiko <[email protected]>Cc Tom Lendacky <[email protected]>Cc Rijo Thomas <[email protected]>Cc Mario Limonciello <[email protected]>Signed-off-by Kim Phillips <[email protected]>
All looks good, thanks.
Quoted 69 lines
---
v1: https://lore.kernel.org/linux-crypto/[email protected]/drivers/crypto/ccp/psp-dev.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)drivers/crypto/ccp/psp-dev.c +18
-5@@ -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:
26ca5f34841f0a86d0883664a1c13be89a01d351Signature · 1 line
2.43.0