Skip to main content

Crate ostrya_sys

Crate ostrya_sys 

Source
Expand description

Wrappers for the Linux fs-verity ioctls, a read-only memory map, the loop device, a sealed memory file, namespace descriptors, ID-mapped mounts, and socket credentials.

A caller seals a file with fs-verity and reads the digest and the parameters that the kernel holds for the sealed file. The seal has the parameters that ostree uses: SHA-256, 4096-byte blocks, and no salt. A caller can also map a file read-only. On Linux, a caller attaches a file to a loop device, and writes bytes to a memory file that it then seals. It reads the type and the owner of a namespace, gives a thread its own file system attributes, sets an ID mapping on a detached mount, reads the groups of the peer of a Unix socket, and takes the socket that systemd passes. The crate depends on rustix. On Linux it also depends on libc, for the two calls that rustix does not give: mount_setattr and SO_PEERGROUPS.

§Entry points

§Examples

The example seals a file and reads its parameters and its digest. The file system of the file must support fs-verity.

use std::fs::File;

use ostrya_sys::{enable_verity, measure_verity, read_verity_descriptor};

// A read-only descriptor, and no writable descriptor to the file.
let file = File::open("object.file")?;
enable_verity(&file)?;
let desc = read_verity_descriptor(&file)?;
// SHA-256, 4096-byte blocks (2 to the power 12), and no salt.
assert_eq!((desc.hash_algorithm, desc.log_blocksize, desc.salt_size), (1, 12, 0));
let digest: [u8; 32] = measure_verity(&file)?;

This crate holds all unsafe code of the ostrya library crates. A SAFETY comment on each unsafe block gives its reasoning.

Re-exports§

pub use imp::VerityDescriptor;
pub use imp::enable_verity;
pub use imp::measure_verity;
pub use imp::read_verity_descriptor;

Structs§

LoopConfig
The configuration of a new loop device.
LoopDevice
An open loop device with a backing file.
Mmap
A read-only, private memory map of an open file.
VerityDescriptor
The fs-verity parameters of a sealed file, from its fsverity_descriptor.

Constants§

LO_FLAGS_AUTOCLEAR
The kernel detaches the backing file at the last close of the device.
LO_FLAGS_DIRECT_IO
The loop device reads the backing file with direct I/O.
LO_FLAGS_READ_ONLY
The loop device is read-only.

Functions§

enable_verity
Enables fs-verity on fd with SHA-256, 4096-byte blocks, and no salt.
measure_verity
Returns the fs-verity SHA-256 digest that the kernel holds for fd.
mount_setattr_idmap
Sets an ID mapping on the detached mount mount, with the user namespace userns.
ns_owner_userns
Returns a descriptor of the user namespace that owns the namespace fd.
ns_type
Returns the type of the namespace that fd refers to.
peer_groups
Returns the raw ids of the supplementary groups of the peer of the Unix socket sock. The peer must have at most max groups.
read_verity_descriptor
Returns the fs-verity parameters that the kernel holds for fd.
seal_contents
Seals the content of a memory file from sealable_memfd.
sealable_memfd
Creates an anonymous memory file that accepts seals.
systemd_listen_fd
Returns the one socket that systemd passes to the process, and sets its close-on-exec flag.
unshare_fs
Gives the calling thread its own copy of its file system attributes: the root directory, the working directory, and the umask.