Skip to contentSkip to conversation

more bio_map_user_iov() leak fixes

PATCH In review Guenter Roeck 2 participants 2 messages Dec 14, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 more bio_map_user_iov() leak fixes

From: Al Viro <[email protected]>

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.

---
Fixed conflicts.
Intended for v4.4.y. Does not apply to v3.18.y or older kernels.

 block/bio.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
block/bio.c +9 -5
index 68bbc835bacc..63363a689922 100644
@@ -1268,6 +1268,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;
@@ -1312,7 +1313,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;
 		}
@@ -1374,10 +1380,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;
-		page_cache_release(pages[j]);
+	bio_for_each_segment_all(bvec, bio, j) {
+		put_page(bvec->bv_page);
 	}
  out:
 	kfree(pages);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Guenter Roeck

From: Al Viro <[email protected]>

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.

Quoted 6 lines

---
Fixed conflicts.
Intended for v4.4.y. Does not apply to v3.18.y or older kernels.

Many thanks for this, now applied.

greg k-h