Skip to content

fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers #2887

Open
krishvishal wants to merge 3 commits intoapache:masterfrom
krishvishal:fix-2878
Open

fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers #2887
krishvishal wants to merge 3 commits intoapache:masterfrom
krishvishal:fix-2878

Conversation

@krishvishal
Copy link
Contributor

Closes #2878

Rationale

Consensus headers previously stored Command2 and Operation enum values directly in repr(C) structs. This is unsound for consensus header structs: arbitrary bytes from the network are reinterpreted as enum discriminants without validation, which is undefined behavior in Rust.

What changed?

  • Change command and operation fields in all consensus headers from enum types (Command2, Operation) to raw u8 to prevent UB when interpreting untrusted bytes from the network as Rust enum discriminants.
  • Add TryFrom<u8> impls for Command2 and Operation with proper error variants (InvalidCommandByte, InvalidOperationByte) in ConsensusError.
  • Fix dispatch_request to return Result<Receiver<R>, ConsensusError> instead of silently dropping unrecognized messages.

@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 62.02532% with 90 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.36%. Comparing base (33bee3d) to head (5c632a5).

Files with missing lines Patch % Lines
core/common/src/types/consensus/header.rs 74.39% 37 Missing and 5 partials ⚠️
core/common/src/types/consensus/message.rs 35.48% 20 Missing ⚠️
core/shard/src/router.rs 0.00% 14 Missing ⚠️
core/simulator/src/client.rs 0.00% 4 Missing ⚠️
core/consensus/src/impls.rs 0.00% 3 Missing ⚠️
core/consensus/src/plane_helpers.rs 75.00% 3 Missing ⚠️
core/partitions/src/iggy_partitions.rs 0.00% 2 Missing ⚠️
core/metadata/src/impls/metadata.rs 0.00% 1 Missing ⚠️
core/simulator/src/packet.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2887      +/-   ##
============================================
+ Coverage     68.33%   68.36%   +0.02%     
  Complexity      739      739              
============================================
  Files          1053     1053              
  Lines         84763    84916     +153     
  Branches      61297    61460     +163     
============================================
+ Hits          57923    58052     +129     
- Misses        24468    24482      +14     
- Partials       2372     2382      +10     
Flag Coverage Δ
csharp 67.43% <ø> (-0.19%) ⬇️
go 6.27% <ø> (ø)
java 54.83% <ø> (ø)
node 92.26% <ø> (-0.04%) ⬇️
python 81.57% <ø> (ø)
rust 70.07% <62.02%> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
core/consensus/src/namespaced_pipeline.rs 97.20% <100.00%> (ø)
core/metadata/src/stm/mod.rs 46.75% <100.00%> (ø)
core/metadata/src/impls/metadata.rs 16.03% <0.00%> (ø)
core/simulator/src/packet.rs 78.97% <75.00%> (-0.16%) ⬇️
core/partitions/src/iggy_partitions.rs 0.00% <0.00%> (ø)
core/consensus/src/impls.rs 42.48% <0.00%> (ø)
core/consensus/src/plane_helpers.rs 56.56% <75.00%> (ø)
core/simulator/src/client.rs 0.00% <0.00%> (ø)
core/shard/src/router.rs 0.00% <0.00%> (ø)
core/common/src/types/consensus/message.rs 58.97% <35.48%> (-1.42%) ⬇️
... and 1 more

... and 13 files with indirect coverage changes

🚀 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.

@krishvishal krishvishal changed the title fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers fix(consensus): prevent UB from untrusted bytes interpreted as enum discriminants in consensus headers Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unsafe impl Pod is unsound for consensus headers containing Command2 and Operation enums

2 participants