cederom commented on PR #4093:
URL: https://github.com/apache/nuttx-apps/pull/4093#issuecomment-7043765329
This is a test response from Claude:
Thanks, this is a useful test. I checked all the known-answer vectors
independently (Python `cryptography` + `hashlib`): AES-CBC 1 and 4 blocks,
SHA-256 "abc" and 256×0xaa, CMAC, GCM ciphertext/tag and GMAC tag all match.
Three things I'd like fixed before merge, then some nits.
### 1. Error paths after an async submit don't cancel the reqid
`async.c` L356 (same at L435, L514, L621)
If `async_wait_ready()` or `CIOCCRYPTRET` fails, the request is still
outstanding when we jump to `err:` and free the session. With a hardware
backend:
- the in-flight `cryptop` still has `crd_key = cse->key`, which
`CIOCFSESSION` frees, and `crp_buf`/`crp_iv` point at the caller's buffer and
the function's stack `iv[]` (only the output is copied into the kernel shadow
buffer);
- `cryptof_poll` is level-triggered on `crp_ret` being non-empty, so when
this result arrives late the next test's `poll()` returns immediately and its
`CIOCCRYPTRET` gets `EAGAIN`. One failure then shows up as several.
Suggest a small helper that sends `COP_FLAG_CANCEL` for `reqid`, called on
every error path after a successful submit (all four helpers). Optionally, loop
poll → `CIOCCRYPTRET` while it returns `EAGAIN`, so the test doesn't assume the
wakeup is for its own reqid.
### 2. "Cancel while in flight" is never exercised on sim
`async.c` L655
On software backends `cryptodev_op()` finishes the request inline through
`crypto_invoke()` → `cryptodevop_cb()`, so by the time we cancel, the result is
always already on `crp_ret`. The in-flight branch (`CRYPTO_F_CANCEL` set, the
callback discarding the result, `cryptodev_cancel_dispatch()`) is never
reached, even though it's the trickiest part of apache/nuttx#22062. Please
either say so in the comment and the commit message ("on a software backend
only the completed-result path is exercised"), or add a case that is guaranteed
to be in flight when cancelled.
### 3. `check_concurrent()` leaks threads on `pthread_create` failure
`async.c` L847
If the 2nd or 3rd `pthread_create()` fails, the threads already started are
never joined and keep writing to `wa_*` after the function returns. Also,
`pthread_create()` returns the error code and doesn't set `errno`, so `warn()`
prints a stale error. Suggest creating the threads one by one, joining whatever
started, and reporting with `warnx("pthread_create: %s", strerror(ret))`.
Minor: the workers run on `CONFIG_PTHREAD_STACK_DEFAULT`, not
`TESTING_CRYPTO_STACKSIZE`. `worker_sha` keeps ~290 bytes locally plus
`warn()`/`printf`, which may be tight on small boards.
`pthread_attr_setstacksize()` would make it deterministic.
### Nits
- `async.c` L700: reqid `0x7001` is also the reqid of the GMAC case (L933).
If GMAC times out, this cancel would match its pending request and pass for the
wrong reason. Use a distinct id, e.g. `0x8001`.
- `async.c` L27: `bool` (L549) and `uint32_t` are used, but
`<stdbool.h>`/`<stdint.h>` aren't included. They only work because other
headers pull them in.
- `async.c` L69: this is a new descriptor from `CRIOGET`, not a `CIOCCLONE`
clone. "private descriptor" would avoid confusion with `clone.c`.
- `async.c` L96: a 16-char literal into `[16]` drops the NUL. That's valid C
(and `aescbc.c` does the same), but GCC 15 warns via
`-Wunterminated-string-initialization` under `-Wextra`.
- `async.c` L885: on `async_open()` failure we return without printing
`async test failed`, so log-scraping CI sees no result line.
- `async.c` L937: the comment says "cancel a completed request", the commit
message says "in flight or already queued". Please make them agree (see 2).
- `Kconfig` L163: should this `depends on !DISABLE_PTHREAD`? It also needs
AES-GCM/CMAC/SHA-256 in the cryptodev backend (e.g.
`CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO`). Other entries don't declare backend
dependencies, so that part is optional.
- `async` is a very generic NSH command name. `cryptoasync` would be less
likely to collide.
### Related, for apache/nuttx#22062
`CIOCFSESSION` doesn't check for in-flight requests that still point at the
session's keys. Probably worth returning `EBUSY` or taking a reference there.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]