* [PATCH] tty: vt: keyboard: add range check to kbs->kb_func index
@ 2017-09-20 21:38 Colin King
2017-09-20 23:40 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-09-20 21:38 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Ingo Molnar; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
A value outside the range 0..MAX_NR_FUNC-1 in kbs->kb_func will
cause an array bounds overflow on func_table. Fix this by adding
a range check.
Detected by CoverityScan, CID#401961 ("Untrusted array index read")
Fixes: 079c9534a96d ("vt:tackle kbd_table")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/tty/vt/keyboard.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index f4166263bb3a..1ecf545a96a8 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1982,6 +1982,11 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
i = kbs->kb_func;
+ if (i < 0 || i >= MAX_NR_FUNC) {
+ ret = -EINVAL;
+ goto reterr;
+ }
+
switch (cmd) {
case KDGKBSENT:
sz = sizeof(kbs->kb_string) - 1; /* sz should have been
--
2.14.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] tty: vt: keyboard: add range check to kbs->kb_func index
2017-09-20 21:38 [PATCH] tty: vt: keyboard: add range check to kbs->kb_func index Colin King
@ 2017-09-20 23:40 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2017-09-20 23:40 UTC (permalink / raw)
To: Colin King
Cc: Greg Kroah-Hartman, Jiri Slaby, Ingo Molnar, kernel-janitors,
linux-kernel
On Wed, Sep 20, 2017 at 10:38:28PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> A value outside the range 0..MAX_NR_FUNC-1 in kbs->kb_func will
> cause an array bounds overflow on func_table. Fix this by adding
> a range check.
>
> Detected by CoverityScan, CID#401961 ("Untrusted array index read")
>
> Fixes: 079c9534a96d ("vt:tackle kbd_table")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/tty/vt/keyboard.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index f4166263bb3a..1ecf545a96a8 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -1982,6 +1982,11 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
> i = kbs->kb_func;
>
> + if (i < 0 || i >= MAX_NR_FUNC) {
kbs->kb_func is an unsigned char and MAX_NR_FUNC is 256 so this check
will never be true.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-20 23:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 21:38 [PATCH] tty: vt: keyboard: add range check to kbs->kb_func index Colin King
2017-09-20 23:40 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®