mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-26 01:03:40 +00:00
Fix slasher OOM (#9141)
Fix a vulnerability in the slasher whereby it would OOM upon processing an invalid attestation with an artificially high `validator_index`. This fix has already been made available to affected users on the `slasher-fix` branch. - Prevent attestations from being passed to the slasher prior to signature verification. This was unnecessary, as they would later be passed on successful validation as well. - Add a defensive cap on the maximum validator index processable by the slasher. The cap is high enough that it shouldn't be reached for several years, and will quickly result in warning logs if forgotten. - Add a regression test that confirms that the issue is fixed. Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -2,8 +2,17 @@ use crate::{AttesterRecord, Config, IndexedAttesterRecord};
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::{Arc, Weak};
|
||||
use tracing::warn;
|
||||
use types::{EthSpec, Hash256, IndexedAttestation};
|
||||
|
||||
/// Hard cap on validator indices accepted by the slasher.
|
||||
///
|
||||
/// Any attestation referencing a validator index above this limit is silently dropped during
|
||||
/// grouping. This is a defence-in-depth measure to prevent pathological memory allocation if an
|
||||
/// attestation with a bogus index somehow reaches the slasher. The value (2^23 = 8,388,608)
|
||||
/// provides generous headroom above the current mainnet validator set (~2M).
|
||||
const MAX_VALIDATOR_INDEX: u64 = 8_388_608;
|
||||
|
||||
/// Staging area for attestations received from the network.
|
||||
///
|
||||
/// Attestations are not grouped by validator index at this stage so that they can be easily
|
||||
@@ -72,6 +81,14 @@ impl<E: EthSpec> AttestationBatch<E> {
|
||||
let mut grouped_attestations = GroupedAttestations { subqueues: vec![] };
|
||||
|
||||
for ((validator_index, _), indexed_record) in self.attesters {
|
||||
if validator_index >= MAX_VALIDATOR_INDEX {
|
||||
warn!(
|
||||
validator_index,
|
||||
"Dropping slasher attestation with out-of-range validator index"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
let subqueue_id = config.validator_chunk_index(validator_index);
|
||||
|
||||
if subqueue_id >= grouped_attestations.subqueues.len() {
|
||||
|
||||
@@ -74,6 +74,11 @@ impl<E: EthSpec> Slasher<E> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
/// Return the number of attestations in the queue.
|
||||
pub fn attestation_queue_len(&self) -> usize {
|
||||
self.attestation_queue.len()
|
||||
}
|
||||
|
||||
/// Accept an attestation from the network and queue it for processing.
|
||||
pub fn accept_attestation(&self, attestation: IndexedAttestation<E>) {
|
||||
self.attestation_queue.queue(attestation);
|
||||
|
||||
Reference in New Issue
Block a user