|WARNING| [v3,2/2] net/tap: fix use after free on interrupt handle

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Tue Nov 10 23:03:32 CET 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172794

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-11-10

**Patch 1/2: net/tap: fix FD leak on netns change**

**Error: fd-number reuse can leave a stale LSC callback registered**

In the reworked `clean:` path of `tap_lsc_intr_handle_set()`, the race against the alarm is detected by comparing fd numbers only:

```c
		/* Alarm may have replaced the fd while unregistering */
		rte_eal_alarm_cancel(tap_lsc_register_alarm, dev);
		if (rte_intr_fd_get(pmd->intr_handle) == fd)
			break;
```

Consider this interleaving:

1. The control thread reads `fd = X` and runs `rte_intr_callback_unregister()`.
2. Before the second cancel, `tap_netns_change()` in the interrupt thread schedules `tap_lsc_register_alarm`, and the alarm runs.
3. The alarm's own teardown closes X via `tap_nl_final(fd)`.
4. The alarm's `tap_lsc_intr_handle_set(dev, 1)` opens a new netlink socket. Linux hands out the lowest free descriptor, so this is very likely X again. It then registers `tap_dev_intr_handler` on it.

Back in the control thread, `rte_intr_fd_get() == fd` is true, so the loop breaks. `tap_nl_final(fd)` then closes the new socket, and the fd is set to -1, but the callback the alarm registered is never unregistered.

That leaves a callback attached to `pmd->intr_handle` with `dev` as its argument. This is exactly the use-after-free scenario patch 2/2 is trying to close on `tap_dev_close()`.

Suggested fix: do not use the fd value as the change detector. Either of these works:
- Keep a generation counter in `pmd_internals`, incremented on every LSC (re)registration, and compare that.
- After the second `rte_eal_alarm_cancel()`, always loop back and unregister again until `rte_intr_callback_unregister()` returns `-ENOENT`. At that point no alarm can be pending, so the state is stable.

Review-Result: ERROR


More information about the test-report mailing list