Skip to content

Commit 2cb14c2

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs: Use ComposefsCmdline to handle missing verity
In a few places we were simply searching for the value of composefs cmdline param in the BLS config options, which would not work as expected in cases where missing verity is allowed as the `?` was being counted as part of the digest. Instead, we now use ComposefsCmdline which properly handles the parsing of `?` and the digest Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 2269c1a commit 2cb14c2

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ pub(crate) fn setup_composefs_bls_boot(
550550
let bootloader = host.require_composefs_booted()?.bootloader.clone();
551551

552552
let boot_dir = storage.require_boot_dir()?;
553-
let current_cfg = get_booted_bls(&boot_dir)?;
553+
let current_cfg = get_booted_bls(&boot_dir, booted_cfs)?;
554554

555555
let mut cmdline = match current_cfg.cfg_type {
556556
BLSConfigType::NonEFI { options, .. } => {
@@ -775,7 +775,12 @@ pub(crate) fn setup_composefs_bls_boot(
775775
let (config_path, booted_bls) = if is_upgrade {
776776
let boot_dir = Dir::open_ambient_dir(&entry_paths.config_path, ambient_authority())?;
777777

778-
let mut booted_bls = get_booted_bls(&boot_dir)?;
778+
let BootSetupType::Upgrade((_, booted_cfs, ..)) = setup_type else {
779+
// This is just for sanity
780+
unreachable!("enum mismatch");
781+
};
782+
783+
let mut booted_bls = get_booted_bls(&boot_dir, booted_cfs)?;
779784
booted_bls.sort_key = Some(secondary_sort_key(&os_id));
780785

781786
let staged_path = loader_path.join(STAGED_BOOT_LOADER_ENTRIES);
@@ -1052,12 +1057,12 @@ fn write_systemd_uki_config(
10521057
(esp_dir.open_dir(TYPE1_ENT_PATH)?, None)
10531058
}
10541059

1055-
BootSetupType::Upgrade(_) => {
1060+
BootSetupType::Upgrade((_, booted_cfs, ..)) => {
10561061
esp_dir
10571062
.create_dir_all(TYPE1_ENT_PATH_STAGED)
10581063
.with_context(|| format!("Creating {TYPE1_ENT_PATH_STAGED}"))?;
10591064

1060-
let mut booted_bls = get_booted_bls(&esp_dir)?;
1065+
let mut booted_bls = get_booted_bls(&esp_dir, booted_cfs)?;
10611066
booted_bls.sort_key = Some(secondary_sort_key(os_id));
10621067

10631068
(esp_dir.open_dir(TYPE1_ENT_PATH_STAGED)?, Some(booted_bls))

crates/lib/src/bootc_composefs/state.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,28 @@ use rustix::{
2828
use crate::bootc_composefs::boot::BootType;
2929
use crate::bootc_composefs::repo::get_imgref;
3030
use crate::bootc_composefs::status::{
31-
ImgConfigManifest, StagedDeployment, get_sorted_type1_boot_entries,
31+
ComposefsCmdline, ImgConfigManifest, StagedDeployment, get_sorted_type1_boot_entries,
3232
};
3333
use crate::parsers::bls_config::BLSConfigType;
3434
use crate::store::{BootedComposefs, Storage};
3535
use crate::{
3636
composefs_consts::{
37-
COMPOSEFS_CMDLINE, COMPOSEFS_STAGED_DEPLOYMENT_FNAME, COMPOSEFS_TRANSIENT_STATE_DIR,
38-
ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST, ORIGIN_KEY_BOOT_TYPE, SHARED_VAR_PATH,
39-
STATE_DIR_RELATIVE,
37+
COMPOSEFS_STAGED_DEPLOYMENT_FNAME, COMPOSEFS_TRANSIENT_STATE_DIR, ORIGIN_KEY_BOOT,
38+
ORIGIN_KEY_BOOT_DIGEST, ORIGIN_KEY_BOOT_TYPE, SHARED_VAR_PATH, STATE_DIR_RELATIVE,
4039
},
4140
parsers::bls_config::BLSConfig,
4241
spec::ImageReference,
4342
spec::{FilesystemOverlay, FilesystemOverlayAccessMode, FilesystemOverlayPersistence},
4443
utils::path_relative_to,
4544
};
4645

47-
pub(crate) fn get_booted_bls(boot_dir: &Dir) -> Result<BLSConfig> {
48-
let cmdline = Cmdline::from_proc()?;
49-
let booted = cmdline
50-
.find(COMPOSEFS_CMDLINE)
51-
.ok_or_else(|| anyhow::anyhow!("Failed to find composefs parameter in kernel cmdline"))?;
52-
46+
pub(crate) fn get_booted_bls(boot_dir: &Dir, booted_cfs: &BootedComposefs) -> Result<BLSConfig> {
5347
let sorted_entries = get_sorted_type1_boot_entries(boot_dir, true)?;
5448

5549
for entry in sorted_entries {
5650
match &entry.cfg_type {
5751
BLSConfigType::EFI { efi } => {
58-
let composefs_param_value = booted.value().ok_or_else(|| {
59-
anyhow::anyhow!("Failed to get composefs kernel cmdline value")
60-
})?;
61-
62-
if efi.as_str().contains(composefs_param_value) {
52+
if efi.as_str().contains(&*booted_cfs.cmdline.digest) {
6353
return Ok(entry);
6454
}
6555
}
@@ -69,9 +59,10 @@ pub(crate) fn get_booted_bls(boot_dir: &Dir) -> Result<BLSConfig> {
6959
anyhow::bail!("options not found in bls config")
7060
};
7161

72-
let opts = Cmdline::from(opts);
62+
let cfs_cmdline = ComposefsCmdline::find_in_cmdline(&Cmdline::from(opts))
63+
.ok_or_else(|| anyhow::anyhow!("composefs param not found in cmdline"))?;
7364

74-
if opts.iter().any(|v| v == booted) {
65+
if cfs_cmdline.digest == booted_cfs.cmdline.digest {
7566
return Ok(entry);
7667
}
7768
}

crates/lib/src/parsers/bls_config.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,11 @@ impl BLSConfig {
191191
}
192192

193193
BLSConfigType::NonEFI { options, .. } => {
194-
let options = options.as_ref().ok_or(anyhow::anyhow!("No options"))?;
194+
let options = options.as_ref().ok_or_else(|| anyhow::anyhow!("No options"))?;
195195

196-
let cmdline = Cmdline::from(&options);
197-
198-
let kv = cmdline
199-
.find(COMPOSEFS_CMDLINE)
196+
let cfs_cmdline = ComposefsCmdline::find_in_cmdline(&Cmdline::from(&options))
200197
.ok_or_else(|| anyhow::anyhow!("No composefs= param"))?;
201198

202-
let value = kv
203-
.value()
204-
.ok_or_else(|| anyhow::anyhow!("Empty composefs= param"))?;
205-
206-
let cfs_cmdline = ComposefsCmdline::new(value);
207-
208199
// TODO(Johan-Liebert1): We lose the info here that this is insecure
209200
Ok(cfs_cmdline.digest.to_string().clone())
210201
}

0 commit comments

Comments
 (0)