-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use composefs crate for fsverity digest reading #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use std::os::fd::AsFd; | |
use anyhow::Result; | ||
use rustix::ioctl; | ||
|
||
use super::FsVerityHashValue; | ||
use super::{FsVerityHashValue, Sha256HashValue}; | ||
|
||
// See /usr/include/linux/fsverity.h | ||
#[repr(C)] | ||
|
@@ -43,36 +43,10 @@ pub fn fs_ioc_enable_verity<F: AsFd, H: FsVerityHashValue>(fd: F) -> Result<()> | |
Ok(()) | ||
} | ||
|
||
#[repr(C)] | ||
pub struct FsVerityDigest<F> { | ||
digest_algorithm: u16, | ||
digest_size: u16, | ||
digest: F, | ||
} | ||
|
||
// #define FS_IOC_MEASURE_VERITY _IORW('f', 134, struct fsverity_digest) | ||
type FsIocMeasureVerity = ioctl::ReadWriteOpcode<b'f', 134, FsVerityDigest<()>>; | ||
|
||
pub fn fs_ioc_measure_verity<F: AsFd, H: FsVerityHashValue>(fd: F) -> Result<H> { | ||
let digest_size = std::mem::size_of::<H>() as u16; | ||
let digest_algorithm = H::ALGORITHM as u16; | ||
|
||
let mut digest = FsVerityDigest::<H> { | ||
digest_algorithm, | ||
digest_size, | ||
digest: H::EMPTY, | ||
}; | ||
|
||
unsafe { | ||
ioctl::ioctl( | ||
fd, | ||
ioctl::Updater::<FsIocMeasureVerity, FsVerityDigest<H>>::new(&mut digest), | ||
)?; | ||
} | ||
|
||
if digest.digest_algorithm != digest_algorithm || digest.digest_size != digest_size { | ||
Err(std::io::Error::from(std::io::ErrorKind::InvalidData))? | ||
} else { | ||
Ok(digest.digest) | ||
} | ||
pub fn fs_ioc_measure_verity<F: AsFd>(fd: F) -> Result<Sha256HashValue> { | ||
let mut digest = composefs::fsverity::Digest::new(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also looking at this, perhaps we should drop the OTOH, and this relates to a larger topic...I feel like in practice we end up converting to hex in many places anyways, so we may as well canonicalize to e.g. this Sha256Digest instead. |
||
composefs::fsverity::fsverity_digest_from_fd(fd.as_fd(), &mut digest)?; | ||
let mut r = Sha256HashValue::EMPTY; | ||
r.copy_from_slice(digest.get()); | ||
Ok(r) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said this code is quite elegant and nice; the generics usage for sha256/sha512 is cool. But OTOH there are no plans to use anything but sha256 for composefs.
What we could do though is move some of this "reimplement composefs core in Rust" into the composefs git repo under the composefs crate under an optional feature flag or something - might be especially useful to "cross test" i.e. verify the C and Rust codepaths do the same thing.