Repository navigation
parse-util: fix ineffective overflow guards in store_loadavg_fixed_point() - #43753
Merged
cdown merged 1 commit intoSep 14, 2026
Merged
Conversation
Ar-maan05
force-pushed
the
fix/loadavg-fixed-point-overflow-guards
branch
from
September 14, 2026 00:27
9646026 to
efdc4b0
Compare
cdown
approved these changes
Sep 14, 2026
Member
Member
|
@bluca My apologies! I looked but unfortunately missed it in the others |
Member
|
No worries, easy to fix |
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.
store_loadavg_fixed_point()guarded both of its<< LOADAVG_PRECISION_BITSshifts against overflow, but neither guard was effective:The integer part was rejected with
i >= (~0UL << LOADAVG_PRECISION_BITS). The shift direction is inverted: that bound is0xFFFFFFFFFFFFF800, so it only rejects the topmost 2048 values of the range, while the smallest value that actually overflowsi << 11is2^53. Everything from2^53up shifted out of the word and was accepted.The fractional part was shifted first and range-checked afterwards, so a large
fwrapped to a small value and then passed thef >= LOADAVG_FIXED_POINT_1_0test.Concretely, on 64 bit:
Both should be
-ERANGE. The existingASSERT_ERROR(..."18446744073709551615.5"..., ERANGE)passes only because~0ULhappens to fall inside the narrow band the broken guard does catch.Validate both parts before shifting instead. Rejecting
f >= 100is exactly equivalent to the old post-shift comparison for every input that previously succeeded, sinceDIV_ROUND_UP(99 << 11, 100) == 2028andDIV_ROUND_UP(100 << 11, 100) == 2048, so there is no behaviour change for valid input; only the values that used to wrap are now rejected.Note this is a latent bug rather than a live one: the only caller of
parse_loadavg_fixed_point()isread_resource_pressure(), which parses kernel-generated/proc/pressure/*and cgroupmemory.pressurefiles where values are capped at100.00, and every directstore_loadavg_fixed_point()caller passes permyriad-derived values already clamped to 0...10000. Fixing the guards keeps the helper correct for future callers.Covered by new cases in
test-parse-util, including the largest integer part that must still be accepted (2^53-1).