Skip to contentSkip to conversation

tee: add overflow check in tee_ioctl_shm_register()

PATCH In review Jens Wiklander 2 participants 2 messages Aug 22, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tee: add overflow check in tee_ioctl_shm_register()

commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream.

With special lengths supplied by user space, tee_shm_register() has an integer overflow when calculating the number of pages covered by a supplied user space memory region.

This may cause pin_user_pages_fast() to do a NULL pointer dereference.

Fix this by adding an an explicit call to access_ok() in tee_ioctl_shm_register() to catch an invalid user space address early.

Fixes 033ddf12bcf5 ("tee: add register user memory")
[JW: backport to stable-4.19 + update commit message]
---
 drivers/tee/tee_core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tee/tee_core.c +4 -0
index d42fc2ae8592..e568cb4b2ffc 100644
@@ -175,6 +175,10 @@ tee_ioctl_shm_register(struct tee_context *ctx,
 	if (data.flags)
 		return -EINVAL;
 
+	if (!access_ok(VERIFY_WRITE, (void __user *)(unsigned long)data.addr,
+		       data.length))
+		return -EFAULT;
+
 	shm = tee_shm_register(ctx, data.addr, data.length,
 			       TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED);
 	if (IS_ERR(shm))
Signature · 1 line
2.31.1
#1 lore raw
Quoted 42 lines · Jens Wiklander

commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream.

With special lengths supplied by user space, tee_shm_register() has an integer overflow when calculating the number of pages covered by a supplied user space memory region.

This may cause pin_user_pages_fast() to do a NULL pointer dereference.

Fix this by adding an an explicit call to access_ok() in tee_ioctl_shm_register() to catch an invalid user space address early.

Fixes 033ddf12bcf5 ("tee: add register user memory")
[JW: backport to stable-4.19 + update commit message]
---
 drivers/tee/tee_core.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tee/tee_core.c +4 -0
index d42fc2ae8592..e568cb4b2ffc 100644
@@ -175,6 +175,10 @@ tee_ioctl_shm_register(struct tee_context *ctx,
 	if (data.flags)
 		return -EINVAL;
 
+	if (!access_ok(VERIFY_WRITE, (void __user *)(unsigned long)data.addr,
+		       data.length))
+		return -EFAULT;
+
 	shm = tee_shm_register(ctx, data.addr, data.length,
 			       TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED);
 	if (IS_ERR(shm))
Signature · 1 line
2.31.1

Now queued up, thanks.

greg k-h