From 438af9164ee68ce9b6a9f5265112a609c7b54a2c Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 29 May 2022 09:45:02 +0100 Subject: [PATCH] Guard the Requester so that the Responder can't do whatever it wants --- datman/src/remote/backup_source_requester.rs | 5 ++++- yama/src/pile/access_guard.rs | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/datman/src/remote/backup_source_requester.rs b/datman/src/remote/backup_source_requester.rs index 5c7dc7c..3ba0200 100644 --- a/datman/src/remote/backup_source_requester.rs +++ b/datman/src/remote/backup_source_requester.rs @@ -11,6 +11,7 @@ use std::sync::Arc; use yama::commands::{load_pile_descriptor, open_pile}; use yama::definitions::{PartialPointerData, TreeNode}; use yama::operations::storing::{pointer_ops_prepare_to_store, pointers_ops_after_store}; +use yama::pile::access_guard::PileGuard; use yama::pile::{Pile, RawPile, StoragePipelineSettings}; use yama::progress::ProgressTracker; use yama::remote::responder::{Responder, ResponderWritingPipeline}; @@ -94,11 +95,13 @@ pub fn chunking< (None, None) }; + let guarded_pile = PileGuard::new(Arc::clone(&raw_pile), true); + let (r_handle, w_handle, join_handles) = Responder::start( read, write, get_number_of_workers("YAMA_RESPONDERS") as u16, - raw_pile, + Arc::new(guarded_pile), writing_pipeline, progress_bar, ); diff --git a/yama/src/pile/access_guard.rs b/yama/src/pile/access_guard.rs index 723a126..3c22adf 100644 --- a/yama/src/pile/access_guard.rs +++ b/yama/src/pile/access_guard.rs @@ -17,8 +17,8 @@ use std::thread; #[derivative(Clone(bound = ""))] // we need to use derivative's Clone impl because Arc causes R to have a bound on Clone // even though that's not needed. https://github.com/rust-lang/rust/issues/26925 -pub struct PileGuard { - underlying: Arc, +pub struct PileGuard { + underlying: R, /// Whether to verify chunk IDs to prevent malicious corruption verify_chunk_ids: bool, } @@ -39,9 +39,16 @@ fn pipeline( Ok(()) } -impl PileGuard {} +impl PileGuard { + pub fn new(underlying: R, verify_chunk_ids: bool) -> Self { + PileGuard { + underlying, + verify_chunk_ids, + } + } +} -impl RawPile for PileGuard { +impl RawPile for PileGuard { fn exists(&self, kind: Keyspace, key: &[u8]) -> anyhow::Result { match kind { Keyspace::Chunk => self.underlying.exists(kind, key),