Message ID | 20220516095448.507876-87-mst@redhat.com |
---|---|
State | New |
Headers | show
Return-Path: <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VHRWdvPf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=<UNKNOWN>) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L1zVB2Qd6z9s2R for <incoming@patchwork.ozlabs.org>; Mon, 16 May 2022 22:44:50 +1000 (AEST) Received: from localhost ([::1]:59174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>) id 1nqa5g-0003Pj-Am for incoming@patchwork.ozlabs.org; Mon, 16 May 2022 08:44:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <mst@redhat.com>) id 1nqY9d-0002tX-R9 for qemu-devel@nongnu.org; Mon, 16 May 2022 06:40:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <mst@redhat.com>) id 1nqY9c-0005oz-13 for qemu-devel@nongnu.org; Mon, 16 May 2022 06:40:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652697643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+A4vB5M07e/rYIfkuHJ1c5xTvbN6acy0VhX/QsPIpxM=; b=VHRWdvPfQWH+ldW9sHRfzyPkco6O6ip6HkAv9M7AqNqycSIPoV2p76dyHlBUeN65MMiz2c oa9PplBwiLifIcaRVgkEbeCv2xHjN5wU8/Qk9Ve7f3jlgpx4lA0oHO86TfJlJlWHq2aoZ9 GdmFZ/IvCPbT9LXBbvPVBaU2MlRtTgs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-jlMHrpmSOuGjFfYNmM5IxQ-1; Mon, 16 May 2022 06:40:42 -0400 X-MC-Unique: jlMHrpmSOuGjFfYNmM5IxQ-1 Received: by mail-wm1-f70.google.com with SMTP id z23-20020a05600c221700b003942fd37764so10139652wml.8 for <qemu-devel@nongnu.org>; Mon, 16 May 2022 03:40:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+A4vB5M07e/rYIfkuHJ1c5xTvbN6acy0VhX/QsPIpxM=; b=RjpgbpRkClFJnmr4QsF5SLdp1cdxla3rCy6Wbg8d9GY0N02CMVhUmow+x+pg5oTjYZ s8YK7Sb5q20VE0T5AoDRYuzA++vn/KzKHWx/Z6cDXrkhrCfZrZPCTc4c5PEwe8Zt3Ojk L9XFsNQceBkCHOzVlxDSKgd4sgDLttSl/IkSc8ALi1VIcOPJPBaHmr274MC9H4ra6Y86 YHI3mEL9L/T+56FQHj/HnMIN2t/KXPR3kJ4cZNaGOAzx/IfxWGVofthGwcVbfOtzR7PD znDd/Z+hkaZFZqqqHAv26r/LBLZ+6hBmkx1KUkpB/q0e6me2daJlZstYlyqh6BGZH3au 0TcQ== X-Gm-Message-State: AOAM532KKGFp2O95s4xDyuepoWsSjTGlMJcezsyWgLphoOfbXLHHaO77 HXMrvGxPDLUAuzN2Rss197hbhRDjr8E98iVpWK5Y1c5p+YTOHqJ39keZhuy7gtUgBBomx2psAoo 56NWNtUELDemDdFjNuCmh9yv6Qq6fJq33o7hk3Ob1K0v2KfynG8mBRn/GfFHy X-Received: by 2002:a05:600c:a4b:b0:37b:ea2b:5583 with SMTP id c11-20020a05600c0a4b00b0037bea2b5583mr27100394wmq.139.1652697640836; Mon, 16 May 2022 03:40:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO/16vYU/x0bRr7glfFBdR5FG5t7UU1gA7Gxx8h1B/L0zgO3OARR1lT3hdGGMEYwJBTAz/ug== X-Received: by 2002:a05:600c:a4b:b0:37b:ea2b:5583 with SMTP id c11-20020a05600c0a4b00b0037bea2b5583mr27100361wmq.139.1652697640418; Mon, 16 May 2022 03:40:40 -0700 (PDT) Received: from redhat.com ([2.55.141.66]) by smtp.gmail.com with ESMTPSA id l5-20020adfc785000000b0020cdcb0efa2sm9210694wrg.34.2022.05.16.03.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 03:40:40 -0700 (PDT) Date: Mon, 16 May 2022 06:40:37 -0400 From: "Michael S. Tsirkin" <mst@redhat.com> To: qemu-devel@nongnu.org Cc: Peter Maydell <peter.maydell@linaro.org>, Si-Wei Liu <si-wei.liu@oracle.com>, Jason Wang <jasowang@redhat.com> Subject: [PULL 86/91] virtio-net: align ctrl_vq index for non-mq guest for vhost_vdpa Message-ID: <20220516095448.507876-87-mst@redhat.com> References: <20220516095448.507876-1-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220516095448.507876-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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: <https://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> Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org> |
Series |
[PULL,01/91] virtio: fix feature negotiation for ACCESS_PLATFORM
|
expand
|
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f9dd012021..ccfb2f3761 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu/atomic.h" #include "qemu/iov.h" +#include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "hw/virtio/virtio.h" @@ -3219,8 +3220,22 @@ static NetClientInfo net_virtio_info = { static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) { VirtIONet *n = VIRTIO_NET(vdev); - NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx)); + NetClientState *nc; assert(n->vhost_started); + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MQ) && idx == 2) { + /* Must guard against invalid features and bogus queue index + * from being set by malicious guest, or penetrated through + * buggy migration stream. + */ + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: bogus vq index ignored\n", __func__); + return false; + } + nc = qemu_get_subqueue(n->nic, n->max_queue_pairs); + } else { + nc = qemu_get_subqueue(n->nic, vq2q(idx)); + } return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx); } @@ -3228,8 +3243,22 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask) { VirtIONet *n = VIRTIO_NET(vdev); - NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx)); + NetClientState *nc; assert(n->vhost_started); + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MQ) && idx == 2) { + /* Must guard against invalid features and bogus queue index + * from being set by malicious guest, or penetrated through + * buggy migration stream. + */ + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: bogus vq index ignored\n", __func__); + return; + } + nc = qemu_get_subqueue(n->nic, n->max_queue_pairs); + } else { + nc = qemu_get_subqueue(n->nic, vq2q(idx)); + } vhost_net_virtqueue_mask(get_vhost_net(nc->peer), vdev, idx, mask); }