From: Pavel Skripkin <paskripkin@gmail.com>
To: Ajay Garg <ajaygargnsit@gmail.com>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tty: vt: keyboard: initialize "kbs" so that kfree(kbs) runs fine even if kbs is not kmalloced.
Date: Sat, 6 Nov 2021 14:05:12 +0300 [thread overview]
Message-ID: <dd7e35fc-d5b2-c41b-f03a-cbf467401205@gmail.com> (raw)
In-Reply-To: <20211106104053.98761-1-ajaygargnsit@gmail.com>
Hi, Ajay!
On 11/6/21 13:40, Ajay Garg wrote:
>
> v1 patch at :
> https://lore.kernel.org/linux-serial/YYZN30qfaKMskVwE@kroah.com/T/#t
>
>
> Changes in v2 :
>
> * Changes as required by scripts/checkpatch.pl
>
> * Checking whether kbs is not NULL before kfree is not required,
> as kfree(NULL) is safe. So, dropped the check.
>
>
> For brevity, here is the background :
>
>
Please, don't put change log into commit message. It should go under ---
> In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of KDGKBSENT or
> KDSKBSENT.
>
> If cmd is none of the above, kbs is not kmalloced, and runs
> direct to kfree(kbs).
>
> Values of local-variables on the stack can take indeterminate values,
> so we initialize kbs to NULL. Then, if kbs is not kmalloced, we have
> kfree(NULL) at the last.
>
> Note that kfree(NULL) is safe.
>
>
These is only one caller of vt_do_kdgkb_ioctl, which simple does:
case KDGKBSENT:
case KDSKBSENT:
return vt_do_kdgkb_ioctl(cmd, up, perm);
It means, that cmd can not be different from KDGKBSENT and KDSKBSENT.
I guess, you found this "issue" via static analysis tool like smatch or
smth similar, but this bug is impossible right now.
>
> Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
> ---
<--- here
> 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 dfef7de8a057..54155fc91cd2 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> {
> unsigned char kb_func;
> unsigned long flags;
> - char *kbs;
> + char *kbs = NULL;
> int ret;
>
> if (get_user(kb_func, &user_kdgkb->kb_func))
>
With regards,
Pavel Skripkin
next prev parent reply other threads:[~2021-11-06 11:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-06 10:40 [PATCH v2] tty: vt: keyboard: initialize "kbs" so that kfree(kbs) runs fine even if kbs is not kmalloced Ajay Garg
2021-11-06 11:05 ` Pavel Skripkin [this message]
2021-11-06 12:16 ` Ajay Garg
2021-11-06 12:45 ` Pavel Skripkin
2021-11-06 18:35 ` Andy Shevchenko
2021-11-06 18:59 ` Ajay Garg
[not found] ` <CAHp75VcZArNXhY2T5RmSmrFrAvd4YGRfpByBb4hYLccNwGDyVA@mail.gmail.com>
2021-11-06 22:06 ` 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=dd7e35fc-d5b2-c41b-f03a-cbf467401205@gmail.com \
--to=paskripkin@gmail.com \
--cc=ajaygargnsit@gmail.com \
--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