From patchwork Thu Mar 12 09:50:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 449360 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 3F8CD14012F for ; Thu, 12 Mar 2015 20:50:56 +1100 (AEDT) Received: from localhost ([::1]:58900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVzlW-0003sr-CV for incoming@patchwork.ozlabs.org; Thu, 12 Mar 2015 05:50:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVzl8-0003Ux-Kt for qemu-devel@nongnu.org; Thu, 12 Mar 2015 05:50:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVzl5-0000f8-Te for qemu-devel@nongnu.org; Thu, 12 Mar 2015 05:50:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVzl5-0000aG-1H; Thu, 12 Mar 2015 05:50:27 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2C9oPYn023162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 12 Mar 2015 05:50:25 -0400 Received: from jason-ThinkPad-T430s.nay.redhat.com ([10.66.70.106]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2C9oJpM021226; Thu, 12 Mar 2015 05:50:21 -0400 From: Jason Wang To: qemu-devel@nongnu.org Date: Thu, 12 Mar 2015 17:50:18 +0800 Message-Id: <1426153818-28804-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang , qemu-stable@nongnu.org, dkoch@verizon.com, "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH V2] virtio: validate the existence of handle_output before calling it 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 don't validate the existence of handle_output which may let a buggy guest to trigger a SIGSEV easily. E.g: 1) write 10 to queue_sel to a virtio net device with only 1 queue 2) setup an arbitrary pfn 3) then notify queue 10 Fixing this by validating the existence of handle_output before. Cc: qemu-stable@nongnu.org Cc: Michael S. Tsirkin Signed-off-by: Jason Wang Reviewed-by: Don Koch Reviewed-by: Fam Zheng --- Changes from V1: - check the existence of both vring.desc and handle_output in the same line - describe the reproducer in the commit log --- hw/virtio/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3c6e430..17c1260 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -759,8 +759,9 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) void virtio_queue_notify_vq(VirtQueue *vq) { - if (vq->vring.desc) { + if (vq->vring.desc && vq->handle_output) { VirtIODevice *vdev = vq->vdev; + trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); vq->handle_output(vdev, vq); }