Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] accel/qaic: memory leak in encode_activate() [1]
--

commit 48133c97c10bb67d1f23799c52aaf49134fd456e
Author: Haoxiang Li <[email protected]>

accel/qaic: Free the DBC buffer on management transfer errors

This commit frees the DBC buffer allocated during message encoding when
a management transfer fails in qaic_manage_msg_xfer().

> diff --git a/drivers/accel/qaic/qaic_control.c 
> b/drivers/accel/qaic/qaic_control.c
> index 2ccc55486aac0..f322887ec53e8 100644
> --- a/drivers/accel/qaic/qaic_control.c
> +++ b/drivers/accel/qaic/qaic_control.c
> @@ -1250,6 +1250,8 @@ static int qaic_manage_msg_xfer(struct qaic_device 
> *qdev, struct qaic_user *usr,
>  
>  lock_failed:
>       free_dma_xfers(qdev, resources);
> +     if (ret)
> +             free_dbc_buf(qdev, resources);
>  encode_failed:
>       spin_lock(&wrappers->lock);
>       list_for_each_entry_safe(wrapper, w, &wrappers->list, list)

[Severity: High]
This problem wasn't introduced by this patch, but can encode_activate()
leak the DMA buffer in resources->buf [1] when a management message
contains more than one QAIC_TRANS_ACTIVATE_FROM_USR transaction?

encode_message() loops over user_msg->count transactions and calls
encode_activate() for each QAIC_TRANS_ACTIVATE_FROM_USR entry.  Each call
allocates a coherent DMA buffer and overwrites resources->buf and
resources->dma_addr without checking whether a buffer was already
allocated for an earlier transaction in the same ioctl:

drivers/accel/qaic/qaic_control.c:encode_activate() {
        ...
        buf = dma_alloc_coherent(&qdev->pdev->dev, size, &dma_addr, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
        ...
        resources->buf = buf;
        resources->dma_addr = dma_addr;
        ...
}

Any earlier allocation in the same message is lost and cannot be freed by
free_dbc_buf(), allowing userspace to exhaust coherent DMA memory.

[1] https://sashiko.dev/#/bug/linux-ad70f5f2-e579-4654-84f6-691a5c89ecc1

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to