From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Keith Busch <kbusch@kernel.org>
Subject: Re: [RFC] bio: fix page leak bio_add_hw_page failure
Date: Sun, 8 Aug 2021 13:57:48 +0100 [thread overview]
Message-ID: <49550f27-2dac-7ee5-1e03-bd22b70b7ca1@gmail.com> (raw)
In-Reply-To: <1edfa6a2ffd66d55e6345a477df5387d2c1415d0.1626653825.git.asml.silence@gmail.com>
On 7/19/21 11:53 AM, Pavel Begunkov wrote:
> __bio_iov_append_get_pages() doesn't put not appended pages on
> bio_add_hw_page() failure, so potentially leaking them, fix it. Also, do
> the same for __bio_iov_iter_get_pages(), even though it looks like it
> can't be triggered by userspace in this case.
Any comments?
>
> Fixes: 0512a75b98f8 ("block: Introduce REQ_OP_ZONE_APPEND")
> Cc: stable@vger.kernel.org # 5.8+
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>
> I haven't tested the fail path, thus RFC. Would be great if someone can
> do it or take over the fix.
>
> block/bio.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 1fab762e079b..d95e3456ba0c 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -979,6 +979,14 @@ static int bio_iov_bvec_set_append(struct bio *bio, struct iov_iter *iter)
> return 0;
> }
>
> +static void bio_put_pages(struct page **pages, size_t size, size_t off)
> +{
> + size_t i, nr = DIV_ROUND_UP(size + (off & ~PAGE_MASK), PAGE_SIZE);
> +
> + for (i = 0; i < nr; i++)
> + put_page(pages[i]);
> +}
> +
> #define PAGE_PTRS_PER_BVEC (sizeof(struct bio_vec) / sizeof(struct page *))
>
> /**
> @@ -1023,8 +1031,10 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
> if (same_page)
> put_page(page);
> } else {
> - if (WARN_ON_ONCE(bio_full(bio, len)))
> - return -EINVAL;
> + if (WARN_ON_ONCE(bio_full(bio, len))) {
> + bio_put_pages(pages + i, left, offset);
> + return -EINVAL;
> + }
> __bio_add_page(bio, page, len, offset);
> }
> offset = 0;
> @@ -1069,6 +1079,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) {
> + bio_put_pages(pages + i, left, offset);
> ret = -EINVAL;
> break;
> }
>
--
Pavel Begunkov
next prev parent reply other threads:[~2021-08-08 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 10:53 [RFC] bio: fix page leak bio_add_hw_page failure Pavel Begunkov
2021-07-19 15:34 ` Ming Lei
2021-07-19 17:06 ` Pavel Begunkov
2021-07-20 2:11 ` Ming Lei
2021-07-21 14:44 ` Pavel Begunkov
2021-08-08 12:57 ` Pavel Begunkov [this message]
2021-08-24 14:05 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49550f27-2dac-7ee5-1e03-bd22b70b7ca1@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).