erts: Disable unsafe optimization in bs_append #9372
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Imagine that we execute the following code, where
X
andY
are integers:The first line sets up
erts_current_bin
,erts_bin_offset
, etc because it obviously should.However, the second line does not do so if
X
is zero, asbuild_size_in_bits
being zero short-circuits the relevant logic.This leaves a dangling pointer that, when we execute
erts_new_bs_put_integer
on the second line, we can land in a code path that ostensibly does not modify the buffer, but may nevertheless do a dummy read/write that is masked off, which can race with a write to the same address on another scheduler. For example, this can occur if there is a garbage collection betweenA
andB
, where the old heap thatA
lived on is picked up by another process on another scheduler beforeB
executes.Note that there does not need to be an actual link between
A
andB
here: all that is necessary is that an expression like<<A/bits, Y:X>>
is executed whereX
is zero. This issue was mostly benign before 9256aad that introduced an read-modify-write in certain cases that would be okay iferts_current_bin
anderts_bin_offset
had been set correctly.While we could fix the read-modify-write issue separately, the invariant that
erts_current_bin
anderts_bin_offset
are up to date has been broken, and it's difficult to tell whether other parts may suffer the same problem. Therefore, we will disable this optimization and reintroduce it again safely at a later time.