in_tail: fix out-of-bounds read in unesc_ends_with_nl#11952
Conversation
An empty docker log message reaches unesc_ends_with_nl with len 0, so flb_unescape_string returns 0 and unesc[unesc_len - 1] reads one byte before the heap buffer. Guard the index on unesc_len. Signed-off-by: saddamr3e <saddamr3e@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA one-line guard ( ChangesDocker mode newline check fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
AddressSanitizer, in_tail with
Docker_Mode Onparsing a container log line whoselogfield is empty ({"log":"","stream":"stdout",...}):modify_json_condcalls theunesc_ends_with_nlpredicate with the value of thelogkey. For an empty valuelenis 0,flb_unescape_stringreturns 0, andunesc[unesc_len - 1]indexesunesc[-1]. Container stdout is attacker-controlled, so a single empty log line triggers the underflow. Guarding the index onunesc_lenkeeps the trailing-newline check correct for non-empty messages.Testing
Feed it a docker json line with an empty message, e.g.
{"log":"","stream":"stdout","time":"2024-01-01T00:00:00Z"}.Reduced the predicate to a standalone harness over the unmodified
flb_unescape_stringandunesc_ends_with_nl:before:
AddressSanitizer: heap-buffer-overflow ... READ of size 1 ... 1 bytes before 1-byte regionat theunesc[unesc_len - 1]line.after: runs clean, returns 0.
ASan flags the read on the unpatched tree and is clean after the patch.
ok-package-testlabel to test for all targets.Documentation
Backporting
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.
Summary by CodeRabbit