WEFT_OS/crates/weft-mount-helper
Marco Allegretti 076ed95eb1
fix(mount-helper): confine what a setuid caller can mount and unmount
weft-mount-helper is meant to be installed setuid root, but it trusted
its caller entirely: it ran veritysetup, mount and umount from the
caller's PATH, mounted a caller's image at any directory, such as over
/etc, and unmounted any mountpoint. Any local user could have gained
root through it.

It now mounts only at an empty directory
/run/user/<uid>/weft/mnt/<name> of the real user, where weft-appd puts
its mountpoints, with every component from <uid> on owned by that user,
not writable by others and opened without following symbolic links,
and mounts through the opened directory, so the path cannot be swapped
meanwhile. It opens the image and hash tree with the real user's
permissions, checks the root hash is a hex digest, mounts read-only with
nosuid, nodev and noexec through mount(2), and unmounts only an EROFS
filesystem at such a directory. veritysetup runs from the absolute path
fixed at build time (WEFT_VERITYSETUP, /usr/sbin/veritysetup by
default), with an empty environment. Devices are named
weft-<uid>-<name>, so a user reaches only their own; a device left by an
interrupted mount is closed by the next mount or unmount at that
directory, and a user may have at most 64 open, counted from the
kernel's list of device-mapper devices under a root-owned lock. Closed standard streams
are reopened on /dev/null before anything else is opened, and errors and
panics are printed as one-line messages.

Run setuid as nobody with a PATH holding a hostile veritysetup and
mount, the helper refuses /etc and another user's directory as
mountpoints, a symbolic link to /etc, a file nobody cannot read, a
malformed root hash, and unmounting /etc or a directory with no image;
a valid request reaches veritysetup at its fixed path, also with the
standard streams closed, and the hostile programs never run. Unit tests cover the mountpoint rules.
2026-10-09 20:56:52 +00:00
..
src fix(mount-helper): confine what a setuid caller can mount and unmount 2026-10-09 20:56:52 +00:00
Cargo.toml fix(mount-helper): confine what a setuid caller can mount and unmount 2026-10-09 20:56:52 +00:00