Skip to content

arm/linux: zero-initialize stack buffers to fix Valgrind warnings#376

Merged
GregoryComer merged 1 commit into
pytorch:mainfrom
vozvivan:fix/cpuinfo-arm-init
Jun 17, 2026
Merged

arm/linux: zero-initialize stack buffers to fix Valgrind warnings#376
GregoryComer merged 1 commit into
pytorch:mainfrom
vozvivan:fix/cpuinfo-arm-init

Conversation

@vozvivan

@vozvivan vozvivan commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

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-allocated proc_cpuinfo_hardware buffer is never populated and may remains uninitialized garbage. Passing it to strnlen and strncmp in cpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_hardware triggers 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_revision and android_properties buffers.

Since cpuinfo_arm_linux_init runs exactly once via pthread_once, the performance overhead of zeroing these bytes is negligible.

Valgrind Trace

==24496== Conditional jump or move depends on uninitialised value(s)
==24496==    at 0x4838B0C: strnlen (vg_replace_strmem.c:468)
==24496==    by 0x1B3CCFF: cpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_hardware
==24496==    by 0x1B3E24B: cpuinfo_arm_linux_decode_chipset
==24496==    by 0x1B3AC47: cpuinfo_arm_linux_init

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.
@meta-cla meta-cla Bot added the cla signed label Apr 5, 2026
fbarchard
fbarchard previously approved these changes Apr 14, 2026
GregoryComer
GregoryComer previously approved these changes Jun 17, 2026
@GregoryComer

Copy link
Copy Markdown
Member

Closing and re-opening to fix stuck CI.

@GregoryComer GregoryComer reopened this Jun 17, 2026
@pytorch-bot pytorch-bot Bot dismissed stale reviews from fbarchard and GregoryComer June 17, 2026 16:48

This PR was reopened (likely due to being reverted), so your approval was removed. Please request another review.

@GregoryComer GregoryComer merged commit f6f4b3e into pytorch:main Jun 17, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants