From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0120.outbound.protection.outlook.com ([104.47.33.120]:58346 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031866AbeCAPX2 (ORCPT ); Thu, 1 Mar 2018 10:23:28 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Al Viro , Sasha Levin Subject: [added to the 4.1 stable tree] more bio_map_user_iov() leak fixes Date: Thu, 1 Mar 2018 15:22:27 +0000 Message-ID: <20180301152116.1486-2-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Al Viro This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 2b04e8f6bbb196cab4b232af0f8d48ff2c7a8058 ] 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 Signed-off-by: Sasha Levin --- block/bio.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/block/bio.c b/block/bio.c index d9cf77c6a847..f90b2abe2fa7 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1290,6 +1290,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; =20 iov_for_each(iov, i, *iter) { unsigned long uaddr =3D (unsigned long) iov.iov_base; @@ -1334,7 +1335,12 @@ struct bio *bio_map_user_iov(struct request_queue *q= , ret =3D get_user_pages_fast(uaddr, local_nr_pages, (iter->type & WRITE) !=3D WRITE, &pages[cur_page]); - if (ret < local_nr_pages) { + if (unlikely(ret < local_nr_pages)) { + for (j =3D cur_page; j < page_limit; j++) { + if (!pages[j]) + break; + put_page(pages[j]); + } ret =3D -EFAULT; goto out_unmap; } @@ -1396,10 +1402,8 @@ struct bio *bio_map_user_iov(struct request_queue *q= , return bio; =20 out_unmap: - for (j =3D 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); --=20 2.14.1