From 52c429c20701834eed2da8a2771e86bbcb2d86aa Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 12 Apr 2025 13:52:42 +0200 Subject: [PATCH 1/2] Add a couple of PROT_READ Even though they are only used for writing, it is still UB to create a mutable reference to memory that can't be read. --- redox-rt/src/proc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index 81fad4f262..c04897fb3a 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -277,7 +277,7 @@ where { page } else if let Some(ref mut stack_page) = stack_page { - stack_page.remap(new_page_no * PAGE_SIZE, PROT_WRITE)?; + stack_page.remap(new_page_no * PAGE_SIZE, PROT_READ | PROT_WRITE)?; stack_page } else { let new = MmapGuard::map( @@ -285,7 +285,7 @@ where &Map { offset: new_page_no * PAGE_SIZE, size: PAGE_SIZE, - flags: PROT_WRITE, + flags: PROT_READ | PROT_WRITE, address: 0, // let kernel decide }, )?; @@ -658,7 +658,7 @@ impl MmapGuard { size, offset, address: 0, - flags: PROT_WRITE, + flags: PROT_READ | PROT_WRITE, }, )?; let slice = &mut *this.as_mut_ptr_slice(); From 4d82cd90f8919ad620b3dde793566b4ada281b2f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 12 Apr 2025 13:54:09 +0200 Subject: [PATCH 2/2] Add a workaround for UB on arm64 --- redox-rt/src/proc.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index c04897fb3a..26b730b861 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -647,6 +647,10 @@ impl MmapGuard { Ok(()) } + + // Without this inline(never), UB somewhere causes the flags to be set to 0 on arm64. + // FIXME Find the UB and fix it + #[inline(never)] pub unsafe fn map_mut_anywhere<'a>( fd: usize, offset: usize,