From 306bb7d6989c4814838652596d9034604fc5a518 Mon Sep 17 00:00:00 2001 From: Timothy Finnegan Date: Fri, 20 Sep 2024 18:39:25 -0700 Subject: [PATCH 1/2] Added an assertion to map_bar that causes the calling driver to panic rather than crash the kernel --- pcid/src/driver_interface/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 2900a1e68c..464e100535 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -373,6 +373,9 @@ impl PciFunctionHandle { Ok(mapped_bar) } else { let (bar, bar_size) = self.config.func.bars[bir as usize].expect_mem(); + + assert!(bar > 0); //Panic, rather than potentially crash the kernel if the bar isnt initialized. + let ptr = unsafe { common::physmap( bar, From 806e8b42b795de5195a48fb52a14476bb5fc6781 Mon Sep 17 00:00:00 2001 From: Timothy Finnegan Date: Fri, 20 Sep 2024 18:42:03 -0700 Subject: [PATCH 2/2] Added an assertion to map_bar that causes the calling driver to panic rather than crash the kernel --- common/src/lib.rs | 6 ++++++ pcid/src/driver_interface/mod.rs | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 66f3686530..f90ed57454 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -126,6 +126,12 @@ pub unsafe fn physmap( ty: MemoryType, ) -> Result<*mut ()> { // TODO: arraystring? + + //Return an error rather than potentially crash the kernel. + if(base_phys == 0) { + return Err(Error::new(EINVAL)); + } + let path = format!( "/scheme/memory/physical@{}", match ty { diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 464e100535..6055fc74be 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -374,8 +374,6 @@ impl PciFunctionHandle { } else { let (bar, bar_size) = self.config.func.bars[bir as usize].expect_mem(); - assert!(bar > 0); //Panic, rather than potentially crash the kernel if the bar isnt initialized. - let ptr = unsafe { common::physmap( bar,