Message ID | 20170301175852.13517-1-cornelia.huck@de.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org> Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B44260453 for <patchwork-qemu-devel@patchwork.kernel.org>; Wed, 1 Mar 2017 17:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64B4E28306 for <patchwork-qemu-devel@patchwork.kernel.org>; Wed, 1 Mar 2017 17:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 595C828526; Wed, 1 Mar 2017 17:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A96C28306 for <patchwork-qemu-devel@patchwork.kernel.org>; Wed, 1 Mar 2017 17:59:26 +0000 (UTC) Received: from localhost ([::1]:47986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org>) id 1cj8X7-0001At-TI for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Mar 2017 12:59:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <cornelia.huck@de.ibm.com>) id 1cj8Wl-00018y-Dg for qemu-devel@nongnu.org; Wed, 01 Mar 2017 12:59:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <cornelia.huck@de.ibm.com>) id 1cj8Wi-0008NJ-Af for qemu-devel@nongnu.org; Wed, 01 Mar 2017 12:59:03 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33002 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <cornelia.huck@de.ibm.com>) id 1cj8Wi-0008N9-4k for qemu-devel@nongnu.org; Wed, 01 Mar 2017 12:59:00 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v21HnuIQ039634 for <qemu-devel@nongnu.org>; Wed, 1 Mar 2017 12:58:59 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 28wxrb6n4w-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for <qemu-devel@nongnu.org>; Wed, 01 Mar 2017 12:58:58 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for <qemu-devel@nongnu.org> from <cornelia.huck@de.ibm.com>; Wed, 1 Mar 2017 17:58:57 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 1 Mar 2017 17:58:54 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id BEB5217D8042; Wed, 1 Mar 2017 18:02:07 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v21HwsE28454558; Wed, 1 Mar 2017 17:58:54 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 234E842041; Wed, 1 Mar 2017 17:58:49 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1BF542049; Wed, 1 Mar 2017 17:58:48 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 1 Mar 2017 17:58:48 +0000 (GMT) From: Cornelia Huck <cornelia.huck@de.ibm.com> To: qemu-devel@nongnu.org Date: Wed, 1 Mar 2017 18:58:52 +0100 X-Mailer: git-send-email 2.8.4 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17030117-0012-0000-0000-000004D906B1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030117-0013-0000-0000-0000176F3A96 Message-Id: <20170301175852.13517-1-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-01_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1703010161 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3] virtio: guard vring access when setting notification X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Cc: Cornelia Huck <cornelia.huck@de.ibm.com>, pbonzini@redhat.com, borntraeger@de.ibm.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org> X-Virus-Scanned: ClamAV using ClamSMTP |
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e487e36..bf8a644 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -288,6 +288,10 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable) { vq->notification = enable; + if (!vq->vring.desc) { + return; + } + rcu_read_lock(); if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) { vring_set_avail_event(vq, vring_avail_idx(vq));
Switching to vring caches exposed an existing bug in virtio_queue_set_notification(): We can't access vring structures if they have not been set up yet. This may happen, for example, for virtio-blk devices with multiple queues: The code will try to switch notifiers for every queue, but the guest may have only set up a subset of them. Fix this by guarding access to the vring memory by checking for vring.desc. The first aio poll will iron out any remaining inconsistencies for later-configured queues (buggy legacy drivers). Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> --- v2->v3: - Switch to a very simple check for !desc, which should be fine for the existing users. We might want to assert that callers don't start aio before DRIVER_OK resp. first kick, but that can wait until after we've fixed this bug. --- hw/virtio/virtio.c | 4 ++++ 1 file changed, 4 insertions(+)