Wednesday, December 2, 2026

F46 Change Proposal: Default zero-initialization of stack variables (system-wide)

Wiki - https://fedoraproject.org/wiki/Changes/Default_zero-initialization_of_stack_variables Discourse Poll - https://discussion.fedoraproject.org/t/f46-change-proposal-default-zero-initialization-of-stack-variables-system-wide/209948/2 This is a proposed Change for Fedora Linux. This document represents a proposed Change. As part of the Changes process, proposals are publicly announced in order to receive community feedback. This proposal will only be implemented if approved by the Fedora Engineering Steering Committee. == Summary == By default, use the following C/C++ compilation flags to avoid uninitialized stack variables when building packages: `-ftrivial-auto-var-init=zero`. The flag is added to the default C/C++ compilation flags in `redhat-rpm-config`. Adding this flag removes a class of uninitialized-stack-memory defects: information disclosure and uninitialized-pointer control-flow. == Owner == * Name: [[User:Nmanthey| Norbert Manthey]], [[User:Trawets| Stewart Smith]] * Email: nmanthey@amazon.de, trawets@amazon.com == Detailed Description == Without automatic-variable initialization, a stack variable holds whatever bytes were previously on the stack. A code path that reads such a variable before it is assigned produces a use-of-uninitialized-value bug. Depending on the variable, this is an information disclosure (leaking prior stack contents, which may include pointers, keys, or other process/kernel memory) or a control-flow hijack (an uninitialized function pointer or length being used). The flag `-ftrivial-auto-var-init=zero` makes the compiler zero-fill these variables at function entry. `zero` is chosen over `pattern` because it is the safer default (a zeroed pointer or length tends to fail closed) and has the lower run-time cost. === Categorization and implementation === This flag is an exploit-mitigation ("hardening") flag, so it is appropriate to carry it in the macro `%_hardening_cflags` in the package `redhat-rpm-config`. Adding the flag is a System-Wide Change: the flag takes full effect once packages are rebuilt, so the change requires a mass rebuild. A package with a measured hotspot can opt out by overriding build flags in the package specfile. glibc is explicitly excluded from this flag. glibc does not receive `-ftrivial-auto-var-init=zero`: its glibc.spec filters the build flags through an `inherit_flags.cflags` allowlist that does not list this flag, so it is dropped for glibc's own compilation. This is deliberate. Forcing the flag onto glibc (by adding it to that allowlist) makes the freshly built, statically linked `ldconfig` crash. This crash is glibc-startup-specific. Hence, adding the flag to glibc, requires a targeted glibc patch. === Prior art === The flag is already in use, upstream and in Fedora. Links point to the exact version that was checked (2026-11-17). * Android: the default build configuration uses the flag ([https://android.googlesource.com/platform/build/soong/+/main/cc/config/global.go soong global.go]); see also the [https://source.android.com/docs/security/test/memory-safety/zero-initialized-memory Android documentation on zero-initialized memory]. * Wolfi: the package `openssf-compiler-options` adds the flag to every clang build ([https://github.com/wolfi-dev/os/blob/8c7be51b00af0e8109c10c12d4400ad18ebd5501/openssf-compiler-options/etc/clang/common.cfg#L29 common.cfg]) and to gcc 12 and 13 builds ([https://github.com/wolfi-dev/os/blob/8c7be51b00af0e8109c10c12d4400ad18ebd5501/openssf-compiler-options/usr/lib/gcc/x86_64-pc-linux-gnu/13/openssf.spec#L3-L10 openssf.spec]). Upstream projects that Fedora ships and that set the flag in their own build files. Each of these has the flag on the compile lines of the Fedora build log (x86_64), so Fedora already builds them with it. * systemd: set for release mode ([https://github.com/systemd/systemd/blob/v262.2/meson.build#L507-L512 meson.build, v262.2]) * QEMU: part of the default hardening flags ([https://github.com/qemu/qemu/blob/v11.2.0-rc0/meson.build#L693-L718 meson.build, v11.2.0-rc0]). * KiCad: zero-initialization by default for every build type except Debug, which uses pattern initialization ([https://github.com/KiCad/kicad-source-mirror/blob/10.0.8/CMakeLists.txt#L448-L483 CMakeLists.txt, 10.0.8]). * NASM: always added when the compiler supports it ([https://github.com/netwide-assembler/nasm/blob/nasm-3.02/configure.ac#L78 configure.ac, nasm-3.02]). === Cost and tradeoffs === Zeroing variables adds a small amount of code and run time. Performance impact is discussed below. Upstream software might fail when adapting the flag. We also detected some problems and had them addressed: * perl5 https://github.com/Perl/perl5/issues/24317 (microbenchmark performance regression) * perl5 https://github.com/Perl/perl5/pull/24334 (microbenchmark performance regression) * apr https://github.com/apache/apr/pull/71 (fix test) === Performance impact === We measured performance impact on Fedora across 18 benchmarks, two CPU vendors (Intel, AMD), with 11 VMs in the same region for each benchmark. The same source RPMs were rebuilt twice, once stock and once with only `-ftrivial-auto-var-init=zero` added. Benchmarks cover compilation, compression, database and web server throughput, as well as perl, openssl, unixbench and pyperformance micro benchmarks. When enabling zero-initialization, measurements show no effect on Unixbench or nginx throughput, small improvements have been measured for Unixbench Shell_Scripts and Execl_Throughput. The worst observed regression is about 2.6% higher xz compression for time. We also ran SPEC CPU 2026 (SPECrate2026, base metric) on Fedora 44 with gcc 16.2.1, on AWS c8g.4xlarge (aarch64, Graviton) and c8i.4xlarge (x86_64, Intel) instances, five VMs per platform and flag set. The flag was passed to the C, C++ and Fortran compilers. Each benchmark ran twice per VM and the slower run counts. The suite score is SPEC's geometric mean of the benchmark ratios. These are estimates, the runs are not reportable under the SPEC run rules. The geometric-mean scores stay the same within measurement noise for both the integer and the floating-point suite. None of the four differences is statistically significant. == Feedback == Initialization has been discussed on the devel email list. The risk of potential performance penalty has been noted, but no strong objection has been raised for this specific compiler flag. == Benefit to Fedora == Enabling this flag removes an entire defect class distribution-wide. Concrete examples where zero-initialization removes the exploitable read: [https://nvd.nist.gov/vuln/detail/CVE-2024-12085 CVE-2024-12085] (rsync), [https://nvd.nist.gov/vuln/detail/CVE-2024-2511 CVE-2024-2511] (OpenSSL), or [https://nvd.nist.gov/vuln/detail/CVE-2026-0915 CVE-2026-0915] (glibc). The change enables an opt-out model. == Scope == * Proposal owners: submit a pull request to `redhat-rpm-config` adding `-ftrivial-auto-var-init=zero` to the default build flags (default on). * Other developers: review and merge the PR. Maintainers may opt out per-package with a justification where a genuine measured hotspot is shown. This exception is expected to be rare. * Release engineering: [https://forge.fedoraproject.org/releng/tickets/issues #Releng issue number] a mass rebuild propagates the flag to all packages. * Policies and guidelines: N/A (not needed for this Change) * Trademark approval: N/A (not needed for this Change) * Alignment with the Fedora Strategy: security and robustness; Fedora "First". == Upgrade/compatibility impact == No ABI change and no on-disk format change. Packages receive the flag when rebuilt; upgrades are unaffected. No user action required. == Early Testing (Optional) == Preview via a COPR carrying the modified redhat-rpm-config, then rebuild a representative package subset and run their test suites. == How To Test == On a system with the updated `redhat-rpm-config`, run `rpm --eval '%{build_cflags}'` and confirm `-ftrivial-auto-var-init=zero` is present. Rebuild a C/C++ package and check the build log confirms the flag reaches real (non-conftest) compiler invocations. Run the package's test suite and a benchmark subset to confirm no functional or significant performance regression. == User Experience == The change is transparent to users. Some latent uninitialized-memory bugs stop being exploitable (variables now read as zero instead of stale stack data). Correct programs behave identically. == Dependencies == The only dependency is redhat-rpm-config.`-ftrivial-auto-var-init` is supported by all GCC (>= 12) and Clang versions Fedora ships. No toolchain update is required. == Contingency Plan == * Contingency mechanism: (What to do? Who will do it?) revert the `redhat-rpm-config` macro change; packages rebuild without the flags. Individual packages can opt out at any time by undefining the macro. * Contingency deadline: final freeze. * Blocks release? N/A (not a System Wide Change) == Documentation == * [https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html GCC manual Optimize Options] covering `-ftrivial-auto-var-init`. * [https://docs.fedoraproject.org/en-US/packaging-guidelines/#_compiler_flags Fedora packaging guidelines: compiler flags] (opt-out mechanism) * [https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html OpenSSF Compiler Options Hardening Guide for C and C++] == Release Notes == Fedora now builds C/C++ packages with `-ftrivial-auto-var-init=zero` by default, zero-initializing stack variables that lack an explicit initializer. This improvement eliminates a class of uninitialized-memory information-disclosure and control-flow bugs. Packages with a measured hot path may opt out in their spec file. -- Aoife Moloney Fedora Operations Architect Fedora Project Matrix: @amoloney:fedora.im IRC: amoloney -- _______________________________________________ devel-announce mailing list -- devel-announce@lists.fedoraproject.org To unsubscribe send an email to devel-announce-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/devel-announce@lists.fedoraproject.org Do not reply to spam, report it: https://forge.fedoraproject.org/infra/tickets/issues/new

No comments:

Post a Comment