|WARNING| acl: reject rules with inverted range

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Tue Nov 10 07:58:35 CET 2026


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

_AI Code Review_

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

# DPDK Patch Review

## Analysis

This patch adds validation for inverted range fields in ACL rules (e.g., port range 80..22 where low > high). The fix prevents crashes and incorrect matching behavior.

### Evidence-Based Findings

**Errors:**

1. **Resource leak on error path** (line in `acl_bld.c:+1516`)
   ```c
   if (acl_check_rule_ranges(&bcx->cfg, rule) != 0)
       return -EINVAL;
   ```
   The function `acl_build_rules()` allocates `br` array via `calloc()` at the start (visible from surrounding context), but this new error path returns without freeing it. All other error paths in this function use `goto error_free` to clean up. This leaks memory when a rule has an inverted range.

   Fix: Change to `{ ret = -EINVAL; goto error_free; }` to match the existing error handling pattern.

2. **Inconsistent return value semantics** (line in `acl_bld.c:+1516`)
   ```c
   if (acl_check_rule_ranges(&bcx->cfg, rule) != 0)
       return -EINVAL;
   ```
   The function `acl_build_rules()` uses a local variable `ret` to propagate errors and returns `ret` at the end. This direct `return -EINVAL` bypasses that pattern. While not strictly a bug, it's inconsistent with the function's style and could confuse future maintainers.

   Suggested fix (combined with #1):
   ```c
   ret = acl_check_rule_ranges(&bcx->cfg, rule);
   if (ret != 0)
       goto error_free;
   ```

**Warnings:**

1. **Function could be static** (line in `acl_bld.c:+1450`)
   ```c
   static int
   acl_check_rule_ranges(const struct rte_acl_config *cfg,
       const struct rte_acl_rule *rule)
   ```
   This function is only called within `acl_bld.c` and has no external visibility. It should be `static`, which it already is -- however, it lacks the `inline` optimization hint that would be appropriate for a function called in a loop. Consider adding `static inline` if this is performance-critical, or leave as `static` if code size matters more.

   Info: This is acceptable as-is; just noting the inline option.

2. **Test could verify error message** (line in `test_acl.c:+1362`)
   ```c
   if (ret != -EINVAL) {
       printf("Line %i: Building ACL context "
               "should have failed!\n", __LINE__);
   ```
   The test verifies that `rte_acl_ipv4vlan_build()` returns `-EINVAL`, but doesn't verify that the new `ACL_LOG(ERR, ...)` message was emitted. While not required, checking for the error message would make the test more robust.

   This is a minor enhancement suggestion only.

3. **Variable naming inconsistency** (line in `test_acl.c:+1277`)
   ```c
   struct acl_ipv4vlan_rule rv;
   ```
   The test uses `rv` as a variable name, but other variables in the same function use more descriptive names like `rule`. Consider renaming to `generic_rule` or similar for consistency.

   Info: Minor style preference only.

**Info:**

1. **Pre-existing: Missing cleanup in test error paths** (lines in `test_acl.c`)
   Not introduced by this patch: The test function `test_invalid_rules()` has multiple error paths that `goto err`, but if `acx` was successfully created, those paths should call `rte_acl_free(acx)` before returning. The patch adds new test code that follows the existing (flawed) pattern. This is a pre-existing issue not caused by this patch.

## Positive Observations

- The fix correctly addresses the security issue (NULL deref crash for 1-byte fields, incorrect matching for 2-byte fields)
- Test coverage is added for the new validation
- The validation logic correctly handles all field sizes (1, 2, 4, 8 bytes)
- Error message includes useful context (rule userdata, field index)

## Final Check

### Pass 1: Correctness bugs
- Resource leak on error path is included 
- Error propagation inconsistency is included 

### Pass 2: Style/process false positives
- No items concluded with "this is fine/correct/acceptable" remain

### Pass 3: Evidence verification
- Error #1: Can quote line `return -EINVAL;` at +1516, leak visible from function context 
- Error #2: Can quote line `return -EINVAL;` at +1516, inconsistent with surrounding error handling 
- Warning #1: Can quote `static int` at +1450, observation about inline is advisory 
- Warning #2: Can quote test code at +1362, suggestion only 
- Info #1: Pre-existing issue, labeled as such 

Review-Result: ERROR


More information about the test-report mailing list