Skip to content

Commit 0cacbc9

Browse files
croissanneallisonkarlitskaya
authored andcommitted
composefs-boot: support writing insecure composefs cmdline
Supports writing `composefs=?<root-id>`. Signed-off-by: Sanne Raymaekers <[email protected]>
1 parent 9b065d3 commit 0cacbc9

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

crates/cfsctl/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ async fn main() -> Result<()> {
291291
&repo,
292292
entry,
293293
&id,
294+
args.insecure,
294295
bootdir,
295296
None,
296297
entry_id.as_deref(),

crates/composefs-boot/src/bootloader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use composefs::{
1111
tree::{Directory, FileSystem, ImageError, Inode, LeafContent, RegularFile},
1212
};
1313

14-
use crate::cmdline::split_cmdline;
14+
use crate::cmdline::{make_cmdline_composefs, split_cmdline};
1515

1616
/// Strips the key (if it matches) plus the following whitespace from a single line in a "Type #1
1717
/// Boot Loader Specification Entry" file.
@@ -101,9 +101,9 @@ impl BootLoaderEntryFile {
101101

102102
/// Adjusts the kernel command-line arguments by adding a composefs= parameter (if appropriate)
103103
/// and adding additional arguments, as requested.
104-
pub fn adjust_cmdline(&mut self, composefs: Option<&str>, extra: &[&str]) {
104+
pub fn adjust_cmdline(&mut self, composefs: Option<&str>, insecure: bool, extra: &[&str]) {
105105
if let Some(id) = composefs {
106-
self.add_cmdline(&format!("composefs={id}"));
106+
self.add_cmdline(&make_cmdline_composefs(id, insecure));
107107
}
108108

109109
for item in extra {

crates/composefs-boot/src/cmdline.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ pub fn get_cmdline_composefs<ObjectID: FsVerityHashValue>(
3838
Ok((ObjectID::from_hex(id)?, false))
3939
}
4040
}
41+
42+
pub fn make_cmdline_composefs(id: &str, insecure: bool) -> String {
43+
match insecure {
44+
true => format!("composefs=?{}", id),
45+
false => format!("composefs={}", id),
46+
}
47+
}

crates/composefs-boot/src/write_boot.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::{
33
path::Path,
44
};
55

6-
use anyhow::{bail, ensure, Result};
6+
use anyhow::{ensure, Result};
77

88
use composefs::{fsverity::FsVerityHashValue, repository::Repository};
99

1010
use crate::{
1111
bootloader::{read_file, BootEntry, Type1Entry, Type2Entry},
12-
cmdline::get_cmdline_value,
12+
cmdline::get_cmdline_composefs,
1313
uki,
1414
};
1515

@@ -18,6 +18,7 @@ pub fn write_t1_simple<ObjectID: FsVerityHashValue>(
1818
bootdir: &Path,
1919
boot_subdir: Option<&str>,
2020
root_id: &ObjectID,
21+
insecure: bool,
2122
cmdline_extra: &[&str],
2223
repo: &Repository<ObjectID>,
2324
) -> Result<()> {
@@ -29,7 +30,7 @@ pub fn write_t1_simple<ObjectID: FsVerityHashValue>(
2930
};
3031

3132
t1.entry
32-
.adjust_cmdline(Some(&root_id.to_hex()), cmdline_extra);
33+
.adjust_cmdline(Some(&root_id.to_hex()), insecure, cmdline_extra);
3334

3435
// Write the content before we write the loader entry
3536
for (filename, file) in &t1.files {
@@ -59,13 +60,11 @@ pub fn write_t2_simple<ObjectID: FsVerityHashValue>(
5960
create_dir_all(&efi_linux)?;
6061
let filename = efi_linux.join(t2.filename.as_ref());
6162
let content = read_file(&t2.file, repo)?;
62-
let Some(composefs) = get_cmdline_value(uki::get_cmdline(&content)?, "composefs=") else {
63-
bail!("The UKI is missing a composefs= commandline parameter");
64-
};
65-
let expected = root_id.to_hex();
63+
let (composefs, _) = get_cmdline_composefs::<ObjectID>(uki::get_cmdline(&content)?)?;
64+
6665
ensure!(
67-
composefs == expected,
68-
"The UKI has the wrong composefs= parameter (is '{composefs}', should be {expected})"
66+
&composefs == root_id,
67+
"The UKI has the wrong composefs= parameter (is '{composefs:?}', should be {root_id:?})"
6968
);
7069
write(filename, content)?;
7170
Ok(())
@@ -99,10 +98,12 @@ pub fn write_t2_simple<ObjectID: FsVerityHashValue>(
9998
/// * entry_id - In case of a BLS entry, the name of file to be generated in `loader/entries`
10099
/// * cmdline_extra - Extra kernel command line arguments
101100
///
101+
#[allow(clippy::too_many_arguments)]
102102
pub fn write_boot_simple<ObjectID: FsVerityHashValue>(
103103
repo: &Repository<ObjectID>,
104104
entry: BootEntry<ObjectID>,
105105
root_id: &ObjectID,
106+
insecure: bool,
106107
boot_partition: &Path,
107108
boot_subdir: Option<&str>,
108109
entry_id: Option<&str>,
@@ -118,6 +119,7 @@ pub fn write_boot_simple<ObjectID: FsVerityHashValue>(
118119
boot_partition,
119120
boot_subdir,
120121
root_id,
122+
insecure,
121123
cmdline_extra,
122124
repo,
123125
)?;
@@ -140,6 +142,7 @@ pub fn write_boot_simple<ObjectID: FsVerityHashValue>(
140142
boot_partition,
141143
boot_subdir,
142144
root_id,
145+
insecure,
143146
cmdline_extra,
144147
repo,
145148
)?;

0 commit comments

Comments
 (0)