Files
RedBear-OS/local/patches/relibc/P3-exec-root-bypass.patch
T

34 lines
1.0 KiB
Diff

diff --git a/src/platform/redox/exec.rs b/src/platform/redox/exec.rs
index 3590413c..1dc131dd 100644
--- a/src/platform/redox/exec.rs
+++ b/src/platform/redox/exec.rs
@@ -129,16 +129,19 @@ pub fn execve(
let Resugid { ruid, rgid, .. } = redox_rt::sys::posix_getresugid();
- let mode = if ruid == stat.st_uid {
- (stat.st_mode >> 3 * 2) & 0o7
- } else if rgid == stat.st_gid {
- (stat.st_mode >> 3 * 1) & 0o7
- } else {
- stat.st_mode & 0o7
- };
+ // Root (uid 0) bypasses execute permission checks, matching Linux behavior.
+ if ruid != 0 {
+ let mode = if ruid == stat.st_uid {
+ (stat.st_mode >> 3 * 2) & 0o7
+ } else if rgid == stat.st_gid {
+ (stat.st_mode >> 3 * 1) & 0o7
+ } else {
+ stat.st_mode & 0o7
+ };
- if mode & 0o1 == 0o0 {
- return Err(Error::new(EPERM));
+ if mode & 0o1 == 0o0 {
+ return Err(Error::new(EACCES));
+ }
}
let cwd: Box<[u8]> = super::path::clone_cwd().unwrap_or_default().into();