[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 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> Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- V2: - replaced literal 8 by BITS_PER_BYTE (Wei Liu) - added test for empty string to parse_bool() --- xen/common/kernel.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/xen/common/kernel.c b/xen/common/kernel.c index ce7cb8adb5..756380be5b 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 * BITS_PER_BYTE; + 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); } } @@ -176,7 +200,8 @@ int __init parse_bool(const char *s) !strcmp("on", s) || !strcmp("true", s) || !strcmp("enable", s) || - !strcmp("1", s) ) + !strcmp("1", s) || + !*s ) return 1; return -1; -- 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 |