Skip to contentSkip to conversation

net/tap-linux.c: avoid abort when setting invalid fd

PATCH In review Houqi (Nick) Zuo 2 participants 2 messages Dec 8, 2025 – Dec 16, 2025 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 net/tap-linux.c: avoid abort when setting invalid fd

This patch removes abort() call in the tap_fd_set_vnet_hdr_len() function. If the fd is found to be in a bad state (e.g., EBADFD
or ENODEV), the function will print an error message.

When QEMU creates a tap device automatically and the tap device is manually removed from the host while the guest is running, the tap device file descriptor becomes invalid. Later, when the guest executes shutdown, the tap_fd_set_vnet_hdr_len() function may be called and abort QEMU with a core dump when attempting to use the invalid fd. The expected behavior for this negative test case is that QEMU should report an error but continue running rather than aborting.

Testing:
- Start QEMU with automatically created tap device
- Manually remove the tap device on the host
- Execute shutdown in the guest
- Verify QEMU reports an error but does not abort

Fixes 0caed25cd171 ("virtio: Call set_features during reset")
---
 net/tap-linux.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
net/tap-linux.c +5 -4
index 2a90b58467..922684f349 100644
@@ -214,10 +214,11 @@ bool tap_probe_has_tunnel(int fd)
 
 void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
-    if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) {
-        fprintf(stderr, "TUNSETVNETHDRSZ ioctl() failed: %s. Exiting.\n",
-                strerror(errno));
-        abort();
+    int ret;
+
+    ret = ioctl(fd, TUNSETVNETHDRSZ, &len);
+    if (ret != 0) {
+        error_report("TUNSETVNETHDRSZ ioctl() failed: %s.", strerror(errno));
     }
 }
 
Signature · 1 line
2.47.3
#1 lore raw
Quoted 13 lines · Houqi (Nick) Zuo

This patch removes abort() call in the tap_fd_set_vnet_hdr_len() function. If the fd is found to be in a bad state (e.g., EBADFD
or ENODEV), the function will print an error message.

When QEMU creates a tap device automatically and the tap device is manually removed from the host while the guest is running, the tap device file descriptor becomes invalid. Later, when the guest executes shutdown, the tap_fd_set_vnet_hdr_len() function may be called and abort QEMU with a core dump when attempting to use the invalid fd. The expected behavior for this negative test case is that QEMU should report an error but continue running rather than aborting.

Quoted 8 lines

Testing:
- Start QEMU with automatically created tap device
- Manually remove the tap device on the host
- Execute shutdown in the guest
- Verify QEMU reports an error but does not abort

Fixes 0caed25cd171 ("virtio: Call set_features during reset")

Queued.

Thanks