On Thu, Nov 02, 2023 at 08:21:35PM +0100, Philipp Stanner wrote: > The functions (v)memdup_user() are utilized to copy userspace arrays. > This is done without overflow checks. > > Use the new wrappers memdup_array_user() and vmemdup_array_user() to > copy the arrays more safely. > @@ -644,7 +644,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) > if (!ct) > return 0; > - unilist = vmemdup_user(list, array_size(sizeof(*unilist), ct)); > + unilist = vmemdup_array_user(list, ct, sizeof(*unilist)); > if (IS_ERR(unilist)) > return PTR_ERR(unilist); a 16bit value times sizeof(something). > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index 1fe6107b539b..802ceb0a5e4c 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -1773,8 +1773,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) ... and here we have if (ct >= MAX_DIACR) return -EINVAL; directly upstream, so it's even better - a value below 256 times sizeof(something) > if (ct) { > > - dia = memdup_user(a->kbdiacr, > - sizeof(struct kbdiacr) * ct); > + dia = memdup_array_user(a->kbdiacr, > + ct, sizeof(struct kbdiacr)); > if (IS_ERR(dia)) > return PTR_ERR(dia); > > @@ -1811,8 +1811,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) > return -EINVAL; Ditto. > if (ct) { > - buf = memdup_user(a->kbdiacruc, > - ct * sizeof(struct kbdiacruc)); > + buf = memdup_array_user(a->kbdiacruc, > + ct, sizeof(struct kbdiacruc));