Skip to content

Commit 46963e2

Browse files
minipli-ossgregkh
authored andcommitted
misc: fastrpc: avoid double fput() on failed usercopy
If the copy back to userland fails for the FASTRPC_IOCTL_ALLOC_DMA_BUFF ioctl(), we shouldn't assume that 'buf->dmabuf' is still valid. In fact, dma_buf_fd() called fd_install() before, i.e. "consumed" one reference, leaving us with none. Calling dma_buf_put() will therefore put a reference we no longer own, leading to a valid file descritor table entry for an already released 'file' object which is a straight use-after-free. Simply avoid calling dma_buf_put() and rely on the process exit code to do the necessary cleanup, if needed, i.e. if the file descriptor is still valid. Fixes: 6cffd79 ("misc: fastrpc: Add support for dmabuf exporter") Acked-by: Christian König <[email protected]> Signed-off-by: Mathias Krause <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 26291c5 commit 46963e2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/misc/fastrpc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,14 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
12881288
}
12891289

12901290
if (copy_to_user(argp, &bp, sizeof(bp))) {
1291-
dma_buf_put(buf->dmabuf);
1291+
/*
1292+
* The usercopy failed, but we can't do much about it, as
1293+
* dma_buf_fd() already called fd_install() and made the
1294+
* file descriptor accessible for the current process. It
1295+
* might already be closed and dmabuf no longer valid when
1296+
* we reach this point. Therefore "leak" the fd and rely on
1297+
* the process exit path to do any required cleanup.
1298+
*/
12921299
return -EFAULT;
12931300
}
12941301

0 commit comments

Comments
 (0)