[SRU][Trusty][PATCH 2/2] more bio_map_user_iov() leak fixes
Kleber Sacilotto de Souza
kleber.souza at canonical.com
Fri Dec 8 13:37:56 UTC 2017
From: Al Viro <viro at 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 at vger.kernel.org
Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>
CVE-2017-12190
(backported from commit 2b04e8f6bbb196cab4b232af0f8d48ff2c7a8058)
[klebers:
- Fixed file path from block/bio.c to fs/bio.c.
- page_cache_release() is defined as put_page(), but keep it as
page_cache_release() for consistency with the rest of the code.]
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza at canonical.com>
---
fs/bio.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/bio.c b/fs/bio.c
index 3311aa0f3dd9..2dde9b514b1c 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1234,6 +1234,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;
@@ -1277,7 +1278,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;
}
@@ -1332,10 +1338,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, i) {
+ page_cache_release(bvec->bv_page);
}
out:
kfree(pages);
--
2.14.1
More information about the kernel-team
mailing list