Skip to content

fix(hk): skip short packets on source port 13 to avoid a crash - #66

Open
MahmoodSeoud wants to merge 1 commit into
spaceinventor:masterfrom
discosat:hk-sport13-upstream
Open

fix(hk): skip short packets on source port 13 to avoid a crash#66
MahmoodSeoud wants to merge 1 commit into
spaceinventor:masterfrom
discosat:hk-sport13-upstream

Conversation

@MahmoodSeoud

Copy link
Copy Markdown

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:

size_t data_len = packet->length - 5 - ((flags & CSP_FRDP) ? 5 : 0);

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant