Skip to content

Commit bb2c766

Browse files
uki-addon: Refuse to remove addons containing composefs= cmdline
Before removing a scoped addon, parse its PE binary and check for a composefs= kernel parameter. If found, early exit as removing that addon would make the system unbootable Global addons are not checked because `composefs=` is rejected at install time for global addons Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent ac80303 commit bb2c766

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

‎crates/lib/src/bootc_composefs/uki_addons_cli.rs‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use cap_std_ext::cap_std::fs::Dir;
77
use fn_error_context::context;
88
use ostree_ext::{
99
composefs::fsverity::{FsVerityHashValue, Sha512HashValue},
10-
composefs_boot::bootloader::{EFI_ADDON_DIR_EXT, EFI_ADDON_FILE_EXT},
10+
composefs_boot::{
11+
bootloader::{EFI_ADDON_DIR_EXT, EFI_ADDON_FILE_EXT},
12+
cmdline::ComposefsCmdline as ComposefsBootCmdline,
13+
uki,
14+
},
1115
composefs_oci::linked_erofs_images,
1216
};
1317

@@ -140,6 +144,31 @@ pub(crate) fn handle_addon_cli_cmd(
140144
.join(get_uki_addon_dir_name(depl_id))
141145
.join(get_scoped_uki_addon_name(addon_name));
142146

147+
// Absolutely make sure the addon doesn't contain `composefs=` cmdline
148+
// if it does, we can't remove it
149+
let mut addon_file = esp
150+
.fd
151+
.open(&addon_path)
152+
.with_context(|| format!("Opening {}", addon_path.display()))?;
153+
154+
match uki::get_cmdline_buffered(&mut addon_file) {
155+
Ok(cmdline_str) => {
156+
let cfs_cmdline_info =
157+
ComposefsBootCmdline::<Sha512HashValue>::from_cmdline(&cmdline_str)
158+
.context("Parsing composefs=")?;
159+
160+
if let Some(cmdline) = cfs_cmdline_info {
161+
anyhow::bail!(
162+
"Composefs commandline {cmdline:?} found in addon {addon_name}, cannot remove"
163+
);
164+
};
165+
}
166+
Err(uki::UkiError::MissingSection(..)) => {
167+
// All good, no cmdline section in this addon
168+
}
169+
Err(e) => Err(e).context("Reading cmdline section from addon")?,
170+
};
171+
143172
esp.fd
144173
.remove_file(&addon_path)
145174
.with_context(|| format!("Failed to remove addon {addon_name}"))?;

0 commit comments

Comments
 (0)