fix: initialize config_gen_ectx on allocation to prevent use-after-poison#546
Merged
fix: initialize config_gen_ectx on allocation to prevent use-after-poison#546
Conversation
…ison Long-story-short: there was random dataplane crash with ASAN build. Now it's gone. Explanation requires detailing about cp/dp config exchanges. The `cp_config_gen_create` and `cp_config_gen_create_from` allocate `cp_config_gen` via `memory_balloc`, which does not(!) zero memory. When the block allocator returns a recycled block, the `config_gen_ectx` field contains stale data from its previous owner. The dataplane worker reads this field via `ADDR_OF(&cp_config_gen->config_gen_ectx)`, which computes a relative pointer: `stored_offset + &field`. With stale (non-zero) content, this resolves to a wild pointer into freed (ASAN-poisoned) memory, causing a `use-after-poison` crash in `worker_loop_round`. The fix explicitly sets `config_gen_ectx = NULL` right after allocation in both creation paths, so `ADDR_OF` correctly returns NULL before `config_gen_ectx_create` has a chance to set the real value. The fun part: the mock previously contained a workaround. This is no longer needed since the fix is now inside `cp_config_gen_create` itself. A regression test (`config_gen_test`) reproduces the bug by polluting the allocator pool with garbage before calling `cp_config_gen_create`. Without the fix, the stale offset resolves to a wild pointer and the volatile read triggers UBSAN/ASAN. With the fix, `ADDR_OF` returns NULL and the access is skipped.
sakateka
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Long-story-short: there was random dataplane crash with ASAN build. Now it's gone.
Explanation requires detailing about cp/dp config exchanges.
The
cp_config_gen_createandcp_config_gen_create_fromallocatecp_config_genviamemory_balloc, which does not(!) zero memory. When the block allocator returns a recycled block, theconfig_gen_ectxfield contains stale data from its previous owner.The dataplane worker reads this field via
ADDR_OF(&cp_config_gen->config_gen_ectx), which computes a relative pointer:stored_offset + &field. With stale (non-zero) content, this resolves to a wild pointer into freed (ASAN-poisoned) memory, causing ause-after-poisoncrash inworker_loop_round.The fix explicitly sets
config_gen_ectx = NULLright after allocation in both creation paths, soADDR_OFcorrectly returns NULL beforeconfig_gen_ectx_createhas a chance to set the real value.The fun part: the mock previously contained a workaround. This is no longer needed since the fix is now inside
cp_config_gen_createitself.A regression test (
config_gen_test) reproduces the bug by polluting the allocator pool with garbage before callingcp_config_gen_create. Without the fix, the stale offset resolves to a wild pointer and the volatile read triggers UBSAN/ASAN. With the fix,ADDR_OFreturns NULL and the access is skipped.