fix(hk): skip short packets on source port 13 to avoid a crash - #66
Open
MahmoodSeoud wants to merge 1 commit into
Open
fix(hk): skip short packets on source port 13 to avoid a crash#66MahmoodSeoud wants to merge 1 commit into
MahmoodSeoud wants to merge 1 commit into
Conversation
hk_param_sniffer() treats every packet it sees on CSP source port 13 as
housekeeping data. To find the payload, it subtracts the size of the header
and footer from the total packet length:
size_t data_len = packet->length - 5 - ((flags & CSP_FRDP) ? 5 : 0);
But port 13 isn't used only for housekeeping data. Smaller packets travel on
it too -- things like control/ack frames and replies from other services --
and those carry no payload at all.
When one of those packets is smaller than the header and footer we subtract,
the result ought to be negative. It can't be: data_len is unsigned, so instead
of dropping below zero it wraps around to a gigantic number (close to SIZE_MAX).
The code then believes the packet is huge and keeps reading far past its end,
into memory that isn't part of the packet -- and crashes. That is the segfault
seen under `prometheus start`.
The fix is simple: before subtracting, check that the packet is actually long
enough to hold a payload. If it is too short, skip it.
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.
hk_param_sniffer() handles any packet whose CSP source port is 13, treating it as housekeeping param data. It works out the payload length by subtracting the header/footer overhead from the packet length:
data_len is unsigned. Source port 13 is also used by other, shorter traffic (control/ack frames, replies from other services), which carries no param payload. For any such packet shorter than the overhead, the subtraction does not go negative -- it wraps around to a huge value (~SIZE_MAX). The mpack reader is then handed that bogus length and reads far past the end of the packet, segfaulting the sniffer under
prometheus start.Fix: check the length first and skip any packet too short to hold a payload.