From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pbs-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BDF651FF16E for <inbox@lore.proxmox.com>; Mon, 14 Apr 2025 15:18:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2A36533BA2; Mon, 14 Apr 2025 15:18:26 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: pbs-devel@lists.proxmox.com Date: Mon, 14 Apr 2025 15:18:22 +0200 Message-Id: <20250414131822.3862594-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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] tape: skip setting encryption if we can't and don't want to X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com> Some settings on changers prevents changing the encryption parameters via the application, e.g. some libraries have a 'encryption disabled' or 'encryption is library managed' option. While the former situation can be fixed by setting the library to 'application managed', the latter is sometimes necessary for FIPS compliance (to ensure the tape data is encrypted). When libraries are configured this way, the code currently fails with 'drive does not support AES-GCM encryption'. Instead of failing, check on first call to set_encryption if we could set it, and save that result. Only fail when encryption is to be enabled but it is not allowed, but ignore the error when the backup should be done unencrypted. With this change, it should be possible to use such configured libraries when there is no encryption configured on the PBS side. (We currently don't have a library with such capabilities to test.) Note that in contrast to normal operation, the tape label will also be encrypted then and will not be readable in case the encryption key is lost or changed. Additionally, return an error for 'drive_set_encryption' in case the drive reports that it does not support hardware encryption, because this is now already caught one level above in 'set_encryption'. This was reported in the community forum: https://forum.proxmox.com/threads/107383/ https://forum.proxmox.com/threads/164941/ Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- pbs-tape/src/sg_tape.rs | 24 +++++++++++++++++++++++- pbs-tape/src/sg_tape/encryption.rs | 10 +--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs index 39e6a2f94..c49714f6e 100644 --- a/pbs-tape/src/sg_tape.rs +++ b/pbs-tape/src/sg_tape.rs @@ -136,6 +136,8 @@ pub struct SgTape { file: File, locate_offset: Option<i64>, info: InquiryInfo, + // auto-detect if we can set the encryption mode + encryption_possible: Option<bool>, } impl SgTape { @@ -158,6 +160,7 @@ impl SgTape { file, info, locate_offset: None, + encryption_possible: None, }) } @@ -690,6 +693,14 @@ impl SgTape { } pub fn set_encryption(&mut self, key_data: Option<([u8; 32], Uuid)>) -> Result<(), Error> { + if self.encryption_possible == Some(false) { + if key_data.is_some() { + bail!("Drive does not support setting encryption mode"); + } else { + // skip trying to set encryption if not supported and don't wanted + return Ok(()); + } + } let key = if let Some((ref key, ref uuid)) = key_data { // derive specialized key for each media-set @@ -710,7 +721,18 @@ impl SgTape { None }; - drive_set_encryption(&mut self.file, key) + match drive_set_encryption(&mut self.file, key) { + Ok(()) => self.encryption_possible = Some(true), + Err(err) => { + self.encryption_possible = Some(false); + if key.is_some() { + bail!("could not set encryption mode on drive: {err}"); + } else { + log::info!("could not set encryption mode on drive: {err}, ignoring."); + } + } + } + Ok(()) } // Note: use alloc_page_aligned_buffer to alloc data transfer buffer diff --git a/pbs-tape/src/sg_tape/encryption.rs b/pbs-tape/src/sg_tape/encryption.rs index 7247d257f..c87986dca 100644 --- a/pbs-tape/src/sg_tape/encryption.rs +++ b/pbs-tape/src/sg_tape/encryption.rs @@ -12,15 +12,7 @@ use crate::sgutils2::{alloc_page_aligned_buffer, SgRaw}; /// /// We always use mixed mode, pub fn drive_set_encryption<F: AsRawFd>(file: &mut F, key: Option<[u8; 32]>) -> Result<(), Error> { - let data = match sg_spin_data_encryption_caps(file) { - Ok(data) => data, - Err(_) if key.is_none() => { - // Assume device does not support HW encryption - // We can simply ignore the clear key request - return Ok(()); - } - Err(err) => return Err(err), - }; + let data = sg_spin_data_encryption_caps(file)?; let algorithm_index = decode_spin_data_encryption_caps(&data)?; -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel