Skip to content

fix(hk): guard data_len underflow in hk_param_sniffer on short sport-… - #11

Closed
MahmoodSeoud wants to merge 2 commits into
masterfrom
mseo-test
Closed

fix(hk): guard data_len underflow in hk_param_sniffer on short sport-…#11
MahmoodSeoud wants to merge 2 commits into
masterfrom
mseo-test

Conversation

@MahmoodSeoud

Copy link
Copy Markdown

…13 packets

hk_param_sniffer() treats any packet whose CSP source port is 13 as an HK param stream and computes the payload length as:

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

data_len is unsigned, so any packet on sport 13 shorter than that 5/10-byte overhead -- e.g. a short RDP control/ack frame, or any other service that shares the port -- underflows data_len to ~SIZE_MAX. param_queue_init() and the mpack reader are then pointed at buffer..buffer+SIZE_MAX and walk off the end of the packet: an out-of-bounds read that segfaults the param sniffer under prometheus start.

Guard the subtraction: a packet too short to carry a param payload is skipped.

Adds tests/hk_sniffer_host.c (fork-isolated) which feeds the real hk_param_sniffer() short sport-13 packets and asserts they are skipped; fails without the guard, passes with it. Wired as hk_sniffer_tests in tests/meson.build. README gains a Testing section.

MahmoodSeoud and others added 2 commits June 4, 2026 15:06
…13 packets

hk_param_sniffer() treats any packet whose CSP source port is 13 as an HK param
stream and computes the payload length as:

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

data_len is unsigned, so any packet on sport 13 shorter than that 5/10-byte
overhead -- e.g. a short RDP control/ack frame, or any other service that shares
the port -- underflows data_len to ~SIZE_MAX. param_queue_init() and the mpack
reader are then pointed at buffer..buffer+SIZE_MAX and walk off the end of the
packet: an out-of-bounds read that segfaults the param sniffer under
`prometheus start`.

Guard the subtraction: a packet too short to carry a param payload is skipped.

Adds tests/hk_sniffer_host.c (fork-isolated) which feeds the real
hk_param_sniffer() short sport-13 packets and asserts they are skipped; fails
without the guard, passes with it. Wired as hk_sniffer_tests in tests/meson.build.
README gains a Testing section.
@MahmoodSeoud

Copy link
Copy Markdown
Author

already included in the master branch with differetn wording

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant