From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 5D0A41FF09B for ; Mon, 14 Sep 2026 13:17:08 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0D52D214CD; Mon, 14 Sep 2026 13:17:08 +0200 (CEST) Message-ID: Date: Mon, 14 Sep 2026 13:17:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Christian Ebner Subject: Re: [PATCH proxmox-backup 6/9] datastore: check that index files are regular files To: Robert Obkircher , pbs-devel@lists.proxmox.com References: <20260731142430.289893-1-r.obkircher@proxmox.com> <20260731142430.289893-7-r.obkircher@proxmox.com> Content-Language: en-US, de-DE In-Reply-To: <20260731142430.289893-7-r.obkircher@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1789384609872 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.667 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: 7H6X7NYBGM56PKWNRUAOPZGGCZ3CN6JV X-Message-ID-Hash: 7H6X7NYBGM56PKWNRUAOPZGGCZ3CN6JV X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Two nits inline. On 7/31/26 4:25 PM, Robert Obkircher wrote: > Return an explicit error message when trying to mmap something other > than a regular file. Previously, this was caught implicitly by the > non-zero size check or by a failing seek. > > Signed-off-by: Robert Obkircher > --- > pbs-datastore/src/dynamic_index.rs | 16 ++++++++-------- > pbs-datastore/src/fixed_index.rs | 15 ++++++++------- > 2 files changed, 16 insertions(+), 15 deletions(-) > > diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs > index 7ee8bdcab..dd0b86f3f 100644 > --- a/pbs-datastore/src/dynamic_index.rs > +++ b/pbs-datastore/src/dynamic_index.rs > @@ -8,6 +8,7 @@ use std::sync::{Arc, Mutex}; > use std::task::Context; > > use anyhow::{Error, bail, format_err}; > +use nix::sys::stat::{SFlag, fstat}; > > use proxmox_io::ReadExt; > use proxmox_sys::mmap::Mmap; > @@ -96,17 +97,16 @@ impl DynamicIndexReader { > } > > pub fn new(mut file: std::fs::File) -> Result { > + let stat = fstat(file.as_raw_fd()).map_err(|e| format_err!("fstat failed - {e}"))?; > + if (stat.st_mode & SFlag::S_IFMT.bits()) != SFlag::S_IFREG.bits() { > + bail!("not a regular file"); > + } > + > // FIXME: This is NOT OUR job! Check the callers of this method and remove this! > file.seek(SeekFrom::Start(0))?; > > let header_size = std::mem::size_of::(); > > - let rawfd = file.as_raw_fd(); > - let stat = match nix::sys::stat::fstat(rawfd) { > - Ok(stat) => stat, > - Err(err) => bail!("fstat failed - {}", err), > - }; > - > let size = stat.st_size as usize; > > if size < header_size { > @@ -611,11 +611,11 @@ mod tests { > > check_error_contains( > DynamicIndexReader::open(Path::new("/dev/stdin")), > - "Illegal seek", > + "not a regular file", > ); > check_error_contains( > DynamicIndexReader::open(Path::new("/dev/zero")), > - "index too small (0)", > + "not a regular file", > ); nit: this check is now somewhat redundant? The check for to small index is already performed further below, so this can be dropped IMO. > > let path = dir.path().join("file"); > diff --git a/pbs-datastore/src/fixed_index.rs b/pbs-datastore/src/fixed_index.rs > index 0145f93d3..1d3d0170a 100644 > --- a/pbs-datastore/src/fixed_index.rs > +++ b/pbs-datastore/src/fixed_index.rs > @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf}; > use std::ptr::NonNull; > > use anyhow::{Context, Error, bail, format_err}; > +use nix::sys::stat::{SFlag, fstat}; > > use proxmox_io::ReadExt; > use proxmox_uuid::Uuid; > @@ -60,15 +61,15 @@ impl FixedIndexReader { > } > > pub fn new(mut file: std::fs::File) -> Result { > + let stat = fstat(file.as_raw_fd()).map_err(|e| format_err!("fstat failed - {e}"))?; > + if (stat.st_mode & SFlag::S_IFMT.bits()) != SFlag::S_IFREG.bits() { > + bail!("not a regular file"); > + } > + > file.seek(SeekFrom::Start(0))?; > > let header_size = std::mem::size_of::(); > > - let stat = match nix::sys::stat::fstat(file.as_raw_fd()) { > - Ok(stat) => stat, > - Err(err) => bail!("fstat failed - {}", err), > - }; > - > let size = stat.st_size as usize; > > if size < header_size { > @@ -608,11 +609,11 @@ mod tests { > > check_error_contains( > FixedIndexReader::open(Path::new("/dev/stdin")), > - "Illegal seek", > + "not a regular file", > ); > check_error_contains( > FixedIndexReader::open(Path::new("/dev/zero")), > - "index too small (0)", > + "not a regular file", > ); nit: same as above, the second error testcase is now redundant. > > let path = dir.path().join("file");