Skip to content

Symlink & Task Fs Root Bugs Fixed; Mount Testsuites Disk And Run Tests With BusyBox.#80

Open
doruche wants to merge 4 commits intomainfrom
dev/drc/chaos
Open

Symlink & Task Fs Root Bugs Fixed; Mount Testsuites Disk And Run Tests With BusyBox.#80
doruche wants to merge 4 commits intomainfrom
dev/drc/chaos

Conversation

@doruche
Copy link
Copy Markdown
Contributor

@doruche doruche commented May 4, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve filesystem/chroot behavior and expand Linux syscall coverage so the kernel can mount a test disk, chroot into it, and run BusyBox-based userspace tests.

Changes:

  • Reworked path resolution and task filesystem lookup to honor a task-local logical root during chroot/symlink traversal.
  • Replaced the old syscall user-pointer helpers with a new user_access module and updated many filesystem/time/task syscalls to use it.
  • Added/updated syscall support and userspace test harness pieces (mount, umount, symlinkat, readlinkat, fcntl, getrandom, credentials stubs, BusyBox-based test runner).

Reviewed changes

Copilot reviewed 81 out of 85 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
scripts/xtask/src/tasks/rootfs/mkfs.rs Rootfs staging directory handling tweak.
scripts/xtask/src/config/kconfig.rs Added generated max-path-length constant plumbing.
conf/platforms/qemu-virt-rv64.toml Updated documented QEMU drive wiring for RV64.
conf/platforms/qemu-virt-la64.toml Updated documented/active block-device mapping for LA64.
conf/.defconfig Added default max path length config.
anemone-rs/src/sys/linux.rs Added low-level syscall wrappers.
anemone-rs/src/runtime.rs Changed panic reporting/exit behavior.
anemone-rs/src/process.rs Added process ID helper and switched exit wrapper to exit_group.
anemone-rs/src/os/linux.rs Expanded safe-ish Linux wrappers for fs/process syscalls.
anemone-rs/src/allocator.rs Renamed allocator/OOM handler types.
anemone-kernel/src/uts/api/uname.rs Migrated uname pointer handling to new user-access API.
anemone-kernel/src/time/api/times.rs Migrated times pointer handling to new user-access API.
anemone-kernel/src/time/api/nanosleep.rs Migrated nanosleep pointer handling to new user-access API.
anemone-kernel/src/time/api/gettimeofday.rs Migrated gettimeofday pointer handling and changed tz behavior.
anemone-kernel/src/task/sig/mod.rs Removed placeholder signal module comment.
anemone-kernel/src/task/mod.rs Changed clear-child-tid storage to raw user VA.
anemone-kernel/src/task/fs.rs Added task-local rooted path lookup helpers.
anemone-kernel/src/task/files.rs Added mutable FD flags and dup >= minfd support.
anemone-kernel/src/task/api/wait4.rs Migrated wait4 status-pointer handling.
anemone-kernel/src/task/api/set_tid_address.rs Switched clear-child-tid syscall to raw VA handling.
anemone-kernel/src/task/api/mod.rs Registered new credentials module.
anemone-kernel/src/task/api/exit/mod.rs Migrated clear-child-tid writeback to new user-access API.
anemone-kernel/src/task/api/execve/syscall.rs Added bounded argv/env/path validation for execve.
anemone-kernel/src/task/api/execve/binfmt/shebang.rs Made shebang resolution use task-root-aware lookup.
anemone-kernel/src/task/api/execve/binfmt/mod.rs Made exec dispatch use rooted lookup.
anemone-kernel/src/task/api/execve/binfmt/elf/mod.rs Added ELF open failure logging.
anemone-kernel/src/task/api/credentials/setuid.rs Added setuid stub syscall.
anemone-kernel/src/task/api/credentials/setgid.rs Added setgid stub syscall.
anemone-kernel/src/task/api/credentials/mod.rs Added credentials syscall module docs/exports.
anemone-kernel/src/task/api/credentials/getuid.rs Added getuid stub syscall.
anemone-kernel/src/task/api/credentials/getgid.rs Added getgid stub syscall.
anemone-kernel/src/task/api/clone/mod.rs Switched clone TID pointers to raw VAs with new validation.
anemone-kernel/src/task/api/clone/clone.rs Updated clone syscall frontend for raw VA args.
anemone-kernel/src/syscall/user_access.rs New syscall user-memory validation/copy helper module.
anemone-kernel/src/syscall/mod.rs Exported new user-access module, disabled old dt module.
anemone-kernel/src/syscall/dt.rs Removed legacy syscall data-transfer helpers.
anemone-kernel/src/sched/mod.rs Minor wording cleanup.
anemone-kernel/src/mm/uspace/vma.rs Removed dead debug comment.
anemone-kernel/src/mm/uspace/mod.rs Permission checking now uses Protection; formatting cleanup.
anemone-kernel/src/mm/uspace/api/munmap.rs Switched validators to new user-access module.
anemone-kernel/src/mm/uspace/api/mprotect.rs Switched validators to new user-access module.
anemone-kernel/src/mm/uspace/api/mmap.rs Switched validators to new user-access module.
anemone-kernel/src/mm/uspace/api/madvise.rs Switched validators to new user-access module.
anemone-kernel/src/mm/uspace/api/brk.rs Switched validators to new user-access module.
anemone-kernel/src/fs/path.rs Added path location comparison and open helper.
anemone-kernel/src/fs/namei.rs Reworked resolver to support explicit logical root.
anemone-kernel/src/fs/mod.rs Re-exported rooted resolver helpers and added KUnit coverage.
anemone-kernel/src/fs/inode.rs Added truncating Linux permission conversion helper.
anemone-kernel/src/fs/api/writev.rs Migrated writev iovec copying to new user-access API.
anemone-kernel/src/fs/api/write.rs Migrated write buffer copying to new user-access API.
anemone-kernel/src/fs/api/unlinkat.rs Made unlinkat use task-root-aware parent lookup.
anemone-kernel/src/fs/api/umount.rs Made umount resolve mountpoints through task-root-aware lookup.
anemone-kernel/src/fs/api/symlinkat.rs Added symlinkat syscall.
anemone-kernel/src/fs/api/stat/newfstatat.rs Migrated newfstatat output pointer handling.
anemone-kernel/src/fs/api/stat/mod.rs Made fstatat use rooted lookup helpers.
anemone-kernel/src/fs/api/stat/fstat.rs Migrated fstat output pointer handling.
anemone-kernel/src/fs/api/readlinkat.rs Added readlinkat syscall.
anemone-kernel/src/fs/api/read.rs Migrated read buffer handling to new user-access API.
anemone-kernel/src/fs/api/pipe2.rs Migrated pipefd output handling to new user-access API.
anemone-kernel/src/fs/api/openat.rs Reworked openat/create path resolution under task root.
anemone-kernel/src/fs/api/mount.rs Made mount source/target resolution task-root-aware.
anemone-kernel/src/fs/api/mod.rs Registered new fs syscalls and Linux mode parsing helpers.
anemone-kernel/src/fs/api/mkdirat.rs Reworked mkdirat path resolution under task root.
anemone-kernel/src/fs/api/getrandom.rs Added getrandom syscall stub.
anemone-kernel/src/fs/api/getdents64.rs Migrated getdents64 buffer handling to new user-access API.
anemone-kernel/src/fs/api/getcwd.rs Migrated getcwd output handling to new user-access API.
anemone-kernel/src/fs/api/fcntl.rs Added initial fcntl syscall support.
anemone-kernel/src/fs/api/chroot.rs Made chroot use task-root-aware lookup.
anemone-kernel/src/fs/api/chdir.rs Made chdir use task-root-aware lookup.
anemone-kernel/src/fs/api/access/mod.rs Made access path resolution task-root-aware.
anemone-kernel/src/fs/api/access/faccessat2.rs Switched path validator to bounded string reader.
anemone-kernel/src/fs/api/access/faccessat.rs Switched path validator to bounded string reader.
anemone-kernel/src/debug/api/dbg_print.rs Bounded debug-print input length.
anemone-kernel/src/arch/riscv64/trampoline.rs Removed unused signal trampoline stub.
anemone-kernel/src/arch/riscv64/mod.rs Stopped referencing trampoline module.
anemone-apps/user-test/src/main.rs Replaced per-binary test loop with BusyBox/chroot-based harness.
anemone-apps/mmap-test/src/main.rs Updated clone/wait APIs in mmap tests.
anemone-apps/init/src/main.rs Updated init to new process APIs and exec path usage.
anemone-abi/src/syscall/riscv.rs Added syscall numbers for new Linux interfaces.
anemone-abi/src/syscall/loongarch.rs Added syscall numbers for new Linux interfaces.
anemone-abi/src/fs.rs Added Linux fcntl constants.
.vscode/settings.json Minor editor config formatting cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 258 to 264
PendingComponent::ParentDir => {
cur_path = walk_parent(&cur_path);
// prevent escaping logical root via '..' components
if cur_path.location_eq(&logical_root) {
kdebugln!("prevent escaping logical root via '..'");
continue;
}
},
Comment on lines 192 to +205
if let Some(wstatus_ptr) = wstatus_ptr {
wstatus_ptr.safe_write(kbuf)?;
let usp = task.clone_uspace();
let mut guard = usp.write();
match UserWritePtr::<i32>::try_new(wstatus_ptr, &mut guard) {
Ok(mut uptr) => uptr.write(kbuf),
Err(e) => {
knoticeln!(
"wait4: failed to write wstatus for reaped child {}: {:?} at address {:#x}",
tgid,
e,
wstatus_ptr.get()
);
},
}
Comment on lines 33 to 37
if let Some(tz) = tz {
// we don't support time zones, so just fill in dummy values
// plus, " The use of the timezone structure is obsolete; the tz argument
// should normally be specified as NULL." says man 2. so it's fine.
tz.safe_write(TimeZone {
tz_minuteswest: 0,
tz_dsttime: 0,
})?;
// we don't support time zones. btw, the use of the timezone structure
// is obsolete; the tz argument should normally be specified as
// NULL." says man 2. so it's fine.
}
Comment on lines +65 to +67
buf.write_bytes_with_null_terminator(&content[..to_write]);

Ok(to_write as u64 + 1)
Comment on lines +8 to +12
#[syscall(SYS_SETUID)]
fn sys_setuid(uid: u32) -> Result<u64, SysError> {
kdebugln!("setuid: uid={}", uid);

Ok(0)
chdir("..").expect("user-test: failed to change directory to /glibc after basic tests");
println!("user-test: basic tests passed.");

loop {}
Comment on lines 95 to +102
clone(
CloneFlags::CLONE_CHILD_SETTID,
CloneFlags::CHILD_SETTID,
None,
None,
null_mut(),
Some(&mut child_tid),
)
.map(|_| child_tid as u32)
Comment on lines +6 to +30
//! Fake implementation for now. See https://xkcd.com/221.

use crate::prelude::{
user_access::{UserWriteSlice, user_addr},
*,
};

#[syscall(SYS_GETRANDOM)]
fn sys_getrandom(
#[validate_with(user_addr)] buf: VirtAddr,
size: usize,
_flags: u32,
) -> Result<u64, SysError> {
const BATCH_SIZE: usize = 256;
const RANDOM_BYTES: &[u8; BATCH_SIZE] = &[0x4; BATCH_SIZE];

let usp = get_current_task().clone_uspace();
let mut guard = usp.write();

let mut buf = UserWriteSlice::<u8>::try_new(buf, size, &mut guard)?;

let to_write = size.min(BATCH_SIZE);
buf.copy_from_slice(&RANDOM_BYTES[..to_write]);

Ok(to_write as u64)
Comment on lines 45 to +46
# "-drive",
# "file=build/rootfs/minimal/rootfs.img,format=raw,if=none,id=x2",
# "file=build/rootfs/minimal-rv/rootfs.img,format=raw,if=none,id=x2",
Comment on lines +17 to +34
match wait4(
WaitFor::ChildWithTgid(tid),
Some(&mut wstatus),
WaitOptions::empty(),
)
.expect("user-test: failed to wait4")
{
Some(tid) => {
println!(
"user-test: child task #{} exited with code {:?}",
tid,
wstatus.read()
)
},
None => {
panic!("user-test: wait4 returned None unexpectedly");
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants