Re: [PATCH] tty: vt: add a bounds checking in vt_do_kdgkb_ioctl()
From: Greg KH
Date: Thu Sep 08 2022 - 04:16:29 EST
On Thu, Sep 08, 2022 at 03:54:03PM +0800, Hangyu Hua wrote:
> As array_index_nospec's comments indicate,a bounds checking need to add
> before calling array_index_nospec.
>
> Signed-off-by: Hangyu Hua <hbh25y@xxxxxxxxx>
> ---
> drivers/tty/vt/keyboard.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index be8313cdbac3..b9845455df79 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -2067,6 +2067,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> if (get_user(kb_func, &user_kdgkb->kb_func))
> return -EFAULT;
>
> + if (kb_func >= MAX_NR_FUNC)
> + return -EFAULT;
Wrong error to return, only ever return that error if you have a memory
fault from copy_to/from_user().
But even then, how can kb_func ever be greater than MAX_NR_FUNC? And
what is wrong with it being MAX_NR_FUNC?
> +
> kb_func = array_index_nospec(kb_func, MAX_NR_FUNC);
Maybe we really don't need this at all, right?
thanks,
greg k-h