qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] block: Fix Transaction leak in bdrv_root_attach_child()
Date: Mon, 3 May 2021 14:51:28 +0300	[thread overview]
Message-ID: <cdef7d37-1d8c-85c3-de0e-0730949bda92@virtuozzo.com> (raw)
In-Reply-To: <9e23f679-84ac-9d1a-09dc-4894cd9d6979@redhat.com>

03.05.2021 14:49, Max Reitz wrote:
> On 03.05.21 13:05, Kevin Wolf wrote:
>> The error path needs to call tran_finalize(), too.
>>
>> Fixes: CID 1452773
>> Fixes: 548a74c0dbc858edd1a7ee3045b5f2fe710bd8b1
>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> ---
>>   block.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index 874c22c43e..5c0ced6238 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -2918,13 +2918,14 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
>>                                      child_role, perm, shared_perm, opaque,
>>                                      &child, tran, errp);
>>       if (ret < 0) {
>> -        bdrv_unref(child_bs);
>> -        return NULL;
>> +        assert(child == NULL);
>> +        goto out;
>>       }
>>       ret = bdrv_refresh_perms(child_bs, errp);
>> -    tran_finalize(tran, ret);
>> +out:
>> +    tran_finalize(tran, ret);
>>       bdrv_unref(child_bs);
>>       return child;
> 
> Looks OK, so:
> 
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> 
> However, the function’s description says that it will return NULL on error.  But if bdrv_refresh_perms() fails, it will still return a non-NULL child.  Is that right?
> 

No, it's reset to NULL on transaction abort, so code is correct. It's not obvious, and I've added a comment and assertion in my version of this fix "[PATCH 1/6] block: fix leak of tran in bdrv_root_attach_child"

-- 
Best regards,
Vladimir


  reply	other threads:[~2021-05-03 11:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 11:05 [PATCH 0/2] block: Fix Transaction leaks Kevin Wolf
2021-05-03 11:05 ` [PATCH 1/2] block: Fix Transaction leak in bdrv_root_attach_child() Kevin Wolf
2021-05-03 11:43   ` Vladimir Sementsov-Ogievskiy
2021-05-03 11:49   ` Max Reitz
2021-05-03 11:51     ` Vladimir Sementsov-Ogievskiy [this message]
2021-05-03 11:53       ` Max Reitz
2021-05-03 12:14         ` Vladimir Sementsov-Ogievskiy
2021-05-03 12:31           ` Vladimir Sementsov-Ogievskiy
2021-05-03 11:05 ` [PATCH 2/2] block: Fix Transaction leak in bdrv_reopen_multiple() Kevin Wolf
2021-05-03 11:40   ` Vladimir Sementsov-Ogievskiy
2021-05-03 12:41     ` Kevin Wolf
2021-05-03 13:09       ` Vladimir Sementsov-Ogievskiy
2021-05-03 14:33         ` Kevin Wolf
2021-05-04  6:52           ` Vladimir Sementsov-Ogievskiy
2021-05-04  6:51   ` Vladimir Sementsov-Ogievskiy
2021-05-04  6:56 ` [PATCH 0/2] block: Fix Transaction leaks Vladimir Sementsov-Ogievskiy
2021-05-05 10:25   ` Kevin Wolf

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=cdef7d37-1d8c-85c3-de0e-0730949bda92@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.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).