Re: [PATCH v2 11/20] kasan: add and integrate kasan boot parameters

From: Marco Elver
Date: Fri Nov 13 2020 - 12:55:22 EST


On Fri, Nov 13, 2020 at 06:52PM +0100, Marco Elver wrote:
> On Tue, Nov 10, 2020 at 11:20PM +0100, 'Andrey Konovalov' via kasan-dev wrote:
> [...]
> > +/* kasan.mode=off/prod/full */
> > +static int __init early_kasan_mode(char *arg)
> > +{
> > + if (!arg)
> > + return -EINVAL;
> > +
> > + if (!strcmp(arg, "off"))
> > + kasan_arg_mode = KASAN_ARG_MODE_OFF;
> > + else if (!strcmp(arg, "prod"))
> > + kasan_arg_mode = KASAN_ARG_MODE_PROD;
> > + else if (!strcmp(arg, "full"))
> > + kasan_arg_mode = KASAN_ARG_MODE_FULL;
> > + else
> > + return -EINVAL;
> > +
> > + return 0;
> > +}
> > +early_param("kasan.mode", early_kasan_mode);
> > +
> > +/* kasan.stack=off/on */
> > +static int __init early_kasan_flag_stacktrace(char *arg)
> > +{
> > + if (!arg)
> > + return -EINVAL;
> > +
> > + if (!strcmp(arg, "off"))
> > + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_OFF;
> > + else if (!strcmp(arg, "on"))
> > + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_ON;
> > + else
> > + return -EINVAL;
> > +
> > + return 0;
> > +}
> > +early_param("kasan.stacktrace", early_kasan_flag_stacktrace);
> > +
> > +/* kasan.fault=report/panic */
> > +static int __init early_kasan_fault(char *arg)
> > +{
> > + if (!arg)
> > + return -EINVAL;
> > +
> > + if (!strcmp(arg, "report"))
> > + kasan_arg_fault = KASAN_ARG_FAULT_REPORT;
> > + else if (!strcmp(arg, "panic"))
> > + kasan_arg_fault = KASAN_ARG_FAULT_PANIC;
> > + else
> > + return -EINVAL;
> > +
> > + return 0;
> > +}
> [...]
>
> The above could be simplified, see suggestion below.
>
> Thanks,
> -- Marco
>
> ------ >8 ------
>
> diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c
> index c91f2c06ecb5..71fc481ad21d 100644
> --- a/mm/kasan/hw_tags.c
> +++ b/mm/kasan/hw_tags.c
> @@ -64,10 +64,8 @@ static int __init early_kasan_mode(char *arg)
> kasan_arg_mode = KASAN_ARG_MODE_PROD;
> else if (!strcmp(arg, "full"))
> kasan_arg_mode = KASAN_ARG_MODE_FULL;
> - else
> - return -EINVAL;
>
> - return 0;
> + return -EINVAL;

Ah that clearly doesn't work. Hmm, never mind this suggestion, sorry.

Thanks,
-- Marco