Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Douglas Gilbert and committed by
Jens Axboe
b2a182a4 a48faebe

+1 -1
+1 -1
lib/scatterlist.c
··· 514 514 elem_len = min_t(u64, length, PAGE_SIZE << order); 515 515 page = alloc_pages(gfp, order); 516 516 if (!page) { 517 - sgl_free(sgl); 517 + sgl_free_order(sgl, order); 518 518 return NULL; 519 519 } 520 520