Skip to content

Commit ca06673

Browse files
composefs/usr: Fix /usr permissions on overlay mount
The upper,work directories being created for `/usr` transient mount always had the mode `0o700` hence only being accessible to root Update `bootc_initramfs_setup::ensure_dir` to accept an optional `mode` argument Fixes: #1833 Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent d92423c commit ca06673

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

crates/initramfs/src/lib.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ pub fn open_dir(dirfd: impl AsFd, name: impl AsRef<Path> + Debug) -> Result<Owne
169169
}
170170

171171
#[context("Ensure dir")]
172-
fn ensure_dir(dirfd: impl AsFd, name: &str) -> Result<OwnedFd> {
173-
match mkdirat(dirfd.as_fd(), name, 0o700.into()) {
172+
fn ensure_dir(dirfd: impl AsFd, name: &str, mode: Option<rustix::fs::Mode>) -> Result<OwnedFd> {
173+
match mkdirat(dirfd.as_fd(), name, mode.unwrap_or(0o700.into())) {
174174
Ok(()) | Err(Errno::EXIST) => {}
175175
Err(err) => Err(err).with_context(|| format!("Creating dir {name}"))?,
176176
}
@@ -203,9 +203,14 @@ fn mount_tmpfs() -> Result<OwnedFd> {
203203
}
204204

205205
#[context("Mounting state as overlay")]
206-
fn overlay_state(base: impl AsFd, state: impl AsFd, source: &str) -> Result<()> {
207-
let upper = ensure_dir(state.as_fd(), "upper")?;
208-
let work = ensure_dir(state.as_fd(), "work")?;
206+
fn overlay_state(
207+
base: impl AsFd,
208+
state: impl AsFd,
209+
source: &str,
210+
mode: Option<rustix::fs::Mode>,
211+
) -> Result<()> {
212+
let upper = ensure_dir(state.as_fd(), "upper", mode)?;
213+
let work = ensure_dir(state.as_fd(), "work", mode)?;
209214

210215
let overlayfs = FsHandle::open("overlay")?;
211216
fsconfig_set_string(overlayfs.as_fd(), "source", source)?;
@@ -224,8 +229,8 @@ fn overlay_state(base: impl AsFd, state: impl AsFd, source: &str) -> Result<()>
224229

225230
/// Mounts a transient overlayfs with passed in fd as the lowerdir
226231
#[context("Mounting transient overlayfs")]
227-
pub fn overlay_transient(base: impl AsFd) -> Result<()> {
228-
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient")
232+
pub fn overlay_transient(base: impl AsFd, mode: Option<rustix::fs::Mode>) -> Result<()> {
233+
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient", mode)
229234
}
230235

231236
#[context("Opening rootfs")]
@@ -287,8 +292,9 @@ fn mount_subdir(
287292
open_dir(&new_root, subdir)?,
288293
open_dir(&state, subdir)?,
289294
"overlay",
295+
None,
290296
),
291-
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?),
297+
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None),
292298
}
293299
}
294300

@@ -350,7 +356,7 @@ pub fn setup_root(args: Args) -> Result<()> {
350356
}
351357

352358
if config.root.transient {
353-
overlay_transient(&new_root)?;
359+
overlay_transient(&new_root, None)?;
354360
}
355361

356362
match composefs::mount::mount_at(&sysroot_clone, &new_root, "sysroot") {

crates/lib/src/bootc_composefs/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub(crate) fn composefs_usr_overlay() -> Result<()> {
246246
return Ok(());
247247
}
248248

249-
overlay_transient(usr)?;
249+
overlay_transient(usr, Some(0o755.into()))?;
250250

251251
println!("A writeable overlayfs is now mounted on /usr");
252252
println!("All changes there will be discarded on reboot.");

0 commit comments

Comments
 (0)