* [PATCH] block: Fix potential page reference leak in __bio_iov_iter_get_pages()
@ 2020-09-01 12:00 Miaohe Lin
2020-09-01 16:09 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2020-09-01 12:00 UTC (permalink / raw)
To: axboe; +Cc: linux-block, linux-kernel, linmiaohe
When bio is full, __bio_iov_iter_get_pages() would return error directly
while left page reference still held in pages. Release these references.
Also advance the iov_iter according to what we have done successfully.
Fixes: 576ed9135489 ("block: use bio_add_page in bio_iov_iter_get_pages")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
block/bio.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/block/bio.c b/block/bio.c
index a9931f23d933..e113073958cb 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1023,7 +1023,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
put_page(page);
} else {
if (WARN_ON_ONCE(bio_full(bio, len)))
- return -EINVAL;
+ goto put_pages;
__bio_add_page(bio, page, len, offset);
}
offset = 0;
@@ -1031,6 +1031,19 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
iov_iter_advance(iter, size);
return 0;
+
+put_pages:
+ /* Advance iov_iter to what we have done yet. */
+ iov_iter_advance(iter, size - left);
+ /* Put the page references still held by pages. */
+ 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;
}
static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] block: Fix potential page reference leak in __bio_iov_iter_get_pages()
@ 2020-09-02 1:46 linmiaohe
0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2020-09-02 1:46 UTC (permalink / raw)
To: Christoph Hellwig
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org
Christoph Hellwig <hch@infradead.org> wrote:
>On Tue, Sep 01, 2020 at 08:00:06AM -0400, Miaohe Lin wrote:
>> When bio is full, __bio_iov_iter_get_pages() would return error
>> directly while left page reference still held in pages. Release these references.
>> Also advance the iov_iter according to what we have done successfully.
>>
>> Fixes: 576ed9135489 ("block: use bio_add_page in
>> bio_iov_iter_get_pages")
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>
>The WARN_ON means something is fundamentally wrong here. I think a few leaked pages are the least of our problems in this case.
Yes, WARN_ON means something is fundamentally wrong here. But IMO it's not really a big problem when bio is full.
We should not simply rely on this WARN_ON and we can handle this gracefully.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-02 1:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-01 12:00 [PATCH] block: Fix potential page reference leak in __bio_iov_iter_get_pages() Miaohe Lin
2020-09-01 16:09 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2020-09-02 1:46 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).