lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200905094006.1925-1-linmiaohe@huawei.com>
Date:   Sat, 5 Sep 2020 05:40:06 -0400
From:   Miaohe Lin <linmiaohe@...wei.com>
To:     <axboe@...nel.dk>, <martin.petersen@...cle.com>,
        <kbusch@...nel.org>, <johannes.thumshirn@....com>, <hare@...e.de>
CC:     <linux-block@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <linmiaohe@...wei.com>
Subject: [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages()

When bio_add_hw_page() failed, we left page reference still held in pages.
Release these references and advance the iov_iter according to what we
have done successfully yet.

Fixes: 0512a75b98f8 ("block: Introduce REQ_OP_ZONE_APPEND")
Signed-off-by: Miaohe Lin <linmiaohe@...wei.com>
---
 block/bio.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index e113073958cb..a323a5446221 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1080,7 +1080,7 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
 		len = min_t(size_t, PAGE_SIZE - offset, left);
 		if (bio_add_hw_page(q, bio, page, len, offset,
 				max_append_sectors, &same_page) != len)
-			return -EINVAL;
+			goto put_pages;
 		if (same_page)
 			put_page(page);
 		offset = 0;
@@ -1088,6 +1088,16 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
 
 	iov_iter_advance(iter, size);
 	return 0;
+put_pages:
+	iov_iter_advance(iter, size - left);
+	for (; left > 0; left -= len, i++) {
+		struct page *page = pages[i];
+
+		len = min_t(size_t, PAGE_SIZE - offset, left);
+		put_page(page);
+		offset = 0;
+	}
+	return -EINVAL;
 }
 
 /**
-- 
2.19.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ