Commit Graph

908 Commits

Author SHA1 Message Date
Red Bear OS dd2cd44368 relibc: epoll_pwait must not panic on EVENT_TIMEOUT_ID
The kernel can inject a synthetic event with id == EVENT_TIMEOUT_ID
when the requested timeout fires. The previous loop iterated the raw
event buffer with events.add(i) (in epoll_event strides) and then
interpreted the result as a syscall::Event, which produced out-of-bounds
reads when the kernel interleaved timeout events with real events.

Two changes:

1. Cast events to Event* first, then add i in Event strides so the
   pointer arithmetic matches the buffer the kernel filled.
2. Filter out entries with id == EVENT_TIMEOUT_ID before copying them
   into the user-visible epoll_event array.

Adds a regression test that builds a synthetic Event buffer with a
timeout entry interleaved and verifies that the timeout entry is
dropped while siblings are preserved.
2026-07-26 16:27:01 +09:00
Red Bear OS 27397a8ca1 Merge upstream/master into submodule/relibc
Sync the relibc fork with 50 upstream commits (socket layer rework,
exec/signal/ptrace/path/timer updates, pthread cleanup, ld_so lifecycle
work bringing mark_ready/run_fini into the tree, dynamically-linked
init support, start.rs allocator-model rewrite, test harness updates).
Satisfies the verify-fork-functions gate (2 previously-missing ld_so
functions now present).

Conflicts resolved (4 files; 46 auto-merged):

- src/start.rs: took upstream's version wholesale. Upstream moved
  allocator/linker initialization into ld_so's new lifecycle (the
  mark_ready/run_fini work this merge brings in), superseding the RB
  alloc_init cluster; the old model's function was already merged out
  and its lone call would not compile.

- redox-rt/src/sys.rs: kept the RB refresh flow with the non-fatal
  lseek fallback (upstream adopted the refresh as a fatal '?' —
  RB's conservative fallback protects spawn for uid-dropped /
  namespace-restricted exec where the kernel cannot refresh).

- src/platform/redox/exec.rs: kept the RB root exec-permission bypass
  (ruid/euid != 0 gate, Linux-matching behavior).

- Cargo.lock: syn 2.0.118 -> 2.0.119 (upstream).

Verified: repo cook relibc --force-rebuild successful;
verify-fork-functions.sh --no-fetch relibc passes;
all 9 forks now pass the gate.
2026-07-19 07:12:56 +09:00
Red Bear OS c6f8a2c208 Remove temporary spawn/execve diagnostics 2026-07-18 23:07:56 +09:00
Red Bear OS 20d4e8746f DIAG(execve): trace exec::execve (real fork+exec path, not posix_spawn) - log exe open + interp(ld.so) open, the two ENOENT-masking points 2026-07-18 20:45:18 +09:00
Red Bear OS e64c914319 DIAG(spawn): emit trace to fd2 (+/scheme/debug); debug: scheme path was wrong 2026-07-18 20:33:03 +09:00
Red Bear OS e532daf4d5 DIAG(spawn): trace Sys::spawn steps to debug: (new_child/cwd/filetable/exe/interp) to locate the login-shell ENOENT 2026-07-18 20:25:21 +09:00
Red Bear OS 733da06876 fix(redox): translate POSIX F_DUPFD_CLOEXEC (1030) to Redox syscall ABI (5)
fcntl(F_DUPFD_CLOEXEC) reached redox_rt/kernel with the POSIX/C value 1030
instead of the Redox syscall value (syscall::F_DUPFD_CLOEXEC=5). redox_rt did
not recognize it as a dup, forwarded the raw command to the kernel, and the
kernel's fcntl fell through to its EINVAL catch-all. That made
OwnedFd::try_clone() return EINVAL, which broke tokio Runtime::build() (its I/O
reactor try_clones the epoll fd) for every tokio user on Redox: all the zbus
system daemons (sessiond/polkit/udisks/upower) and the login shell. F_DUPFD and
plain dup worked because they share the same value in both namespaces;
F_DUPFD_CLOEXEC was the sole untranslated command.

Also drop the ineffective epoll_ctl EINVAL/EBADF retry loop: it was based on a
disproven 'transient scheme churn' theory; epoll registrations always succeed
immediately. The real dup failure is fixed above.
2026-07-17 22:59:55 +09:00
auronandace f1e905dcb5 eliminate 2 expects 2026-07-17 11:04:15 +01:00
auronandace eed996c612 work around triggering some clippy lints 2026-07-17 08:32:49 +01:00
Red Bear OS 415fa3c8c2 epoll: retry EPOLL_CTL_ADD/MOD on transient EINVAL/EBADF (Redox)
Registering an fd with /scheme/event can transiently fail with
EINVAL/EBADF while the scheme backing the fd is still starting up or the
fd table is churning during early boot (e.g. a tokio/mio reactor built by
a daemon that races ahead of ipcd's uds_stream scheme). Without recovery,
tokio's Runtime::build aborts the whole runtime with "Invalid argument
(os error 22)", killing every zbus daemon (sessiond, polkit, udisks,
upower) and any tokio program including the login shell.

Retry the /scheme/event registration write with a 5ms backoff, up to ~2s,
on EINVAL/EBADF; a genuinely permanent failure still surfaces after the
bounded window. Redox-only. This is the registration-site counterpart to
the existing park-path recovery in the P0-epoll-redox-recovery tokio patch.
2026-07-17 00:31:27 +09:00
auronandace 7375a196c6 add annotations and safety notes for timer functions 2026-07-16 10:00:19 +01:00
auronandace feebedbd55 import ToString 2026-07-16 09:11:52 +01:00
auronandace f3c0b52846 tackle more clippy lints 2026-07-16 08:59:10 +01:00
Red Bear OS a7663b3adf redox: drop now-unused EPERM import after setrlimit rewrite 2026-07-16 06:52:23 +09:00
Red Bear OS 323b95416b redox: implement getrlimit/setrlimit with a per-process limits table (finite RLIMIT_NOFILE) 2026-07-16 06:39:43 +09:00
Jeremy Soller 7fcce3822c Merge branch 'clippy-green3' into 'master'
tackle more clippy lints for redox

See merge request redox-os/relibc!1549
2026-07-15 10:27:40 -06:00
Jeremy Soller 4a6f7854a9 Merge branch 'merge-ld-libc' into 'master'
feat(ld.so): merge with libc.so

Closes #284

See merge request redox-os/relibc!1547
2026-07-15 10:25:12 -06:00
Anhad Singh 260bccbd3c fix(ld): make environ preemptable
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 22:40:29 +10:00
auronandace ce28b8786a follow-up eliminating more as casts 2026-07-15 10:54:26 +01:00
auronandace 6671339ec3 revert cfg and remove unused import 2026-07-15 10:44:50 +01:00
auronandace e320c755ff tackle more clippy lints for redox 2026-07-15 10:30:48 +01:00
Anhad Singh 6697881222 feat(alloc): cleanup
* Storing a pointer to the allocator in TCB is no longer necessary.
* `AtomicPtr` to store the allocator is no longer required as the
  allocator is not swapped on init if the program was dynamically
  linked.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-15 18:26:27 +10:00
Red Bear OS a0b7e0ab64 fix(spawn): install bootstrap fds in child file table
The copied child table did not reliably retain the thread and process descriptors at the numbers exported through auxv. Explicitly clone both descriptors into the selected child table before loading the image, and remove the ineffective parent-handle leak.
2026-07-14 18:55:06 +09:00
auronandace b632453fd4 follow-up casts in redox socket 2026-07-14 09:50:26 +01:00
auronandace da54c331f5 revert two casts 2026-07-14 09:29:44 +01:00
auronandace 70505f0a6f address some clippy lints in redox 2026-07-14 09:16:29 +01:00
Red Bear OS 7a8c7564ba fix(spawn): leak child thread fd to prevent race with dynamic linker
posix_spawn creates a new context and returns its thread fd to the
parent. The kernel currently does not keep a self-reference to the child
context's thread fd, so when the parent closes its handle, the child's
thread object may be destroyed before the dynamic linker reads
AT_REDOX_THR_FD from auxv and opens regs/env. Leak the parent handle
until the kernel is fixed to retain a reference per context.
2026-07-14 16:37:24 +09:00
Anhad Singh 14b3122696 misc(logger): return an error on failure
...instead of logging.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-07-14 17:01:55 +10:00
Red Bear OS d2648af84a fix(pipe2): use FILETABLE-aware open/dup to keep kernel/userspace fd tables in sync 2026-07-14 08:01:33 +09:00
Red Bear OS eac112e919 relibc: fix pipe2 to use raw syscalls + register_external_fd
The previous pipe2 implementation used redox_rt::sys::open() which goes
through the FILETABLE's insert_upper mechanism. This can collide with
the untracked namespace fd (ns_fd) stored in DYNAMIC_PROC_INFO, causing
the kernel to overwrite the namespace fd entry with a pipe scheme root
entry. Subsequent open() calls then resolve to the wrong scheme, and
kdup fails with EBADF because it receives a write-end (odd) ID instead
of a read-end (even) ID.

Fix: bypass the open() function entirely and use raw syscall::openat +
syscall::dup, then register both fds with register_external_fd so the
FILETABLE tracks them correctly.
2026-07-13 22:13:02 +03:00
Red Bear OS 9ada7b78bb relibc: remove PIPE_DIAG debug noise, fix F_SETFD arg in pipe2
Remove eprintln debug output from pipe2() FdGuard::open error path.
Fix F_SETFD argument: pass flags & O_CLOEXEC instead of write_flags
(which includes O_WRONLY — not an fd flag).
2026-07-13 21:13:04 +03:00
Red Bear OS 5049c25a79 diag: print ns_fd in pipe2 on failure 2026-07-12 12:15:24 +03:00
Red Bear OS fa54b985ff absorb: 27 orphaned relibc patches re-applied (Phase 1.0A)
Per local/docs/PATCH-PRESERVATION-AUDIT-2026-07-12.md the relibc
fork was carrying only 34 of 90 patches in local/patches/relibc/.
The other 56 patches' content was silently missing from the fork.

This commit re-applies 27 patches that genuinely still apply
cleanly. Recovery covers:

- eventfd implementation (sys/eventfd.h + eventfd.rs)
- signalfd implementation (sys/signalfd.h + signalfd.rs)
- timerfd implementation (sys/timerfd.h + timerfd.rs)
- bits/eventfd.h header
- spawn() function: cbindgen + stdint fix
- P3-timerfd-cbindgen-fix
- cbindgen language=C fixes for sys/{timerfd,semaphore}
- stdint include chain fixes
- strtold implementation
- dns aaaa getaddrinfo ipv6
- various stack/threading/header threading fixes
- dup3 syscalls
- waitid implementation
- bits/timespec reverse_from
- open_memstream integration

24 files changed.
2026-07-12 01:29:50 +03:00
Jeremy Soller 52bb3bbfe3 Merge branch 'ptr-offset-by-literal-lint' into 'master'
add ptr_offset_by_literal clippy lint and set to deny

See merge request redox-os/relibc!1527
2026-07-06 06:04:43 -06:00
auronandace bf6dc24407 add ptr_offset_by_literal clippy lint and set to deny 2026-07-06 12:40:43 +01:00
Wildan M 812982556a Parse flags when logging openat 2026-07-06 05:35:13 +07:00
Jeremy Soller 9930a90de0 Merge branch 'all-path' into 'master'
Adapt with new redox-path

See merge request redox-os/relibc!1504
2026-07-05 10:53:21 -06:00
Wildan M 2e8ee25139 Add open trace logging 2026-07-05 19:28:23 +07:00
Wildan M c0cdc017d3 Adapt with new redox-path 2026-07-05 19:27:57 +07:00
Wildan M 7f4c3803bc Fix curl EOPNOSUPP due to MSG_NOSIGNAL 2026-07-05 15:33:40 +07:00
auronandace e714c570bc make mut_from_ref deny 2026-07-02 08:28:38 +01:00
Ibuki Omatsu fba233467a refactor: Move fd allocation logic into userspace 2026-07-01 08:08:23 -06:00
Wildan M b5e764d967 Fix posix_spawn launching sh script 2026-06-23 12:22:31 +07:00
Wildan M c234ace91d Use ArrayString for Cwd 2026-06-22 22:13:24 +07:00
Mathew John Roberts 4e4ed8b8c7 Merge branch 'dis-spawn-test' into 'master'
Disable spawn test temporarily

See merge request redox-os/relibc!1484
2026-06-21 19:37:51 +01:00
Wildan M c47b492717 Disable spawn test temporarily 2026-06-21 14:54:58 +07:00
Wildan M 73a8c843a8 Fix relative program path handling in posix_spawn 2026-06-21 14:12:05 +07:00
Wildan M 5779743a9a Remove posix_spawn string allocation 2026-06-20 12:31:32 +07:00
Wildan M 56d5fe6bce Fix posix_spawn various issues 2026-06-20 07:05:28 +07:00
Mathew John Roberts 09ae605623 Apply 1 suggestion(s) to 1 file(s)
Co-authored-by: Wildan Mubarok <willnode@wellosoft.net>
2026-06-18 13:02:25 +01:00