|WARNING| [v1,3/3] net/cnxk: use timing-safe MAC address comparison

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Mon Aug 3 08:49:58 CEST 2026


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

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-03

# DPDK Patch Review

## Patch 1/3: common/cpt: use timing-safe digest comparison

### Errors

**Incorrect return value semantics for rte_memeq_timingsafe()**

The patch inverts the condition when replacing `memcmp()` with `rte_memeq_timingsafe()`, but the semantics are incorrect. `memcmp()` returns 0 when bytes are equal; `rte_memeq_timingsafe()` returns **true (non-zero)** when bytes are equal. The patch correctly inverts the if-else branches, which is correct.

However, reviewing the actual code change shows the logic is correct after all:
- Original: `if (memcmp(...))` -- true when NOT equal - AUTH_FAILED
- New: `if (rte_memeq_timingsafe(...))` -- true when equal - SUCCESS

The inversion of the if-else bodies matches the inverted condition semantics. **No issue here.**

### Warnings

None.

---

## Patch 2/3: crypto/nitrox: use timing-safe salt comparison

### Errors

**Incorrect application of timing-safe comparison to salt**

The function `softreq_copy_salt()` is checking whether the salt has **changed** to determine if it needs to be copied from the IV. The salt comparison here is not a cryptographic verification operation -- it is an optimization to avoid redundant memcpy when the salt is already loaded.

A salt is **not secret** in GCM/CCM -- it is transmitted in the clear as part of the IV/nonce. There is no security benefit to constant-time comparison here, and the timing leak (if any) reveals only whether the application reused the same salt between operations, which is not sensitive.

**More critically, the original code returns early (line 687: `return 0;`) when the salts match, meaning no copy is needed. With the patch, the semantics are:**

- Original: `if (!memcmp(...))` - salts match - return 0 (no copy needed) 
- Patched: `if (rte_memeq_timingsafe(...))` - salts match - return 0

Wait, `rte_memeq_timingsafe()` returns **true** when equal, which is non-zero, and `memcmp()` returns **0** when equal. So:

- Original: `!memcmp(...)` is true when salts match
- Patched: `rte_memeq_timingsafe(...)` is true when salts match

**Both return 0 when salts match -- the logic is preserved.** 

However, the **cryptographic justification is wrong**. Salt comparison is not a secret-dependent branch. This change adds unnecessary overhead (constant-time comparison) where it provides no security benefit. The salt is public; timing leaks on salt comparison do not constitute a vulnerability.

**Recommendation:** Revert this patch. The original `memcmp()` is correct and appropriate for salt comparison. If the patch is retained, the commit message should clarify that salt is not secret and this change is unnecessary for security.

### Warnings

**Incorrect security analysis in commit message**

The commit message states the salt comparison "can leak timing information about the salt value," implying this is a vulnerability. AES-GCM salts are not secret -- they are part of the nonce transmitted with the ciphertext. There is no timing attack here.

---

## Patch 3/3: net/cnxk: use timing-safe MAC address comparison

### Errors

**Incorrect application of timing-safe comparison to MAC address lookup**

The function `nix_find_mac_addr()` searches an array of MAC addresses to find a match (likely for MAC filtering or address table management). MAC addresses are **not secret** -- they are transmitted in cleartext in every Ethernet frame.

Timing-safe comparison provides no security benefit here. The function is a lookup/search operation, not cryptographic verification. The "attacker" (network peer) already knows the MAC address being searched for because it is in the Ethernet header.

**Additionally, the semantics may be incorrect:**

- Original: `!memcmp(...)` -- true when addresses match - return index
- Patched: `rte_memeq_timingsafe(...)` -- true when addresses match - return index

The logic is preserved, but `rte_memeq_timingsafe()` is significantly slower than `memcmp()` for a lookup that is not cryptographic and may be called in a performance-sensitive path (MAC address filtering).

**Recommendation:** Revert this patch. MAC address comparison does not require constant-time semantics. If the goal is defense-in-depth against unspecified future vulnerabilities, that should be justified explicitly, but it is not appropriate to add constant-time overhead to non-cryptographic operations without a threat model.

### Warnings

**Performance impact in non-crypto code path**

MAC address lookup may be called frequently (per-packet or per-flow). Replacing a fast short-circuit comparison with constant-time comparison adds unnecessary overhead in a non-security-critical path.

---

## Summary

**Patch 1/3:** Correct -- auth tag verification should use timing-safe comparison.

**Patch 2/3:** Incorrect application -- salt is not secret; timing-safe comparison is unnecessary and adds overhead.

**Patch 3/3:** Incorrect application -- MAC addresses are public; timing-safe comparison is inappropriate for a lookup operation.

**Recommendation:**
- Accept patch 1/3 (MAC verification in crypto path is the correct use case).
- Reject patches 2/3 and 3/3 (salts and MAC addresses are not secret; `memcmp()` is correct for these comparisons).

If the goal is to use `rte_memeq_timingsafe()` universally "to be safe," that should be discussed and justified separately, as it imposes performance costs on non-cryptographic operations. The current DPDK crypto guidelines specify timing-safe comparison only for **authentication tags, digests, MACs, and ICVs** -- i.e., values used to accept or reject attacker-supplied data in a cryptographic verification context.


More information about the test-report mailing list