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:
bjorn3
2025-12-07 19:51:45 +01:00
parent 45a58f1a9e
commit 4dae665cbf
9 changed files with 2 additions and 80 deletions
-5
View File
@@ -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;
-3
View File
@@ -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(|_| ())
-11
View File
@@ -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;
-2
View File
@@ -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<()>;
-4
View File
@@ -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(),
-4
View File
@@ -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)?;
+1 -32
View File
@@ -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