|
|
1072c8 |
From 89732bf03b26daaebbd3e6e031e79459ae3f77e1 Mon Sep 17 00:00:00 2001
|
|
|
a6baaf |
From: Jon Maloy <jmaloy@redhat.com>
|
|
|
a6baaf |
Date: Tue, 29 Jun 2021 03:42:39 -0400
|
|
|
a6baaf |
Subject: [PATCH 1/9] net: introduce qemu_receive_packet()
|
|
|
a6baaf |
MIME-Version: 1.0
|
|
|
a6baaf |
Content-Type: text/plain; charset=UTF-8
|
|
|
a6baaf |
Content-Transfer-Encoding: 8bit
|
|
|
a6baaf |
|
|
|
a6baaf |
RH-Author: Jon Maloy <jmaloy@redhat.com>
|
|
|
a6baaf |
Message-id: <20210629034247.3286477-2-jmaloy@redhat.com>
|
|
|
a6baaf |
Patchwork-id: 101785
|
|
|
a6baaf |
O-Subject: [RHEL-8.4.0.z qemu-kvm PATCH v2 1/9] net: introduce qemu_receive_packet()
|
|
|
a6baaf |
Bugzilla: 1932917
|
|
|
a6baaf |
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
|
|
|
a6baaf |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
a6baaf |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
a6baaf |
|
|
|
a6baaf |
From: Jason Wang <jasowang@redhat.com>
|
|
|
a6baaf |
|
|
|
a6baaf |
Some NIC supports loopback mode and this is done by calling
|
|
|
a6baaf |
nc->info->receive() directly which in fact suppresses the effort of
|
|
|
a6baaf |
reentrancy check that is done in qemu_net_queue_send().
|
|
|
a6baaf |
|
|
|
a6baaf |
Unfortunately we can't use qemu_net_queue_send() here since for
|
|
|
a6baaf |
loopback there's no sender as peer, so this patch introduce a
|
|
|
a6baaf |
qemu_receive_packet() which is used for implementing loopback mode
|
|
|
a6baaf |
for a NIC with this check.
|
|
|
a6baaf |
|
|
|
a6baaf |
NIC that supports loopback mode will be converted to this helper.
|
|
|
a6baaf |
|
|
|
a6baaf |
This is intended to address CVE-2021-3416.
|
|
|
a6baaf |
|
|
|
a6baaf |
Cc: Prasad J Pandit <ppandit@redhat.com>
|
|
|
a6baaf |
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
a6baaf |
Cc: qemu-stable@nongnu.org
|
|
|
a6baaf |
Signed-off-by: Jason Wang <jasowang@redhat.com>
|
|
|
a6baaf |
|
|
|
a6baaf |
(cherry picked from commit 705df5466c98f3efdd2b68d3b31dad86858acad7)
|
|
|
a6baaf |
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
a6baaf |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
a6baaf |
---
|
|
|
a6baaf |
include/net/net.h | 5 +++++
|
|
|
a6baaf |
include/net/queue.h | 8 ++++++++
|
|
|
a6baaf |
net/net.c | 38 +++++++++++++++++++++++++++++++-------
|
|
|
a6baaf |
net/queue.c | 22 ++++++++++++++++++++++
|
|
|
a6baaf |
4 files changed, 66 insertions(+), 7 deletions(-)
|
|
|
a6baaf |
|
|
|
a6baaf |
diff --git a/include/net/net.h b/include/net/net.h
|
|
|
a6baaf |
index e175ba9677..1b32a8aaec 100644
|
|
|
a6baaf |
--- a/include/net/net.h
|
|
|
a6baaf |
+++ b/include/net/net.h
|
|
|
a6baaf |
@@ -142,12 +142,17 @@ void *qemu_get_nic_opaque(NetClientState *nc);
|
|
|
a6baaf |
void qemu_del_net_client(NetClientState *nc);
|
|
|
a6baaf |
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
|
|
|
a6baaf |
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
|
|
|
a6baaf |
+int qemu_can_receive_packet(NetClientState *nc);
|
|
|
a6baaf |
int qemu_can_send_packet(NetClientState *nc);
|
|
|
a6baaf |
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
|
|
|
a6baaf |
int iovcnt);
|
|
|
a6baaf |
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
|
|
|
a6baaf |
int iovcnt, NetPacketSent *sent_cb);
|
|
|
a6baaf |
ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
|
|
|
a6baaf |
+ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size);
|
|
|
a6baaf |
+ssize_t qemu_receive_packet_iov(NetClientState *nc,
|
|
|
a6baaf |
+ const struct iovec *iov,
|
|
|
a6baaf |
+ int iovcnt);
|
|
|
a6baaf |
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
|
|
|
a6baaf |
ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
|
|
|
a6baaf |
int size, NetPacketSent *sent_cb);
|
|
|
a6baaf |
diff --git a/include/net/queue.h b/include/net/queue.h
|
|
|
a6baaf |
index c0269bb1dc..9f2f289d77 100644
|
|
|
a6baaf |
--- a/include/net/queue.h
|
|
|
a6baaf |
+++ b/include/net/queue.h
|
|
|
a6baaf |
@@ -55,6 +55,14 @@ void qemu_net_queue_append_iov(NetQueue *queue,
|
|
|
a6baaf |
|
|
|
a6baaf |
void qemu_del_net_queue(NetQueue *queue);
|
|
|
a6baaf |
|
|
|
a6baaf |
+ssize_t qemu_net_queue_receive(NetQueue *queue,
|
|
|
a6baaf |
+ const uint8_t *data,
|
|
|
a6baaf |
+ size_t size);
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ssize_t qemu_net_queue_receive_iov(NetQueue *queue,
|
|
|
a6baaf |
+ const struct iovec *iov,
|
|
|
a6baaf |
+ int iovcnt);
|
|
|
a6baaf |
+
|
|
|
a6baaf |
ssize_t qemu_net_queue_send(NetQueue *queue,
|
|
|
a6baaf |
NetClientState *sender,
|
|
|
a6baaf |
unsigned flags,
|
|
|
a6baaf |
diff --git a/net/net.c b/net/net.c
|
|
|
a6baaf |
index 84aa6d8d00..d0b651ca95 100644
|
|
|
a6baaf |
--- a/net/net.c
|
|
|
a6baaf |
+++ b/net/net.c
|
|
|
a6baaf |
@@ -516,6 +516,17 @@ int qemu_set_vnet_be(NetClientState *nc, bool is_be)
|
|
|
a6baaf |
#endif
|
|
|
a6baaf |
}
|
|
|
a6baaf |
|
|
|
a6baaf |
+int qemu_can_receive_packet(NetClientState *nc)
|
|
|
a6baaf |
+{
|
|
|
a6baaf |
+ if (nc->receive_disabled) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ } else if (nc->info->can_receive &&
|
|
|
a6baaf |
+ !nc->info->can_receive(nc)) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ }
|
|
|
a6baaf |
+ return 1;
|
|
|
a6baaf |
+}
|
|
|
a6baaf |
+
|
|
|
a6baaf |
int qemu_can_send_packet(NetClientState *sender)
|
|
|
a6baaf |
{
|
|
|
a6baaf |
int vm_running = runstate_is_running();
|
|
|
a6baaf |
@@ -528,13 +539,7 @@ int qemu_can_send_packet(NetClientState *sender)
|
|
|
a6baaf |
return 1;
|
|
|
a6baaf |
}
|
|
|
a6baaf |
|
|
|
a6baaf |
- if (sender->peer->receive_disabled) {
|
|
|
a6baaf |
- return 0;
|
|
|
a6baaf |
- } else if (sender->peer->info->can_receive &&
|
|
|
a6baaf |
- !sender->peer->info->can_receive(sender->peer)) {
|
|
|
a6baaf |
- return 0;
|
|
|
a6baaf |
- }
|
|
|
a6baaf |
- return 1;
|
|
|
a6baaf |
+ return qemu_can_receive_packet(sender->peer);
|
|
|
a6baaf |
}
|
|
|
a6baaf |
|
|
|
a6baaf |
static ssize_t filter_receive_iov(NetClientState *nc,
|
|
|
a6baaf |
@@ -667,6 +672,25 @@ ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size)
|
|
|
a6baaf |
return qemu_send_packet_async(nc, buf, size, NULL);
|
|
|
a6baaf |
}
|
|
|
a6baaf |
|
|
|
a6baaf |
+ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size)
|
|
|
a6baaf |
+{
|
|
|
a6baaf |
+ if (!qemu_can_receive_packet(nc)) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ }
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ return qemu_net_queue_receive(nc->incoming_queue, buf, size);
|
|
|
a6baaf |
+}
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ssize_t qemu_receive_packet_iov(NetClientState *nc, const struct iovec *iov,
|
|
|
a6baaf |
+ int iovcnt)
|
|
|
a6baaf |
+{
|
|
|
a6baaf |
+ if (!qemu_can_receive_packet(nc)) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ }
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ return qemu_net_queue_receive_iov(nc->incoming_queue, iov, iovcnt);
|
|
|
a6baaf |
+}
|
|
|
a6baaf |
+
|
|
|
a6baaf |
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
|
|
|
a6baaf |
{
|
|
|
a6baaf |
return qemu_send_packet_async_with_flags(nc, QEMU_NET_PACKET_FLAG_RAW,
|
|
|
a6baaf |
diff --git a/net/queue.c b/net/queue.c
|
|
|
1072c8 |
index c679d79f4b..5f0f9ffcaf 100644
|
|
|
a6baaf |
--- a/net/queue.c
|
|
|
a6baaf |
+++ b/net/queue.c
|
|
|
a6baaf |
@@ -182,6 +182,28 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue,
|
|
|
a6baaf |
return ret;
|
|
|
a6baaf |
}
|
|
|
a6baaf |
|
|
|
a6baaf |
+ssize_t qemu_net_queue_receive(NetQueue *queue,
|
|
|
a6baaf |
+ const uint8_t *data,
|
|
|
a6baaf |
+ size_t size)
|
|
|
a6baaf |
+{
|
|
|
a6baaf |
+ if (queue->delivering) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ }
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ return qemu_net_queue_deliver(queue, NULL, 0, data, size);
|
|
|
a6baaf |
+}
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ssize_t qemu_net_queue_receive_iov(NetQueue *queue,
|
|
|
a6baaf |
+ const struct iovec *iov,
|
|
|
a6baaf |
+ int iovcnt)
|
|
|
a6baaf |
+{
|
|
|
a6baaf |
+ if (queue->delivering) {
|
|
|
a6baaf |
+ return 0;
|
|
|
a6baaf |
+ }
|
|
|
a6baaf |
+
|
|
|
a6baaf |
+ return qemu_net_queue_deliver_iov(queue, NULL, 0, iov, iovcnt);
|
|
|
a6baaf |
+}
|
|
|
a6baaf |
+
|
|
|
a6baaf |
ssize_t qemu_net_queue_send(NetQueue *queue,
|
|
|
a6baaf |
NetClientState *sender,
|
|
|
a6baaf |
unsigned flags,
|
|
|
a6baaf |
--
|
|
|
a6baaf |
2.27.0
|
|
|
a6baaf |
|