Patch "misc: fastrpc: avoid double fput() on failed usercopy" has been added to the 5.4-stable tree

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

 



This is a note to let you know that I've just added the patch titled

    misc: fastrpc: avoid double fput() on failed usercopy

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     misc-fastrpc-avoid-double-fput-on-failed-usercopy.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 501781f1f49e5a7ce1b6979561854cce8548edbb
Author: Mathias Krause <minipli@xxxxxxxxxxxxxx>
Date:   Thu Jan 27 14:02:18 2022 +0100

    misc: fastrpc: avoid double fput() on failed usercopy
    
    [ Upstream commit 46963e2e0629cb31c96b1d47ddd89dc3d8990b34 ]
    
    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: 6cffd79504ce ("misc: fastrpc: Add support for dmabuf exporter")
    Acked-by: Christian König <christian.koenig@xxxxxxx>
    Signed-off-by: Mathias Krause <minipli@xxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220127130218.809261-1-minipli@xxxxxxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index f76c64084f4b2..fb5ddf3864fdd 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1245,7 +1245,14 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
 	}
 
 	if (copy_to_user(argp, &bp, sizeof(bp))) {
-		dma_buf_put(buf->dmabuf);
+		/*
+		 * The usercopy failed, but we can't do much about it, as
+		 * dma_buf_fd() already called fd_install() and made the
+		 * file descriptor accessible for the current process. It
+		 * might already be closed and dmabuf no longer valid when
+		 * we reach this point. Therefore "leak" the fd and rely on
+		 * the process exit path to do any required cleanup.
+		 */
 		return -EFAULT;
 	}
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux