NetBSD Problem Report #60839

From www@netbsd.org  Fri Oct  2 18:09:57 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id BBA161A923B
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  2 Oct 2026 18:09:56 +0000 (UTC)
Message-Id: <20261002180955.ADF2B1A923C@mollari.NetBSD.org>
Date: Fri,  2 Oct 2026 18:09:55 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: use -ftrivial-auto-var-init
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60839
>Category:       kern
>Synopsis:       use -ftrivial-auto-var-init
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 02 18:10:00 +0000 2026
>Last-Modified:  Tue Oct 06 13:10:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
Acme Variable Initialization, Ink.
>Environment:
>Description:

	As proposed on tech-kern:

	> tl;dr: Turn on gcc/clang compiler option in kernel to fully
	> initialize all kernel stack variables, as zero on release
	> builds and nonzero pattern in current builds, to
	> systematically plug kernel stack memory disclosure leaks with
	> almost zero performance impact?

	https://mail-index.NetBSD.org/tech-kern/2026/07/20/msg031158.html

	Would be nice if the choice of zero vs pattern could easily
	depend on `options DIAGNOSTIC' or `options DEBUG'.

>How-To-Repeat:

>Fix:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/dev/pci
Date: Fri, 2 Oct 2026 18:53:06 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 18:53:06 UTC 2026

 Modified Files:
 	src/sys/dev/pci: if_alc.c

 Log Message:
 alc(4): Avoid acting on stack garbage if readreg fails.

 Found by:

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/if_alc.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/dev/pci
Date: Fri, 2 Oct 2026 18:53:19 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 18:53:19 UTC 2026

 Modified Files:
 	src/sys/dev/pci: if_wm.c

 Log Message:
 wm(4): Avoid acting on stack garbage if readreg fails.

 Found by:

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.802 -r1.803 src/sys/dev/pci/if_wm.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/conf
Date: Fri, 2 Oct 2026 18:53:54 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 18:53:54 UTC 2026

 Modified Files:
 	src/sys/conf: Makefile.kern.inc

 Log Message:
 sys: Flip on -ftrivial-auto-var-init=pattern for the kernel build.

 Note: HAVE_GCC (if defined) is a major version number, but HAVE_LLVM
 (if defined) is yes or no, hence the weird conditionals here.

 TBD: Would like to make the choice of `pattern' vs `zero' conditional
 on `options DEBUG' or something but that's trickier than I want to
 figure out right now; let's just get this on at all to start.

 TBD: Kernel modules.

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.306 -r1.307 src/sys/conf/Makefile.kern.inc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/conf
Date: Fri, 2 Oct 2026 19:52:26 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 19:52:26 UTC 2026

 Modified Files:
 	src/sys/conf: Makefile.kern.inc

 Log Message:
 sys: Use ACTIVE_CC to choose -ftrivial-auto-var-init.

 I'm a little fuzzy on the finer semantics of ACTIVE_CC vs
 HAVE_GCC/HAVE_LLVM from share/mk/bsd.README, but I think this is the
 intended way to conditionalize decisions like this.

 PR PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.307 -r1.308 src/sys/conf/Makefile.kern.inc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/powerplay
Date: Fri, 2 Oct 2026 20:56:36 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 20:56:36 UTC 2026

 Modified Files:
 	src/sys/external/bsd/drm2/dist/drm/amd/powerplay: smu_internal.h

 Log Message:
 amdgpu powerplay: Avoid stack garbage if smu callbacks are missing.

 Found by:

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 \
     src/sys/external/bsd/drm2/dist/drm/amd/powerplay/smu_internal.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/external/cddl/osnet/dist/uts/common/dtrace
Date: Fri, 2 Oct 2026 21:13:05 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 21:13:05 UTC 2026

 Modified Files:
 	src/external/cddl/osnet/dist/uts/common/dtrace: dtrace.c

 Log Message:
 dtrace: Avoid uninitialized stack garbage.

 Found by:

 PR kern/60839: use -ftrivial-auto-var-init

 This applies the code change of the following FreeBSD commit, but I
 didn't understand the comment so I rewrote it:

 commit f222a6b88614db13ae83c8110281e690d1381a4c
 Author: Bryan Drewery <bdrewery@FreeBSD.org>
 Date:   Fri Dec 18 09:58:03 2020 -0800

     dtrace: Fix /"string" == NULL/ comparisons using an uninitialized value.

     A test of this is funcs/tst.strtok.d which has this filter:

         BEGIN
         /(this->field = strtok(this->str, ",")) == NULL/
         {
                 exit(1);
         }
     The test will randomly fail with exit status of 1 indicating that this->field
     was NULL even though printing it out shows it is not.

     This is compiled to the DTrace instruction set:
         // Pushed arguments not shown here
         // call strtok() and set result into %r1
         07: 2f001f01    call DIF_SUBR(31), %r1          ! strtok
         // set thread local scalar this->field from %r1
         08: 39050101    stls %r1, DT_VAR(1281)          ! DT_VAR(1281) = "field"
         // Prepare for the == comparison
         // Set right side of %r2 to NULL
         09: 25000102    setx DT_INTEGER[1], %r2         ! 0x0
         // string compare %r1 (strtok result) to %r2
         10: 27010200    scmp %r1, %r2

     In this case only %r1 is loaded with a string limit set to lim1.  %r2 being
     NULL does not get loaded and does not set lim2.  Then we call dtrace_strncmp()
     with MIN(lim1, lim2) resulting in passing 0 and comparing neither side.
     dtrace_strncmp() handles this case fine and it already has been while
     being lucky with what lim2 was [un]initialized as.

     Reviewed by:    markj, Don Morris <dgmorris AT earthlink.net>
     Sponsored by:   Dell EMC
     Differential Revision:  https://reviews.freebsd.org/D27671


 To generate a diff of this commit:
 cvs rdiff -u -r1.42 -r1.43 \
     src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/share/mk
Date: Fri, 2 Oct 2026 21:26:31 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 21:26:31 UTC 2026

 Modified Files:
 	src/share/mk: bsd.kmodule.mk

 Log Message:
 bsd.kmodule.mk: Enable -ftrivial-auto-var-init for kernel modules.

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.88 -r1.89 src/share/mk/bsd.kmodule.mk

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/rump
Date: Fri, 2 Oct 2026 21:29:04 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Oct  2 21:29:04 UTC 2026

 Modified Files:
 	src/sys/rump: Makefile.rump

 Log Message:
 rump: Enable -ftrivial-auto-var-init like the hard kernel.

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.140 -r1.141 src/sys/rump/Makefile.rump

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/conf
Date: Tue, 6 Oct 2026 04:29:58 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Oct  6 04:29:58 UTC 2026

 Modified Files:
 	src/sys/conf: Makefile.kern.inc

 Log Message:
 sys: Disable -ftrivial-auto-var-init if -Os is in play.

 This should help avoid the code expansion that broke the zaurus and
 ews4800mips builds.

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.308 -r1.309 src/sys/conf/Makefile.kern.inc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60839 CVS commit: src/sys/arch/zaurus/conf
Date: Tue, 6 Oct 2026 13:08:56 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Oct  6 13:08:56 UTC 2026

 Modified Files:
 	src/sys/arch/zaurus/conf: GENERIC INSTALL

 Log Message:
 zaurus: MOve COPTS="-Os" from INSTALL to GENERIC.

 INSTALL includes GENERIC, so no change to INSTALL.  But the reason
 for -Os (a size limitation of the bootloader, checked at build-time)
 appears to apply just as well to any kernel, not just INSTALL, and
 the recent change to flip on -ftrivial-auto-var-init bumped GENERIC
 over the limit too:

 Checking kernel size...
 Fatal: kernel size must be less than 5MB.
 Fatal: kernel size: 5247920, max kernel size: 5242880
 --- netbsd ---

 *** Failed target: netbsd
 *** In directory: /home/builds/ab/HEAD/zaurus/20261006081837Z-obj/home/source/ab/HEAD/src/sys/arch/zaurus/compile/GENERIC

 Setting COPTS="-Os" both tells the compiler to make smaller code, and
 turns off the -ftrivial-auto-var-init logic in Makefile.kern.inc,
 which with any luck should help fix the zaurus build.

 PR kern/60839: use -ftrivial-auto-var-init


 To generate a diff of this commit:
 cvs rdiff -u -r1.97 -r1.98 src/sys/arch/zaurus/conf/GENERIC
 cvs rdiff -u -r1.41 -r1.42 src/sys/arch/zaurus/conf/INSTALL

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.