linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
@ 2022-08-16  5:17 Andrew Donnellan
  2022-08-16 12:14 ` Yury Norov
  2022-08-16 19:25 ` Kees Cook
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Donnellan @ 2022-08-16  5:17 UTC (permalink / raw)
  To: linux-hardening, linuxppc-dev; +Cc: Erhard Furtner, Emese Revfy, Yury Norov

Commit 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
node_random()") refactored some code by moving node_random() from
lib/nodemask.c to include/linux/nodemask.h, thus requiring nodemask.h to
include random.h, which conditionally defines add_latent_entropy()
depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.

This broke the build on powerpc, where nodemask.h is indirectly included
in arch/powerpc/kernel/prom_init.c, part of the early boot machinery that
is excluded from the latent entropy plugin using
DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag
to disable the actual plugin, we don't undefine LATENT_ENTROPY_PLUGIN.

This leads to the following:

    CC      arch/powerpc/kernel/prom_init.o
  In file included from ./include/linux/nodemask.h:97,
                   from ./include/linux/mmzone.h:17,
                   from ./include/linux/gfp.h:7,
                   from ./include/linux/xarray.h:15,
                   from ./include/linux/radix-tree.h:21,
                   from ./include/linux/idr.h:15,
                   from ./include/linux/kernfs.h:12,
                   from ./include/linux/sysfs.h:16,
                   from ./include/linux/kobject.h:20,
                   from ./include/linux/pci.h:35,
                   from arch/powerpc/kernel/prom_init.c:24:
  ./include/linux/random.h: In function 'add_latent_entropy':
  ./include/linux/random.h:25:46: error: 'latent_entropy' undeclared (first use in this function); did you mean 'add_latent_entropy'?
     25 |         add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
        |                                              ^~~~~~~~~~~~~~
        |                                              add_latent_entropy
  ./include/linux/random.h:25:46: note: each undeclared identifier is reported only once for each function it appears in
  make[2]: *** [scripts/Makefile.build:249: arch/powerpc/kernel/prom_init.o] Fehler 1
  make[1]: *** [scripts/Makefile.build:465: arch/powerpc/kernel] Fehler 2
  make: *** [Makefile:1855: arch/powerpc] Error 2

Change the DISABLE_LATENT_ENTROPY_PLUGIN flags to undefine
LATENT_ENTROPY_PLUGIN for files where the plugin is disabled.

Cc: Yury Norov <yury.norov@gmail.com>
Cc: Emese Revfy <re.emese@gmail.com>
Fixes: 36d4b36b6959 ("lib/nodemask: inline next_node_in() and node_random()")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216367
Link: https://lore.kernel.org/linuxppc-dev/alpine.DEB.2.22.394.2208152006320.289321@ramsan.of.borg/
Reported-by: Erhard Furtner <erhard_f@mailbox.org>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
---
 scripts/Makefile.gcc-plugins | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 692d64a70542..e4deaf5fa571 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -4,7 +4,7 @@ gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)	+= latent_entropy_plugin.so
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)		\
 		+= -DLATENT_ENTROPY_PLUGIN
 ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
-    DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable
+    DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable -ULATENT_ENTROPY_PLUGIN
 endif
 export DISABLE_LATENT_ENTROPY_PLUGIN
 
-- 
2.30.2


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

* Re: [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
  2022-08-16  5:17 [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file Andrew Donnellan
@ 2022-08-16 12:14 ` Yury Norov
  2022-08-17  3:09   ` Andrew Donnellan
  2022-08-16 19:25 ` Kees Cook
  1 sibling, 1 reply; 5+ messages in thread
From: Yury Norov @ 2022-08-16 12:14 UTC (permalink / raw)
  To: Andrew Donnellan
  Cc: Erhard Furtner, Emese Revfy, linuxppc-dev, linux-hardening

On Tue, Aug 16, 2022 at 03:17:20PM +1000, Andrew Donnellan wrote:
> Commit 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
> node_random()") refactored some code by moving node_random() from
> lib/nodemask.c to include/linux/nodemask.h, thus requiring nodemask.h to
> include random.h, which conditionally defines add_latent_entropy()
> depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.
> 
> This broke the build on powerpc, where nodemask.h is indirectly included
> in arch/powerpc/kernel/prom_init.c, part of the early boot machinery that
> is excluded from the latent entropy plugin using
> DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag
> to disable the actual plugin, we don't undefine LATENT_ENTROPY_PLUGIN.
> 
> This leads to the following:
> 
>     CC      arch/powerpc/kernel/prom_init.o
>   In file included from ./include/linux/nodemask.h:97,
>                    from ./include/linux/mmzone.h:17,
>                    from ./include/linux/gfp.h:7,
>                    from ./include/linux/xarray.h:15,

As a side note, xarray can go with gfp_types.h instead of gfp.h

>                    from ./include/linux/radix-tree.h:21,
>                    from ./include/linux/idr.h:15,
>                    from ./include/linux/kernfs.h:12,
>                    from ./include/linux/sysfs.h:16,
>                    from ./include/linux/kobject.h:20,
>                    from ./include/linux/pci.h:35,
>                    from arch/powerpc/kernel/prom_init.c:24:
>   ./include/linux/random.h: In function 'add_latent_entropy':
>   ./include/linux/random.h:25:46: error: 'latent_entropy' undeclared (first use in this function); did you mean 'add_latent_entropy'?
>      25 |         add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
>         |                                              ^~~~~~~~~~~~~~
>         |                                              add_latent_entropy
>   ./include/linux/random.h:25:46: note: each undeclared identifier is reported only once for each function it appears in
>   make[2]: *** [scripts/Makefile.build:249: arch/powerpc/kernel/prom_init.o] Fehler 1
>   make[1]: *** [scripts/Makefile.build:465: arch/powerpc/kernel] Fehler 2
>   make: *** [Makefile:1855: arch/powerpc] Error 2
> 
> Change the DISABLE_LATENT_ENTROPY_PLUGIN flags to undefine
> LATENT_ENTROPY_PLUGIN for files where the plugin is disabled.
> 
> Cc: Yury Norov <yury.norov@gmail.com>
> Cc: Emese Revfy <re.emese@gmail.com>
> Fixes: 36d4b36b6959 ("lib/nodemask: inline next_node_in() and node_random()")

I think it rather fixes 38addce8b600ca33 ("gcc-plugins: Add
latent_entropy plugin").

For the rest,
Reviewed-by: Yury Norov <yury.norov@gmail.com>

> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216367
> Link: https://lore.kernel.org/linuxppc-dev/alpine.DEB.2.22.394.2208152006320.289321@ramsan.of.borg/
> Reported-by: Erhard Furtner <erhard_f@mailbox.org>
> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
> ---
>  scripts/Makefile.gcc-plugins | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
> index 692d64a70542..e4deaf5fa571 100644
> --- a/scripts/Makefile.gcc-plugins
> +++ b/scripts/Makefile.gcc-plugins
> @@ -4,7 +4,7 @@ gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)	+= latent_entropy_plugin.so
>  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)		\
>  		+= -DLATENT_ENTROPY_PLUGIN
>  ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
> -    DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable
> +    DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable -ULATENT_ENTROPY_PLUGIN
>  endif
>  export DISABLE_LATENT_ENTROPY_PLUGIN
>  
> -- 
> 2.30.2

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

* Re: [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
  2022-08-16  5:17 [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file Andrew Donnellan
  2022-08-16 12:14 ` Yury Norov
@ 2022-08-16 19:25 ` Kees Cook
  2022-08-17  3:09   ` Andrew Donnellan
  1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2022-08-16 19:25 UTC (permalink / raw)
  To: linuxppc-dev, linux-hardening, ajd; +Cc: erhard_f, Kees Cook, yury.norov

On Tue, 16 Aug 2022 15:17:20 +1000, Andrew Donnellan wrote:
> Commit 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
> node_random()") refactored some code by moving node_random() from
> lib/nodemask.c to include/linux/nodemask.h, thus requiring nodemask.h to
> include random.h, which conditionally defines add_latent_entropy()
> depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.
> 
> This broke the build on powerpc, where nodemask.h is indirectly included
> in arch/powerpc/kernel/prom_init.c, part of the early boot machinery that
> is excluded from the latent entropy plugin using
> DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc flag
> to disable the actual plugin, we don't undefine LATENT_ENTROPY_PLUGIN.
> 
> [...]

Applied to for-next/hardening, thanks!

[1/1] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
      https://git.kernel.org/kees/c/2d08c71d2c79

-- 
Kees Cook


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

* Re: [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
  2022-08-16 12:14 ` Yury Norov
@ 2022-08-17  3:09   ` Andrew Donnellan
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Donnellan @ 2022-08-17  3:09 UTC (permalink / raw)
  To: Yury Norov; +Cc: Erhard Furtner, Emese Revfy, linuxppc-dev, linux-hardening

On Tue, 2022-08-16 at 05:14 -0700, Yury Norov wrote:
> On Tue, Aug 16, 2022 at 03:17:20PM +1000, Andrew Donnellan wrote:
> > Commit 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
> > node_random()") refactored some code by moving node_random() from
> > lib/nodemask.c to include/linux/nodemask.h, thus requiring
> > nodemask.h to
> > include random.h, which conditionally defines add_latent_entropy()
> > depending on whether the macro LATENT_ENTROPY_PLUGIN is defined.
> > 
> > This broke the build on powerpc, where nodemask.h is indirectly
> > included
> > in arch/powerpc/kernel/prom_init.c, part of the early boot
> > machinery that
> > is excluded from the latent entropy plugin using
> > DISABLE_LATENT_ENTROPY_PLUGIN. It turns out that while we add a gcc
> > flag
> > to disable the actual plugin, we don't undefine
> > LATENT_ENTROPY_PLUGIN.
> > 
> > This leads to the following:
> > 
> >     CC      arch/powerpc/kernel/prom_init.o
> >   In file included from ./include/linux/nodemask.h:97,
> >                    from ./include/linux/mmzone.h:17,
> >                    from ./include/linux/gfp.h:7,
> >                    from ./include/linux/xarray.h:15,
> 
> As a side note, xarray can go with gfp_types.h instead of gfp.h

Indeed, I just saw your patch to fix this.

> 
> > Fixes: 36d4b36b6959 ("lib/nodemask: inline next_node_in() and
> > node_random()")
> 
> I think it rather fixes 38addce8b600ca33 ("gcc-plugins: Add
> latent_entropy plugin").

You're right, I was in a rush and should have tagged that
appropriately.

> 
> For the rest,
> Reviewed-by: Yury Norov <yury.norov@gmail.com>

Thanks!


-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited


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

* Re: [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file
  2022-08-16 19:25 ` Kees Cook
@ 2022-08-17  3:09   ` Andrew Donnellan
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Donnellan @ 2022-08-17  3:09 UTC (permalink / raw)
  To: Kees Cook, linuxppc-dev, linux-hardening; +Cc: erhard_f, yury.norov

On Tue, 2022-08-16 at 12:25 -0700, Kees Cook wrote:
> Applied to for-next/hardening, thanks!
> 
> [1/1] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin
> disabled for a file
>       https://git.kernel.org/kees/c/2d08c71d2c79
> 

Thanks Kees!

Can we make sure this lands in rc2?

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited


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

end of thread, other threads:[~2022-08-17  3:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16  5:17 [PATCH] gcc-plugins: Undefine LATENT_ENTROPY_PLUGIN when plugin disabled for a file Andrew Donnellan
2022-08-16 12:14 ` Yury Norov
2022-08-17  3:09   ` Andrew Donnellan
2022-08-16 19:25 ` Kees Cook
2022-08-17  3:09   ` Andrew Donnellan

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).