Skip to content

Commit bd41a30

Browse files
committed
dbus: rauc: only install bundles from primary channel
Allowing arbitrary URL in the install request always felt wrong. Only allow installations from the primary update channel.
1 parent 67d4fed commit bd41a30

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

src/dbus/rauc.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,33 +394,50 @@ impl Rauc {
394394
})?;
395395

396396
let conn_task = conn.clone();
397+
let channels = inst.channels.clone();
397398
let (mut install_stream, _) = inst.install.clone().subscribe_unbounded();
398399

399400
// Forward the "install" topic from the broker framework to RAUC
400401
wtb.spawn_task("rauc-forward-install", async move {
401402
let proxy = InstallerProxy::new(&conn_task).await.unwrap();
402403

403404
while let Some(update_request) = install_stream.next().await {
404-
let url = match update_request.url {
405-
Some(url) => url,
406-
None => continue,
405+
let channels = match channels.try_get() {
406+
Some(chs) => chs,
407+
None => {
408+
warn!("Got install request with no channels available yet");
409+
continue;
410+
}
407411
};
408412

409-
// Poor-mans validation. It feels wrong to let someone point to any
410-
// file on the TAC from the web interface.
411-
if url.starts_with("http://") || url.starts_with("https://") {
412-
let manifest_hash: Option<zbus::zvariant::Value> =
413-
update_request.manifest_hash.map(|mh| mh.into());
414-
415-
let mut args = HashMap::new();
416-
417-
if let Some(manifest_hash) = &manifest_hash {
418-
args.insert("require-manifest-hash", manifest_hash);
413+
let primary = match channels.primary() {
414+
Some(primary) => primary,
415+
None => {
416+
warn!("Got install request with no primary channel configured");
417+
continue;
419418
}
419+
};
420420

421-
if let Err(e) = proxy.install_bundle(&url, args).await {
422-
error!("Failed to install bundle: {}", e);
421+
let url = match &update_request.url {
422+
None => &primary.url,
423+
Some(url) if url == &primary.url => &primary.url,
424+
Some(_) => {
425+
warn!("Got install request with URL not matching primary channel URL");
426+
continue;
423427
}
428+
};
429+
430+
let manifest_hash: Option<zbus::zvariant::Value> =
431+
update_request.manifest_hash.map(|mh| mh.into());
432+
433+
let mut args = HashMap::new();
434+
435+
if let Some(manifest_hash) = &manifest_hash {
436+
args.insert("require-manifest-hash", manifest_hash);
437+
}
438+
439+
if let Err(e) = proxy.install_bundle(url, args).await {
440+
error!("Failed to install bundle: {}", e);
424441
}
425442
}
426443

src/dbus/rauc/update_channels.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,9 @@ impl Channels {
173173
pub fn into_vec(self) -> Vec<Channel> {
174174
self.0
175175
}
176+
177+
#[cfg(not(feature = "demo_mode"))]
178+
pub(super) fn primary(&self) -> Option<&Channel> {
179+
self.0.iter().find(|ch| ch.primary)
180+
}
176181
}

0 commit comments

Comments
 (0)