Skip to contentSkip to conversation

swiotlb: Fix use after free on error handling path

PATCH Applied Dan Carpenter 2 participants 2 messages Jul 15, 2022 – Jul 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swiotlb: Fix use after free on error handling path

Don't dereference "mem" after it has been freed. Flip the two kfree()s around to address this bug.

Fixes 26ffb91fa5e0 ("swiotlb: split up the global swiotlb lock")
---
 kernel/dma/swiotlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/dma/swiotlb.c +1 -1
index bf2ae98a42b4..78af9e455c59 100644
@@ -980,8 +980,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
 		mem->areas = kcalloc(nareas, sizeof(*mem->areas),
 				GFP_KERNEL);
 		if (!mem->areas) {
-			kfree(mem);
 			kfree(mem->slots);
+			kfree(mem);
 			return -ENOMEM;
 		}
 
Signature · 1 line
2.35.1