arm/linux: zero-initialize stack buffers to fix Valgrind warnings#376
Open
vozvivan wants to merge 1 commit intopytorch:mainfrom
Open
arm/linux: zero-initialize stack buffers to fix Valgrind warnings#376vozvivan wants to merge 1 commit intopytorch:mainfrom
vozvivan wants to merge 1 commit intopytorch:mainfrom
Conversation
On modern arm64 kernels, /proc/cpuinfo may legitimately omit the "Hardware" field. Other optional identification sources, such as "Revision" or Android property-based identifiers, may also be absent depending on the platform. Default-initialize the corresponding stack buffers / structs so missing optional identifiers are treated as empty values rather than uninitialized memory.
fbarchard
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes Valgrind and MemorySanitizer warnings caused by reading uninitialized stack memory.
1. Bugfix:
On modern AArch64 kernels, the "Hardware" line is often completely absent from
/proc/cpuinfo. When this happens, the stack-allocatedproc_cpuinfo_hardwarebuffer is never populated and may remains uninitialized garbage. Passing it tostrnlenandstrncmpincpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_hardwaretriggers memory analyzer warnings. Adding= {0}ensures it safely defaults to an empty string""and fixes the issue.2. Follow-up hardening:
To proactively prevent the exact same issue on other platforms (or Android) where OS-specific properties might be missing, I also zero-initialized the adjacent
proc_cpuinfo_revisionandandroid_propertiesbuffers.Since
cpuinfo_arm_linux_initruns exactly once viapthread_once, the performance overhead of zeroing these bytes is negligible.Valgrind Trace