* Re: [Qemu-devel] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 7:10 ` Markus Armbruster
@ 2014-10-30 7:33 ` zhanghailiang
2014-10-30 7:42 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-10-30 13:54 ` Michael Tokarev
2 siblings, 0 replies; 11+ messages in thread
From: zhanghailiang @ 2014-10-30 7:33 UTC (permalink / raw)
To: Markus Armbruster, arei.gonglei
Cc: qemu-trivial, peter.huangpeng, qemu-devel, lcapitulino
On 2014/10/30 15:10, Markus Armbruster wrote:
> <arei.gonglei@huawei.com> writes:
>
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> After commit 4c7e251a (), when dump memory completed,
>> the s->fd will be closed twice. We should return
>> directly when dump completed.
>>
>> Using do/while block, make the badly chosen return
>> values of get_next_block() more visible and fix
>> this issue.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>
> I'm afraid the commit message is a bit misleading. Let's examine what
> exactly happens.
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return unsuccessfully. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> Is this correct?
>
Yep, this is really a stupid mistake i made when i do clean work for dump.c,
what lucky thing is there is no version release after the commit.
Thanks for your good catch.;)
> If yes, let's use this commit message:
>
> dump: Fix dump-guest-memory termination and use-after-close
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return failure. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> The obvious fix is to restore the return lost in commit 4c7e251a. But
> the root cause of the bug is needlessly opaque loop control. Replace it
> by a clean do ... while loop.
>
> This makes the badly chosen return values of get_next_block() more
> visible. Cleaning that up is outside the scope of this bug fix.
>
> You can then add my R-by.
>
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 7:10 ` Markus Armbruster
2014-10-30 7:33 ` zhanghailiang
@ 2014-10-30 7:42 ` Michael Tokarev
2014-10-30 9:23 ` Markus Armbruster
2014-10-30 13:54 ` Michael Tokarev
2 siblings, 1 reply; 11+ messages in thread
From: Michael Tokarev @ 2014-10-30 7:42 UTC (permalink / raw)
To: Markus Armbruster, arei.gonglei
Cc: qemu-trivial, peter.huangpeng, qemu-devel, lcapitulino
30.10.2014 10:10, Markus Armbruster wrote:
> <arei.gonglei@huawei.com> writes:
>
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> After commit 4c7e251a (), when dump memory completed,
>> the s->fd will be closed twice. We should return
>> directly when dump completed.
>>
>> Using do/while block, make the badly chosen return
>> values of get_next_block() more visible and fix
>> this issue.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>
> I'm afraid the commit message is a bit misleading. Let's examine what
> exactly happens.
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return unsuccessfully. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> Is this correct?
Heh. I was starring at all this last 20 minutes, re-reading the
original v1 patch and your (Marcus) followup suggestion, trying to
match the commit description with the actual happening and with the
"no return" case which was before this patch. Oh well.
Yes, this looks correct indeed, we come to the same conclusion.
But at this stage I really wonder if this is a -trivial material.
(I can apply it to -trivial because no maintainer is listed for
this file and because after some digging it becomes obvious).
/mjt
> If yes, let's use this commit message:
>
> dump: Fix dump-guest-memory termination and use-after-close
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return failure. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> The obvious fix is to restore the return lost in commit 4c7e251a. But
> the root cause of the bug is needlessly opaque loop control. Replace it
> by a clean do ... while loop.
>
> This makes the badly chosen return values of get_next_block() more
> visible. Cleaning that up is outside the scope of this bug fix.
>
> You can then add my R-by.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 7:42 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2014-10-30 9:23 ` Markus Armbruster
2014-10-30 10:50 ` Gonglei
0 siblings, 1 reply; 11+ messages in thread
From: Markus Armbruster @ 2014-10-30 9:23 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-trivial, lcapitulino, arei.gonglei, peter.huangpeng,
qemu-devel
Michael Tokarev <mjt@tls.msk.ru> writes:
> 30.10.2014 10:10, Markus Armbruster wrote:
>> <arei.gonglei@huawei.com> writes:
>>
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> After commit 4c7e251a (), when dump memory completed,
>>> the s->fd will be closed twice. We should return
>>> directly when dump completed.
>>>
>>> Using do/while block, make the badly chosen return
>>> values of get_next_block() more visible and fix
>>> this issue.
>>>
>>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>>
>> I'm afraid the commit message is a bit misleading. Let's examine what
>> exactly happens.
>>
>> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
>> returns "no more". We then call dump_completed(). But we neglect to
>> break the loop! Broken in commit 4c7e251a.
>>
>> Because of that, we dump the last block again. This attempts to write
>> to s->fd, which fails if we're lucky. The error makes dump_iterate()
>> return unsuccessfully. It's the only way it can ever return.
>>
>> Theoretical: if we're not so lucky, something else has opened something
>> for writing and got the same fd. dump_iterate() then keeps looping,
>> messing up the something else's output, until a write fails, or the
>> process mercifully terminates.
>>
>> Is this correct?
>
> Heh. I was starring at all this last 20 minutes, re-reading the
> original v1 patch and your (Marcus) followup suggestion, trying to
> match the commit description with the actual happening and with the
> "no return" case which was before this patch. Oh well.
>
> Yes, this looks correct indeed, we come to the same conclusion.
> But at this stage I really wonder if this is a -trivial material.
Distinguished old math professor does a proof on the blackboard. At
some point he faces the audience and says "this is trivial". Faces
blackboard, pauses. "Is it trivial?" Pauses again. Storms out of the
classroom. After ten minutes, he comes back and exclaims "it *is*
trivial!"
> (I can apply it to -trivial because no maintainer is listed for
> this file and because after some digging it becomes obvious).
Appreciated!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 9:23 ` Markus Armbruster
@ 2014-10-30 10:50 ` Gonglei
0 siblings, 0 replies; 11+ messages in thread
From: Gonglei @ 2014-10-30 10:50 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-trivial@nongnu.org, lcapitulino@redhat.com, Michael Tokarev,
Huangpeng (Peter), qemu-devel@nongnu.org
On 2014/10/30 17:23, Markus Armbruster wrote:
> Michael Tokarev <mjt@tls.msk.ru> writes:
>
>> 30.10.2014 10:10, Markus Armbruster wrote:
>>> <arei.gonglei@huawei.com> writes:
>>>
>>>> From: Gonglei <arei.gonglei@huawei.com>
>>>>
>>>> After commit 4c7e251a (), when dump memory completed,
>>>> the s->fd will be closed twice. We should return
>>>> directly when dump completed.
>>>>
>>>> Using do/while block, make the badly chosen return
>>>> values of get_next_block() more visible and fix
>>>> this issue.
>>>>
>>>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>>>
>>> I'm afraid the commit message is a bit misleading. Let's examine what
>>> exactly happens.
>>>
>>> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
>>> returns "no more". We then call dump_completed(). But we neglect to
>>> break the loop! Broken in commit 4c7e251a.
>>>
>>> Because of that, we dump the last block again. This attempts to write
>>> to s->fd, which fails if we're lucky. The error makes dump_iterate()
>>> return unsuccessfully. It's the only way it can ever return.
>>>
>>> Theoretical: if we're not so lucky, something else has opened something
>>> for writing and got the same fd. dump_iterate() then keeps looping,
>>> messing up the something else's output, until a write fails, or the
>>> process mercifully terminates.
>>>
>>> Is this correct?
>>
>> Heh. I was starring at all this last 20 minutes, re-reading the
>> original v1 patch and your (Marcus) followup suggestion, trying to
>> match the commit description with the actual happening and with the
>> "no return" case which was before this patch. Oh well.
>>
>> Yes, this looks correct indeed, we come to the same conclusion.
>> But at this stage I really wonder if this is a -trivial material.
>
> Distinguished old math professor does a proof on the blackboard. At
> some point he faces the audience and says "this is trivial". Faces
> blackboard, pauses. "Is it trivial?" Pauses again. Storms out of the
> classroom. After ten minutes, he comes back and exclaims "it *is*
> trivial!"
>
:)
>> (I can apply it to -trivial because no maintainer is listed for
>> this file and because after some digging it becomes obvious).
>
> Appreciated!
Do I need to send v3 for changing commit message, or
/mjt do it directly? Thanks
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 7:10 ` Markus Armbruster
2014-10-30 7:33 ` zhanghailiang
2014-10-30 7:42 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2014-10-30 13:54 ` Michael Tokarev
2014-10-31 1:43 ` Gonglei
2014-10-31 6:51 ` Markus Armbruster
2 siblings, 2 replies; 11+ messages in thread
From: Michael Tokarev @ 2014-10-30 13:54 UTC (permalink / raw)
To: Markus Armbruster, arei.gonglei
Cc: qemu-trivial, peter.huangpeng, qemu-devel, lcapitulino
30.10.2014 10:10, Markus Armbruster wrote:
[]
> I'm afraid the commit message is a bit misleading. Let's examine what
> exactly happens.
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return unsuccessfully. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> Is this correct?
>
> If yes, let's use this commit message:
>
> dump: Fix dump-guest-memory termination and use-after-close
>
> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
> returns "no more". We then call dump_completed(). But we neglect to
> break the loop! Broken in commit 4c7e251a.
>
> Because of that, we dump the last block again. This attempts to write
> to s->fd, which fails if we're lucky. The error makes dump_iterate()
> return failure. It's the only way it can ever return.
>
> Theoretical: if we're not so lucky, something else has opened something
> for writing and got the same fd. dump_iterate() then keeps looping,
> messing up the something else's output, until a write fails, or the
> process mercifully terminates.
>
> The obvious fix is to restore the return lost in commit 4c7e251a. But
> the root cause of the bug is needlessly opaque loop control. Replace it
> by a clean do ... while loop.
>
> This makes the badly chosen return values of get_next_block() more
> visible. Cleaning that up is outside the scope of this bug fix.
>
> You can then add my R-by.
So I'm applying this -- which is your patch and your commit message, and
I really wonder why this is Reviewed-by and not Signed-off-by, with your
authorship? It really should be...
Thanks,
/mjt
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 13:54 ` Michael Tokarev
@ 2014-10-31 1:43 ` Gonglei
2014-10-31 7:18 ` Michael Tokarev
2014-10-31 6:51 ` Markus Armbruster
1 sibling, 1 reply; 11+ messages in thread
From: Gonglei @ 2014-10-31 1:43 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster,
Huangpeng (Peter), lcapitulino@redhat.com
On 2014/10/30 21:54, Michael Tokarev wrote:
> So I'm applying this -- which is your patch and your commit message, and
> I really wonder why this is Reviewed-by and not Signed-off-by, with your
> authorship? It really should be...
Yes, maybe it should be. But I have to say something:
First, I posted a patch fix the fd leak problem. Markus reviewed it and gave
his reviewing comments which I think is better, and then I posted
the version 2 with Markus' suggestion. As your meaning, I should add the
Signed-off-by tag of Markus? But for me, I don't get Markus' authorization,
so I can't do this, and maybe he have other comments for version 2.
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-31 1:43 ` Gonglei
@ 2014-10-31 7:18 ` Michael Tokarev
2014-10-31 7:40 ` Gonglei
0 siblings, 1 reply; 11+ messages in thread
From: Michael Tokarev @ 2014-10-31 7:18 UTC (permalink / raw)
To: Gonglei
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster,
Huangpeng (Peter), lcapitulino@redhat.com
31.10.2014 04:43, Gonglei wrote:
> On 2014/10/30 21:54, Michael Tokarev wrote:
>
>> So I'm applying this -- which is your patch and your commit message, and
>> I really wonder why this is Reviewed-by and not Signed-off-by, with your
>> authorship? It really should be...
>
> Yes, maybe it should be. But I have to say something:
> First, I posted a patch fix the fd leak problem. Markus reviewed it and gave
> his reviewing comments which I think is better, and then I posted
> the version 2 with Markus' suggestion. As your meaning, I should add the
> Signed-off-by tag of Markus? But for me, I don't get Markus' authorization,
> so I can't do this, and maybe he have other comments for version 2.
Um. I didn't want to offend you in any way. I was just pointing out that
it was actually Marcus who did the rest of the work, besides discovering the
original problem. Again, it is both his change and his commit message...
Let's agree to have Signed-off-by from both of you ;)
Thanks,
/mjt
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-31 7:18 ` Michael Tokarev
@ 2014-10-31 7:40 ` Gonglei
0 siblings, 0 replies; 11+ messages in thread
From: Gonglei @ 2014-10-31 7:40 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org, Markus Armbruster,
Huangpeng (Peter), lcapitulino@redhat.com
On 2014/10/31 15:18, Michael Tokarev wrote:
> 31.10.2014 04:43, Gonglei wrote:
>> On 2014/10/30 21:54, Michael Tokarev wrote:
>>
>>> So I'm applying this -- which is your patch and your commit message, and
>>> I really wonder why this is Reviewed-by and not Signed-off-by, with your
>>> authorship? It really should be...
>>
>> Yes, maybe it should be. But I have to say something:
>> First, I posted a patch fix the fd leak problem. Markus reviewed it and gave
>> his reviewing comments which I think is better, and then I posted
>> the version 2 with Markus' suggestion. As your meaning, I should add the
>> Signed-off-by tag of Markus? But for me, I don't get Markus' authorization,
>> so I can't do this, and maybe he have other comments for version 2.
>
> Um. I didn't want to offend you in any way. I was just pointing out that
> it was actually Marcus who did the rest of the work, besides discovering the
> original problem. Again, it is both his change and his commit message...
>
> Let's agree to have Signed-off-by from both of you ;)
Yes, of course.
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] dump: fix use-after-free for s->fd
2014-10-30 13:54 ` Michael Tokarev
2014-10-31 1:43 ` Gonglei
@ 2014-10-31 6:51 ` Markus Armbruster
1 sibling, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2014-10-31 6:51 UTC (permalink / raw)
To: Michael Tokarev
Cc: qemu-trivial, peter.huangpeng, arei.gonglei, qemu-devel,
lcapitulino
Michael Tokarev <mjt@tls.msk.ru> writes:
> 30.10.2014 10:10, Markus Armbruster wrote:
> []
>> I'm afraid the commit message is a bit misleading. Let's examine what
>> exactly happens.
>>
>> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
>> returns "no more". We then call dump_completed(). But we neglect to
>> break the loop! Broken in commit 4c7e251a.
>>
>> Because of that, we dump the last block again. This attempts to write
>> to s->fd, which fails if we're lucky. The error makes dump_iterate()
>> return unsuccessfully. It's the only way it can ever return.
>>
>> Theoretical: if we're not so lucky, something else has opened something
>> for writing and got the same fd. dump_iterate() then keeps looping,
>> messing up the something else's output, until a write fails, or the
>> process mercifully terminates.
>>
>> Is this correct?
>>
>> If yes, let's use this commit message:
>>
>> dump: Fix dump-guest-memory termination and use-after-close
>>
>> dump_iterate() dumps blocks in a loop. Eventually, get_next_block()
>> returns "no more". We then call dump_completed(). But we neglect to
>> break the loop! Broken in commit 4c7e251a.
>>
>> Because of that, we dump the last block again. This attempts to write
>> to s->fd, which fails if we're lucky. The error makes dump_iterate()
>> return failure. It's the only way it can ever return.
>>
>> Theoretical: if we're not so lucky, something else has opened something
>> for writing and got the same fd. dump_iterate() then keeps looping,
>> messing up the something else's output, until a write fails, or the
>> process mercifully terminates.
>>
>> The obvious fix is to restore the return lost in commit 4c7e251a. But
>> the root cause of the bug is needlessly opaque loop control. Replace it
>> by a clean do ... while loop.
>>
>> This makes the badly chosen return values of get_next_block() more
>> visible. Cleaning that up is outside the scope of this bug fix.
>>
>> You can then add my R-by.
>
> So I'm applying this -- which is your patch and your commit message, and
> I really wonder why this is Reviewed-by and not Signed-off-by, with your
> authorship? It really should be...
You can add mine in addition to Gonglei's.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread