x86/sgx: Fix a resource leak in sgx_init()
Subsystems (3)
Jarkko Sakkinen
maintainerPATCH 1/1 x86/sgx: Fix a resource leak in sgx_init()
If sgx_page_cache_init() fails in the middle, a trivial return statement causes unused memory and virtual address space reserved for the EPC section, not freed. Fix this by using the same rollback, as when sgx_page_reclaimer_init() fails.
Cc [email protected] # 5.11
Fixes e7e0545299d8 ("x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections")
Signed-off-by Jarkko Sakkinen <[email protected]>
--- arch/x86/kernel/cpu/sgx/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/main.c +4 -2
@@ -708,8 +708,10 @@ static int __init sgx_init(void)if (!cpu_feature_enabled (X86_FEATURE_SGX ))return -ENODEV ; -if (!sgx_page_cache_init ()) -return -ENOMEM ; +if (!sgx_page_cache_init ()) { + ret = -ENOMEM ; + goto err_page_cache; + }if (!sgx_page_reclaimer_init ()) { ret = -ENOMEM ;
Signature · 1 line
2.30.1