Skip to content

Commit cb6bfbb

Browse files
croissanneallisonkarlitskaya
authored andcommitted
fsverity: distinguish between verity missing and not supported
When measuring the verity, distinguish between fs-verity not being enabled on the file, and the filesystem itself not supporting fs-verity. Signed-off-by: Sanne Raymaekers <[email protected]>
1 parent 828895c commit cb6bfbb

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

crates/composefs/src/fsverity/ioctl.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ pub(super) fn fs_ioc_measure_verity<H: FsVerityHashValue>(
107107
}
108108
Ok(digest.digest)
109109
}
110-
Err(Errno::NODATA | Errno::NOTTY | Errno::OPNOTSUPP) => {
111-
Err(MeasureVerityError::VerityMissing)
112-
}
110+
Err(Errno::NODATA) => Err(MeasureVerityError::VerityMissing),
111+
Err(Errno::NOTTY | Errno::OPNOTSUPP) => Err(MeasureVerityError::FilesystemNotSupported),
113112
Err(Errno::OVERFLOW) => Err(MeasureVerityError::InvalidDigestSize {
114113
expected: digest.digest_size,
115114
}),
@@ -124,19 +123,29 @@ mod tests {
124123
use rustix::fd::FromRawFd;
125124
use tempfile::tempfile_in;
126125

127-
use crate::fsverity::Sha256HashValue;
126+
use crate::{fsverity::Sha256HashValue, test::tempfile};
128127

129128
use super::*;
130129

131130
#[test]
132131
fn test_measure_verity_opt() {
133-
let tf = tempfile::tempfile().unwrap();
132+
let tf = tempfile();
134133
assert!(matches!(
135134
fs_ioc_measure_verity::<Sha256HashValue>(&tf),
136135
Err(MeasureVerityError::VerityMissing)
137136
));
138137
}
139138

139+
#[test_with::path(/dev/shm)]
140+
#[test]
141+
fn test_measure_verity_not_supported() {
142+
let tf = tempfile_in("/dev/shm").unwrap();
143+
assert!(matches!(
144+
fs_ioc_measure_verity::<Sha256HashValue>(&tf),
145+
Err(MeasureVerityError::FilesystemNotSupported)
146+
));
147+
}
148+
140149
#[test_with::path(/dev/shm)]
141150
#[test]
142151
fn test_fs_ioc_enable_verity_wrong_fs() {

crates/composefs/src/fsverity/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub enum MeasureVerityError {
1515
Io(#[from] Error),
1616
#[error("fs-verity is not enabled on file")]
1717
VerityMissing,
18+
#[error("fs-verity is not support by filesystem")]
19+
FilesystemNotSupported,
1820
#[error("Expected algorithm {expected}, found {found}")]
1921
InvalidDigestAlgorithm { expected: u16, found: u16 },
2022
#[error("Expected digest size {expected}")]
@@ -110,7 +112,9 @@ pub fn measure_verity_opt<H: FsVerityHashValue>(
110112
) -> Result<Option<H>, MeasureVerityError> {
111113
match ioctl::fs_ioc_measure_verity(fd) {
112114
Ok(result) => Ok(Some(result)),
113-
Err(MeasureVerityError::VerityMissing) => Ok(None),
115+
Err(MeasureVerityError::VerityMissing | MeasureVerityError::FilesystemNotSupported) => {
116+
Ok(None)
117+
}
114118
Err(other) => Err(other),
115119
}
116120
}
@@ -253,7 +257,7 @@ mod tests {
253257

254258
assert!(matches!(
255259
measure_verity::<Sha256HashValue>(&tf).unwrap_err(),
256-
MeasureVerityError::VerityMissing
260+
MeasureVerityError::FilesystemNotSupported
257261
));
258262

259263
assert!(measure_verity_opt::<Sha256HashValue>(&tf)
@@ -262,7 +266,7 @@ mod tests {
262266

263267
assert!(matches!(
264268
ensure_verity_equal(&tf, &Sha256HashValue::EMPTY).unwrap_err(),
265-
CompareVerityError::Measure(MeasureVerityError::VerityMissing)
269+
CompareVerityError::Measure(MeasureVerityError::FilesystemNotSupported)
266270
));
267271
}
268272

0 commit comments

Comments
 (0)