From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3FE1569D6B for ; Mon, 10 Aug 2020 13:26:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 364371498A for ; Mon, 10 Aug 2020 13:25:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 8546F14980 for ; Mon, 10 Aug 2020 13:25:32 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4F71844548 for ; Mon, 10 Aug 2020 13:25:32 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Mon, 10 Aug 2020 13:25:08 +0200 Message-Id: <20200810112509.70129-6-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200810112509.70129-1-f.gruenbichler@proxmox.com> References: <20200810112509.70129-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.044 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 4/5] verify: also check chunk CryptMode X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Aug 2020 11:26:03 -0000 and in-line verify_stored_chunk to avoid double-loading each chunk. Signed-off-by: Fabian Grünbichler --- Notes: not 100% happy with this src/backup/datastore.rs | 6 ------ src/backup/verify.rs | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 5b6075ec..afdff224 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -551,12 +551,6 @@ impl DataStore { self.chunk_store.insert_chunk(chunk, digest) } - pub fn verify_stored_chunk(&self, digest: &[u8; 32], expected_chunk_size: u64) -> Result<(), Error> { - let blob = self.load_chunk(digest)?; - blob.verify_unencrypted(expected_chunk_size as usize, digest)?; - Ok(()) - } - pub fn load_blob(&self, backup_dir: &BackupDir, filename: &str) -> Result { let mut path = self.base_path(); path.push(backup_dir.relative_path()); diff --git a/src/backup/verify.rs b/src/backup/verify.rs index ec47534c..fa2f0aa5 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -40,6 +40,7 @@ fn verify_index_chunks( index: Box, verified_chunks: &mut HashSet<[u8;32]>, corrupt_chunks: &mut HashSet<[u8; 32]>, + crypt_mode: CryptMode, worker: &WorkerTask, ) -> Result<(), Error> { @@ -51,9 +52,38 @@ fn verify_index_chunks( let info = index.chunk_info(pos).unwrap(); let size = info.range.end - info.range.start; + let chunk = match datastore.load_chunk(&info.digest) { + Err(err) => { + corrupt_chunks.insert(info.digest); + worker.log(format!("can't verify chunk, load failed - {}", err)); + errors += 1; + continue; + }, + Ok(chunk) => chunk, + }; + + let chunk_crypt_mode = match chunk.crypt_mode() { + Err(err) => { + corrupt_chunks.insert(info.digest); + worker.log(format!("can't verify chunk, unknown CryptMode - {}", err)); + errors += 1; + continue; + }, + Ok(mode) => mode, + }; + + if chunk_crypt_mode != crypt_mode { + worker.log(format!( + "chunk CryptMode {:?} does not match index CryptMode {:?}", + chunk_crypt_mode, + crypt_mode + )); + errors += 1; + } + if !verified_chunks.contains(&info.digest) { if !corrupt_chunks.contains(&info.digest) { - if let Err(err) = datastore.verify_stored_chunk(&info.digest, size) { + if let Err(err) = chunk.verify_unencrypted(size as usize, &info.digest) { corrupt_chunks.insert(info.digest); worker.log(format!("{}", err)); errors += 1; @@ -98,7 +128,7 @@ fn verify_fixed_index( bail!("wrong index checksum"); } - verify_index_chunks(datastore, Box::new(index), verified_chunks, corrupt_chunks, worker) + verify_index_chunks(datastore, Box::new(index), verified_chunks, corrupt_chunks, info.chunk_crypt_mode(), worker) } fn verify_dynamic_index( @@ -124,7 +154,7 @@ fn verify_dynamic_index( bail!("wrong index checksum"); } - verify_index_chunks(datastore, Box::new(index), verified_chunks, corrupt_chunks, worker) + verify_index_chunks(datastore, Box::new(index), verified_chunks, corrupt_chunks, info.chunk_crypt_mode(), worker) } /// Verify a single backup snapshot -- 2.20.1