From: Al Viro Date: Sat, 23 Sep 2017 19:51:23 +0000 (-0400) Subject: more bio_map_user_iov() leak fixes X-Git-Tag: v3.2.97~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fab3702764bd73f2f9b8e1c140ef1de845e3071;p=thirdparty%2Fkernel%2Fstable.git 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 [bwh: Backported to 3.2: adjust filename, context] Signed-off-by: Ben Hutchings --- diff --git a/fs/bio.c b/fs/bio.c index 1fa6b825240d8..081747c89b627 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -976,6 +976,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; @@ -1019,7 +1020,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; } @@ -1074,10 +1080,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);