Hard code the default scheme to file
Init no longer changes the default scheme to initfs at any point in time. And for sandboxing you would be switching scheme namespace, not default scheme. It should be possible to mix and match relibc version from before and after this change without breaking exec, though I haven't tested it.
This commit is contained in:
+1
-11
@@ -55,8 +55,6 @@ pub struct InterpOverride {
|
||||
|
||||
pub struct ExtraInfo<'a> {
|
||||
pub cwd: Option<&'a [u8]>,
|
||||
// Default scheme for the process
|
||||
pub default_scheme: Option<&'a [u8]>,
|
||||
// POSIX states that while sigactions are reset, ignored sigactions will remain ignored.
|
||||
pub sigignmask: u64,
|
||||
// POSIX also states that the sigprocmask must be preserved across execs.
|
||||
@@ -310,8 +308,7 @@ pub fn fexec_impl(
|
||||
|
||||
let total_args_envs_auxvpointee_size = args.iter().map(|arg| arg.len() + 1).sum::<usize>()
|
||||
+ envs.iter().map(|env| env.len() + 1).sum::<usize>()
|
||||
+ extrainfo.cwd.map_or(0, |s| s.len() + 1)
|
||||
+ extrainfo.default_scheme.map_or(0, |s| s.len() + 1);
|
||||
+ extrainfo.cwd.map_or(0, |s| s.len() + 1);
|
||||
let args_envs_size_aligned = total_args_envs_auxvpointee_size.next_multiple_of(PAGE_SIZE);
|
||||
let target_args_env_address =
|
||||
find_free_target_addr(&tree, args_envs_size_aligned).ok_or(Error::new(ENOMEM))?;
|
||||
@@ -356,13 +353,6 @@ pub fn fexec_impl(
|
||||
push(AT_REDOX_INITIAL_CWD_LEN)?;
|
||||
}
|
||||
|
||||
if let Some(default_scheme) = extrainfo.default_scheme {
|
||||
push(append(default_scheme)?)?;
|
||||
push(AT_REDOX_INITIAL_DEFAULT_SCHEME_PTR)?;
|
||||
push(default_scheme.len())?;
|
||||
push(AT_REDOX_INITIAL_DEFAULT_SCHEME_LEN)?;
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
{
|
||||
push((extrainfo.sigignmask >> 32) as usize)?;
|
||||
|
||||
@@ -888,14 +888,6 @@ pub unsafe extern "C" fn rmdir(path: *const c_char) -> c_int {
|
||||
Sys::rmdir(path).map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn set_default_scheme(scheme: *const c_char) -> c_int {
|
||||
let scheme = CStr::from_ptr(scheme);
|
||||
Sys::set_default_scheme(scheme)
|
||||
.map(|_| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setegid.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn setegid(gid: gid_t) -> c_int {
|
||||
|
||||
@@ -44,11 +44,6 @@ pub const AT_REDOX_INHERITED_SIGPROCMASK: usize = 36;
|
||||
#[cfg(all(target_os = "redox", target_pointer_width = "32"))]
|
||||
pub const AT_REDOX_INHERITED_SIGPROCMASK_HI: usize = 37;
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
pub const AT_REDOX_INITIAL_DEFAULT_SCHEME_PTR: usize = 38;
|
||||
#[cfg(target_os = "redox")]
|
||||
pub const AT_REDOX_INITIAL_DEFAULT_SCHEME_LEN: usize = 39;
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
pub const AT_REDOX_UMASK: usize = 40;
|
||||
|
||||
|
||||
@@ -96,9 +96,6 @@ impl Pal for Sys {
|
||||
fn chdir(path: CStr) -> Result<()> {
|
||||
e_raw(unsafe { syscall!(CHDIR, path.as_ptr()) }).map(|_| ())
|
||||
}
|
||||
fn set_default_scheme(scheme: CStr) -> Result<()> {
|
||||
Err(Errno(EOPNOTSUPP))
|
||||
}
|
||||
|
||||
fn chmod(path: CStr, mode: mode_t) -> Result<()> {
|
||||
e_raw(unsafe { syscall!(FCHMODAT, AT_FDCWD, path.as_ptr(), mode, 0) }).map(|_| ())
|
||||
|
||||
@@ -354,17 +354,6 @@ pub unsafe fn init(auxvs: Box<[[usize; 2]]>) {
|
||||
}
|
||||
}
|
||||
|
||||
if let (Some(scheme_ptr), Some(scheme_len)) = (
|
||||
get_auxv(&auxvs, AT_REDOX_INITIAL_DEFAULT_SCHEME_PTR),
|
||||
get_auxv(&auxvs, AT_REDOX_INITIAL_DEFAULT_SCHEME_LEN),
|
||||
) {
|
||||
let scheme_bytes: &'static [u8] =
|
||||
unsafe { core::slice::from_raw_parts(scheme_ptr as *const u8, scheme_len) };
|
||||
if let Ok(scheme) = core::str::from_utf8(scheme_bytes) {
|
||||
self::sys::path::set_default_scheme_manual(scheme.into());
|
||||
}
|
||||
}
|
||||
|
||||
let mut inherited_sigignmask = 0_u64;
|
||||
if let Some(mask) = get_auxv(&auxvs, AT_REDOX_INHERITED_SIGIGNMASK) {
|
||||
inherited_sigignmask |= mask as u64;
|
||||
|
||||
@@ -37,8 +37,6 @@ pub trait Pal {
|
||||
|
||||
fn chdir(path: CStr) -> Result<()>;
|
||||
|
||||
fn set_default_scheme(scheme: CStr) -> Result<(), Errno>;
|
||||
|
||||
fn chmod(path: CStr, mode: mode_t) -> Result<()>;
|
||||
|
||||
fn chown(path: CStr, owner: uid_t, group: gid_t) -> Result<()>;
|
||||
|
||||
@@ -128,9 +128,6 @@ pub fn execve(
|
||||
}
|
||||
|
||||
let cwd: Box<[u8]> = super::path::clone_cwd().unwrap_or_default().into();
|
||||
let default_scheme: Box<[u8]> = super::path::clone_default_scheme()
|
||||
.unwrap_or_else(|| Box::from("file"))
|
||||
.into();
|
||||
|
||||
// Path to interpreter binary and args if found
|
||||
let (interpreter_path, interpreter_args) = { parse_interpreter(&mut image_file)? };
|
||||
@@ -248,7 +245,6 @@ pub fn execve(
|
||||
|
||||
let extrainfo = ExtraInfo {
|
||||
cwd: Some(&cwd),
|
||||
default_scheme: Some(&default_scheme),
|
||||
sigignmask: redox_rt::signal::get_sigignmask_to_inherit(),
|
||||
sigprocmask,
|
||||
umask: redox_rt::sys::get_umask(),
|
||||
|
||||
@@ -172,10 +172,6 @@ impl Pal for Sys {
|
||||
path::chdir(path)?;
|
||||
Ok(())
|
||||
}
|
||||
fn set_default_scheme(path: CStr) -> Result<()> {
|
||||
let path = path.to_str().map_err(|_| Errno(EINVAL))?;
|
||||
Ok(path::set_default_scheme(path)?)
|
||||
}
|
||||
|
||||
fn chmod(path: CStr, mode: mode_t) -> Result<()> {
|
||||
let file = File::open(path, fcntl::O_PATH | fcntl::O_CLOEXEC)?;
|
||||
|
||||
@@ -58,24 +58,6 @@ pub fn getcwd(mut buf: Out<[u8]>) -> Option<usize> {
|
||||
Some(cwd.len())
|
||||
}
|
||||
|
||||
/// Sets the default scheme
|
||||
///
|
||||
/// By default absolute paths resolve to /scheme/file, calling this function
|
||||
/// allows a different scheme to be used as the root. This property is inherited
|
||||
/// by child processes.
|
||||
///
|
||||
/// Resets CWD to /.
|
||||
pub fn set_default_scheme(scheme: &str) -> Result<()> {
|
||||
let _siglock = tmp_disable_signals();
|
||||
let mut cwd_guard = CWD.lock();
|
||||
let mut default_scheme_guard = DEFAULT_SCHEME.lock();
|
||||
|
||||
*cwd_guard = None;
|
||||
*default_scheme_guard = Some(scheme.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: How much of this logic should be in redox-path?
|
||||
fn canonicalize_with_cwd_internal(cwd: Option<&str>, path: &str) -> Result<String> {
|
||||
let path = canonicalize_using_cwd(cwd, path).ok_or(Error::new(ENOENT))?;
|
||||
@@ -90,9 +72,7 @@ fn canonicalize_with_cwd_internal(cwd: Option<&str>, path: &str) -> Result<Strin
|
||||
Ok(if standard_scheme || legacy_scheme {
|
||||
path
|
||||
} else {
|
||||
let mut default_scheme_guard = DEFAULT_SCHEME.lock();
|
||||
let default_scheme = default_scheme_guard.get_or_insert_with(|| Box::from("file"));
|
||||
let mut result = format!("/scheme/{}{}", default_scheme, path);
|
||||
let mut result = format!("/scheme/file{}", path);
|
||||
|
||||
// Trim trailing / to keep path canonical.
|
||||
if result.as_bytes().last() == Some(&b'/') {
|
||||
@@ -111,28 +91,17 @@ pub fn canonicalize(path: &str) -> Result<String> {
|
||||
|
||||
// TODO: arraystring?
|
||||
static CWD: Mutex<Option<Box<str>>> = Mutex::new(None);
|
||||
static DEFAULT_SCHEME: Mutex<Option<Box<str>>> = Mutex::new(None);
|
||||
|
||||
pub fn set_cwd_manual(cwd: Box<str>) {
|
||||
let _siglock = tmp_disable_signals();
|
||||
*CWD.lock() = Some(cwd);
|
||||
}
|
||||
|
||||
pub fn set_default_scheme_manual(scheme: Box<str>) {
|
||||
let _siglock = tmp_disable_signals();
|
||||
*DEFAULT_SCHEME.lock() = Some(scheme)
|
||||
}
|
||||
|
||||
pub fn clone_cwd() -> Option<Box<str>> {
|
||||
let _siglock = tmp_disable_signals();
|
||||
CWD.lock().clone()
|
||||
}
|
||||
|
||||
pub fn clone_default_scheme() -> Option<Box<str>> {
|
||||
let _siglock = tmp_disable_signals();
|
||||
DEFAULT_SCHEME.lock().clone()
|
||||
}
|
||||
|
||||
// TODO: Move to redox-rt, or maybe part of it?
|
||||
pub fn open(path: &str, flags: usize) -> Result<usize> {
|
||||
// TODO: SYMLOOP_MAX
|
||||
|
||||
Reference in New Issue
Block a user