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

Handle potential error from newBlockRangeBatcher #13344

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Handle potential error from newBlockRangeBatcher #13344

merged 1 commit into from
Dec 15, 2023

Conversation

jtraglia
Copy link
Contributor

@jtraglia jtraglia commented Dec 14, 2023

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

This is a really interesting bug that I'm surprised errcheck didn't identify. The error from newBlockRangeBatcher isn't checked. This could actually be exploited to crash Prysm with a nil pointer dereference.

batcher, err := newBlockRangeBatcher(rp, s.cfg.beaconDB, s.rateLimiter, s.cfg.chain.IsCanonical, ticker)
var batch blockBatch
wQuota := params.BeaconNetworkConfig().MaxRequestBlobSidecars
for batch, ok = batcher.next(ctx, stream); ok; batch, ok = batcher.next(ctx, stream) {

Details

If an attacker sends a BlobSidecarsByRange request with the start slot greater than the current slot, it will return a rangeParams with size: 0.

// Peers may overshoot the current slot when in initial sync, so we don't want to penalize them by treating the
// request as an error. So instead we return a set of params that acts as a noop.
if rp.start > current {
return rangeParams{start: current, end: current, size: 0}, nil
}

When newBlockRangeBatcher gets this, it will return nil, someErr which doesn't get checked:

if rp.size == 0 {
return nil, fmt.Errorf("invalid batch size of %d", rp.size)
}

Then it will nil pointer dereference when batcher.next() is called:

batcher, err := newBlockRangeBatcher(rp, s.cfg.beaconDB, s.rateLimiter, s.cfg.chain.IsCanonical, ticker)
var batch blockBatch
wQuota := params.BeaconNetworkConfig().MaxRequestBlobSidecars
for batch, ok = batcher.next(ctx, stream); ok; batch, ok = batcher.next(ctx, stream) {

This is not exploitable until the Deneb hardfork. The RPC handler is only registered at that epoch.

if currEpoch >= params.BeaconConfig().DenebForkEpoch {
s.registerRPCHandlersDeneb()
}

@jtraglia jtraglia requested a review from a team as a code owner December 14, 2023 20:56
@jtraglia jtraglia requested review from potuz, rkapka and nisdas December 14, 2023 20:56
@prestonvanloon
Copy link
Member

Upstream issue kisielk/errcheck#7

@kasey kasey added this pull request to the merge queue Dec 15, 2023
Merged via the queue into prysmaticlabs:develop with commit 97dfec8 Dec 15, 2023
17 checks passed
@jtraglia jtraglia deleted the handle-batcher-err branch December 15, 2023 13:53
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.

3 participants