From 4b8d2e45c6643ec2c9af68f6c2d56d28ca6d2b4e Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Fri, 10 Jul 2020 12:48:40 +0200 Subject: [PATCH] Add AT_PHDR --- src/elf.rs | 5 +++++ src/syscall/process.rs | 12 +++++++----- syscall | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/elf.rs b/src/elf.rs index 123d44d..183ed84 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -73,6 +73,11 @@ impl<'a> Elf<'a> { pub fn entry(&self) -> usize { self.header.e_entry as usize } + + /// Get the program header offset + pub fn program_headers(&self) -> usize { + self.header.e_phoff as usize + } } pub struct ElfSections<'a> { diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 9c794de..4c3277b 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -23,7 +23,7 @@ use crate::scheme::FileHandle; use crate::start::usermode; use crate::syscall::data::{SigAction, Stat}; use crate::syscall::error::*; -use crate::syscall::flag::{wifcontinued, wifstopped, AT_ENTRY, AT_NULL, CloneFlags, +use crate::syscall::flag::{wifcontinued, wifstopped, AT_ENTRY, AT_NULL, AT_PHDR, CloneFlags, CLONE_FILES, CLONE_FS, CLONE_SIGHAND, CLONE_STACK, CLONE_VFORK, CLONE_VM, MapFlags, PROT_EXEC, PROT_READ, PROT_WRITE, PTRACE_EVENT_CLONE, PTRACE_STOP_EXIT, SigActionFlags, SIG_BLOCK, SIG_DFL, SIG_SETMASK, SIG_UNBLOCK, @@ -821,7 +821,7 @@ fn fexec_noreturn( push(arg); } - // drop(auxv); // no longer required + drop(auxv); // no longer required let mut arg_size = 0; @@ -923,7 +923,7 @@ fn fexec_noreturn( unsafe { usermode(entry, sp, 0, singlestep) } } -pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>]>, name_override_opt: Option>, auxv: Option>) -> Result { +pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>]>, name_override_opt: Option>, auxv: Option>) -> Result { let (uid, gid) = { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::new(ESRCH))?; @@ -1013,8 +1013,10 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]> auxv.push(AT_ENTRY); auxv.push(elf.entry()); + auxv.push(AT_PHDR); + auxv.push(elf.program_headers()); - auxv.into_boxed_slice() + auxv }; // We check the validity of all loadable sections here @@ -1078,7 +1080,7 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]> // This is the point of no return, quite literaly. Any checks for validity need // to be done before, and appropriate errors returned. Otherwise, we have nothing // to return to. - fexec_noreturn(setuid, setgid, name.into_boxed_slice(), data.into_boxed_slice(), args, vars, auxv); + fexec_noreturn(setuid, setgid, name.into_boxed_slice(), data.into_boxed_slice(), args, vars, auxv.into_boxed_slice()); } pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) -> Result { diff --git a/syscall b/syscall index 10994ea..6346fd6 160000 --- a/syscall +++ b/syscall @@ -1 +1 @@ -Subproject commit 10994eaa96e92890d945bec77023378fe374a114 +Subproject commit 6346fd671ef6e1650062a8cd3097c0b0d17c92cb