qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] block: fix backing file segfault


From: Peter Feiner
Subject: Re: [Qemu-devel] [PATCH] block: fix backing file segfault
Date: Thu, 9 Jan 2014 23:07:30 -0500

On Thu, Jan 9, 2014 at 5:59 AM, Kevin Wolf <address@hidden> wrote:
> I think if there is no bs->backing_hd->file, we should get the filename
> from bs->backing_hd->filename instead of leaving it empty.
>
> In fact, can we always do that or does bs->backing_hd normally lack the
> filename? If so, perhaps that is what we need to fix, so we can always
> directly use bs->backing_hd->filename here.

In the NBD example, bs->backing_hd->filename is "".

I can take a stab at your proposed fix but I'm not very familiar with
this code. In particular, I don't know what bs->backing_file is
actually used for. The patch that introduced the pstrcpy mentions
hmp's info block command, but the output looks fine AFAICT:

% ./x86_64-softmmu/qemu-system-x86_64 -monitor stdio -nographic
file-overlay.qcow2
QEMU 1.7.50 monitor - type 'help' for more information
(qemu) info block
ide0-hd0: file-overlay.qcow2 (qcow2)
    Backing file:     base.file (chain depth: 1)
...

I'll take a look and report back.

On Thu, Jan 9, 2014 at 5:59 AM, Kevin Wolf <address@hidden> wrote:
> [ CCing Max, who was recently active in this area, for another opinion ]
>
> Am 08.01.2014 um 20:43 hat Peter Feiner geschrieben:
>> When a backing file is opened such that (1) a protocol is directly
>> used as the block driver and (2) the block driver has bdrv_file_open,
>> bdrv_open_backing_file segfaults. The problem arises because
>> bdrv_open_common returns without setting bd->backing_hd->file.
>>
>> To effect (1), you seem to have to use the -F flag in qemu-img. There
>> are several block drivers that satisfy (2), such as "file" and "nbd".
>> Here are some concrete examples:
>>
>>     #!/bin/bash
>>
>>     echo Test file format
>>     ./qemu-img create -f file base.file 1m
>>     ./qemu-img create -f qcow2 -F file -o backing_file=base.file\
>>         file-overlay.qcow2
>>     ./qemu-img convert -O raw file-overlay.qcow2 file-convert.raw
>>
>>     echo Test nbd format
>>     SOCK=$PWD/nbd.sock
>>     ./qemu-img create -f raw base.raw 1m
>>     ./qemu-nbd -t -k $SOCK base.raw &
>>     trap "kill $!" EXIT
>>     while ! test -e $SOCK; do sleep 1; done
>>     ./qemu-img create -f qcow2 -F nbd -o backing_file=nbd:unix:$SOCK\
>>         nbd-overlay.qcow2
>>     ./qemu-img convert -O raw nbd-overlay.qcow2 nbd-convert.raw
>>
>> Without this patch, the two qemu-img convert commands segfault.
>>
>> This is a regression that was introduced in v1.7 by
>> dbecebddfa4932d1c83915bcb9b5ba5984eb91be.
>>
>> Signed-off-by: Peter Feiner <address@hidden>
>> ---
>>  block.c |    5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index 64e7d22..a4a172d 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -1016,8 +1016,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
>> *options, Error **errp)
>>          error_free(local_err);
>>          return ret;
>>      }
>> -    pstrcpy(bs->backing_file, sizeof(bs->backing_file),
>> -            bs->backing_hd->file->filename);
>> +    if (bs->backing_hd->file)
>> +        pstrcpy(bs->backing_file, sizeof(bs->backing_file),
>> +                bs->backing_hd->file->filename);
>>      return 0;
>>  }
>
> I think if there is no bs->backing_hd->file, we should get the filename
> from bs->backing_hd->filename instead of leaving it empty.
>
> In fact, can we always do that or does bs->backing_hd normally lack the
> filename? If so, perhaps that is what we need to fix, so we can always
> directly use bs->backing_hd->filename here.
>
> Kevin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]