summaryrefslogtreecommitdiffstats
path: root/block/bio.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2017-09-23 15:51:23 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2017-10-10 23:54:57 -0400
commit2b04e8f6bbb196cab4b232af0f8d48ff2c7a8058 (patch)
tree8be4924951564fb02964129570dd5c64c5e63584 /block/bio.c
parent95d78c28b5a85bacbc29b8dba7c04babb9b0d467 (diff)
more bio_map_user_iov() leak fixes
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. Cc: stable@vger.kernel.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'block/bio.c')
-rw-r--r--block/bio.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/block/bio.c b/block/bio.c
index 0d6439e89acb..9e9606d26cc6 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1331,6 +1331,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
1331 int ret, offset; 1331 int ret, offset;
1332 struct iov_iter i; 1332 struct iov_iter i;
1333 struct iovec iov; 1333 struct iovec iov;
1334 struct bio_vec *bvec;
1334 1335
1335 iov_for_each(iov, i, *iter) { 1336 iov_for_each(iov, i, *iter) {
1336 unsigned long uaddr = (unsigned long) iov.iov_base; 1337 unsigned long uaddr = (unsigned long) iov.iov_base;
@@ -1375,7 +1376,12 @@ struct bio *bio_map_user_iov(struct request_queue *q,
1375 ret = get_user_pages_fast(uaddr, local_nr_pages, 1376 ret = get_user_pages_fast(uaddr, local_nr_pages,
1376 (iter->type & WRITE) != WRITE, 1377 (iter->type & WRITE) != WRITE,
1377 &pages[cur_page]); 1378 &pages[cur_page]);
1378 if (ret < local_nr_pages) { 1379 if (unlikely(ret < local_nr_pages)) {
1380 for (j = cur_page; j < page_limit; j++) {
1381 if (!pages[j])
1382 break;
1383 put_page(pages[j]);
1384 }
1379 ret = -EFAULT; 1385 ret = -EFAULT;
1380 goto out_unmap; 1386 goto out_unmap;
1381 } 1387 }
@@ -1431,10 +1437,8 @@ struct bio *bio_map_user_iov(struct request_queue *q,
1431 return bio; 1437 return bio;
1432 1438
1433 out_unmap: 1439 out_unmap:
1434 for (j = 0; j < nr_pages; j++) { 1440 bio_for_each_segment_all(bvec, bio, j) {
1435 if (!pages[j]) 1441 put_page(bvec->bv_page);
1436 break;
1437 put_page(pages[j]);
1438 } 1442 }
1439 out: 1443 out:
1440 kfree(pages); 1444 kfree(pages);