fix char-signedness out-of-bounds read in url and header lookup tables#3376
Open
ubeddulla wants to merge 1 commit into
Open
fix char-signedness out-of-bounds read in url and header lookup tables#3376ubeddulla wants to merge 1 commit into
ubeddulla wants to merge 1 commit into
Conversation
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
Two +128-biased 256-entry lookup tables are read out of bounds when an input byte has the high bit set, on builds where
charis unsigned (aarch64, riscv64).g_url_parsing_fast_action_map(uri.cpp, used byURI::SetHttpURLandParseURL) is indexed with(int)*p, where*pwalks the untrusted request-URI. On an unsigned-charplatform a byte in0x80..0xFFgives index128..255, soraw[256..383]is read, up to 127 bytes past the table.g_tolower_map(ascii_tolowerincase_ignored_flat_map.h) has the same +128 bias and is indexed by the promotedcharargument. It is reached fromCaseIgnoredHasherover HTTP header names and from HPACK, so the same high-bit byte over-reads the 256-entry table. The note already there records an aarch64 char-signedness crash; making the parameterintdid not fix it, because acharargument still promotes to0..255.On x86_64 (
charsigned) both indices fall in[-128,127]and stay in bounds, which is why the current CI does not surface it.What is changed and the side effects?
Changed:
Fold the index back into signed-char range at the three lookup sites with a
(signed char)cast. The table layout is untouched and behavior on signed-charplatforms is unchanged. Verified with an ASan build under-funsigned-char: a URL host byte0xC3and a header-name byte>= 0x80each trip a buffer-overflow before the change and run clean after, andascii_toloweroutput matches the expected value for all 256 byte values.Side effects:
Performance effects: none (a single cast).
Breaking backward compatibility: no.
Check List: