Blame 0001-net-tap-fix-crash-on-hotplug.patch

47a69f
From 3f6be9c84782a0943ea21a8a6f8a5d055b65f2d5 Mon Sep 17 00:00:00 2001
47a69f
Message-Id: <3f6be9c84782a0943ea21a8a6f8a5d055b65f2d5.1619018363.git.crobinso@redhat.com>
47a69f
From: Cole Robinson <crobinso@redhat.com>
47a69f
Date: Wed, 21 Apr 2021 11:12:07 -0400
47a69f
Subject: [PATCH-for-6.0] net: tap: fix crash on hotplug
47a69f
47a69f
Attempting to hotplug a tap nic with libvirt will crash qemu:
47a69f
47a69f
$ sudo virsh attach-interface f32 network default
47a69f
error: Failed to attach interface
47a69f
error: Unable to read from monitor: Connection reset by peer
47a69f
47a69f
0x000055875b7f3a99 in tap_send (opaque=0x55875e39eae0) at ../net/tap.c:206
47a69f
206	        if (!s->nc.peer->do_not_pad) {
47a69f
gdb$ bt
47a69f
47a69f
s->nc.peer may not be set at this point. This seems to be an
47a69f
expected case, as qemu_send_packet_* explicitly checks for NULL
47a69f
s->nc.peer later.
47a69f
47a69f
Fix it by checking for s->nc.peer here too. Padding is applied if
47a69f
s->nc.peer is not set.
47a69f
47a69f
https://bugzilla.redhat.com/show_bug.cgi?id=1949786
47a69f
Fixes: 969e50b61a2
47a69f
47a69f
Signed-off-by: Cole Robinson <crobinso@redhat.com>
47a69f
---
47a69f
* Or should we skip padding if nc.peer is unset? I didn't dig into it
47a69f
* tap-win3.c and slirp.c may need a similar fix, but the slirp case
47a69f
  didn't crash in a simple test.
47a69f
47a69f
 net/tap.c | 2 +-
47a69f
 1 file changed, 1 insertion(+), 1 deletion(-)
47a69f
47a69f
diff --git a/net/tap.c b/net/tap.c
47a69f
index dd42ac6134..937559dbb8 100644
47a69f
--- a/net/tap.c
47a69f
+++ b/net/tap.c
47a69f
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
47a69f
             size -= s->host_vnet_hdr_len;
47a69f
         }
47a69f
 
47a69f
-        if (!s->nc.peer->do_not_pad) {
47a69f
+        if (!s->nc.peer || !s->nc.peer->do_not_pad) {
47a69f
             if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
47a69f
                 buf = min_pkt;
47a69f
                 size = min_pktsz;
47a69f
-- 
47a69f
2.31.1
47a69f