[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <868025b485b94480ad17d0ec971b3ee9@AcuMS.aculab.com>
Date: Sat, 6 Nov 2021 16:40:16 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Pavel Skripkin' <paskripkin@...il.com>,
Ajay Garg <ajaygargnsit@...il.com>,
"linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] tty: vt: keyboard: do not copy an extra-byte in
copy_to_user
From: Pavel Skripkin
> Sent: 06 November 2021 11:24
>
> Hi, Ajay!
>
> On 11/6/21 12:20, Ajay Garg wrote:
> > Both (statically-allocated) "user_kdgkb->kb_string" and
> > (dynamically-allocated) "kbs" are of length "len", so we must
> > not copy more than "len" bytes.
> >
> > Signed-off-by: Ajay Garg <ajaygargnsit@...il.com>
> > ---
> > drivers/tty/vt/keyboard.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> > index c7fbbcdcc346..dfef7de8a057 100644
> > --- a/drivers/tty/vt/keyboard.c
> > +++ b/drivers/tty/vt/keyboard.c
> > @@ -2070,7 +2070,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> > len = strlcpy(kbs, func_table[kb_func] ? : "", len);
>
> ^^^^^^^^^
>
> len is reinitialized here, i.e len passed to kmalloc and len passed to
> copy_to_user() can be different.
>
> strlcpy() returns strlen() of source string (2nd argument), that's why
> we need +1 here to pass null byte to user.
>
> Am I missing something?
You want strscpy() - returns the number of characters/bytes it copied.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists