From: David Laight <David.Laight@ACULAB.COM>
To: 'Pavel Skripkin' <paskripkin@gmail.com>,
Ajay Garg <ajaygargnsit@gmail.com>,
"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] tty: vt: keyboard: do not copy an extra-byte in copy_to_user
Date: Sat, 6 Nov 2021 16:40:16 +0000 [thread overview]
Message-ID: <868025b485b94480ad17d0ec971b3ee9@AcuMS.aculab.com> (raw)
In-Reply-To: <9eafae1f-d9f0-298d-cf20-212865d0becc@gmail.com>
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@gmail.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)
next prev parent reply other threads:[~2021-11-06 16:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-06 9:20 [PATCH] tty: vt: keyboard: do not copy an extra-byte in copy_to_user Ajay Garg
2021-11-06 11:23 ` Pavel Skripkin
2021-11-06 12:05 ` Ajay Garg
2021-11-06 12:39 ` Pavel Skripkin
2021-11-06 16:40 ` David Laight [this message]
2021-11-06 19:20 ` Ajay Garg
2021-11-06 19:46 ` Ajay Garg
2021-11-06 20:18 ` Pavel Skripkin
2021-11-06 20:30 ` Ajay Garg
2021-11-06 20:34 ` Pavel Skripkin
2021-11-06 20:44 ` Ajay Garg
2021-11-06 20:48 ` Pavel Skripkin
2021-11-08 8:59 ` Ajay Garg
2021-11-08 11:58 ` Pavel Skripkin
2021-11-08 12:12 ` Ajay Garg
2021-11-10 5:22 ` Jiri Slaby
2021-11-10 7:37 ` Pavel Skripkin
2021-11-10 8:57 ` Ajay Garg
2021-11-10 9:06 ` Greg KH
2021-11-10 9:32 ` Ajay Garg
2021-11-06 19:56 ` Pavel Skripkin
2021-11-06 20:07 ` Ajay Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=868025b485b94480ad17d0ec971b3ee9@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=ajaygargnsit@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=paskripkin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox