mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
@ 2026-09-15 20:10 Arnd Bergmann
  2026-09-16  8:49 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2026-09-15 20:10 UTC (permalink / raw)
  To: Mickaël Salaün, Paul Moore, James Morris,
	Serge E. Hallyn, Tingmao Wang, Justin Suess
  Cc: Arnd Bergmann, Günther Noack, Sebastian Andrzej Siewior,
	linux-security-module, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc has a bug with -ftrivial-auto-var-init=pattern that produces a
warning for correct code that uses sparse bitfields:

security/landlock/fs.c: In function 'is_access_to_paths_allowed.isra':
security/landlock/fs.c:767:28: error: '_layer_masks_child1' is used uninitialized [-Werror=uninitialized]
  767 |         struct layer_masks _layer_masks_child1, _layer_masks_child2;
      |                            ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c:767:28: note: '_layer_masks_child1' declared here
  767 |         struct layer_masks _layer_masks_child1, _layer_masks_child2;
      |                            ^~~~~~~~~~~~~~~~~~~
security/landlock/fs.c: In function 'hook_unix_find':
security/landlock/fs.c:1649:28: error: 'layer_masks' is used uninitialized [-Werror=uninitialized]
 1649 |         struct layer_masks layer_masks;
      |                            ^~~~~~~~~~~
security/landlock/fs.c:1649:28: note: 'layer_masks' declared here
 1649 |         struct layer_masks layer_masks;
      |                            ^~~~~~~~~~~

To work around this, change the definition of struct layer_mask to
use an explictit padding field. This also avoids the extra attributes
for aligning the structure.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110743
Link: https://lore.kernel.org/all/20260619082133.3504146-1-arnd@kernel.org/
Fixes: a260c0055665 ("landlock: Add a place for flags to layer rules")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: rebased to linux-next-20260914

I originally sent this in June, but got no reply and this still
happens with gcc-16.2, which is the latest stable release.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 security/landlock/access.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/security/landlock/access.h b/security/landlock/access.h
index bbbb41f41147..f41ac3fc6476 100644
--- a/security/landlock/access.h
+++ b/security/landlock/access.h
@@ -81,6 +81,9 @@ struct layer_mask {
 	 */
 	access_mask_t quiet : 1;
 #endif /* CONFIG_SECURITY_LANDLOCK_LOG */
+	access_mask_t __pad : ((sizeof(access_mask_t) * 8) -
+				LANDLOCK_NUM_ACCESS_MAX -
+				IS_ENABLED(CONFIG_SECURITY_LANDLOCK_LOG));
 } __packed __aligned(sizeof(access_mask_t));
 
 /*
-- 
2.53.0


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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-15 20:10 [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning Arnd Bergmann
@ 2026-09-16  8:49 ` Sebastian Andrzej Siewior
  2026-09-16 12:25   ` Mickaël Salaün
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-16  8:49 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Mickaël Salaün, Paul Moore, James Morris,
	Serge E. Hallyn, Tingmao Wang, Justin Suess, Arnd Bergmann,
	Günther Noack, linux-security-module, linux-kernel

On 2026-09-15 22:10:30 [+0200], Arnd Bergmann wrote:
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110743
> Link: https://lore.kernel.org/all/20260619082133.3504146-1-arnd@kernel.org/
> Fixes: a260c0055665 ("landlock: Add a place for flags to layer rules")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: rebased to linux-next-20260914
> 
> I originally sent this in June, but got no reply and this still
> happens with gcc-16.2, which is the latest stable release.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

This looks reasonable. I don't see this with gcc-16.2 and the referenced
gcc bug has it as fixed.

Sebastian

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-16  8:49 ` Sebastian Andrzej Siewior
@ 2026-09-16 12:25   ` Mickaël Salaün
  2026-09-16 21:06     ` Arnd Bergmann
  0 siblings, 1 reply; 8+ messages in thread
From: Mickaël Salaün @ 2026-09-16 12:25 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Arnd Bergmann, Paul Moore, James Morris, Serge E. Hallyn,
	Tingmao Wang, Justin Suess, Arnd Bergmann, Günther Noack,
	linux-security-module, linux-kernel

On Wed, Sep 16, 2026 at 10:49:47AM +0200, Sebastian Andrzej Siewior wrote:
> On 2026-09-15 22:10:30 [+0200], Arnd Bergmann wrote:
> > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110743
> > Link: https://lore.kernel.org/all/20260619082133.3504146-1-arnd@kernel.org/
> > Fixes: a260c0055665 ("landlock: Add a place for flags to layer rules")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > v2: rebased to linux-next-20260914
> > 
> > I originally sent this in June, but got no reply and this still
> > happens with gcc-16.2, which is the latest stable release.

Thanks Arnd, I missed it.  It's in my -next branch now.

> > 
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> This looks reasonable. I don't see this with gcc-16.2 and the referenced
> gcc bug has it as fixed.

If GCC is fixed now, should we keep this work around?

> 
> Sebastian
> 

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-16 12:25   ` Mickaël Salaün
@ 2026-09-16 21:06     ` Arnd Bergmann
  2026-09-17  7:09       ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2026-09-16 21:06 UTC (permalink / raw)
  To: Mickaël Salaün, Sebastian Andrzej Siewior
  Cc: Arnd Bergmann, Paul Moore, James Morris, Serge E. Hallyn,
	Tingmao Wang, Justin Suess, Günther Noack,
	linux-security-module, linux-kernel

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

On Wed, Sep 16, 2026, at 14:25, Mickaël Salaün wrote:
> On Wed, Sep 16, 2026 at 10:49:47AM +0200, Sebastian Andrzej Siewior wrote:
>> On 2026-09-15 22:10:30 [+0200], Arnd Bergmann wrote:
>> > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110743
>> > Link: https://lore.kernel.org/all/20260619082133.3504146-1-arnd@kernel.org/
>> > Fixes: a260c0055665 ("landlock: Add a place for flags to layer rules")
>> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> > ---
>> > v2: rebased to linux-next-20260914
>> > 
>> > I originally sent this in June, but got no reply and this still
>> > happens with gcc-16.2, which is the latest stable release.
>
> Thanks Arnd, I missed it.  It's in my -next branch now.
>
>> > 
>> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> 
>> This looks reasonable. I don't see this with gcc-16.2 and the referenced
>> gcc bug has it as fixed.
>
> If GCC is fixed now, should we keep this work around?

As far as I can tell, 16.2 is still affected, even though it should be
fixed in HEAD. gcc-16.3 won't be released until spring 2027 though.

It is possible that there are additional configuration options that
have to be set just right to reproduce the issue. I've attached a
configuration that triggered it for me this week.

      Arnd

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 51237 bytes --]

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-16 21:06     ` Arnd Bergmann
@ 2026-09-17  7:09       ` Sebastian Andrzej Siewior
  2026-09-17 10:26         ` Arnd Bergmann
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-17  7:09 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Mickaël Salaün, Arnd Bergmann, Paul Moore,
	James Morris, Serge E. Hallyn, Tingmao Wang, Justin Suess,
	Günther Noack, linux-security-module, linux-kernel

On 2026-09-16 23:06:30 [+0200], Arnd Bergmann wrote:
> As far as I can tell, 16.2 is still affected, even though it should be
> fixed in HEAD. gcc-16.3 won't be released until spring 2027 though.
> 
> It is possible that there are additional configuration options that
> have to be set just right to reproduce the issue. I've attached a
> configuration that triggered it for me this week.

This is from v7.2. I tried this and v7.3-rc3 and did not notice a
warning (other than unrelated stack size from drm). I did notice:

-CONFIG_CC_VERSION_TEXT="x86_64-linux-gcc (GCC) 16.2.0"
+CONFIG_CC_VERSION_TEXT="gcc (Debian 16.2.0-2) 16.2.0"
 CONFIG_GCC_VERSION=160200
-CONFIG_AS_VERSION=20285426
+CONFIG_AS_VERSION=24700
-CONFIG_LD_VERSION=20285426
+CONFIG_LD_VERSION=24700
+CONFIG_CC_HAS_MARCH_NATIVE=y

which might be the culprit. There were other things, too, so the
oldconfig was not clean (such as missing CONFIG_VIRTUALIZATION).

>       Arnd

Sebastian

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-17  7:09       ` Sebastian Andrzej Siewior
@ 2026-09-17 10:26         ` Arnd Bergmann
  2026-09-17 10:45           ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2026-09-17 10:26 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Mickaël Salaün, Arnd Bergmann, Paul Moore,
	James Morris, Serge E. Hallyn, Tingmao Wang, Justin Suess,
	Günther Noack, linux-security-module, linux-kernel

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

On Thu, Sep 17, 2026, at 09:09, Sebastian Andrzej Siewior wrote:
> On 2026-09-16 23:06:30 [+0200], Arnd Bergmann wrote:
>> As far as I can tell, 16.2 is still affected, even though it should be
>> fixed in HEAD. gcc-16.3 won't be released until spring 2027 though.
>> 
>> It is possible that there are additional configuration options that
>> have to be set just right to reproduce the issue. I've attached a
>> configuration that triggered it for me this week.
>
> This is from v7.2. I tried this and v7.3-rc3 and did not notice a
> warning (other than unrelated stack size from drm). I did notice:
>
> -CONFIG_CC_VERSION_TEXT="x86_64-linux-gcc (GCC) 16.2.0"
> +CONFIG_CC_VERSION_TEXT="gcc (Debian 16.2.0-2) 16.2.0"
>  CONFIG_GCC_VERSION=160200
> -CONFIG_AS_VERSION=20285426
> +CONFIG_AS_VERSION=24700
> -CONFIG_LD_VERSION=20285426
> +CONFIG_LD_VERSION=24700
> +CONFIG_CC_HAS_MARCH_NATIVE=y
>
> which might be the culprit. There were other things, too, so the
> oldconfig was not clean (such as missing CONFIG_VIRTUALIZATION).

I checked again and found that this is a config that did produce
the issue a few weeks ago, but doesn't today for me.
I found a different config from this week and managed to reproduce
the problem on today's linux-next using both gcc-16.2 and gcc-17.0
from yesterday, so there is still a related issue that is not
fixed in gcc, even though one at least one of them was fixed.

      Arnd

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 42783 bytes --]

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-17 10:26         ` Arnd Bergmann
@ 2026-09-17 10:45           ` Sebastian Andrzej Siewior
  2026-09-17 11:36             ` Arnd Bergmann
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-17 10:45 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Mickaël Salaün, Arnd Bergmann, Paul Moore,
	James Morris, Serge E. Hallyn, Tingmao Wang, Justin Suess,
	Günther Noack, linux-security-module, linux-kernel

On 2026-09-17 12:26:17 [+0200], Arnd Bergmann wrote:
> I checked again and found that this is a config that did produce
> the issue a few weeks ago, but doesn't today for me.
> I found a different config from this week and managed to reproduce
> the problem on today's linux-next using both gcc-16.2 and gcc-17.0
> from yesterday, so there is still a related issue that is not
> fixed in gcc, even though one at least one of them was fixed.

Confirmed. I see the warning on arm64 while x86-64 is quiet. The patch
fixes the issue.

You might need to update gcc bug tracker.

>       Arnd

Sebastian

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

* Re: [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning
  2026-09-17 10:45           ` Sebastian Andrzej Siewior
@ 2026-09-17 11:36             ` Arnd Bergmann
  0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2026-09-17 11:36 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Mickaël Salaün, Arnd Bergmann, Paul Moore,
	James Morris, Serge E. Hallyn, Tingmao Wang, Justin Suess,
	Günther Noack, linux-security-module, linux-kernel

On Thu, Sep 17, 2026, at 12:45, Sebastian Andrzej Siewior wrote:
> On 2026-09-17 12:26:17 [+0200], Arnd Bergmann wrote:
>> I checked again and found that this is a config that did produce
>> the issue a few weeks ago, but doesn't today for me.
>> I found a different config from this week and managed to reproduce
>> the problem on today's linux-next using both gcc-16.2 and gcc-17.0
>> from yesterday, so there is still a related issue that is not
>> fixed in gcc, even though one at least one of them was fixed.
>
> Confirmed. I see the warning on arm64 while x86-64 is quiet. The patch
> fixes the issue.
>
> You might need to update gcc bug tracker.

Correction: I noticed the failing gcc-17 binary was an old one,
the current snapshot does not produce the warning any more.
It does seem like the fix was not yet backported to older compilers,
and seeing that the final gcc-13.x was released, we will
continue to need the kernel workaround. I assume the compiler
fix will eventually make its way into the other stable branches.

      Arnd

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

end of thread, other threads:[~2026-09-17 11:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 20:10 [PATCH] [v2] landlock: work around gcc-16 -Wuninitialized warning Arnd Bergmann
2026-09-16  8:49 ` Sebastian Andrzej Siewior
2026-09-16 12:25   ` Mickaël Salaün
2026-09-16 21:06     ` Arnd Bergmann
2026-09-17  7:09       ` Sebastian Andrzej Siewior
2026-09-17 10:26         ` Arnd Bergmann
2026-09-17 10:45           ` Sebastian Andrzej Siewior
2026-09-17 11:36             ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®