diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2017-09-23 15:51:23 -0400 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2018-01-01 20:51:50 +0000 |
commit | 4b0266192d2b1701c1b316de139f200b8315e0cf (patch) | |
tree | 05ea14917194584fb748a7d4823d00842a1f1d82 | |
parent | 897b6ce29ca160db586408d847c5d07214e114fc (diff) | |
download | linux-stable-4b0266192d2b1701c1b316de139f200b8315e0cf.tar.gz linux-stable-4b0266192d2b1701c1b316de139f200b8315e0cf.tar.bz2 linux-stable-4b0266192d2b1701c1b316de139f200b8315e0cf.zip |
more bio_map_user_iov() leak fixes
commit 2b04e8f6bbb196cab4b232af0f8d48ff2c7a8058 upstream.
we need to take care of failure exit as well - pages already
in bio should be dropped by analogue of bio_unmap_pages(),
since their refcounts had been bumped only once per reference
in bio.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | block/bio.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/block/bio.c b/block/bio.c index dcc6365bcc11..4218dab2bb47 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1286,6 +1286,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q, struct bio *bio; int cur_page = 0; int ret, offset; + struct bio_vec *bvec; for (i = 0; i < iov_count; i++) { unsigned long uaddr = (unsigned long)iov[i].iov_base; @@ -1329,7 +1330,12 @@ static struct bio *__bio_map_user_iov(struct request_queue *q, ret = get_user_pages_fast(uaddr, local_nr_pages, write_to_vm, &pages[cur_page]); - if (ret < local_nr_pages) { + if (unlikely(ret < local_nr_pages)) { + for (j = cur_page; j < page_limit; j++) { + if (!pages[j]) + break; + put_page(pages[j]); + } ret = -EFAULT; goto out_unmap; } @@ -1384,10 +1390,8 @@ static struct bio *__bio_map_user_iov(struct request_queue *q, return bio; out_unmap: - for (i = 0; i < nr_pages; i++) { - if(!pages[i]) - break; - page_cache_release(pages[i]); + bio_for_each_segment_all(bvec, bio, j) { + put_page(bvec->bv_page); } out: kfree(pages); |