Skip to content

in_collectd: reject parts with length < 4 and fix null-terminator OOB [Backport to 4.2]#11896

Merged
cosmo0920 merged 1 commit into
4.2from
fix/collectd-infinite-loop-4.2
Jun 3, 2026
Merged

in_collectd: reject parts with length < 4 and fix null-terminator OOB [Backport to 4.2]#11896
cosmo0920 merged 1 commit into
4.2from
fix/collectd-infinite-loop-4.2

Conversation

@cosmo0920

Copy link
Copy Markdown
Contributor

Backporting of #11849.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e80e789a-6c5d-4c7f-a3c2-75a4e1c956ee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/collectd-infinite-loop-4.2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cosmo0920 cosmo0920 changed the title in_collectd: reject parts with length < 4 and fix null-terminator OOB in_collectd: reject parts with length < 4 and fix null-terminator OOB [Backport to 4.2] Jun 3, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a7858c29b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +293 to 294
if (size > 0 && ptr[size - 1] == '\0') {
hdr.type = ptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject malformed string parts instead of keeping stale type

When a packet already set hdr.type, an empty or unterminated PART_TYPE now just skips this assignment and leaves the previous type in place, so the following PART_VALUE can be encoded under stale metadata instead of rejecting the malformed identifier. This is reachable with a multi-value collectd datagram where a later type part has part_len == 4 or lacks the trailing NUL; returning an error here (and for the other string identifiers) avoids silently corrupting the emitted metric labels.

Useful? React with 👍 / 👎.

@cosmo0920 cosmo0920 added this to the Fluent Bit v4.2.5 milestone Jun 3, 2026
The collectd binary protocol parser enters an infinite loop when it
receives a part with part_len=0: the loop counters are not advanced
and the while condition remains true forever. A single 4-byte UDP
packet can permanently hang the worker thread.

Additionally, the null-terminator check for string parts reads one
byte past the end of the received data (ptr[size] where size =
part_len - 4 accesses buf[part_len], which is past the buffer when
the last part fills exactly to the end).

Fix both by rejecting parts with part_len < 4 (minimum valid part
is 4 bytes: 2 type + 2 length) and checking ptr[size - 1] instead
of ptr[size] for the null terminator.

Signed-off-by: Tristan <tristan@talencesecurity.com>
@cosmo0920 cosmo0920 force-pushed the fix/collectd-infinite-loop-4.2 branch from 9a7858c to a485cc0 Compare June 3, 2026 01:31
@cosmo0920 cosmo0920 merged commit 7d28260 into 4.2 Jun 3, 2026
24 checks passed
@cosmo0920 cosmo0920 deleted the fix/collectd-infinite-loop-4.2 branch June 3, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant