Skip to content

fix(cpp): take EpsCopyInputStream::PopLimit token by rvalue reference - #28619

Closed
yashanil98 wants to merge 2 commits into
protocolbuffers:mainfrom
yashanil98:fix/issue-27298-limittoken-poison
Closed

yashanil98 wants to merge 2 commits into
protocolbuffers:mainfrom
yashanil98:fix/issue-27298-limittoken-poison

Conversation

@yashanil98

Copy link
Copy Markdown
Contributor

EpsCopyInputStream::LimitToken guards its payload with ASan memory poisoning (poisoned when empty, unpoisoned while it holds a live token). PopLimit accepted the token by value:

[[nodiscard]] bool PopLimit(LimitToken delta) { ... std::move(delta).token() ... }

With a by-value parameter, the compiler can place the parameter in the same stack slot as the moved-from caller token. The move assignment then poisons the moved-from token, i.e. the very slot the parameter occupies, and PopLimit reads it via token(), which ASan reports as a use-after-poison abort. This reproduces before main() during static descriptor initialization when protobuf is built with -fsanitize=address (reported on aarch64 in #27298), e.g.:

ERROR: AddressSanitizer: use-after-poison READ of size 4
  #0 EpsCopyInputStream::PopLimit(EpsCopyInputStream::LimitToken)
  #1 ParseContext::ParseLengthDelimitedInlined(...)
  ...
  Memory access is inside this variable: agg.tmp  (a LimitToken temporary)

Take the token by rvalue reference (LimitToken&& delta) instead. This removes the extra by-value copy and the shared-slot hazard: the token binds directly to the callers object, which is unpoisoned while live. All three callers (ParseLengthDelimitedInlined, ParseWithLengthInlined, ParseContext::ParseMessage) already pass std::move(old), and the body already consumes the token as an rvalue, so behavior is unchanged.

Fixes #27298.

Test plan: the bug reproduces only under ASan (poisoning is a no-op otherwise) and protobuf has no in-repo ASan-poisoning regression harness for the parser, so this is verified by (1) the change being a by-value to rvalue-reference signature refactor with no behavioral change, all callers already moving the token, and (2) a full CMake/Ninja build plus the parsing test suites staying green: tests --gtest_filter=*TcTable*:*Parse*:*WireFormat*:*Reflection*:*ExtensionSet*:*DynamicMessage*:*Arena* passes (~3000 tests, 0 failures). I do not have the reporters ASan+aarch64 toolchain to run the exact repro.

LimitToken guards its payload with ASan memory poisoning. PopLimit accepted
the token by value, so the compiler could place the by-value parameter in the
same stack slot as the moved-from caller token; the move then poisoned that
slot and PopLimit's read of it tripped a use-after-poison abort under ASan
during descriptor initialization. Bind the token by rvalue reference instead,
removing the extra copy and the shared-slot hazard. All three callers already
pass std::move, and the body already consumes the token as an rvalue, so
behavior is unchanged.

Fixes protocolbuffers#27298.
@shaod2
shaod2 self-requested a review July 21, 2026 17:20
@shaod2 shaod2 added c++ 🅰️ safe for tests Mark a commit as safe to run presubmits over labels Jul 21, 2026
@shaod2 shaod2 added 🅰️ safe for tests Mark a commit as safe to run presubmits over and removed 🅰️ safe for tests Mark a commit as safe to run presubmits over labels Jul 29, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jul 29, 2026
wperron added a commit to cloudflare/workerd that referenced this pull request Nov 18, 2026
tracer-test aborts under ASan + UBSan before main runs, while protobuf
registers the OTLP schemas' generated descriptors.
EpsCopyInputStream::LimitToken poisons its token once it is used, and
PopLimit() took the token by value. Clang 22 can give that parameter
the stack slot of the moved-from token, so the move poisons the
parameter and PopLimit() reads poisoned memory
(protocolbuffers/protobuf#27298).

protobuf 37.0 takes the token by rvalue reference
(protocolbuffers/protobuf#28619). No stable release has the fix yet,
so this freezes protobuf at 37.0-rc3 until 37.0 is out. Its
dependencies are already at or below the versions workerd uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wperron added a commit to cloudflare/workerd that referenced this pull request Nov 19, 2026
tracer-test aborts under ASan + UBSan before main runs, while protobuf
registers the OTLP schemas' generated descriptors.
EpsCopyInputStream::LimitToken poisons its token once it is used, and
PopLimit() took the token by value. Clang 22 can give that parameter
the stack slot of the moved-from token, so the move poisons the
parameter and PopLimit() reads poisoned memory
(protocolbuffers/protobuf#27298).

protobuf 37.0 takes the token by rvalue reference
(protocolbuffers/protobuf#28619). No stable release has the fix yet,
so this freezes protobuf at 37.0-rc3 until 37.0 is out. Its
dependencies are already at or below the versions workerd uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wperron added a commit to cloudflare/workerd that referenced this pull request Nov 19, 2026
tracer-test aborts under ASan + UBSan before main runs, while protobuf
registers the OTLP schemas' generated descriptors.
EpsCopyInputStream::LimitToken poisons its token once it is used, and
PopLimit() took the token by value. Clang 22 can give that parameter
the stack slot of the moved-from token, so the move poisons the
parameter and PopLimit() reads poisoned memory
(protocolbuffers/protobuf#27298).

protobuf 37.0 takes the token by rvalue reference
(protocolbuffers/protobuf#28619). No stable release has the fix yet,
so this freezes protobuf at 37.0-rc3 until 37.0 is out. Its
dependencies are already at or below the versions workerd uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wperron added a commit to cloudflare/workerd that referenced this pull request Nov 19, 2026
tracer-test aborts under ASan + UBSan before main runs, while protobuf
registers the OTLP schemas' generated descriptors.
EpsCopyInputStream::LimitToken poisons its token once it is used, and
PopLimit() took the token by value. Clang 22 can give that parameter
the stack slot of the moved-from token, so the move poisons the
parameter and PopLimit() reads poisoned memory
(protocolbuffers/protobuf#27298).

protobuf 37.0 takes the token by rvalue reference
(protocolbuffers/protobuf#28619). No stable release has the fix yet,
so this freezes protobuf at 37.0-rc3 until 37.0 is out. Its
dependencies are already at or below the versions workerd uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++: ASan use-after-poison in EpsCopyInputStream::PopLimit(LimitToken) on Linux arm64 with Clang 22 ASan+UBSan

2 participants