[bug report] accel/habanalabs: enforce release order of compute device and dma-buf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Tomer Tayar,

Commit 09524eb8824e ("accel/habanalabs: enforce release order of
compute device and dma-buf") from Jan 22, 2023 (linux-next), leads to
the following Smatch static checker warning:

	drivers/accel/habanalabs/common/memory.c:1844 hl_release_dmabuf()
	error: dereferencing freed memory 'ctx' (line 1841)

drivers/accel/habanalabs/common/memory.c
    1827 static void hl_release_dmabuf(struct dma_buf *dmabuf)
    1828 {
    1829         struct hl_dmabuf_priv *hl_dmabuf = dmabuf->priv;
    1830         struct hl_ctx *ctx;
    1831 
    1832         if (!hl_dmabuf)
    1833                 return;
    1834 
    1835         ctx = hl_dmabuf->ctx;
    1836 
    1837         if (hl_dmabuf->memhash_hnode)
    1838                 memhash_node_export_put(ctx, hl_dmabuf->memhash_hnode);
    1839 
    1840         atomic_dec(&ctx->hdev->dmabuf_export_cnt);
    1841         hl_ctx_put(ctx);
                            ^^^
This will free ctx on the last reference

    1842 
    1843         /* Paired with get_file() in export_dmabuf() */
--> 1844         fput(ctx->hpriv->file_priv->filp);
                      ^^^
Potential use after free

    1845 
    1846         kfree(hl_dmabuf);
    1847 }

regards,
dan carpenter



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux