Skip to content

Commit 90d75cf

Browse files
etienne-lmsjforissier
authored andcommitted
tee: fix unbalanced context refcount in register shm from fd
Successful registration of a memory reference in the scope of a TEE content must increase the context refcount. This change adds this missing refcount increase. The context refcount is already decremented when such shm reference is freed by its owner, in tee_shm_release(), hence current unbalance refcount before this path is applied. Fixes: 02b91c7 ("tee: new ioctl to a register tee_shm from a dmabuf file descriptor") Signed-off-by: Etienne Carriere <[email protected]> Tested-by: Etienne Carriere <[email protected]> (Qemu armv7/v8) Acked-by: Jens Wiklander <[email protected]> [jf: update SHA-1 of commit in Fixes: tag after rebasing onto v4.18] Signed-off-by: Jerome Forissier <[email protected]>
1 parent 54bab7b commit 90d75cf

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/tee/tee_shm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ struct tee_shm *tee_shm_register_fd(struct tee_context *ctx, int fd)
366366
if (!tee_device_get(ctx->teedev))
367367
return ERR_PTR(-EINVAL);
368368

369+
teedev_ctx_get(ctx);
370+
369371
ref = kzalloc(sizeof(*ref), GFP_KERNEL);
370372
if (!ref) {
371373
rc = ERR_PTR(-ENOMEM);
@@ -446,6 +448,7 @@ struct tee_shm *tee_shm_register_fd(struct tee_context *ctx, int fd)
446448
dma_buf_put(ref->dmabuf);
447449
}
448450
kfree(ref);
451+
teedev_ctx_put(ctx);
449452
tee_device_put(ctx->teedev);
450453
return rc;
451454
}

0 commit comments

Comments
 (0)