From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YmbQH-0003SV-L2 for qemu-devel@nongnu.org; Mon, 27 Apr 2015 01:17:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YmbQC-0000sD-M0 for qemu-devel@nongnu.org; Mon, 27 Apr 2015 01:17:37 -0400 Date: Mon, 27 Apr 2015 13:17:28 +0800 From: Fam Zheng Message-ID: <20150427051728.GE384@ad.nay.redhat.com> References: <1429871600-10180-1-git-send-email-famz@redhat.com> <1429871600-10180-3-git-send-email-famz@redhat.com> <553A2245.9060304@redhat.com> <553A2E45.508@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <553A2E45.508@redhat.com> 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: Paolo Bonzini Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, Stefan Hajnoczi , qemu-stable@nongnu.org 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); > >> + } > >> + }