From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ylc95-0001i4-4Z for qemu-devel@nongnu.org; Fri, 24 Apr 2015 07:51:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ylc94-0004Ai-4K for qemu-devel@nongnu.org; Fri, 24 Apr 2015 07:51:46 -0400 Sender: Paolo Bonzini Message-ID: <553A2E45.508@redhat.com> Date: Fri, 24 Apr 2015 13:51:33 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1429871600-10180-1-git-send-email-famz@redhat.com> <1429871600-10180-3-git-send-email-famz@redhat.com> <553A2245.9060304@redhat.com> In-Reply-To: <553A2245.9060304@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 2/2] block: Fix NULL deference for unaligned write if qiov is NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, qemu-stable@nongnu.org, Stefan Hajnoczi 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); >> + } >> + }