|WARNING| [v6,4/4] test/crypto: add asym test suite for AESNI_MB
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Tue Nov 10 13:48:20 CET 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172799
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-11-10
# DPDK Patch Review
## Patch 1/4: crypto/ipsec_mb: add support for IPsecMB 3.0
### Errors
1. **Use-after-free potential in `aesni_gcm_set_ops()`**
```c
/* Set IMB_MGR pointers. */
ops[GCM_KEY_128].mb_mgr = mb_mgr;
ops[GCM_KEY_192].mb_mgr = mb_mgr;
ops[GCM_KEY_256].mb_mgr = mb_mgr;
```
The `mb_mgr` pointer is stored in the ops structure, but the caller (`aesni_gcm_session_configure()`) receives `mb_mgr` as a parameter whose lifetime is not under this function's control. If `mb_mgr` is freed while the ops structure is still in use, these stored pointers become dangling. The ops are stored in a per-lcore TLS variable (`RTE_DEFINE_PER_LCORE(struct aesni_gcm_ops, gcm_ops[GCM_NUM_KEY_TYPES])`), so they persist beyond the scope of `aesni_gcm_set_ops()`. Every function pointer call then dereferences `ops->mb_mgr`, relying on the pointer remaining valid.
**Fix:** Either document that `mb_mgr` must remain valid for the lifetime of the ops structure, or do not store the pointer if the library's threading model guarantees the same `mb_mgr` is always passed.
2. **Missing error propagation in `aesni_mb_set_session_cipher_parameters()`**
```c
#if IMB_VERSION(3, 0, 0) <= IMB_VERSION_NUM
} else if (is_nxan) {
if (xform->cipher.key.length != 32) {
IPSEC_MB_LOG(ERR, "Invalid cipher key length");
return -EINVAL;
}
if (xform->cipher.iv.length != 16) {
IPSEC_MB_LOG(ERR, "Invalid cipher IV length");
return -EINVAL;
}
sess->template_job.key_len_in_bytes = 32;
if (is_nxan_exp_key) {
IMB_AES_KEYEXP_256(mb_mgr, xform->cipher.key.data,
sess->cipher.expanded_nea5_keys.encode,
sess->cipher.expanded_nea5_keys.decode);
```
`IMB_AES_KEYEXP_256()` can fail (returns int in some library versions), but the return value is not checked. If key expansion fails, `sess->cipher.expanded_nea5_keys` contains undefined data, leading to incorrect encryption/decryption.
**Fix:** Check the return value and propagate the error:
```c
int ret = IMB_AES_KEYEXP_256(mb_mgr, xform->cipher.key.data,
sess->cipher.expanded_nea5_keys.encode,
sess->cipher.expanded_nea5_keys.decode);
if (ret != 0) {
IPSEC_MB_LOG(ERR, "Key expansion failed");
return -EINVAL;
}
```
### Warnings
1. **Inconsistent version macro usage**
The patch uses `#if IMB_VERSION(3, 0, 0) > IMB_VERSION_NUM` to conditionally compile wrapper functions for library versions **before** 3.0, but the wrapper block is large (130+ lines) and duplicates the function signature for every key size. This is correct but verbose.
Consider whether a single generic wrapper with a function pointer table indexed by key size would reduce duplication, though this is an optimization suggestion, not a bug.
2. **Function signature change without ABI versioning**
All the wrapper function typedefs in `pmd_aesni_gcm_priv.h` change signatures to add an `IMB_MGR *state` parameter:
```c
typedef void (*aesni_gcm_t)(const struct gcm_key_data *gcm_key_data,
struct gcm_context_data *gcm_ctx_data,
- uint8_t *out, const uint8_t *in,
+ void *out, const void *in,
uint64_t plaintext_len, const void *iv,
const void *aad, uint64_t aad_len,
- uint8_t *auth_tag, uint64_t auth_tag_len);
+ void *auth_tag, uint64_t auth_tag_len, IMB_MGR *state);
```
This is an internal API (not exported to applications), but it is a change that affects all function pointer calls. The patch correctly updates all call sites, but this is worth flagging as a significant internal API change that must not leak into installed headers.
3. **Potentially unbounded loop in descriptor traversal** (pre-existing, not introduced)
The GCM processing functions walk mbuf chains with:
```c
while (total_len) {
dst = rte_pktmbuf_mtod_offset(dst_m, uint8_t *, data_offset);
src = rte_pktmbuf_mtod_offset(src_m, uint8_t *, data_offset);
/* ... */
total_len -= part_len;
}
```
If the mbuf chain is malformed (loops back on itself or has inconsistent lengths), this could run indefinitely. However, this is pre-existing code and not changed by this patch, so it is **Info** only.
---
## Patch 2/4: crypto/ipsec_mb: add support for 256-NxA4/5/6 algorithms
### Errors
None.
### Warnings
1. **Missing bounds check on user-supplied AAD length**
```c
case RTE_CRYPTO_AEAD_SNOW5G_NCA4:
sess->template_job.u.NCA.aad_len_in_bytes = xform->aead.aad_length;
```
The `xform->aead.aad_length` is copied directly from user configuration without validation. The capabilities advertise:
```c
.aad_size = {
.min = 0,
.max = 65535,
.increment = 1
},
```
but no explicit check enforces this in the session configuration. If a malicious or buggy application passes a length outside this range, the behavior is undefined (the library may reject it, or it may cause a buffer overrun depending on how the library allocates AAD buffers internally).
**Fix:** Add validation:
```c
if (xform->aead.aad_length > 65535) {
IPSEC_MB_LOG(ERR, "AAD length exceeds maximum");
return -EINVAL;
}
```
2. **Hardening: digest size validation relies on library**
```c
/* digest size must be between 4 and 16 */
if (sess->auth.req_digest_len < 4 ||
sess->auth.req_digest_len > 16) {
IPSEC_MB_LOG(ERR, "Invalid digest size");
return -EINVAL;
}
```
This check is correct, but it duplicates the constraint already in the capabilities table. If the capability table and the code diverge in a future release, the discrepancy will not be caught at compile time.
**Suggestion (Info):** Add a compile-time assert or a comment linking the check to the capability definition to ensure they stay in sync.
---
## Patch 3/4: crypto/ipsec_mb: add support for ML-KEM and ML-DSA
### Errors
1. **Missing error check on `imb_ml_kem_set_pubkey()` in encap path**
```c
case RTE_CRYPTO_ML_KEM_OP_ENCAP:
{
struct rte_crypto_ml_kem_encap_op *encap = &mlkem->encap;
sess->asym.ml_kem.encap_params.m_32 = encap->message.data;
sess->asym.ml_kem.encap_params.m_len = encap->message.length;
encap->ek.length = aesni_mb_ml_kem_ek_sz(sess->asym.ml_kem.alg);
encap->cipher.length = aesni_mb_ml_kem_ct_sz(sess->asym.ml_kem.alg);
rc = imb_ml_kem_set_pubkey(sess->asym.ml_kem.ctx,
encap->ek.data, encap->ek.length);
if (rc == 0)
rc = imb_ml_kem_encap(sess->asym.ml_kem.ctx,
encap->cipher.data, encap->cipher.length,
encap->sk.data, encap->sk.length,
&sess->asym.ml_kem.encap_params);
}
```
The error check `if (rc == 0)` prevents calling `imb_ml_kem_encap()` if `set_pubkey()` failed, but if `set_pubkey()` fails, `op->status` remains `RTE_CRYPTO_OP_STATUS_NOT_PROCESSED` because `rc` is nonzero, and the operation is marked as `RTE_CRYPTO_OP_STATUS_ERROR` at the end. This is correct.
However, the same pattern in the **DECAP** case:
```c
case RTE_CRYPTO_ML_KEM_OP_DECAP:
{
struct rte_crypto_ml_kem_decap_op *decap = &mlkem->decap;
decap->dk.length = aesni_mb_ml_kem_dk_sz(sess->asym.ml_kem.alg);
decap->cipher.length = aesni_mb_ml_kem_ct_sz(sess->asym.ml_kem.alg);
rc = imb_ml_kem_set_privkey(sess->asym.ml_kem.ctx,
decap->dk.data, decap->dk.length);
if (rc == 0)
rc = imb_ml_kem_decap(sess->asym.ml_kem.ctx,
decap->sk.data, decap->sk.length,
decap->cipher.data, decap->cipher.length,
NULL);
}
```
passes `NULL` as the last parameter to `imb_ml_kem_decap()`. If this parameter is a required output buffer (e.g., for the decapsulated shared secret), passing NULL will cause a null pointer dereference inside the library.
**Fix:** Verify the library API documentation. If the last parameter is required, allocate a buffer and populate `decap->sk` from it. If the library writes the shared secret to `decap->sk.data` directly, pass that pointer. If NULL is valid (e.g., the shared secret is written elsewhere), document why.
2. **Missing cleanup on error paths in `aesni_mb_dequeue_burst()`**
```c
if (pmd_data->asym_session_created) {
struct rte_crypto_op *tmp_dq[IMB_MAX_BURST_SIZE];
uint16_t sym_cnt = 0;
nb_submit_ops = rte_ring_dequeue_burst(qp->ingress_queue,
(void **)tmp_dq, n, NULL);
for (i = 0; i < nb_submit_ops; i++) {
if (tmp_dq[i]->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
aesni_mb_asym_process(tmp_dq[i]);
ops[processed_jobs++] = tmp_dq[i];
} else {
deqd_ops[sym_cnt++] = tmp_dq[i];
}
}
/* What remains are only symmetric ops. */
nb_submit_ops = sym_cnt;
}
```
The loop calls `aesni_mb_asym_process(tmp_dq[i])` which can set `op->status = RTE_CRYPTO_OP_STATUS_ERROR`, but the operation is still added to `ops[processed_jobs++]`. This is correct -- the operation is completed (with an error status) and returned to the caller. No leak.
### Warnings
1. **Session cleanup not called on `aesni_mb_asym_session_configure()` failure**
```c
static int
aesni_mb_asym_session_configure(IMB_MGR *mb_mgr,
void *priv_sess,
const struct rte_crypto_asym_xform *xform)
{
(void)mb_mgr;
struct aesni_mb_session *sess = (struct aesni_mb_session *) priv_sess;
int ret = 0;
sess->asym.xform_type = xform->xform_type;
switch (sess->asym.xform_type) {
case RTE_CRYPTO_ASYM_XFORM_ML_KEM:
{
/* ... key expansion ... */
ret = imb_ml_kem_new(mb_mgr, sess->asym.ml_kem.alg, &sess->asym.ml_kem.ctx);
if (ret) {
IPSEC_MB_LOG(ERR, "Failed to create ML KEM session");
return ret; // <-- early return without cleanup
}
```
If `imb_ml_kem_new()` fails, the function returns immediately without setting `sess->asym.ml_kem.ctx = NULL`. The caller (`ipsec_mb_asym_session_configure()`) does not call `aesni_mb_asym_session_clear()` on failure. If the application retries session creation and the failure was partial (e.g., library allocated some internal state before failing), the next call to `imb_ml_kem_new()` may leak or double-allocate.
**Fix:** Set `sess->asym.ml_kem.ctx = NULL` on failure, or ensure the caller invokes `aesni_mb_asym_session_clear()` on any configuration error.
2. **Missing validation of `message.length` and `seed.length`**
In `aesni_mb_asym_process()`, the ML-KEM and ML-DSA operations copy user-supplied buffer pointers and lengths directly into library parameters:
```c
sess->asym.ml_kem.encap_params.m_32 = encap->message.data;
sess->asym.ml_kem.encap_params.m_len = encap->message.length;
```
If `encap->message.length` is not exactly 32 bytes (the expected length for ML-KEM encapsulation randomness), the library will reject it or read out of bounds. The patch does not validate this.
**Fix:** Add length checks before calling the library:
```c
if (encap->message.length != 32) {
op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
return;
}
```
---
## Patch 4/4: test/crypto: add asym test suite for AESNI_MB
### Errors
None.
### Warnings
None.
---
## Summary
**Patch 1/4:**
- **2 Errors:** Use-after-free risk from storing `mb_mgr` pointer; missing error check on `IMB_AES_KEYEXP_256()`.
- **3 Warnings:** Verbose wrapper duplication; internal API signature change; pre-existing unbounded mbuf chain walk.
**Patch 2/4:**
- **0 Errors.**
- **2 Warnings:** Missing bounds check on AAD length; duplicated digest size constraint.
**warning: review has no Review-Result line, severity inferred from prose (response may be truncated)
More information about the test-report
mailing list