diff mbox series

[SRU,Zesty,2/2] more bio_map_user_iov() leak fixes

Message ID 20171208133848.18906-3-kleber.souza@canonical.com
State New
Headers show
Series Fix for CVE-2017-12190 | expand

Commit Message

Kleber Sacilotto de Souza Dec. 8, 2017, 1:38 p.m. UTC
From: Al Viro <viro@zeniv.linux.org.uk>

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>

CVE-2017-12190
(cherry picked from commit 2b04e8f6bbb196cab4b232af0f8d48ff2c7a8058)
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
---
 block/bio.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index 13185834b253..c71ac78d6919 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1320,6 +1320,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;
@@ -1364,7 +1365,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;
 		}
@@ -1426,10 +1432,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);