Skip to content

Commit 42e2db3

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs: Build composefs cmdline
Instead of writing format strings to create a composefs= parameter in the cmdline, add a build method to ComposefsCmdline to build a cmdline from options Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 2cb14c2 commit 42e2db3

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ use rustix::{mount::MountFlags, path::Arg};
9393
use schemars::JsonSchema;
9494
use serde::{Deserialize, Serialize};
9595

96-
use crate::task::Task;
9796
use crate::{
9897
bootc_composefs::repo::get_imgref,
9998
composefs_consts::{TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED},
@@ -106,6 +105,7 @@ use crate::{
106105
bootc_composefs::state::{get_booted_bls, write_composefs_state},
107106
composefs_consts::TYPE1_BOOT_DIR_PREFIX,
108107
};
108+
use crate::{bootc_composefs::status::ComposefsCmdline, task::Task};
109109
use crate::{
110110
bootc_composefs::status::get_container_manifest_and_config, bootc_kargs::compute_new_kargs,
111111
};
@@ -116,8 +116,8 @@ use crate::{
116116
};
117117
use crate::{
118118
composefs_consts::{
119-
BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST,
120-
STAGED_BOOT_LOADER_ENTRIES, STATE_DIR_ABS, USER_CFG, USER_CFG_STAGED,
119+
BOOT_LOADER_ENTRIES, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST, STAGED_BOOT_LOADER_ENTRIES,
120+
STATE_DIR_ABS, USER_CFG, USER_CFG_STAGED,
121121
},
122122
spec::{Bootloader, Host},
123123
};
@@ -525,14 +525,9 @@ pub(crate) fn setup_composefs_bls_boot(
525525

526526
cmdline_options.extend(&root_setup.kargs);
527527

528-
// TODO(Johan-Liebert1): Use ComposefsCmdline
529-
let composefs_cmdline = if state.composefs_options.allow_missing_verity {
530-
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
531-
} else {
532-
format!("{COMPOSEFS_CMDLINE}={id_hex}")
533-
};
534-
535-
cmdline_options.extend(&Cmdline::from(&composefs_cmdline));
528+
let composefs_cmdline =
529+
ComposefsCmdline::build(&id_hex, state.composefs_options.allow_missing_verity);
530+
cmdline_options.extend(&Cmdline::from(&composefs_cmdline.to_string()));
536531

537532
// Locate ESP partition device
538533
let esp_part = root_setup.device_info.find_partition_of_esp()?;
@@ -564,14 +559,12 @@ pub(crate) fn setup_composefs_bls_boot(
564559
};
565560

566561
// Copy all cmdline args, replacing only `composefs=`
567-
let param = if booted_cfs.cmdline.allow_missing_fsverity {
568-
format!("{COMPOSEFS_CMDLINE}=?{id_hex}")
569-
} else {
570-
format!("{COMPOSEFS_CMDLINE}={id_hex}")
571-
};
562+
let cfs_cmdline =
563+
ComposefsCmdline::build(&id_hex, booted_cfs.cmdline.allow_missing_fsverity)
564+
.to_string();
572565

573-
let param =
574-
Parameter::parse(&param).context("Failed to create 'composefs=' parameter")?;
566+
let param = Parameter::parse(&cfs_cmdline)
567+
.context("Failed to create 'composefs=' parameter")?;
575568
cmdline.add_or_modify(&param);
576569

577570
// Locate ESP partition device

crates/lib/src/bootc_composefs/soft_reboot.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::{
2-
bootc_composefs::{service::start_finalize_stated_svc, status::get_composefs_status},
2+
bootc_composefs::{
3+
service::start_finalize_stated_svc,
4+
status::{ComposefsCmdline, get_composefs_status},
5+
},
36
cli::SoftRebootMode,
4-
composefs_consts::COMPOSEFS_CMDLINE,
57
store::{BootedComposefs, Storage},
68
};
79
use anyhow::{Context, Result};
@@ -106,18 +108,14 @@ pub(crate) async fn prepare_soft_reboot_composefs(
106108

107109
create_dir_all(NEXTROOT).context("Creating nextroot")?;
108110

109-
let cmdline = if booted_cfs.cmdline.allow_missing_fsverity {
110-
Cmdline::from(format!("{COMPOSEFS_CMDLINE}=?{deployment_id}"))
111-
} else {
112-
Cmdline::from(format!("{COMPOSEFS_CMDLINE}={deployment_id}"))
113-
};
111+
let cmdline = ComposefsCmdline::build(deployment_id, booted_cfs.cmdline.allow_missing_fsverity);
114112

115113
let args = bootc_initramfs_setup::Args {
116114
cmd: vec![],
117115
sysroot: PathBuf::from("/sysroot"),
118116
config: Default::default(),
119117
root_fs: None,
120-
cmdline: Some(cmdline),
118+
cmdline: Some(Cmdline::from(cmdline.to_string())),
121119
target: Some(NEXTROOT.into()),
122120
};
123121

crates/lib/src/bootc_composefs/status.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ impl ComposefsCmdline {
8080
}
8181
}
8282

83+
pub(crate) fn build(digest: &str, allow_missing_fsverity: bool) -> Self {
84+
ComposefsCmdline {
85+
allow_missing_fsverity,
86+
digest: digest.into(),
87+
}
88+
}
89+
8390
/// Search for the `composefs=` parameter in the passed in kernel command line
8491
pub(crate) fn find_in_cmdline(cmdline: &Cmdline) -> Option<Self> {
8592
match cmdline.find(COMPOSEFS_CMDLINE) {

crates/lib/src/parsers/bls_config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::fmt::Display;
1515
use uapi_version::Version;
1616

1717
use crate::bootc_composefs::status::ComposefsCmdline;
18-
use crate::composefs_consts::{COMPOSEFS_CMDLINE, UKI_NAME_PREFIX};
18+
use crate::composefs_consts::UKI_NAME_PREFIX;
1919

2020
#[derive(Debug, PartialEq, Eq, Default)]
2121
pub enum BLSConfigType {
@@ -191,13 +191,14 @@ impl BLSConfig {
191191
}
192192

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

196198
let cfs_cmdline = ComposefsCmdline::find_in_cmdline(&Cmdline::from(&options))
197199
.ok_or_else(|| anyhow::anyhow!("No composefs= param"))?;
198200

199-
// TODO(Johan-Liebert1): We lose the info here that this is insecure
200-
Ok(cfs_cmdline.digest.to_string().clone())
201+
Ok(cfs_cmdline.digest.to_string())
201202
}
202203

203204
BLSConfigType::Unknown => anyhow::bail!("Unknown config type"),

crates/lib/src/ukify.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use cap_std_ext::cap_std::fs::Dir;
1414
use fn_error_context::context;
1515

1616
use crate::bootc_composefs::digest::compute_composefs_digest;
17-
use crate::composefs_consts::COMPOSEFS_CMDLINE;
17+
use crate::bootc_composefs::status::ComposefsCmdline;
1818

1919
/// Build a UKI from the given rootfs.
2020
///
@@ -84,12 +84,9 @@ pub(crate) fn build_ukify(
8484
let mut cmdline = crate::bootc_kargs::get_kargs_in_root(&root, std::env::consts::ARCH)?;
8585

8686
// Add the composefs digest
87-
let composefs_param = if allow_missing_fsverity {
88-
format!("{COMPOSEFS_CMDLINE}=?{composefs_digest}")
89-
} else {
90-
format!("{COMPOSEFS_CMDLINE}={composefs_digest}")
91-
};
92-
cmdline.extend(&Cmdline::from(composefs_param));
87+
cmdline.extend(&Cmdline::from(
88+
ComposefsCmdline::build(&composefs_digest, allow_missing_fsverity).to_string(),
89+
));
9390

9491
// Add any extra kargs provided via --karg
9592
for karg in extra_kargs {

0 commit comments

Comments
 (0)