From: Jens Axboe <axboe@kernel.dk>
To: Justin Tee <justin.tee@broadcom.com>, Ming Lei <ming.lei@redhat.com>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] block: fix memleak of bio integrity data
Date: Thu, 5 Dec 2019 11:38:05 -0700 [thread overview]
Message-ID: <33d14d7e-2033-8680-8746-d259b51209e7@kernel.dk> (raw)
In-Reply-To: <f4f0f90a-0541-a25b-f9a6-f7e0762d6e28@broadcom.com>
On 12/5/19 11:30 AM, Justin Tee wrote:
> On 12/5/2019 12:09 AM, Ming Lei wrote:
>> On Thu, Dec 05, 2019 at 03:49:32PM +0800, Ming Lei wrote:
>>> On Wed, Dec 04, 2019 at 09:41:24PM -0800, Justin Tee wrote:
>>>> Hi Ming,
>>>>
>>>> I understand the patch, but I have a concern.
>>>>
>>>> Is it possible to come across a double-free? from bio_endio ->
>>>> bio_integrity_endio -> __bio_integrity_endio -> bio_integrity_free; And
>>>> then, resuming in bio_endio -> bio_uninit -> bio_integrity_free;. Maybe
>>>> it's even possible queue_work bio_integrity_verify_fn was scheduled and
>>>> called bio_integrity_free from there as well. So, should also remove
>>>> bio_integrity_free from bio_integrity_verify_fn and __bio_integrity_endio
>>>> routines?
>>>
>>> Yeah, double-free could be caused for READ between bio_integrity_verify_fn()
>>> and bio_uninit().
>>
>> ooops, the above race doesn't exist because __bio_integrity_endio()
>> returns false and bio_endio() won't call bio_uninit(). And bio_uninit()
>> is only called from bio_endio() when bio_integrity_verify_fn() exits.
>>
>> Also we can't remove the bio_integrity_free() from bio_integrity_verify_fn(),
>> otherwise this bio may never be ended because bio_integrity_endio() will
>> schedule the verify_fn again if bio_integrity_verify_fn() won't clear
>> REQ_INTEGRITY.
>>
>> So bio_integrity_free() is always called serially, and the flag of REQ_INTEGRITY
>> guarantees that it is only freed once.
>>
>> I think there isn't such double free you mentioned.
>>
>> Thanks,
>> Ming
>>
>>
>>
>
> Right agreed, the REQ_INTEGRITY flag is what is guaranteeing freeing
> only once.
>
> Thanks for clearing this up. I'm good with the patch.
Thanks all - I have applied the patch, and re-instated Justin's
signed-off-by.
--
Jens Axboe
next prev parent reply other threads:[~2019-12-05 18:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 2:09 [PATCH] block: fix memleak of bio integrity data Ming Lei
[not found] ` <CAAmqgVN6huL60c9aw41yC6wz6fG0w-T4xR0Tuoz0PqX2BqwKDA@mail.gmail.com>
2019-12-05 7:49 ` Ming Lei
2019-12-05 8:09 ` Ming Lei
2019-12-05 18:30 ` Justin Tee
2019-12-05 18:38 ` Jens Axboe [this message]
2019-12-05 9:52 ` Christoph Hellwig
2019-12-05 10:08 ` John Garry
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=33d14d7e-2033-8680-8746-d259b51209e7@kernel.dk \
--to=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=justin.tee@broadcom.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
/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