linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kconfig: Sanitize make randconfig generated .config
@ 2020-01-22 10:03 Vincenzo Frascino
  2020-02-01  3:12 ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Frascino @ 2020-01-22 10:03 UTC (permalink / raw)
  To: masahiroy; +Cc: linux-kbuild, linux-kernel, vincenzo.frascino

"make randconfig" calculates the probability of a tristate option (yes,
mod, no) based on srand()/rand() and can be fed with a seed.
At the last step of randconfig some option are chosen randomly and their
tristate set based on similar mechanism.
After this passage the resulting .config is not sanitized, hence it
might result in an inconsistent set of options being selected.

This was noticed on arm64 using KCONFIG_SEED=0x40C5E904. During
randomize_choice_values() CONFIG_BIG_ENDIAN is enabled. Since CONFIG_EFI
was enabled at a previous step, and depends on !CONFIG_BIG_ENDIAN the
resulting .config is inconsistent.

Fix the issue making sure that randconfig sanitizes the generated
.config as a last step.

Cc: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
---
 scripts/kconfig/conf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 1f89bf1558ce..c0fcaa4e9762 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -654,6 +654,11 @@ int main(int ac, char **av)
 	case randconfig:
 		/* Really nothing to do in this loop */
 		while (conf_set_all_new_symbols(def_random)) ;
+		/*
+		 * .config at this point might contain
+		 * incompatible options. Sanitize it.
+		 */
+		sym_clear_all_valid();
 		break;
 	case defconfig:
 		conf_set_all_new_symbols(def_default);
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kconfig: Sanitize make randconfig generated .config
  2020-01-22 10:03 [PATCH] kconfig: Sanitize make randconfig generated .config Vincenzo Frascino
@ 2020-02-01  3:12 ` Masahiro Yamada
  2020-02-01  5:15   ` Masahiro Yamada
  2020-02-07 10:40   ` Vincenzo Frascino
  0 siblings, 2 replies; 4+ messages in thread
From: Masahiro Yamada @ 2020-02-01  3:12 UTC (permalink / raw)
  To: Vincenzo Frascino; +Cc: Linux Kbuild mailing list, Linux Kernel Mailing List

Hi.


On Wed, Jan 22, 2020 at 7:03 PM Vincenzo Frascino
<vincenzo.frascino@arm.com> wrote:
>
> "make randconfig" calculates the probability of a tristate option (yes,
> mod, no) based on srand()/rand() and can be fed with a seed.
> At the last step of randconfig some option are chosen randomly and their
> tristate set based on similar mechanism.
> After this passage the resulting .config is not sanitized, hence it
> might result in an inconsistent set of options being selected.
>
> This was noticed on arm64 using KCONFIG_SEED=0x40C5E904. During
> randomize_choice_values() CONFIG_BIG_ENDIAN is enabled. Since CONFIG_EFI
> was enabled at a previous step, and depends on !CONFIG_BIG_ENDIAN the
> resulting .config is inconsistent.
>
> Fix the issue making sure that randconfig sanitizes the generated
> .config as a last step.
>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> ---
>  scripts/kconfig/conf.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> index 1f89bf1558ce..c0fcaa4e9762 100644
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -654,6 +654,11 @@ int main(int ac, char **av)
>         case randconfig:
>                 /* Really nothing to do in this loop */
>                 while (conf_set_all_new_symbols(def_random)) ;
> +               /*
> +                * .config at this point might contain
> +                * incompatible options. Sanitize it.
> +                */
> +               sym_clear_all_valid();

Thanks for the report, but clearing
all the valid flags is a big hammer.
I do not think it is a proper fix.


I checked the code, and I noticed the root cause of
this bug.

I will send a different patch later.




>                 break;
>         case defconfig:
>                 conf_set_all_new_symbols(def_default);
> --
> 2.25.0
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kconfig: Sanitize make randconfig generated .config
  2020-02-01  3:12 ` Masahiro Yamada
@ 2020-02-01  5:15   ` Masahiro Yamada
  2020-02-07 10:40   ` Vincenzo Frascino
  1 sibling, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2020-02-01  5:15 UTC (permalink / raw)
  To: Vincenzo Frascino; +Cc: Linux Kbuild mailing list, Linux Kernel Mailing List

On Sat, Feb 1, 2020 at 12:12 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Hi.
>
>
> On Wed, Jan 22, 2020 at 7:03 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
> >
> > "make randconfig" calculates the probability of a tristate option (yes,
> > mod, no) based on srand()/rand() and can be fed with a seed.
> > At the last step of randconfig some option are chosen randomly and their
> > tristate set based on similar mechanism.
> > After this passage the resulting .config is not sanitized, hence it
> > might result in an inconsistent set of options being selected.
> >
> > This was noticed on arm64 using KCONFIG_SEED=0x40C5E904. During
> > randomize_choice_values() CONFIG_BIG_ENDIAN is enabled. Since CONFIG_EFI
> > was enabled at a previous step, and depends on !CONFIG_BIG_ENDIAN the
> > resulting .config is inconsistent.
> >
> > Fix the issue making sure that randconfig sanitizes the generated
> > .config as a last step.
> >
> > Cc: Masahiro Yamada <masahiroy@kernel.org>
> > Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> > ---
> >  scripts/kconfig/conf.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> > index 1f89bf1558ce..c0fcaa4e9762 100644
> > --- a/scripts/kconfig/conf.c
> > +++ b/scripts/kconfig/conf.c
> > @@ -654,6 +654,11 @@ int main(int ac, char **av)
> >         case randconfig:
> >                 /* Really nothing to do in this loop */
> >                 while (conf_set_all_new_symbols(def_random)) ;
> > +               /*
> > +                * .config at this point might contain
> > +                * incompatible options. Sanitize it.
> > +                */
> > +               sym_clear_all_valid();
>
> Thanks for the report, but clearing
> all the valid flags is a big hammer.
> I do not think it is a proper fix.
>
>
> I checked the code, and I noticed the root cause of
> this bug.
>
> I will send a different patch later.


I think this is a more correct fix-up:
https://patchwork.kernel.org/patch/11360945/


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kconfig: Sanitize make randconfig generated .config
  2020-02-01  3:12 ` Masahiro Yamada
  2020-02-01  5:15   ` Masahiro Yamada
@ 2020-02-07 10:40   ` Vincenzo Frascino
  1 sibling, 0 replies; 4+ messages in thread
From: Vincenzo Frascino @ 2020-02-07 10:40 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Linux Kbuild mailing list, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2347 bytes --]



On 01/02/2020 03:12, Masahiro Yamada wrote:
> Hi.
> 
> 
> On Wed, Jan 22, 2020 at 7:03 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
>>
>> "make randconfig" calculates the probability of a tristate option (yes,
>> mod, no) based on srand()/rand() and can be fed with a seed.
>> At the last step of randconfig some option are chosen randomly and their
>> tristate set based on similar mechanism.
>> After this passage the resulting .config is not sanitized, hence it
>> might result in an inconsistent set of options being selected.
>>
>> This was noticed on arm64 using KCONFIG_SEED=0x40C5E904. During
>> randomize_choice_values() CONFIG_BIG_ENDIAN is enabled. Since CONFIG_EFI
>> was enabled at a previous step, and depends on !CONFIG_BIG_ENDIAN the
>> resulting .config is inconsistent.
>>
>> Fix the issue making sure that randconfig sanitizes the generated
>> .config as a last step.
>>
>> Cc: Masahiro Yamada <masahiroy@kernel.org>
>> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
>> ---
>>  scripts/kconfig/conf.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
>> index 1f89bf1558ce..c0fcaa4e9762 100644
>> --- a/scripts/kconfig/conf.c
>> +++ b/scripts/kconfig/conf.c
>> @@ -654,6 +654,11 @@ int main(int ac, char **av)
>>         case randconfig:
>>                 /* Really nothing to do in this loop */
>>                 while (conf_set_all_new_symbols(def_random)) ;
>> +               /*
>> +                * .config at this point might contain
>> +                * incompatible options. Sanitize it.
>> +                */
>> +               sym_clear_all_valid();
> 
> Thanks for the report, but clearing
> all the valid flags is a big hammer.
> I do not think it is a proper fix.
> 
>

Ok, it is fine by me to find a better solution in this case. Not being on the
critical path of execution it did not look like to me very heavy but my
experience with the tool code is limited :)

> I checked the code, and I noticed the root cause of
> this bug.
> 
> I will send a different patch later.
> 
> 
> 
> 
>>                 break;
>>         case defconfig:
>>                 conf_set_all_new_symbols(def_default);
>> --
>> 2.25.0
>>
> 
> 

-- 
Regards,
Vincenzo

[-- Attachment #2: pEpkey.asc --]
[-- Type: application/pgp-keys, Size: 14291 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-07 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-22 10:03 [PATCH] kconfig: Sanitize make randconfig generated .config Vincenzo Frascino
2020-02-01  3:12 ` Masahiro Yamada
2020-02-01  5:15   ` Masahiro Yamada
2020-02-07 10:40   ` Vincenzo Frascino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).