public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Skripkin <paskripkin@gmail.com>
To: Ajay Garg <ajaygargnsit@gmail.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	jirislaby@kernel.org, kernel@esmil.dk,
	David Laight <David.Laight@aculab.com>
Cc: "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 23:18:27 +0300	[thread overview]
Message-ID: <6b58a3e1-f2ea-cc4c-03b2-06334b559373@gmail.com> (raw)
In-Reply-To: <CAHP4M8UcZ=ttB8jbN1yOY6YH8SiQ27NhdEKi9SDH1CWG-GY6eg@mail.gmail.com>

On 11/6/21 22:46, Ajay Garg wrote:
> Actually, on further thoughts, even David's solution will require an
> extra check, if -E2BIG is returned.
> 
> So, I guess the solution suggested by me looks the best
> (https://lore.kernel.org/linux-serial/868025b485b94480ad17d0ec971b3ee9@AcuMS.aculab.com/T/#m1c4aaa4347b02fd4c11ce611ff5029fcb71c37a1)
> :
> 
> 1.
> == Do not use the return value from strlcpy. ==
> 
>                  len = strlcpy(kbs, func_table[kb_func] ? : "", len);
> =>
>                  strlcpy(kbs, func_table[kb_func] ? : "", len);
> 
> 
> 2.
> == Calculate the actual length of kbs, add 1, and then copy those many
> bytes to user-buffer ==
> 
> ret = copy_to_user(user_kdgkb->kb_string, kbs, len + 1) ?
>                          -EFAULT : 0;
> =>
> ret = copy_to_user(user_kdgkb->kb_string, kbs, strlen(kbs) + 1) ?
>                          -EFAULT : 0;
> 

But isn't strlen(kbs) is guaranteed to be equal to strlcpy() return 
value in this case? As I said in previous emails,
strlen(func_table[kb_func]) < sizeof(user_kdgkb->kb_string) by design of 
this function.

Do we need extra strlen() call here? Let's see what more experienced 
people think about it :)



With regards,
Pavel Skripkin

  reply	other threads:[~2021-11-06 20:18 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
2021-11-06 19:20     ` Ajay Garg
2021-11-06 19:46       ` Ajay Garg
2021-11-06 20:18         ` Pavel Skripkin [this message]
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=6b58a3e1-f2ea-cc4c-03b2-06334b559373@gmail.com \
    --to=paskripkin@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=ajaygargnsit@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=kernel@esmil.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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