From patchwork Mon Jul 13 05:46:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 494227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 94254140280 for ; Mon, 13 Jul 2015 15:47:23 +1000 (AEST) Received: from localhost ([::1]:52985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWaH-0006tB-Pe for incoming@patchwork.ozlabs.org; Mon, 13 Jul 2015 01:47:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWZv-0006Hm-Ax for qemu-devel@nongnu.org; Mon, 13 Jul 2015 01:47:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEWZs-0006Hw-59 for qemu-devel@nongnu.org; Mon, 13 Jul 2015 01:46:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEWZr-0006Hm-Vw for qemu-devel@nongnu.org; Mon, 13 Jul 2015 01:46:56 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 1E121B6698 for ; Mon, 13 Jul 2015 05:46:55 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-4-152.pek2.redhat.com [10.72.4.152]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6D5kqAT025330; Mon, 13 Jul 2015 01:46:53 -0400 From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com Date: Mon, 13 Jul 2015 13:46:47 +0800 Message-Id: <1436766411-29144-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang Subject: [Qemu-devel] [PATCH 1/5] virtio-pci: ignore unaligned read/write in virtio_address_space_read()/write() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We abort on unaligned read/write in virtio_address_space_read()/write() but since len in under control of guest so qemu will simply crash when booting a modern guest (guest is try to read when len is zero). Fix this by ignoring unaligned write or read. Fixes 1e40356ce5f6ccfa0bb57104a533c62952c560ce ("virtio fix cfg endian-ness for BE targets") Signed-off-by: Jason Wang --- hw/virtio/virtio-pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index ccca2b6..bed9735 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -466,8 +466,8 @@ void virtio_address_space_write(AddressSpace *as, hwaddr addr, */ addr &= ~(len - 1); - /* Make sure caller aligned buf properly */ - assert(!(((uintptr_t)buf) & (len - 1))); + if (!(((uintptr_t)buf) & (len - 1))) + return; switch (len) { case 1: @@ -498,8 +498,8 @@ virtio_address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len) */ addr &= ~(len - 1); - /* Make sure caller aligned buf properly */ - assert(!(((uintptr_t)buf) & (len - 1))); + if (!(((uintptr_t)buf) & (len - 1))) + return; switch (len) { case 1: