Skip to content

Commit

Permalink
Merge pull request #16 from FrameworkComputer/kernel-lockdown
Browse files Browse the repository at this point in the history
portio: Bail on Linux if kernel is locked down
  • Loading branch information
JohnAZoidberg authored Nov 13, 2023
2 parents 999b271 + aaee360 commit 14ca5ad
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions framework_lib/src/chromium_ec/portio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn init() -> bool {
}

if !Uid::effective().is_root() {
println!("Must be root to use port based I/O for EC communication.");
error!("Must be root to use port based I/O for EC communication.");
*init = Initialized::Failed;
return false;
}
Expand All @@ -220,12 +220,21 @@ fn init() -> bool {
portio_mec::mec_init();
} else {
// 8 for request/response header, 0xFF for response
ioperm(EC_LPC_ADDR_HOST_ARGS as u64, 8 + 0xFF, 1);

ioperm(EC_LPC_ADDR_HOST_CMD as u64, 1, 1);
ioperm(EC_LPC_ADDR_HOST_DATA as u64, 1, 1);

ioperm(NPC_MEMMAP_OFFSET as u64, super::EC_MEMMAP_SIZE as u64, 1);
let res = ioperm(EC_LPC_ADDR_HOST_ARGS as u64, 8 + 0xFF, 1);
if res != 0 {
error!(
"ioperm failed. portio driver is likely block by Linux kernel lockdown mode"
);
return false;
}

let res = ioperm(EC_LPC_ADDR_HOST_CMD as u64, 1, 1);
assert_eq!(res, 0);
let res = ioperm(EC_LPC_ADDR_HOST_DATA as u64, 1, 1);
assert_eq!(res, 0);

let res = ioperm(NPC_MEMMAP_OFFSET as u64, super::EC_MEMMAP_SIZE as u64, 1);
assert_eq!(res, 0);
}
}
*init = Initialized::Succeeded;
Expand Down

0 comments on commit 14ca5ad

Please sign in to comment.