hwcaps: dont return an uninitialized hwcap on elf_aux_info failure#466
Open
EylonKrause wants to merge 1 commit into
Open
hwcaps: dont return an uninitialized hwcap on elf_aux_info failure#466EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
On FreeBSD/OpenBSD, GetElfHwcapFromElfAuxInfo left `hwcap` uninitialized and ignored the elf_aux_info() return value. elf_aux_info() only writes the output buffer on success; when the requested entry is absent (e.g. AT_HWCAP2, which CpuFeatures_GetHardwareCapabilities requests unconditionally, on arch/kernel combinations that lack it) it returns non-zero and leaves the buffer untouched, so the function returned an indeterminate stack value that is then bit-tested for CPU features. Initialize to 0 and return 0 on failure, matching the Linux getauxval path.
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
On FreeBSD/OpenBSD,
GetElfHwcapFromElfAuxInforeads the ELF hwcaps viaelf_aux_info:hwcapis uninitialized and theelf_aux_inforeturn value is ignored.elf_aux_infoonly writes*bufon success; when the requested entry is absent it returns non-zero and leaves the buffer untouched.CpuFeatures_GetHardwareCapabilitiesrequestsAT_HWCAP2unconditionally, andAT_HWCAP2is genuinely absent on some arch/kernel combinations — so on those, this returns an indeterminate stack value, which is then bit-tested for CPU features → non-deterministic false detection.Fix
Initialize
hwcap = 0and return 0 whenelf_aux_infofails, mirroring the Linuxgetauxvalpath (which returns 0 when the entry is unavailable).Testing
FreeBSD/OpenBSD-only path, so not exercised on this Linux host; the fix is a straightforward initialize + return-check (the uninitialized read is clear from the source).