Skip to content

Commit

Permalink
sgl_alloc_order: fix memory leak
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
doug-gilbert authored and axboe committed Oct 16, 2020
1 parent a48faeb commit b2a182a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/scatterlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b2a182a

Please sign in to comment.