Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] accel/amdxdna: missing Fixes trailers for 71829d7f2f70 and 3a0ff7b98af4 --
commit 9793e7703171a10921840797a04510b39e48e1d3 Author: Bilal Hashim <[email protected]> > accel/amdxdna: Fix NULL pointer dereference and u32 underflow in aie2_message > > amdxdna_cmd_get_payload() returns NULL and sets *size = 0 when the > user-supplied command header in the shared command BO has an invalid > AMDXDNA_CMD_COUNT (for example, count <= num_masks or exceeding the BO > size), or if amdxdna_gem_vmap() fails. > > However, the eight command payload helpers in aie2_message.c do not > check the return value of amdxdna_cmd_get_payload() for NULL before > dereferencing it or passing it to memcpy(): > > 1. In aie2_init_exec_dpu_req(): > - `if (cmd_len - sizeof(*sn) > sizeof(dpu_req->payload))` performs an > unsigned 32-bit subtraction (`u32 cmd_len - sizeof(*sn)`). If > `cmd_len < sizeof(*sn)` (for instance, `cmd_len == 4`), on 64-bit > architectures `sizeof(*sn)` is `size_t`, so `(size_t)cmd_len - > sizeof(*sn)` wraps around and is rejected, unless `cmd_len` is 0 > (when `sn == NULL`) or if `sn` is dereferenced when `cmd_len` is > valid for the check on 32-bit platforms. More importantly, when > `cmd_len < sizeof(*sn)` or `sn == NULL`, `cmd_len < sizeof(*sn)` > is not explicitly checked first. > 2. In aie2_init_exec_cu_req(), aie2_cmdlist_fill_cf(), and > aie2_cmdlist_fill_npu_cf(): > - When `amdxdna_cmd_get_payload()` returns `NULL` with `cmd_len == 0`, > the size check (`cmd_len > ...` or `*size < sizeof(...) + cmd_len`) > passes, and if `amdxdna_cmd_get_cu_idx()` succeeds (because the CU > mask word in the command BO is non-zero), `cmd` (`NULL`) is passed > to `memcpy()`, or in future/non-zero paths dereferenced directly. > 3. Similarly, in aie2_cmdlist_fill_dpu(), aie2_cmdlist_fill_npu_dpu(), > aie2_cmdlist_fill_npu_preempt(), and aie2_cmdlist_fill_npu_elf(), > checking `!sn` / `!pd` right after `amdxdna_cmd_get_payload()` makes > the error handling explicit and consistent with > aie2_cmdlist_multi_execbuf(). > > Add explicit NULL checks after every amdxdna_cmd_get_payload() call and > check `cmd_len < sizeof(*sn)` in aie2_init_exec_dpu_req() before > subtracting `sizeof(*sn)`. > > Signed-off-by: Bilal Hashim <[email protected]> [Severity: Low] 71829d7f2f70 ("accel/amdxdna: Use MSG_OP_CHAIN_EXEC_NPU when supported") dropped the NULL payload checks when refactoring the CF, DPU, and NPU helpers, and 3a0ff7b98af4 ("accel/amdxdna: Support preemption requests") added aie2_cmdlist_fill_npu_preempt() and aie2_cmdlist_fill_npu_elf() without them. Should this include: Fixes: 71829d7f2f70 ("accel/amdxdna: Use MSG_OP_CHAIN_EXEC_NPU when supported") Fixes: 3a0ff7b98af4 ("accel/amdxdna: Support preemption requests") -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
