|
|
80913e |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
80913e |
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
|
|
|
80913e |
Date: Tue, 7 Jul 2020 15:12:25 -0400
|
|
|
80913e |
Subject: [PATCH] term: Fix overflow on user inputs
|
|
|
80913e |
|
|
|
80913e |
This requires a very weird input from the serial interface but can cause
|
|
|
80913e |
an overflow in input_buf (keys) overwriting the next variable (npending)
|
|
|
80913e |
with the user choice:
|
|
|
80913e |
|
|
|
80913e |
(pahole output)
|
|
|
80913e |
|
|
|
80913e |
struct grub_terminfo_input_state {
|
|
|
80913e |
int input_buf[6]; /* 0 24 */
|
|
|
80913e |
int npending; /* 24 4 */ <- CORRUPT
|
|
|
80913e |
...snip...
|
|
|
80913e |
|
|
|
80913e |
The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow
|
|
|
80913e |
npending with "q" (aka increase npending to 161). The simplest fix is to
|
|
|
80913e |
just to disallow overwrites input_buf, which exactly what this patch does.
|
|
|
80913e |
|
|
|
80913e |
Fixes: CID 292449
|
|
|
80913e |
|
|
|
80913e |
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
|
|
|
80913e |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
80913e |
Upstream-commit-id: 98dfa546777
|
|
|
80913e |
---
|
|
|
80913e |
grub-core/term/terminfo.c | 9 ++++++---
|
|
|
80913e |
1 file changed, 6 insertions(+), 3 deletions(-)
|
|
|
80913e |
|
|
|
80913e |
diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
|
|
|
80913e |
index 537a5c0cb0b..44d0b3b19fb 100644
|
|
|
80913e |
--- a/grub-core/term/terminfo.c
|
|
|
80913e |
+++ b/grub-core/term/terminfo.c
|
|
|
80913e |
@@ -398,7 +398,7 @@ grub_terminfo_getwh (struct grub_term_output *term)
|
|
|
80913e |
}
|
|
|
80913e |
|
|
|
80913e |
static void
|
|
|
80913e |
-grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
|
|
|
80913e |
+grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int max_len,
|
|
|
80913e |
int (*readkey) (struct grub_term_input *term))
|
|
|
80913e |
{
|
|
|
80913e |
int c;
|
|
|
80913e |
@@ -414,6 +414,9 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
|
|
|
80913e |
if (c == -1) \
|
|
|
80913e |
return; \
|
|
|
80913e |
\
|
|
|
80913e |
+ if (*len >= max_len) \
|
|
|
80913e |
+ return; \
|
|
|
80913e |
+ \
|
|
|
80913e |
keys[*len] = c; \
|
|
|
80913e |
(*len)++; \
|
|
|
80913e |
}
|
|
|
80913e |
@@ -602,8 +605,8 @@ grub_terminfo_getkey (struct grub_term_input *termi)
|
|
|
80913e |
return ret;
|
|
|
80913e |
}
|
|
|
80913e |
|
|
|
80913e |
- grub_terminfo_readkey (termi, data->input_buf,
|
|
|
80913e |
- &data->npending, data->readkey);
|
|
|
80913e |
+ grub_terminfo_readkey (termi, data->input_buf, &data->npending,
|
|
|
80913e |
+ GRUB_TERMINFO_READKEY_MAX_LEN, data->readkey);
|
|
|
80913e |
|
|
|
80913e |
#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
|
|
|
80913e |
if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC
|