|WARNING| net/memif: fix use after free on listener socket close

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Wed Nov 4 18:27:59 CET 2026


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

_AI Code Review_

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

# DPDK Patch Review

## Correctness Bugs

**Error:** Resource leak on error path - interrupt handle not freed on unregister failure

```c
if (pmd->role != MEMIF_ROLE_CLIENT) {
	rte_intr_callback_unregister_sync(socket->intr_handle,
		memif_listener_handler, socket);
	rte_intr_fd_close(socket->intr_handle);
	rte_intr_instance_free(socket->intr_handle);
}
```

`rte_intr_callback_unregister_sync()` can fail (e.g., if the callback was never registered). The return value is not checked, so if it fails, the code proceeds to close and free the interrupt handle without knowing whether the unregister succeeded. If the unregister failed because the callback was not found, this is likely fine, but if it failed for another reason (EINVAL, other errors), proceeding blindly could be incorrect.

**Suggested fix:** Check the return value and handle errors appropriately:

```c
if (pmd->role != MEMIF_ROLE_CLIENT) {
	int ret = rte_intr_callback_unregister_sync(socket->intr_handle,
		memif_listener_handler, socket);
	if (ret < 0 && ret != -ENOENT) {
		MIF_LOG(WARNING, "Failed to unregister interrupt callback: %s",
			strerror(-ret));
		/* Continue cleanup anyway - handle must be freed */
	}
	rte_intr_fd_close(socket->intr_handle);
	rte_intr_instance_free(socket->intr_handle);
}
```

**Note:** The actual severity depends on what happens if `rte_intr_callback_unregister_sync()` fails. If failure is always benign (callback wasn't registered), this may be acceptable as-is. However, without error checking, we cannot distinguish benign from serious failures.

## Code Style

No style issues identified. The patch follows DPDK formatting conventions:
- Proper indentation
- Line length within limits
- Function call formatting is correct

## API and Documentation

**Info:** Missing release notes update

This is a bug fix for a use-after-free issue. While the patch has a `Fixes:` tag, significant bug fixes should be documented in the release notes under the "Fixed Issues" section for the current release.

**Suggested addition to release notes:**
```
* **net/memif: Fixed use-after-free on listener socket close**

  Fixed a race condition where the interrupt handler could access freed
  memory when removing a device. Changed to use synchronous callback
  unregister to ensure the handler completes before freeing resources.
```

However, this is marked Info rather than Warning because the requirement for release notes on bug fixes is not absolute in all cases, and the `Fixes:` tag provides traceability.

## Assessment

The patch correctly addresses the use-after-free issue described in the commit message by switching from `rte_intr_callback_unregister()` to `rte_intr_callback_unregister_sync()`. This ensures the handler completes before proceeding with resource cleanup.

The primary concern is the lack of error checking on the unregister call, which could mask other issues if the operation fails unexpectedly.

Review-Result: ERROR


More information about the test-report mailing list