Skip to contentSkip to conversation

x86/sgx: Fix a resource leak in sgx_init()

PATCH Superseded Jarkko Sakkinen 1 participant 1 message Mar 2, 2021

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 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.

Fixes e7e0545299d8 ("x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections")
---
 arch/x86/kernel/cpu/sgx/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/main.c +4 -2
index 8df81a3ed945..52d070fb4c9a 100644
@@ -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