diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2020-10-15 14:57:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-11-05 11:43:22 +0100 |
commit | c421c082088ef10baec2612cea5973907a6acc21 (patch) | |
tree | 482055e6cab15efb958e33671f55d6fb122f3c3b /lib | |
parent | 742fd49cf811ca164489e339b862e3fb8e240a73 (diff) |
sgl_alloc_order: fix memory leak
[ Upstream commit b2a182a40278bc5849730e66bca01a762188ed86 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/scatterlist.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 5813072bc589..29346184fcf2 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -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; } |