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: Fam Zheng
Subject: Re: [Qemu-devel] [PATCH v2 2/2] block: Fix NULL deference for unaligned write if qiov is NULL
Date: Mon, 27 Apr 2015 13:17:28 +0800
User-agent: Mutt/1.5.23 (2014-03-12)

On Fri, 04/24 13:51, Paolo Bonzini wrote:
> 
> 
> 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.

Yes, good catch!

Fam

> 
> 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]