|
|
80913e |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
80913e |
From: Daniel Axtens <dja@axtens.net>
|
|
|
80913e |
Date: Fri, 22 Jan 2021 16:07:29 +1100
|
|
|
80913e |
Subject: [PATCH] lib/arg: Block repeated short options that require an
|
|
|
80913e |
argument
|
|
|
80913e |
|
|
|
80913e |
Fuzzing found the following crash:
|
|
|
80913e |
|
|
|
80913e |
search -hhhhhhhhhhhhhf
|
|
|
80913e |
|
|
|
80913e |
We didn't allocate enough option space for 13 hints because the
|
|
|
80913e |
allocation code counts the number of discrete arguments (i.e. argc).
|
|
|
80913e |
However, the shortopt parsing code will happily keep processing
|
|
|
80913e |
a combination of short options without checking if those short
|
|
|
80913e |
options require an argument. This means you can easily end writing
|
|
|
80913e |
past the allocated option space.
|
|
|
80913e |
|
|
|
80913e |
This fixes a OOB write which can cause heap corruption.
|
|
|
80913e |
|
|
|
80913e |
Fixes: CVE-2021-20225
|
|
|
80913e |
|
|
|
80913e |
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
|
|
80913e |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
80913e |
---
|
|
|
80913e |
grub-core/lib/arg.c | 13 +++++++++++++
|
|
|
80913e |
1 file changed, 13 insertions(+)
|
|
|
80913e |
|
|
|
80913e |
diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c
|
|
|
b32e65 |
index 3288609a5..537c5e94b 100644
|
|
|
80913e |
--- a/grub-core/lib/arg.c
|
|
|
80913e |
+++ b/grub-core/lib/arg.c
|
|
|
80913e |
@@ -299,6 +299,19 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|
|
80913e |
it can have an argument value. */
|
|
|
80913e |
if (*curshort)
|
|
|
80913e |
{
|
|
|
80913e |
+ /*
|
|
|
80913e |
+ * Only permit further short opts if this one doesn't
|
|
|
80913e |
+ * require a value.
|
|
|
80913e |
+ */
|
|
|
80913e |
+ if (opt->type != ARG_TYPE_NONE &&
|
|
|
80913e |
+ !(opt->flags & GRUB_ARG_OPTION_OPTIONAL))
|
|
|
80913e |
+ {
|
|
|
80913e |
+ grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
80913e |
+ N_("missing mandatory option for `%s'"),
|
|
|
80913e |
+ opt->longarg);
|
|
|
80913e |
+ goto fail;
|
|
|
80913e |
+ }
|
|
|
80913e |
+
|
|
|
80913e |
if (parse_option (cmd, opt, 0, usr) || grub_errno)
|
|
|
80913e |
goto fail;
|
|
|
80913e |
}
|