2019-04-10 20:29:35

by Jerome Glisse

[permalink] [raw]
Subject: [PATCH] block: do not leak memory in bio_copy_user_iov()

From: Jérôme Glisse <[email protected]>

When bio_add_pc_page() fails in bio_copy_user_iov() we should free
the page we just allocated otherwise we are leaking it.

Signed-off-by: Jérôme Glisse <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: Linus Torvalds <[email protected]>
Cc: [email protected]
---
block/bio.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index b64cedc7f87c..716510ecd7ff 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1298,8 +1298,11 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
}
}

- if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes)
+ if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes) {
+ if (!map_data)
+ __free_page(page);
break;
+ }

len -= bytes;
offset = 0;
--
2.20.1


2019-04-10 22:14:20

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: [PATCH] block: do not leak memory in bio_copy_user_iov()

Looks good.

Reviewed-by: Chaitanya Kulkarni <[email protected]>

On 04/10/2019 01:28 PM, [email protected] wrote:
> From: J?r?me Glisse <[email protected]>
>
> When bio_add_pc_page() fails in bio_copy_user_iov() we should free
> the page we just allocated otherwise we are leaking it.
>
> Signed-off-by: J?r?me Glisse <[email protected]>
> Cc: Jens Axboe <[email protected]>
> Cc: [email protected]
> Cc: Linus Torvalds <[email protected]>
> Cc: [email protected]
> ---
> block/bio.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index b64cedc7f87c..716510ecd7ff 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1298,8 +1298,11 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
> }
> }
>
> - if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes)
> + if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes) {
> + if (!map_data)
> + __free_page(page);
> break;
> + }
>
> len -= bytes;
> offset = 0;
>

2019-04-10 22:16:06

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] block: do not leak memory in bio_copy_user_iov()

On 4/10/19 2:27 PM, [email protected] wrote:
> From: Jérôme Glisse <[email protected]>
>
> When bio_add_pc_page() fails in bio_copy_user_iov() we should free
> the page we just allocated otherwise we are leaking it.

Applied, thanks.

--
Jens Axboe