Skip to content

Commit 7e86960

Browse files
committed
setup-root: Fix overlay permissions
The overlayfs merged view inherits its root permissions from the upperdir; creating it as 0700 breaks unprivileged processes accessing it. This mirrors what systemd does in volatile-root.c and nspawn-mount.c. Fixes: #287 Assisted-by: OpenCode (claude-sonnet-4-6@default) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 5d5e76e commit 7e86960

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • crates/composefs-setup-root/src

crates/composefs-setup-root/src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ fn open_dir(dirfd: impl AsFd, name: impl AsRef<Path> + Debug) -> rustix::io::Res
111111
})
112112
}
113113

114-
fn ensure_dir(dirfd: impl AsFd, name: &str) -> rustix::io::Result<OwnedFd> {
115-
match mkdirat(dirfd.as_fd(), name, 0o700.into()) {
114+
fn ensure_dir(dirfd: impl AsFd, name: &str, mode: Mode) -> rustix::io::Result<OwnedFd> {
115+
match mkdirat(dirfd.as_fd(), name, mode) {
116116
Ok(()) | Err(Errno::EXIST) => {}
117117
Err(err) => Err(err)?,
118118
}
@@ -143,8 +143,13 @@ fn mount_tmpfs() -> Result<OwnedFd> {
143143
}
144144

145145
fn overlay_state(base: impl AsFd, state: impl AsFd, source: &str) -> Result<()> {
146-
let upper = ensure_dir(state.as_fd(), "upper")?;
147-
let work = ensure_dir(state.as_fd(), "work")?;
146+
// upper must be 0755: the overlayfs merged view inherits permissions from
147+
// upperdir, so 0700 would make / (or the mounted subdir) inaccessible to
148+
// non-root processes (dbus, anything that drops privileges).
149+
// work is kernel-internal and never visible in the merged view; 0700 is fine.
150+
// See: https://github.com/composefs/composefs-rs/issues/287
151+
let upper = ensure_dir(state.as_fd(), "upper", 0o755.into())?;
152+
let work = ensure_dir(state.as_fd(), "work", 0o700.into())?;
148153

149154
let overlayfs = FsHandle::open("overlay")?;
150155
fsconfig_set_string(overlayfs.as_fd(), "source", source)?;

0 commit comments

Comments
 (0)