Skip to content

Commit 8742b2d

Browse files
committed
Merge tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull habanalabs fix from Al Viro: "Yet another use-after-free fix due to dma_buf_fd() misuse" * tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: habanalabs: fix UAF in export_dmabuf()
2 parents 0e39a73 + 33927f3 commit 8742b2d

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

drivers/accel/habanalabs/common/memory.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,6 @@ static void hl_release_dmabuf(struct dma_buf *dmabuf)
18291829
struct hl_dmabuf_priv *hl_dmabuf = dmabuf->priv;
18301830
struct hl_ctx *ctx;
18311831

1832-
if (!hl_dmabuf)
1833-
return;
1834-
18351832
ctx = hl_dmabuf->ctx;
18361833

18371834
if (hl_dmabuf->memhash_hnode)
@@ -1859,7 +1856,12 @@ static int export_dmabuf(struct hl_ctx *ctx,
18591856
{
18601857
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
18611858
struct hl_device *hdev = ctx->hdev;
1862-
int rc, fd;
1859+
CLASS(get_unused_fd, fd)(flags);
1860+
1861+
if (fd < 0) {
1862+
dev_err(hdev->dev, "failed to get a file descriptor for a dma-buf, %d\n", fd);
1863+
return fd;
1864+
}
18631865

18641866
exp_info.ops = &habanalabs_dmabuf_ops;
18651867
exp_info.size = total_size;
@@ -1872,13 +1874,6 @@ static int export_dmabuf(struct hl_ctx *ctx,
18721874
return PTR_ERR(hl_dmabuf->dmabuf);
18731875
}
18741876

1875-
fd = dma_buf_fd(hl_dmabuf->dmabuf, flags);
1876-
if (fd < 0) {
1877-
dev_err(hdev->dev, "failed to get a file descriptor for a dma-buf, %d\n", fd);
1878-
rc = fd;
1879-
goto err_dma_buf_put;
1880-
}
1881-
18821877
hl_dmabuf->ctx = ctx;
18831878
hl_ctx_get(hl_dmabuf->ctx);
18841879
atomic_inc(&ctx->hdev->dmabuf_export_cnt);
@@ -1890,13 +1885,9 @@ static int export_dmabuf(struct hl_ctx *ctx,
18901885
get_file(ctx->hpriv->file_priv->filp);
18911886

18921887
*dmabuf_fd = fd;
1888+
fd_install(take_fd(fd), hl_dmabuf->dmabuf->file);
18931889

18941890
return 0;
1895-
1896-
err_dma_buf_put:
1897-
hl_dmabuf->dmabuf->priv = NULL;
1898-
dma_buf_put(hl_dmabuf->dmabuf);
1899-
return rc;
19001891
}
19011892

19021893
static int validate_export_params_common(struct hl_device *hdev, u64 addr, u64 size, u64 offset)

0 commit comments

Comments
 (0)