Skip to content

Avoid eager MQTT response buffer access#2515

Merged
grcevski merged 1 commit into
open-telemetry:mainfrom
MrAlias:fix-eager-resp-buff-deref-panic
Jun 26, 2026
Merged

Avoid eager MQTT response buffer access#2515
grcevski merged 1 commit into
open-telemetry:mainfrom
MrAlias:fix-eager-resp-buff-deref-panic

Conversation

@MrAlias

@MrAlias MrAlias commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • A previous change eagerly dereferenced the response buffer via rpkt.UnsafeView() at function entry which can panic if rpkt is nil even when the request buffer (pkt) contains a valid MQTT packet.
  • The goal is to make ProcessPossibleMQTTEvent robust for callers that may pass a nil response buffer while preserving existing behavior when the response buffer is present.

Description

  • In pkg/ebpf/common/mqtt_detect_transform.go defer the response-buffer dereference and replace the eager rpkt.UnsafeView() with a lazy call inside the error path: ProcessMQTTEvent(rpkt.UnsafeView()).
  • In pkg/ebpf/common/mqtt_detect_transform_test.go add a regression test case PUBLISH in request buffer without response buffer and adjust the test harness to pass a nil *largebuf.LargeBuffer when response is absent so the function is exercised with a nil response buffer.
  • Applied formatting (gofmt) to the modified files.

Testing

  • go test ./pkg/internal/ebpf/mqttparser
  • go test ./pkg/internal/largebuf
  • go test ./pkg/ebpf/common -run TestProcessPossibleMQTTEvent

@MrAlias MrAlias added this to the v0.10.0 milestone Jun 26, 2026
@MrAlias MrAlias requested a review from a team as a code owner June 26, 2026 16:01
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.88%. Comparing base (914ffa4) to head (20b3775).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ebpf/common/mqtt_detect_transform.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2515      +/-   ##
==========================================
- Coverage   69.24%   68.88%   -0.36%     
==========================================
  Files         345      345              
  Lines       46747    46795      +48     
==========================================
- Hits        32372    32237     -135     
- Misses      12330    12521     +191     
+ Partials     2045     2037       -8     
Flag Coverage Δ
integration-test 50.65% <33.33%> (-0.28%) ⬇️
integration-test-arm 26.44% <25.00%> (-1.86%) ⬇️
integration-test-vm-5.15-lts ?
integration-test-vm-6.18-lts ?
k8s-integration-test 35.76% <33.33%> (+0.06%) ⬆️
oats-test 35.34% <33.33%> (-0.02%) ⬇️
unittests 63.36% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MrAlias MrAlias added bug Something isn't working go Related to Go code labels Jun 26, 2026

@grcevski grcevski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@grcevski grcevski merged commit 0be89c3 into open-telemetry:main Jun 26, 2026
98 checks passed
@MrAlias MrAlias deleted the fix-eager-resp-buff-deref-panic branch June 26, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Related to Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants