Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data race condition, concurrent writes to the err variable, causes Undefined Behavior #11349

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Oct 4, 2024

The main issue is that after #10910 the err variable is shared between requests because it uses the same address as the err defined outside the func.

This is an UB because we are overwriting memory and will cause crashes like #11335, where the check for not nil happens then gets overwrite with nil and crashes.

Fixes #11350

@bogdandrutu bogdandrutu requested a review from a team as a code owner October 4, 2024 05:10
@bogdandrutu bogdandrutu requested a review from codeboten October 4, 2024 05:10
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.54%. Comparing base (2d25853) to head (6b3b2cb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11349   +/-   ##
=======================================
  Coverage   91.54%   91.54%           
=======================================
  Files         428      428           
  Lines       20230    20233    +3     
=======================================
+ Hits        18519    18522    +3     
  Misses       1337     1337           
  Partials      374      374           

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

@bogdandrutu bogdandrutu added the release:blocker The issue must be resolved before cutting the next release label Oct 4, 2024
Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

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

I am honestly surprised that the golangci-lint or the race detector didn't catch this.

The other way you could resolve this is by having a named returned value for the lambda being created so that would shadow the error previously defined. However, this would be flagged by the shadow linter.

Alternatively, discourage anonymous functions being declared within methods could also be another way to stop this from occurring again in the project?

.chloggen/fix-ub-proc-helper.yaml Outdated Show resolved Hide resolved
@bogdandrutu bogdandrutu changed the title Fix data race condition, concurrent writes to the err variable, causes UB Fix data race condition, concurrent writes to the err variable, causes Undefined Behavior Oct 4, 2024
@bogdandrutu bogdandrutu merged commit d6cd593 into open-telemetry:main Oct 4, 2024
49 checks passed
@bogdandrutu bogdandrutu deleted the fix-ub-proc-helper branch October 4, 2024 06:33
@github-actions github-actions bot added this to the next release milestone Oct 4, 2024
jackgopack4 pushed a commit to jackgopack4/opentelemetry-collector that referenced this pull request Oct 8, 2024
…s Undefined Behavior (open-telemetry#11349)

The main issue is that after
open-telemetry#10910 the
err variable is shared between requests because it uses the same address
as the err defined outside the func.

This is an UB because we are overwriting memory and will cause crashes
like
open-telemetry#11335,
where the check for not nil happens then gets overwrite with nil and
crashes.

Fixes
open-telemetry#11350

---------

Signed-off-by: Bogdan Drutu <[email protected]>
HongChenTW pushed a commit to HongChenTW/opentelemetry-collector that referenced this pull request Dec 19, 2024
…s Undefined Behavior (open-telemetry#11349)

The main issue is that after
open-telemetry#10910 the
err variable is shared between requests because it uses the same address
as the err defined outside the func.

This is an UB because we are overwriting memory and will cause crashes
like
open-telemetry#11335,
where the check for not nil happens then gets overwrite with nil and
crashes.

Fixes
open-telemetry#11350

---------

Signed-off-by: Bogdan Drutu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:blocker The issue must be resolved before cutting the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory corruption or data race access in the collector
3 participants