Skip to content

Commit a79ab00

Browse files
committed
bootloader: Mount the ESP with restricted fmask+dmask
This avoids warnings from `bootctl install` for good reasons. Visible from `bootc install` using systemd-boot. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 817d7d1 commit a79ab00

5 files changed

Lines changed: 25 additions & 14 deletions

File tree

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use ostree_ext::composefs_boot::{
2525
os_release::OsReleaseInfo, uki,
2626
};
2727
use ostree_ext::composefs_oci::image::create_filesystem as create_composefs_filesystem;
28-
use rustix::path::Arg;
28+
use rustix::{mount::MountFlags, path::Arg};
2929
use schemars::JsonSchema;
3030
use serde::{Deserialize, Serialize};
3131

@@ -155,6 +155,12 @@ pub fn get_esp_partition(device: &str) -> Result<(String, Option<String>)> {
155155
Ok((esp.node.clone(), esp.uuid.clone()))
156156
}
157157

158+
/// Mount the ESP from the provided device
159+
pub fn mount_esp(device: &str) -> Result<TempMount> {
160+
let flags = MountFlags::NOEXEC | MountFlags::NOSUID;
161+
TempMount::mount_dev(device, "vfat", flags, Some(c"fmask=0177,dmask=0077"))
162+
}
163+
158164
pub fn get_sysroot_parent_dev() -> Result<String> {
159165
let sysroot = Utf8PathBuf::from("/sysroot");
160166

@@ -418,7 +424,7 @@ pub(crate) fn setup_composefs_bls_boot(
418424
),
419425

420426
Bootloader::Systemd => {
421-
let efi_mount = TempMount::mount_dev(&esp_device).context("Mounting ESP")?;
427+
let efi_mount = mount_esp(&esp_device).context("Mounting ESP")?;
422428

423429
let mounted_efi = Utf8PathBuf::from(efi_mount.dir.path().as_str()?);
424430
let efi_linux_dir = mounted_efi.join(EFI_LINUX);
@@ -857,7 +863,7 @@ pub(crate) fn setup_composefs_uki_boot(
857863
}
858864
};
859865

860-
let esp_mount = TempMount::mount_dev(&esp_device).context("Mounting ESP")?;
866+
let esp_mount = mount_esp(&esp_device).context("Mounting ESP")?;
861867

862868
let mut boot_label = String::new();
863869

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::path::Path;
22

3-
use crate::bootc_composefs::boot::{get_esp_partition, get_sysroot_parent_dev, BootType};
3+
use crate::bootc_composefs::boot::{
4+
get_esp_partition, get_sysroot_parent_dev, mount_esp, BootType,
5+
};
46
use crate::bootc_composefs::rollback::{rename_exchange_bls_entries, rename_exchange_user_cfg};
57
use crate::spec::Bootloader;
68
use crate::{
@@ -85,7 +87,7 @@ pub(crate) async fn composefs_backend_finalize() -> Result<()> {
8587
// NOTE: Assumption here that ESP will always be present
8688
let (esp_part, ..) = get_esp_partition(&sysroot_parent)?;
8789

88-
let esp_mount = TempMount::mount_dev(&esp_part)?;
90+
let esp_mount = mount_esp(&esp_part)?;
8991
let boot_dir = Dir::open_ambient_dir("/sysroot/boot", ambient_authority())
9092
.context("Opening sysroot/boot")?;
9193

crates/lib/src/bootc_composefs/status.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use std::{io::Read, sync::OnceLock};
22

33
use anyhow::{Context, Result};
44
use bootc_kernel_cmdline::utf8::Cmdline;
5-
use bootc_mount::tempmount::TempMount;
65
use fn_error_context::context;
76

87
use crate::{
9-
bootc_composefs::boot::{get_esp_partition, get_sysroot_parent_dev, BootType},
8+
bootc_composefs::boot::{get_esp_partition, get_sysroot_parent_dev, mount_esp, BootType},
109
composefs_consts::{COMPOSEFS_CMDLINE, TYPE1_ENT_PATH, USER_CFG},
1110
parsers::{
1211
bls_config::{parse_bls_config, BLSConfig, BLSConfigType},
@@ -349,7 +348,7 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
349348
let parent = get_sysroot_parent_dev()?;
350349
let (esp_part, ..) = get_esp_partition(&parent)?;
351350

352-
let esp_mount = TempMount::mount_dev(&esp_part)?;
351+
let esp_mount = mount_esp(&esp_part)?;
353352

354353
let dir = esp_mount.fd.try_clone().context("Cloning fd")?;
355354
let guard = Some(esp_mount);

crates/lib/src/bootloader.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use bootc_blockdev::{Partition, PartitionTable};
99
use bootc_mount as mount;
1010

1111
#[cfg(any(feature = "composefs-backend", feature = "install-to-disk"))]
12-
use bootc_mount::tempmount::TempMount;
13-
12+
use crate::bootc_composefs::boot::mount_esp;
1413
use crate::utils;
1514

1615
/// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel)
@@ -90,7 +89,7 @@ pub(crate) fn install_systemd_boot(
9089
.find(|p| p.parttype.as_str() == ESP_GUID)
9190
.ok_or_else(|| anyhow::anyhow!("ESP partition not found"))?;
9291

93-
let esp_mount = TempMount::mount_dev(&esp_part.node).context("Mounting ESP")?;
92+
let esp_mount = mount_esp(&esp_part.node).context("Mounting ESP")?;
9493
let esp_path = Utf8Path::from_path(esp_mount.dir.path())
9594
.ok_or_else(|| anyhow::anyhow!("Failed to convert ESP mount path to UTF-8"))?;
9695

crates/mount/src/tempmount.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::{Context, Result};
55
use camino::Utf8Path;
66
use cap_std_ext::cap_std::{ambient_authority, fs::Dir};
77
use fn_error_context::context;
8-
use rustix::mount::{move_mount, unmount, MoveMountFlags, UnmountFlags};
8+
use rustix::mount::{move_mount, unmount, MountFlags, MoveMountFlags, UnmountFlags};
99

1010
pub struct TempMount {
1111
pub dir: tempfile::TempDir,
@@ -15,13 +15,18 @@ pub struct TempMount {
1515
impl TempMount {
1616
/// Mount device/partition on a tempdir which will be automatically unmounted on drop
1717
#[context("Mounting {dev}")]
18-
pub fn mount_dev(dev: &str) -> Result<Self> {
18+
pub fn mount_dev(
19+
dev: &str,
20+
fstype: &str,
21+
flags: MountFlags,
22+
data: Option<&std::ffi::CStr>,
23+
) -> Result<Self> {
1924
let tempdir = tempfile::TempDir::new()?;
2025

2126
let utf8path = Utf8Path::from_path(tempdir.path())
2227
.ok_or(anyhow::anyhow!("Failed to convert path to UTF-8 Path"))?;
2328

24-
crate::mount(dev, utf8path)?;
29+
rustix::mount::mount(dev, utf8path.as_std_path(), fstype, flags, data)?;
2530

2631
let fd = Dir::open_ambient_dir(tempdir.path(), ambient_authority())
2732
.with_context(|| format!("Opening {:?}", tempdir.path()));

0 commit comments

Comments
 (0)