Skip to content

Commit b0623e4

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 3f5a3c7 commit b0623e4

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

crates/initramfs/src/lib.rs

Lines changed: 10 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<u32>) -> 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,9 @@ 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(base: impl AsFd, state: impl AsFd, source: &str, mode: Option<u32>) -> Result<()> {
207+
let upper = ensure_dir(state.as_fd(), "upper", mode)?;
208+
let work = ensure_dir(state.as_fd(), "work", mode)?;
209209

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

225225
/// Mounts a transient overlayfs with passed in fd as the lowerdir
226226
#[context("Mounting transient overlayfs")]
227-
pub fn overlay_transient(base: impl AsFd) -> Result<()> {
228-
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient")
227+
pub fn overlay_transient(base: impl AsFd, mode: Option<u32>) -> Result<()> {
228+
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient", mode)
229229
}
230230

231231
#[context("Opening rootfs")]
@@ -287,8 +287,9 @@ fn mount_subdir(
287287
open_dir(&new_root, subdir)?,
288288
open_dir(&state, subdir)?,
289289
"overlay",
290+
None,
290291
),
291-
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?),
292+
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None),
292293
}
293294
}
294295

@@ -350,7 +351,7 @@ pub fn setup_root(args: Args) -> Result<()> {
350351
}
351352

352353
if config.root.transient {
353-
overlay_transient(&new_root)?;
354+
overlay_transient(&new_root, None)?;
354355
}
355356

356357
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))?;
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)