summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2017-09-23 22:51:23 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-10-18 10:38:31 +0300
commit02fb540228593ed28ac19040d403996f907ff6a7 (patch)
treeecba3ad516facd54b3c70175d4da7c27bacda236
parentffe1d63bc4570ee980a59996667c296c5be7252e (diff)
downloadlinux-02fb540228593ed28ac19040d403996f907ff6a7.tar.xz
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--block/bio.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/block/bio.c b/block/bio.c
index 963accba165c..a49d8e77d750 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1327,6 +1327,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
int ret, offset;
struct iov_iter i;
struct iovec iov;
+ struct bio_vec *bvec;
iov_for_each(iov, i, *iter) {
unsigned long uaddr = (unsigned long) iov.iov_base;
@@ -1371,7 +1372,12 @@ struct bio *bio_map_user_iov(struct request_queue *q,
ret = get_user_pages_fast(uaddr, local_nr_pages,
(iter->type & WRITE) != WRITE,
&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;
}
@@ -1427,10 +1433,8 @@ struct bio *bio_map_user_iov(struct request_queue *q,
return bio;
out_unmap:
- for (j = 0; j < nr_pages; j++) {
- if (!pages[j])
- break;
- put_page(pages[j]);
+ bio_for_each_segment_all(bvec, bio, j) {
+ put_page(bvec->bv_page);
}
out:
kfree(pages);