]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/block-do-not-leak-memory-in-bio_copy_user_iov.patch
Linux 4.14.112
[thirdparty/kernel/stable-queue.git] / queue-4.19 / block-do-not-leak-memory-in-bio_copy_user_iov.patch
1 From a3761c3c91209b58b6f33bf69dd8bb8ec0c9d925 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= <jglisse@redhat.com>
3 Date: Wed, 10 Apr 2019 16:27:51 -0400
4 Subject: block: do not leak memory in bio_copy_user_iov()
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Jérôme Glisse <jglisse@redhat.com>
10
11 commit a3761c3c91209b58b6f33bf69dd8bb8ec0c9d925 upstream.
12
13 When bio_add_pc_page() fails in bio_copy_user_iov() we should free
14 the page we just allocated otherwise we are leaking it.
15
16 Cc: linux-block@vger.kernel.org
17 Cc: Linus Torvalds <torvalds@linux-foundation.org>
18 Cc: stable@vger.kernel.org
19 Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
20 Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
21 Signed-off-by: Jens Axboe <axboe@kernel.dk>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 block/bio.c | 5 ++++-
26 1 file changed, 4 insertions(+), 1 deletion(-)
27
28 --- a/block/bio.c
29 +++ b/block/bio.c
30 @@ -1240,8 +1240,11 @@ struct bio *bio_copy_user_iov(struct req
31 }
32 }
33
34 - if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes)
35 + if (bio_add_pc_page(q, bio, page, bytes, offset) < bytes) {
36 + if (!map_data)
37 + __free_page(page);
38 break;
39 + }
40
41 len -= bytes;
42 offset = 0;