Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
* [RESEND PATCH] sgl_alloc_order: fix memory leak
@ 2020-10-15 18:57 Douglas Gilbert
  2020-10-16 15:31 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Douglas Gilbert @ 2020-10-15 18:57 UTC (permalink / raw)
  To: linux-scsi, linux-block, linux-kernel; +Cc: martin.petersen, axboe, bvanassche

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>
---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 5d63a8857f36..c448642e0f78 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;
 		}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH] sgl_alloc_order: fix memory leak
  2020-10-15 18:57 [RESEND PATCH] sgl_alloc_order: fix memory leak Douglas Gilbert
@ 2020-10-16 15:31 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-10-16 15:31 UTC (permalink / raw)
  To: Douglas Gilbert, linux-scsi, linux-block, linux-kernel
  Cc: martin.petersen, bvanassche

On 10/15/20 12:57 PM, Douglas Gilbert wrote:
> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 18:57 [RESEND PATCH] sgl_alloc_order: fix memory leak Douglas Gilbert
2020-10-16 15:31 ` Jens Axboe

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org
	public-inbox-index linux-block

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git