linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages()
@ 2020-09-05  9:40 Miaohe Lin
  2020-09-09  7:09 ` Johannes Thumshirn
  0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2020-09-05  9:40 UTC (permalink / raw)
  To: axboe, martin.petersen, kbusch, johannes.thumshirn, hare
  Cc: linux-block, linux-kernel, linmiaohe

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@huawei.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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages()
  2020-09-05  9:40 [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages() Miaohe Lin
@ 2020-09-09  7:09 ` Johannes Thumshirn
  0 siblings, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2020-09-09  7:09 UTC (permalink / raw)
  To: Miaohe Lin, axboe, martin.petersen, kbusch, hare
  Cc: linux-block, linux-kernel

On 05/09/2020 11:41, Miaohe Lin wrote:
> When bio_add_hw_page() failed, we left page reference still held in pages.

I'd add "from iov_iter_get_pages()" to the above sentence.

Otherwise
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages()
@ 2020-09-09  7:21 linmiaohe
  0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2020-09-09  7:21 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: linux-block, linux-kernel, axboe, martin.petersen, kbusch, hare

Johannes Thumshirn <Johannes.Thumshirn@wdc.com> wrote:
>On 05/09/2020 11:41, Miaohe Lin wrote:
>> When bio_add_hw_page() failed, we left page reference still held in pages.
>
>I'd add "from iov_iter_get_pages()" to the above sentence.
>

Sounds good. Will add it in v2.

>Otherwise
>Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Many Thanks for review.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-09  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05  9:40 [PATCH] block: Fix potential page reference leak in __bio_iov_append_get_pages() Miaohe Lin
2020-09-09  7:09 ` Johannes Thumshirn
2020-09-09  7:21 linmiaohe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).