Re: [PATCH] tee: add overflow check in tee_ioctl_shm_register()

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

 



On Mon, Aug 22, 2022 at 03:12:27PM +0200, Jens Wiklander wrote:
> 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")
> Cc: stable@xxxxxxxxxxxxxxx # 5.4
> Cc: stable@xxxxxxxxxxxxxxx # 5.10
> Reported-by: Nimish Mishra <neelam.nimish@xxxxxxxxx>
> Reported-by: Anirban Chakraborty <ch.anirban00727@xxxxxxxxx>
> Reported-by: Debdeep Mukhopadhyay <debdeep.mukhopadhyay@xxxxxxxxx>
> Suggested-by: Jerome Forissier <jerome.forissier@xxxxxxxxxx>
> Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> [JW: backport to stable 5.4 and 5.10 + update commit message]

You already sent me a 5.4 version here:
	https://lore.kernel.org/r/20220822092621.3691771-1-jens.wiklander@xxxxxxxxxx

And I applied that.

And for 5.10, it's already in the tree as commit 578c349570d2 ("tee: add
overflow check in register_shm_helper()") and was in the 5.10.137
release.

> Signed-off-by: Jens Wiklander <jens.wiklander@xxxxxxxxxx>
> ---
>  drivers/tee/tee_core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
> index a7ccd4d2bd10..2db144d2d26f 100644
> --- a/drivers/tee/tee_core.c
> +++ b/drivers/tee/tee_core.c
> @@ -182,6 +182,9 @@ tee_ioctl_shm_register(struct tee_context *ctx,
>  	if (data.flags)
>  		return -EINVAL;
>  
> +	if (!access_ok((void __user *)(unsigned long)data.addr, data.length))
> +		return -EFAULT;

What I took in 5.10.137 was:

+       if (!access_ok((void __user *)addr, length))
+               return ERR_PTR(-EFAULT);

Should I fix it up to look like what you sent here instead?

confused,

greg k-h



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux