diff mbox series

tee: shm: fix use-after-free via temporarily dropped reference

Message ID 20180507095841.6452-1-jens.wiklander@linaro.org
State Accepted
Commit bb765d1c331f62b59049d35607ed2e365802bef9
Headers show
Series tee: shm: fix use-after-free via temporarily dropped reference | expand

Commit Message

Jens Wiklander May 7, 2018, 9:58 a.m. UTC
From: Jann Horn <jannh@google.com>


Bump the file's refcount before moving the reference into the fd table,
not afterwards. The old code could drop the file's refcount to zero for a
short moment before calling get_file() via get_dma_buf().

This code can only be triggered on ARM systems that use Linaro's OP-TEE.

Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem")
Signed-off-by: Jann Horn <jannh@google.com>

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

---
 drivers/tee/tee_shm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.17.0

Comments

Volodymyr Babchuk May 7, 2018, 2:54 p.m. UTC | #1
Hi Jens,

On 7 May 2018 at 12:58, Jens Wiklander <jens.wiklander@linaro.org> wrote:
> From: Jann Horn <jannh@google.com>

>

> Bump the file's refcount before moving the reference into the fd table,

> not afterwards. The old code could drop the file's refcount to zero for a

> short moment before calling get_file() via get_dma_buf().

>

> This code can only be triggered on ARM systems that use Linaro's OP-TEE.

>

> Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem")

> Signed-off-by: Jann Horn <jannh@google.com>

> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

Reviewed-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>


-- 
WBR Volodymyr Babchuk aka lorc [+380976646013]
mailto: vlad.babchuk@gmail.com
diff mbox series

Patch

diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 556960a1bab3..07d3be6f0780 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -360,9 +360,10 @@  int tee_shm_get_fd(struct tee_shm *shm)
 	if (!(shm->flags & TEE_SHM_DMA_BUF))
 		return -EINVAL;
 
+	get_dma_buf(shm->dmabuf);
 	fd = dma_buf_fd(shm->dmabuf, O_CLOEXEC);
-	if (fd >= 0)
-		get_dma_buf(shm->dmabuf);
+	if (fd < 0)
+		dma_buf_put(shm->dmabuf);
 	return fd;
 }