|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 39/52] xen: check parameter validity when parsing command line
Where possible check validity of parameters in _cmdline_parse() and
issue a warning message in case of an error detected.
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Tim Deegan <tim@xxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
xen/common/kernel.c | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index ce7cb8adb5..3fd3abe79c 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -23,9 +23,11 @@ enum system_state system_state = SYS_STATE_early_boot;
xen_commandline_t saved_cmdline;
static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
-static void __init assign_integer_param(
+static int __init assign_integer_param(
const struct kernel_param *param, uint64_t val)
{
+ unsigned int bits = param->len * 8;
+
switch ( param->len )
{
case sizeof(uint8_t):
@@ -43,14 +45,17 @@ static void __init assign_integer_param(
default:
BUG();
}
+
+ return ( (val & (~0ULL << bits)) && ~(val | (~0ULL >> (65 - bits))) ) ?
+ -EOVERFLOW : 0;
}
static void __init _cmdline_parse(const char *cmdline)
{
char opt[128], *optval, *optkey, *q;
- const char *p = cmdline;
+ const char *p = cmdline, *s;
const struct kernel_param *param;
- int bool_assert;
+ int bool_assert, rc = 0;
for ( ; ; )
{
@@ -97,8 +102,9 @@ static void __init _cmdline_parse(const char *cmdline)
!strncmp(param->name, opt, q + 1 - opt) )
{
optval[-1] = '=';
- ((void (*)(const char *))param->var)(q);
+ rc = ((int (*)(const char *))param->var)(q);
optval[-1] = '\0';
+ break;
}
continue;
}
@@ -106,24 +112,34 @@ static void __init _cmdline_parse(const char *cmdline)
switch ( param->type )
{
case OPT_STR:
+ rc = 0;
strlcpy(param->var, optval, param->len);
break;
case OPT_UINT:
- assign_integer_param(
+ rc = assign_integer_param(
param,
- simple_strtoll(optval, NULL, 0));
+ simple_strtoll(optval, &s, 0));
+ if ( *s )
+ rc = -EINVAL;
break;
case OPT_BOOL:
- if ( !parse_bool(optval) )
+ rc = parse_bool(optval);
+ if ( rc == -1 )
+ break;
+ if ( !rc )
bool_assert = !bool_assert;
+ rc = 0;
assign_integer_param(param, bool_assert);
break;
case OPT_SIZE:
- assign_integer_param(
+ rc = assign_integer_param(
param,
- parse_size_and_unit(optval, NULL));
+ parse_size_and_unit(optval, &s));
+ if ( *s )
+ rc = -EINVAL;
break;
case OPT_CUSTOM:
+ rc = -EINVAL;
if ( !bool_assert )
{
if ( *optval )
@@ -131,13 +147,21 @@ static void __init _cmdline_parse(const char *cmdline)
safe_strcpy(opt, "no");
optval = opt;
}
- ((void (*)(const char *))param->var)(optval);
+ rc = ((int (*)(const char *))param->var)(optval);
break;
default:
BUG();
break;
}
+
+ break;
}
+
+ if ( rc )
+ printk("parameter \"%s\" has invalid value \"%s\"!\n", optkey,
+ optval);
+ if ( param >= __setup_end )
+ printk("parameter \"%s\" unknown!\n", optkey);
}
}
--
2.12.3
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |