Skip to contentSkip to conversation

sgl_alloc_order: fix memory leak

PATCH RESEND Applied Douglas Gilbert 2 participants 2 messages Oct 15, 2020 – Oct 16, 2020

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

PATCH RESEND 1/1 sgl_alloc_order: fix memory leak

sgl_alloc_order() can fail when 'length' is large on a memory constrained system. When order > 0 it will potentially be making several multi-page allocations with the later ones more likely to fail than the earlier one. So it is important that sgl_alloc_order() frees up any pages it has obtained before returning NULL. In the case when order > 0 it calls the wrong free page function and leaks. In testing the leak was sufficient to bring down my 8 GiB laptop with OOM.

---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/scatterlist.c +1 -1
index 5d63a8857f36..c448642e0f78 100644
@@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length,
 		elem_len = min_t(u64, length, PAGE_SIZE << order);
 		page = alloc_pages(gfp, order);
 		if (!page) {
-			sgl_free(sgl);
+			sgl_free_order(sgl, order);
 			return NULL;
 		}
 
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Douglas Gilbert

sgl_alloc_order() can fail when 'length' is large on a memory constrained system. When order > 0 it will potentially be making several multi-page allocations with the later ones more likely to fail than the earlier one. So it is important that sgl_alloc_order() frees up any pages it has obtained before returning NULL. In the case when order > 0 it calls the wrong free page function and leaks. In testing the leak was sufficient to bring down my 8 GiB laptop with OOM.

I've picked this one up, thanks.

Signature · 1 line
Jens Axboe