From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9AEF0A0540 for ; Thu, 7 Jul 2022 09:56:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 96CD5406B4; Thu, 7 Jul 2022 09:56:20 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by mails.dpdk.org (Postfix) with ESMTP id 951B7415D7 for ; Thu, 7 Jul 2022 09:56:18 +0200 (CEST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id F046D3F04C for ; Thu, 7 Jul 2022 07:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1657180578; bh=upZ/Vp23x/UMaN+iC4goKT1rQX6ZU1/6KwsvDThfM7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U+Exu9XzIJ/+1OKSoMdBhOzDJkJJvxrdXRfPaQjHa1cOnSzTmvT1HsgzogSs9Zn81 ZuwOiFS0M6MuvqEeflo8iYFNXU1ueZPlj2SIf7atwE6gJl5SoQ8m1BDbcc6/9HUfBu nL0kf8SO+6fVG/a/BOXQNQxazn9EN3bd+JjRZPl+xf3bT21OFCxK9Crn58TmpjRAvf k/EB/rHglswx4LhkDorzAiirVDnMGIjCNuBt404Iju5d40/9cmP00DEgEHgGGy7RoG oQLBiqt3vI2qKL2gL3Hd3geyHh3RO9sRWUfQQVGlnPPQ+BYrT10ekWRrfwZTh4grGx tvDw0OUSz5KmA== Received: by mail-ed1-f69.google.com with SMTP id g7-20020a056402424700b00435ac9c7a8bso13386865edb.14 for ; Thu, 07 Jul 2022 00:56:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=upZ/Vp23x/UMaN+iC4goKT1rQX6ZU1/6KwsvDThfM7c=; b=Wm1xvdS6hidl6zkaYZ44JQmv85L4uKHcDbB2XrNUORWrhNLX4fmhzgdf37jyH+Oi/m 9JWDek5TwS3FKXlVYJGpO1No/iWb4A/Weq+WUd1KuYg96P8LcW3XkkehJ6KrrvZBPKhO eNtEU6oVqHJ3eOohDNYsaxDUHEVf+Xc8ur6hRCOs3Y0X4agU6D5TlTt9XBrqxePY0lfj hsUC2v6FvdS3I0qhTppgVaiyznZnXxUWqKZujA6SEHg9/9yEFHYTzd1S0U+lpMDeKVkZ MVpRiSgRTKJoMrUSzoWpEAa7hmNIrhaMfDqRPwmSp4Dq3FCwd5GQsT5B0+AuPBEDNlSK M0gQ== X-Gm-Message-State: AJIora9gnIK3E/3SzaKQLrz9h3zrrjNKzOBsQGwS+KL6EecCmT7vMHEE rrQJSaYjyUVxJOmJUoqUk83d/1FR2dvGTvvopiRtSDNhmC8kqgziwr5G6k1lyy0hYzTQEMuUs/l YuM4FchxtCUBd2PIKq8GSBHYW X-Received: by 2002:a17:907:6d96:b0:72a:87ba:446d with SMTP id sb22-20020a1709076d9600b0072a87ba446dmr32622802ejc.574.1657180577721; Thu, 07 Jul 2022 00:56:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vPUzYeV1f+b4ajqt5NwTTQJglsqG9hA4kYELXddWKr/RY2FsJKOkIyINYX7fsQ8BADYY7Ekg== X-Received: by 2002:a17:907:6d96:b0:72a:87ba:446d with SMTP id sb22-20020a1709076d9600b0072a87ba446dmr32622784ejc.574.1657180577453; Thu, 07 Jul 2022 00:56:17 -0700 (PDT) Received: from Keschdeichel.fritz.box ([2a02:6d40:3a4f:7b00:c19b:938e:7c97:afe2]) by smtp.gmail.com with ESMTPSA id jz2-20020a170906bb0200b00726314d0655sm18522363ejb.39.2022.07.07.00.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 00:56:16 -0700 (PDT) From: christian.ehrhardt@canonical.com To: Yuan Wang Cc: Wei Ling , Maxime Coquelin , dpdk stable Subject: patch 'net/vhost: fix access to freed memory' has been queued to stable release 19.11.13 Date: Thu, 7 Jul 2022 09:54:12 +0200 Message-Id: <20220707075522.194223-17-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220707075522.194223-1-christian.ehrhardt@canonical.com> References: <20220707075522.194223-1-christian.ehrhardt@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 19.11.13 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 07/09/22. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/cpaelzer/dpdk-stable-queue This queued commit can be viewed at: https://github.com/cpaelzer/dpdk-stable-queue/commit/c7926bd5b5bd0b67910eed63f17cc3f0bc8fb4de Thanks. Christian Ehrhardt --- >From c7926bd5b5bd0b67910eed63f17cc3f0bc8fb4de Mon Sep 17 00:00:00 2001 From: Yuan Wang Date: Sat, 12 Mar 2022 00:35:12 +0800 Subject: [PATCH] net/vhost: fix access to freed memory [ upstream commit 9dc6bb06824f3c5887f0436ddba5ab9116cb277e ] This patch fixes heap-use-after-free reported by ASan. It is possible for the rte_vhost_dequeue_burst() to access the vq is freed when numa_realloc() gets called in the device running state. The control plane will set the vq->access_lock to protected the vq from the data plane. Unfortunately the lock will fail at the moment the vq is freed, allowing the rte_vhost_dequeue_burst() to access the fields of the vq, which will trigger a heap-use-after-free error. In the case of multiple queues, the vhost pmd can access other queues that are not ready when the first queue is ready, which makes no sense and also allows numa_realloc() and rte_vhost_dequeue_burst() access to vq to happen at the same time. By controlling vq->allow_queuing we can make the pmd access only the queues that are ready. Fixes: 1ce3c7fe149 ("net/vhost: emulate device start/stop behavior") Signed-off-by: Yuan Wang Tested-by: Wei Ling Reviewed-by: Maxime Coquelin --- drivers/net/vhost/rte_eth_vhost.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 428aacf0a7..0926a43781 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -656,6 +656,7 @@ update_queuing_status(struct rte_eth_dev *dev) { struct pmd_internal *internal = dev->data->dev_private; struct vhost_queue *vq; + struct rte_vhost_vring_state *state; unsigned int i; int allow_queuing = 1; @@ -666,12 +667,17 @@ update_queuing_status(struct rte_eth_dev *dev) rte_atomic32_read(&internal->dev_attached) == 0) allow_queuing = 0; + state = vring_states[dev->data->port_id]; + /* Wait until rx/tx_pkt_burst stops accessing vhost device */ for (i = 0; i < dev->data->nb_rx_queues; i++) { vq = dev->data->rx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, allow_queuing); + if (allow_queuing && state->cur[vq->virtqueue_id]) + rte_atomic32_set(&vq->allow_queuing, 1); + else + rte_atomic32_set(&vq->allow_queuing, 0); while (rte_atomic32_read(&vq->while_queuing)) rte_pause(); } @@ -680,7 +686,10 @@ update_queuing_status(struct rte_eth_dev *dev) vq = dev->data->tx_queues[i]; if (vq == NULL) continue; - rte_atomic32_set(&vq->allow_queuing, allow_queuing); + if (allow_queuing && state->cur[vq->virtqueue_id]) + rte_atomic32_set(&vq->allow_queuing, 1); + else + rte_atomic32_set(&vq->allow_queuing, 0); while (rte_atomic32_read(&vq->while_queuing)) rte_pause(); } @@ -854,6 +863,8 @@ vring_state_changed(int vid, uint16_t vring, int enable) state->max_vring = RTE_MAX(vring, state->max_vring); rte_spinlock_unlock(&state->lock); + update_queuing_status(eth_dev); + VHOST_LOG(INFO, "vring%u is %s\n", vring, enable ? "enabled" : "disabled"); -- 2.37.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2022-07-07 09:54:11.930120095 +0200 +++ 0017-net-vhost-fix-access-to-freed-memory.patch 2022-07-07 09:54:10.817823702 +0200 @@ -1 +1 @@ -From 9dc6bb06824f3c5887f0436ddba5ab9116cb277e Mon Sep 17 00:00:00 2001 +From c7926bd5b5bd0b67910eed63f17cc3f0bc8fb4de Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 9dc6bb06824f3c5887f0436ddba5ab9116cb277e ] + @@ -31 +33 @@ -index 070f0e6dfd..8a6595504a 100644 +index 428aacf0a7..0926a43781 100644 @@ -34 +36 @@ -@@ -720,6 +720,7 @@ update_queuing_status(struct rte_eth_dev *dev) +@@ -656,6 +656,7 @@ update_queuing_status(struct rte_eth_dev *dev) @@ -42 +44 @@ -@@ -730,12 +731,17 @@ update_queuing_status(struct rte_eth_dev *dev) +@@ -666,12 +667,17 @@ update_queuing_status(struct rte_eth_dev *dev) @@ -61 +63 @@ -@@ -744,7 +750,10 @@ update_queuing_status(struct rte_eth_dev *dev) +@@ -680,7 +686,10 @@ update_queuing_status(struct rte_eth_dev *dev) @@ -73 +75 @@ -@@ -967,6 +976,8 @@ vring_state_changed(int vid, uint16_t vring, int enable) +@@ -854,6 +863,8 @@ vring_state_changed(int vid, uint16_t vring, int enable)