mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix edgecase in nocopy section
do not try to decrypt data for sections that are nocopy, this can lead to spurious decryption errors
This commit is contained in:
parent
529cdcc67d
commit
9f43e1df0a
4 changed files with 41 additions and 15 deletions
|
|
@ -24,6 +24,7 @@ pub const MINIELF_FLG_EHF: u8 = 8;
|
||||||
pub const MINIELF_FLG_EHH: u8 = 0x10;
|
pub const MINIELF_FLG_EHH: u8 = 0x10;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct MiniElfSection {
|
pub struct MiniElfSection {
|
||||||
// Virtual address of this section
|
// Virtual address of this section
|
||||||
pub virt: u32,
|
pub virt: u32,
|
||||||
|
|
@ -490,8 +491,12 @@ impl MiniElf {
|
||||||
);
|
);
|
||||||
#[cfg(feature = "swap")]
|
#[cfg(feature = "swap")]
|
||||||
if let Some(swap) = allocator.swap_hal.as_mut() {
|
if let Some(swap) = allocator.swap_hal.as_mut() {
|
||||||
let dump_disk = swap.decrypt_src_page_at(dump_pa_src & !(PAGE_SIZE - 1));
|
if !section.no_copy() {
|
||||||
dump_slice(&dump_disk[dump_pa_src & (PAGE_SIZE - 1)..], " Src [:20] ");
|
let dump_disk = swap.decrypt_src_page_at(dump_pa_src & !(PAGE_SIZE - 1));
|
||||||
|
dump_slice(&dump_disk[dump_pa_src & (PAGE_SIZE - 1)..], " Src [:20] ");
|
||||||
|
} else {
|
||||||
|
println!(" -- nocopy --");
|
||||||
|
};
|
||||||
let dump_swap = swap.decrypt_swap_from(
|
let dump_swap = swap.decrypt_swap_from(
|
||||||
dest_offset & !(PAGE_SIZE - 1),
|
dest_offset & !(PAGE_SIZE - 1),
|
||||||
(section.virt as usize) & !(PAGE_SIZE - 1),
|
(section.virt as usize) & !(PAGE_SIZE - 1),
|
||||||
|
|
@ -501,12 +506,17 @@ impl MiniElf {
|
||||||
&dump_swap[(section.virt as usize) & (PAGE_SIZE - 1)..],
|
&dump_swap[(section.virt as usize) & (PAGE_SIZE - 1)..],
|
||||||
" Dst [:20] ",
|
" Dst [:20] ",
|
||||||
);
|
);
|
||||||
let dump_disk = swap
|
if !section.no_copy() {
|
||||||
.decrypt_src_page_at((dump_pa_src + section.len() - 20) & !(PAGE_SIZE - 1));
|
let dump_disk = swap.decrypt_src_page_at(
|
||||||
dump_slice(
|
(dump_pa_src + section.len() - 20) & !(PAGE_SIZE - 1),
|
||||||
&dump_disk[(dump_pa_src + section.len() - 20) & (PAGE_SIZE - 1)..],
|
);
|
||||||
" Src [-20:] ",
|
dump_slice(
|
||||||
);
|
&dump_disk[(dump_pa_src + section.len() - 20) & (PAGE_SIZE - 1)..],
|
||||||
|
" Src [-20:] ",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(" -- nocopy --");
|
||||||
|
}
|
||||||
// recompute the end section mapping, because PA/VA mappings don't have to be
|
// recompute the end section mapping, because PA/VA mappings don't have to be
|
||||||
// linear (in fact they go in the opposite direction)
|
// linear (in fact they go in the opposite direction)
|
||||||
if let Some(pa_dst_end) = dump_pa_end_dst {
|
if let Some(pa_dst_end) = dump_pa_end_dst {
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,10 @@ pub fn phase_1(cfg: &mut BootConfig) {
|
||||||
// smashed if the stack overflows! It should be all 0's if the stack did not overrun.
|
// smashed if the stack overflows! It should be all 0's if the stack did not overrun.
|
||||||
#[cfg(feature = "swap")]
|
#[cfg(feature = "swap")]
|
||||||
if SDBG && VDBG {
|
if SDBG && VDBG {
|
||||||
for (_i, _r) in
|
for (_i, _r) in cfg.runtime_page_tracker
|
||||||
cfg.runtime_page_tracker[cfg.runtime_page_tracker.len() - 1024..].chunks(32).enumerate()
|
[cfg.runtime_page_tracker.len() - 1024.min(cfg.runtime_page_tracker.len())..]
|
||||||
|
.chunks(32)
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
println!(" rpt {:08x}: {:02x?}", cfg.runtime_page_tracker.len() - 1024 + _i * 32, _r);
|
println!(" rpt {:08x}: {:02x?}", cfg.runtime_page_tracker.len() - 1024 + _i * 32, _r);
|
||||||
}
|
}
|
||||||
|
|
@ -687,7 +689,10 @@ fn copy_processes(cfg: &mut BootConfig) {
|
||||||
|
|
||||||
let mut last_copy_vaddr = 0;
|
let mut last_copy_vaddr = 0;
|
||||||
|
|
||||||
for section in inis.sections.iter() {
|
for (index, section) in inis.sections.iter().enumerate() {
|
||||||
|
if SDBG {
|
||||||
|
println!("Section {}: {:x?}", index, section);
|
||||||
|
}
|
||||||
let mut dst_page_vaddr = section.virt as usize;
|
let mut dst_page_vaddr = section.virt as usize;
|
||||||
let mut bytes_to_copy = section.len();
|
let mut bytes_to_copy = section.len();
|
||||||
|
|
||||||
|
|
@ -734,8 +739,9 @@ fn copy_processes(cfg: &mut BootConfig) {
|
||||||
let src_swap_img_page = src_swap_img_addr & !(PAGE_SIZE - 1);
|
let src_swap_img_page = src_swap_img_addr & !(PAGE_SIZE - 1);
|
||||||
let src_swap_img_offset = src_swap_img_addr & (PAGE_SIZE - 1);
|
let src_swap_img_offset = src_swap_img_addr & (PAGE_SIZE - 1);
|
||||||
// it's almost free to check, so we check at every loop start
|
// it's almost free to check, so we check at every loop start
|
||||||
if cfg.swap_hal.as_ref().expect("swap HAL uninit").decrypt_page_addr()
|
if (cfg.swap_hal.as_ref().expect("swap HAL uninit").decrypt_page_addr()
|
||||||
!= src_swap_img_page
|
!= src_swap_img_page)
|
||||||
|
&& !section.no_copy()
|
||||||
{
|
{
|
||||||
cfg.swap_hal
|
cfg.swap_hal
|
||||||
.as_mut()
|
.as_mut()
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,8 @@ pub fn early_init() {
|
||||||
// don't futz with it" is actually the answer that goes to production.
|
// don't futz with it" is actually the answer that goes to production.
|
||||||
use utralib::utra::sysctrl;
|
use utralib::utra::sysctrl;
|
||||||
|
|
||||||
use crate::platform::cramium;
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// this is MANDATORY for any chip stapbility in real silicon, as the initial
|
// this is MANDATORY for any chip stability in real silicon, as the initial
|
||||||
// clocks are too unstable to do anything otherwise. However, for the simulation
|
// clocks are too unstable to do anything otherwise. However, for the simulation
|
||||||
// environment, this can (should?) be dropped
|
// environment, this can (should?) be dropped
|
||||||
let daric_cgu = sysctrl::HW_SYSCTRL_BASE as *mut u32;
|
let daric_cgu = sysctrl::HW_SYSCTRL_BASE as *mut u32;
|
||||||
|
|
@ -644,6 +643,7 @@ pub fn early_init() {
|
||||||
// safety: this is safe because we are in machine mode, and vaddr/paddr always pairs up
|
// safety: this is safe because we are in machine mode, and vaddr/paddr always pairs up
|
||||||
let mut usb = unsafe {
|
let mut usb = unsafe {
|
||||||
cramium_hal::usb::driver::CorigineUsb::new(
|
cramium_hal::usb::driver::CorigineUsb::new(
|
||||||
|
0, // is dummy in no-std
|
||||||
0, // is dummy in no-std
|
0, // is dummy in no-std
|
||||||
cramium_hal::usb::driver::CRG_UDC_MEMBASE,
|
cramium_hal::usb::driver::CRG_UDC_MEMBASE,
|
||||||
csr,
|
csr,
|
||||||
|
|
|
||||||
|
|
@ -368,6 +368,16 @@ impl SwapHal {
|
||||||
(self.image_mac_start + (offset / 4096) * size_of::<Tag>()) as u32
|
(self.image_mac_start + (offset / 4096) * size_of::<Tag>()) as u32
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
if crate::VVDBG {
|
||||||
|
println!(
|
||||||
|
"Decrypting nonce {:x?}, aad {:x?}, tag {:x?}, data{:x?}..{:x?}",
|
||||||
|
nonce,
|
||||||
|
&aad[..self.aad_len],
|
||||||
|
&tag,
|
||||||
|
&self.buf.data[..16],
|
||||||
|
&self.buf.data[self.buf.data.len() - 16..]
|
||||||
|
);
|
||||||
|
}
|
||||||
match self.src_cipher.decrypt_in_place_detached(
|
match self.src_cipher.decrypt_in_place_detached(
|
||||||
Nonce::from_slice(&nonce),
|
Nonce::from_slice(&nonce),
|
||||||
&aad[..self.aad_len],
|
&aad[..self.aad_len],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue