Skip to content

Commit 14ca5ad

Browse files
Merge pull request #16 from FrameworkComputer/kernel-lockdown
portio: Bail on Linux if kernel is locked down
2 parents 999b271 + aaee360 commit 14ca5ad

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

framework_lib/src/chromium_ec/portio.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn init() -> bool {
210210
}
211211

212212
if !Uid::effective().is_root() {
213-
println!("Must be root to use port based I/O for EC communication.");
213+
error!("Must be root to use port based I/O for EC communication.");
214214
*init = Initialized::Failed;
215215
return false;
216216
}
@@ -220,12 +220,21 @@ fn init() -> bool {
220220
portio_mec::mec_init();
221221
} else {
222222
// 8 for request/response header, 0xFF for response
223-
ioperm(EC_LPC_ADDR_HOST_ARGS as u64, 8 + 0xFF, 1);
224-
225-
ioperm(EC_LPC_ADDR_HOST_CMD as u64, 1, 1);
226-
ioperm(EC_LPC_ADDR_HOST_DATA as u64, 1, 1);
227-
228-
ioperm(NPC_MEMMAP_OFFSET as u64, super::EC_MEMMAP_SIZE as u64, 1);
223+
let res = ioperm(EC_LPC_ADDR_HOST_ARGS as u64, 8 + 0xFF, 1);
224+
if res != 0 {
225+
error!(
226+
"ioperm failed. portio driver is likely block by Linux kernel lockdown mode"
227+
);
228+
return false;
229+
}
230+
231+
let res = ioperm(EC_LPC_ADDR_HOST_CMD as u64, 1, 1);
232+
assert_eq!(res, 0);
233+
let res = ioperm(EC_LPC_ADDR_HOST_DATA as u64, 1, 1);
234+
assert_eq!(res, 0);
235+
236+
let res = ioperm(NPC_MEMMAP_OFFSET as u64, super::EC_MEMMAP_SIZE as u64, 1);
237+
assert_eq!(res, 0);
229238
}
230239
}
231240
*init = Initialized::Succeeded;

0 commit comments

Comments
 (0)