* [PATCH v4.4] more bio_map_user_iov() leak fixes
@ 2017-12-14 2:18 Guenter Roeck
2017-12-14 17:46 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2017-12-14 2:18 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: stable, Al Viro, Guenter Roeck
From: Al Viro <viro@zeniv.linux.org.uk>
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.
Cc: stable@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
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(-)
diff --git a/block/bio.c b/block/bio.c
index 68bbc835bacc..63363a689922 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4.4] more bio_map_user_iov() leak fixes
2017-12-14 2:18 [PATCH v4.4] more bio_map_user_iov() leak fixes Guenter Roeck
@ 2017-12-14 17:46 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2017-12-14 17:46 UTC (permalink / raw)
To: Guenter Roeck; +Cc: stable, Al Viro
On Wed, Dec 13, 2017 at 06:18:27PM -0800, Guenter Roeck wrote:
> From: Al Viro <viro@zeniv.linux.org.uk>
>
> 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.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-14 17:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 2:18 [PATCH v4.4] more bio_map_user_iov() leak fixes Guenter Roeck
2017-12-14 17:46 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.