RFC netfilter: nfnetlink_queue: handle packet ID reuse and large gaps
Get series with b4
b4 am [email protected] change-id 20261106-nfqueue-review-1840e52eafdbVersions newest first
- v1 RFC Latest3 patches 5 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | netfilter: nfnetlink_queue: reject duplicate pending packet IDsnet/ | +4 | 0 replies | |
| 2/3 | netfilter: nfnetlink_queue: fix batch verdict ordering across large ID gapsinclude/ net/ | +62 | 1 reply | |
| 3/3 | netfilter: nfnetlink_queue: test packet ID ordering and collisionsnet/ net/ net/ | +922 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH RFC net 0/3] netfilter: nfnetlink_queue: handle packet ID reuse and large gaps
This series addresses packet-ID reuse and batch-verdict ordering in NFQUEUE. I am posting it as an RFC to discuss the handling of ambiguous batch boundaries and the additional sequence state used to resolve them.
An old packet can remain queued while newer packets receive individual verdicts. Queue length therefore does not bound the distance between pending packet IDs. After a complete 32-bit ID cycle, two pending packets can have the same ID, making verdict lookup ambiguous. Even before reuse, the signed 32-bit comparison in the batch handler can select the wrong FIFO prefix when IDs are separated by half an ID cycle or more.
For example, with pending IDs [1, 0x80000002], a batch verdict through 1 currently selects both packets instead of only the first. If the queue contains [1, 2, 0x80000003], removing 2 individually and then batching through 2 also selects both remaining packets instead of only 1. These cases are covered by synthetic KUnit tests that seed the sequence values directly.
Patch 1 rejects an incoming duplicate ID before list insertion or userspace notification, preserving the existing pending packet. The incoming packet follows the existing enqueue-failure policy: drop by default, or accept with FAIL_OPEN.
Patch 2 uses an exact queued boundary to select the FIFO prefix. For a boundary no longer queued, it uses a 64-bit queue sequence and a per-entry 32-bit epoch to recover issuance order. Ambiguous missing boundaries return -ERANGE without changing the queue. The wire format is unchanged, but the rejection behavior is userspace-visible. This does not distinguish stale verdicts after an ID has been released and reused.
Patch 3 adds 45 KUnit cases covering ordering, wraparound, missing boundaries, collisions and the actual enqueue path. Each case uses a private network namespace.
I would appreciate feedback on:
- Whether -ERANGE with the queue unchanged is the appropriate response for an ambiguous missing batch boundary.
- Whether the per-entry epoch and widened queue counter are appropriate for handling boundaries that have already been removed.
- Whether the existing drop/FAIL_OPEN policy is the preferred way to handle an incoming packet whose ID is still pending.
Validation:
- Focused UML KUnit run: 45 cases passed with GCC 13.3 and W=1.
- Kconfig dependency checks with NFQUEUE built in: tests enabled with KUNIT=y and NET_NS=y, and disabled with KUNIT=m or NET_NS=n.
- Full x86-64 allmodconfig with GCC 13.3 and allyesconfig with Clang 18.1.3: both passed with W=1 and CONFIG_WERROR=n.
- Separate GCC builds of NFQUEUE and all eight other direct users of nf_queue.h passed in both configurations with W=1 and CONFIG_WERROR=y, without compiler diagnostics.
The full builds disabled WERROR after unrelated failures were reproduced on the unpatched base. GCC allyesconfig also encountered an unrelated MCTP KUnit static assertion failure on that base; the full allyesconfig build therefore used Clang. Runtime coverage is the focused KUnit suite; no throughput or latency measurements are included.
Codex assisted with developing and reviewing this series, fixing the KUnit dependencies and namespace isolation, running validation, and preparing the submission text.
---
Alireza Asgari (3):
netfilter: nfnetlink_queue: reject duplicate pending packet IDs
netfilter: nfnetlink_queue: fix batch verdict ordering across large ID gaps
netfilter: nfnetlink_queue: test packet ID ordering and collisions
include/net/netfilter/nf_queue.h | 1 + net/netfilter/Kconfig | 12 + net/netfilter/nfnetlink_queue.c | 78 ++- net/netfilter/nfnetlink_queue_gap_test.c | 906 +++++++++++++++++++++++++++++++ 4 files changed, 988 insertions(+), 9 deletions(-)
---
base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
change-id: 20261106-nfqueue-review-1840e52eafdb
Best regards,
Signature · 1 line
Alireza Asgari <[email protected]>