qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 2/2] block: Fix NULL deference for unaligned


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v2 2/2] block: Fix NULL deference for unaligned write if qiov is NULL
Date: Fri, 24 Apr 2015 13:51:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0


On 24/04/2015 13:00, Paolo Bonzini wrote:
>> -        qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1));
>> -        qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size);
>> -        use_local_qiov = true;
>> +        if (qiov) {
>> +            qemu_iovec_init(&local_qiov, qiov ? qiov->niov + 2 : 1);
>> +            qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1));
>> +            qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size);
>> +            use_local_qiov = true;
>> +            bytes += offset & (align - 1);
>> +            offset = offset & ~(align - 1);
>> +        } else {
>> +            memset(head_buf + (offset & (align - 1)), 0,
>> +                   align - (offset & (align - 1)));

Actually, is the byte count correct if bytes < align?  In the case of
your testcase, you'd destroy bytes 1536..4095.

Same for the computation of bytes, below.  It could underflow.

Perhaps a qemu-iotests testcase, using qemu-io, is also necessary.

Paolo

>> +            ret = bdrv_aligned_pwritev(bs, &req, offset & ~(align - 1), 
>> align,
>> +                                       &head_qiov, 0);
>> +            if (ret < 0) {
>> +                goto fail;
>> +            }
>> +            bytes -= align - (offset & (align - 1));
>> +            offset = ROUND_UP(offset, align);
>> +        }
>> +    }



reply via email to

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