]> Projects (at) Tadryanom (dot) Me - AdrOS.git/log
AdrOS.git
7 weeks agorootfs-handoff: add ext2 filesystem state verification
Tulio A M Mendes [Thu, 11 Jun 2026 03:53:01 +0000 (00:53 -0300)]
rootfs-handoff: add ext2 filesystem state verification

- Added EFSCK error code to errno.h (102)
- Added ext2_verify_state() function in ext2.c to check filesystem state
- Verifies ext2 superblock fields: s_state (clean/dirty) and s_errors (error policy)
- Returns -EFSCK if filesystem is dirty (needs fsck)
- Returns -EROFS if filesystem has errors configured for read-only mount
- Returns -EINVAL if filesystem has errors configured for panic
- Modified init.c to call ext2_verify_state() before mounting ext2
- Forces read-only mount if filesystem verification fails
- Added TODO comment for remount,rw after verification (requires syscall support)
- This implements the 'Root verification and remount,rw after checks' item from ROOTFS_HANDOFF_PLAN.md

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agorootfs-handoff: Milestone D - adapt /sbin/init and fstab for post-handoff
Tulio A M Mendes [Thu, 11 Jun 2026 03:40:43 +0000 (00:40 -0300)]
rootfs-handoff: Milestone D - adapt /sbin/init and fstab for post-handoff

- Updated /etc/fstab with documentation for post-handoff configuration
- Documented that root filesystem is already mounted by kernel on /newroot
- Documented that early /init performs pivot_root to make /newroot the new root
- Documented that virtual filesystems are moved by early /init
- Documented that /sbin/init runs after handoff and skips already-mounted filesystems
- /sbin/init already has is_mounted() check to avoid duplicate mounts
- No code changes needed in /sbin/init - already compatible with handoff

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agorootfs-handoff: Milestone C - integrate pivot_root in early /init
Tulio A M Mendes [Thu, 11 Jun 2026 03:39:26 +0000 (00:39 -0300)]
rootfs-handoff: Milestone C - integrate pivot_root in early /init

- Added full pivot_root implementation to initrd_init.c
- Added mkdir_p() for recursive directory creation
- Added mount_virtual_fs() to mount virtual filesystems
- Added move_mount() to move mounts using MS_MOVE flag
- Early /init now moves /dev, /proc, /tmp to /newroot
- Performs pivot_root to make /newroot the new root
- Unmounts old root after pivot
- Executes /sbin/init from the new root
- Added MS_MOVE definition (not in ulibc)
- Fixed includes to use ulibc headers (syscall.h instead of sys/syscall.h)
- Used pivot_root() wrapper from ulibc instead of raw syscall

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agorootfs-handoff: Milestone B - add early userspace /init
Tulio A M Mendes [Thu, 11 Jun 2026 03:37:10 +0000 (00:37 -0300)]
rootfs-handoff: Milestone B - add early userspace /init

- Created user/cmds/initrd_init/initrd_init.c as early /init program
- Created user/cmds/initrd_init/Makefile
- Added initrd_init to USER_CMD_NAMES in main Makefile
- Changed default init path from /sbin/init to /init in cmdline.c
- Early /init checks if /newroot is mounted by kernel
- If /newroot is mounted, executes /sbin/init (basic handoff)
- If /newroot is not mounted, falls back to /sbin/init directly
- Milestone C will add pivot_root and mount moving functionality

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agorootfs-handoff: Milestone E - add boot policy parameters
Tulio A M Mendes [Thu, 11 Jun 2026 03:34:38 +0000 (00:34 -0300)]
rootfs-handoff: Milestone E - add boot policy parameters

- Add rootfstype= parameter to specify explicit filesystem type
- Add rootflags= parameter for comma-separated mount options (ro, nosuid, nodev, noexec)
- Add ro/rw flags to control read-only or read-write mount
- Add rootdelay=N parameter to wait N seconds before mounting
- Add rootwait flag (recognized but not yet implemented)
- Parse and apply mount flags to root filesystem
- Add process.h include for process_sleep()

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agorootfs-handoff: Milestone A - redefine root= semantics to mount on /newroot
Tulio A M Mendes [Thu, 11 Jun 2026 03:33:03 +0000 (00:33 -0300)]
rootfs-handoff: Milestone A - redefine root= semantics to mount on /newroot

- Create /newroot directory during kernel init
- Mount root= device on /newroot instead of /disk
- Keep /disk as optional secondary mountpoint for manual use
- Update comments to reflect staging purpose of /newroot
- This change prepares for future pivot_root handoff

Test Results:
- Smoke test: 131/131 PASS
- Battery test: 157/157 PASS
- Analyzer: PASS
- Zero regressions

7 weeks agodocs: remove URGENT_SECURITY_STATUS_2026-06-09.md
Tulio A M Mendes [Thu, 11 Jun 2026 03:19:18 +0000 (00:19 -0300)]
docs: remove URGENT_SECURITY_STATUS_2026-06-09.md

All items from this TODO document have been completed:
- H1: AIO validation (fd mode, read-only mount)
- H3: SHM_RDONLY attach
- H6: Fixed VAs removed (kva_alloc_pages)
- H7: Tmpfs quotas + overflow hardening
- M2: access() with real IDs
- M6: Overlayfs wrapper lifetime
- M8: CSPRNG (ChaCha20-based DRBG)
- UID Infrastructure: /etc/passwd, auth, login, utmp/wtmp
- L1: ENAMETOOLONG standardization
- L2: getlogin/who/utmp

Document is no longer needed as reference.

7 weeks agocsprng: fix undefined behavior in entropy pool initialization
Tulio A M Mendes [Thu, 11 Jun 2026 03:05:21 +0000 (00:05 -0300)]
csprng: fix undefined behavior in entropy pool initialization

Fixed cppcheck error: shifting 64-bit value by 504 bits is undefined.
The TSC has only 64 bits (8 bytes), but the loop was iterating 64 times.
Changed to extract only 8 bytes from TSC and fill remaining pool with
tick count variations.

Test: make test-all PASS (131/131 smoke, 38/38 analyzer, 111/111 host)

7 weeks agouid: add utmp syscalls and integrate with login
Tulio A M Mendes [Thu, 11 Jun 2026 02:58:29 +0000 (23:58 -0300)]
uid: add utmp syscalls and integrate with login

Implement UID Infrastructure: integração utmp/wtmp (completed).

Added syscalls for utmp management:
- SYSCALL_UTMP_LOGIN (145): register login session
- SYSCALL_UTMP_LOGOUT (146): register logout
- SYSCALL_UTMP_DEAD (147): register process death

Updated kernel syscall.c to handle utmp syscalls.
Updated kernel include/syscall.h with new syscall numbers.
Updated userspace include/syscall.h with new syscall numbers.
Updated userspace include/utmp.h with utmp_login/logout/dead declarations.
Updated userspace src/utmp.c with syscall wrappers.
Updated login command to call utmp_login() with TTY name and hostname.

Test: make test-battery PASS (157/157)

7 weeks agouid: add login command with password authentication
Tulio A M Mendes [Thu, 11 Jun 2026 02:55:13 +0000 (23:55 -0300)]
uid: add login command with password authentication

Implement UID Infrastructure: login real (completed).

Added user/cmds/login/login.c with:
- Username prompt
- Password prompt with echo disabled (termios)
- Password verification using check_password()
- UID/GID setting after successful authentication
- Home directory change
- Shell execution (from /etc/passwd or default /bin/sh)
- Loop for retry on failed login

Added user/cmds/login/Makefile.
Updated Makefile to include login in USER_CMD_NAMES.

Test: make test-battery PASS (157/157)

7 weeks agouid: add /etc/shadow and check_password function
Tulio A M Mendes [Thu, 11 Jun 2026 02:53:47 +0000 (23:53 -0300)]
uid: add /etc/shadow and check_password function

Implement UID Infrastructure: autenticação real (completed).

Added /etc/shadow file with basic entries (root:root, daemon:*, nobody:*).
Updated Makefile to include /etc/shadow in initrd.
Added check_password() function in pwd_grp.c to verify passwords against /etc/shadow.
Added check_password() declaration in pwd.h.
Password verification uses plaintext comparison for now (TODO: add SHA256/crypt).
Locked accounts (passwd starts with '*' or '!') are rejected.

Test: make test-battery PASS (157/157)

7 weeks agouid: add /etc/passwd to initrd for UID infrastructure
Tulio A M Mendes [Thu, 11 Jun 2026 02:51:53 +0000 (23:51 -0300)]
uid: add /etc/passwd to initrd for UID infrastructure

Implement UID Infrastructure: parser /etc/passwd (completed).

Added /etc/passwd file with basic entries (root, daemon, nobody).
Updated Makefile to include /etc/passwd in initrd.
Existing pwd_grp.c already implements getpwnam/getpwuid/setpwent/endpwent/getpwent
with /etc/passwd parsing and static fallback.

Test: make test-battery PASS (157/157)

7 weeks agoutmp: add kernel utmp database infrastructure
Tulio A M Mendes [Thu, 11 Jun 2026 02:45:47 +0000 (23:45 -0300)]
utmp: add kernel utmp database infrastructure

Implement L2 (partial): kernel utmp database infrastructure.

Added utmp.h with Linux-compatible utmp structure and record types.
Implemented utmp.c with:
- utmp_init(): Initialize utmp database
- utmp_login(): Register user login session
- utmp_logout(): Mark session as DEAD_PROCESS
- utmp_dead(): Record process exit status
- utmp_get_by_pid(): Find utmp entry by PID

Reduced UTMP_MAX_ENTRIES to 32 to avoid BSS overflow.
Not initialized in boot (deferred to when needed) to prevent SMP panic.

Test: make test-battery PASS (157/157), make analyzer PASS

Note: Userspace integration (getlogin/who) and login session
registration still needed for complete L2 implementation.

7 weeks agooverlayfs: improve wrapper lifetime management with root refcount
Tulio A M Mendes [Thu, 11 Jun 2026 02:14:05 +0000 (23:14 -0300)]
overlayfs: improve wrapper lifetime management with root refcount

Implement M6: overlayfs wrapper lifetime improvements.

Added is_root flag to overlay_node to distinguish root from wrapper nodes.
Modified overlay_root_close() to properly manage root node refcount and
free overlayfs structure when root is finally closed.
Initialized root node refcount to 1 and set is_root flag in overlayfs_create_root().

This ensures proper cleanup of overlayfs structures when the filesystem
is unmounted, preventing memory leaks of the overlayfs structure and root node.

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agovfs: add ENAMETOOLONG checks to path helpers in fs.c
Tulio A M Mendes [Thu, 11 Jun 2026 02:12:56 +0000 (23:12 -0300)]
vfs: add ENAMETOOLONG checks to path helpers in fs.c

Implement L1: standardize ENAMETOOLONG across all path helpers.

Added path length checks (PATH_MAX = 128) to:
- vfs_lookup_depth(): Check path length before lookup
- vfs_lookup_parent(): Check path length before parent lookup
- vfs_mkdirp(): Check path length before recursive mkdir

These functions now return NULL or -ENAMETOOLONG when paths exceed
128 characters, matching the behavior already present in syscall.c
helpers (copy_user_cstr, path_resolve_user).

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agoshm: implement SHM_RDONLY flag for read-only attach
Tulio A M Mendes [Thu, 11 Jun 2026 02:11:18 +0000 (23:11 -0300)]
shm: implement SHM_RDONLY flag for read-only attach

Implement H3: SHM permissions complete with SHM_RDONLY attach.

Added SHM_RDONLY flag (0x1000) to shm.h for shmat syscall.
Modified shm_at() to accept shmflg parameter and:
- Check write permission only if SHM_RDONLY is not set
- Map pages without VMM_FLAG_RW when SHM_RDONLY is set
- This allows read-only shared memory segments for POSIX compliance

Updated syscall handler to pass shmflg from sc_arg2 to shm_at().

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agovfs: add vfs_check_permission_real for POSIX strict access()
Tulio A M Mendes [Thu, 11 Jun 2026 02:09:53 +0000 (23:09 -0300)]
vfs: add vfs_check_permission_real for POSIX strict access()

Implement M2: POSIX access() with real IDs instead of effective IDs.

Added vfs_check_permission_real() function that uses current_process->uid
and current_process->gid instead of euid/egid for POSIX strict compliance.
The access() syscall now uses this function, while other operations continue
to use vfs_check_permission() with effective IDs.

This ensures access() behaves according to POSIX specification which requires
real IDs for permission checks, while preserving existing behavior for other
file operations that use effective IDs.

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agokva_alloc: document linear mapping overlap with boot.S
Tulio A M Mendes [Thu, 11 Jun 2026 01:45:54 +0000 (22:45 -0300)]
kva_alloc: document linear mapping overlap with boot.S

Add documentation note explaining that the KVA allocator region
(0xC0500000..0xC0800000) falls within the initial 16MB linear mapping
set up by boot.S (0xC0000000..0xC0100000). This means V2P() works by
coincidence for addresses in this range, but code should use
vmm_virt_to_phys() instead to be portable and future-proof.

This documents the architectural fragility identified during H6
regression analysis.

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agovirtio-blk: fix memory leak on vring page allocation failure
Tulio A M Mendes [Thu, 11 Jun 2026 01:45:05 +0000 (22:45 -0300)]
virtio-blk: fix memory leak on vring page allocation failure

Bug: If pmm_alloc_page() failed in the middle of the vring page
allocation loop, previously allocated physical pages and the VA range
were not freed, causing a memory leak.

Fix: Add rollback loop on allocation failure to:
1. Unmap and free previously allocated physical pages
2. Free the VA range via kva_free_pages()

This is a pre-existing bug that was exposed during H6 regression
analysis, not a regression introduced by H6.

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agovirtio-blk: fix V2P usage for kva_alloc addresses (H6 regression)
Tulio A M Mendes [Thu, 11 Jun 2026 01:43:33 +0000 (22:43 -0300)]
virtio-blk: fix V2P usage for kva_alloc addresses (H6 regression)

Bug: virtio_blk_init used V2P() macro to convert vring virtual address
to physical address. After H6, vring_va comes from kva_alloc_pages()
which may not be in the linear mapping region. V2P assumes linear
mapping (VA = PA + 0xC0000000), which is fragile.

Fix: Replace V2P(vring_va) with vmm_virt_to_phys(vring_va) to use
the proper VMM translation function that works for any mapped virtual
address.

This fixes the regression introduced by H6 where virtio-blk relied on
coincidental overlap between kva_alloc range (0xC0500000..0xC0800000)
and the initial 16MB linear mapping (0xC0000000..0xC0100000).

Test: make test-battery PASS (157/157), make analyzer PASS

7 weeks agokva: implement dynamic VA allocator to remove fixed VAs (H6)
Tulio A M Mendes [Thu, 11 Jun 2026 01:19:23 +0000 (22:19 -0300)]
kva: implement dynamic VA allocator to remove fixed VAs (H6)

Created kernel virtual address allocator to replace fixed VAs:
- include/kva_alloc.h: KVA allocator interface
- src/kernel/kva_alloc.c: Bitmap-based allocator with spinlock protection
  - Region: 0xC0500000 .. 0xC0800000 (3 MB, 768 pages)
  - kva_alloc_init(): Initialize bitmap and spinlock
  - kva_alloc_pages(): Allocate contiguous page range
  - kva_free_pages(): Free allocated range

Migrated fixed VA usages to dynamic allocation:
- src/hal/x86/mm.c: hal_mm_map_physical_range() now uses kva_alloc_pages
  instead of fixed KVA_PHYS_MAP (0xDC000000U)
- src/drivers/virtio_blk.c: virtio vring allocation now uses kva_alloc_pages
  instead of fixed VIRTIO_VRING_VA (0xC0340000U)

Removed obsolete constants:
- include/arch/x86/kernel_va_map.h: Removed KVA_PHYS_MAP constant
  Updated layout comment to document KVA allocator region

Boot integration:
- src/kernel/main.c: Added kva_alloc_init() call after kheap_init()

Validation:
- make -j$(nproc): PASS
- make test SMOKE_SMP=4: 131/131 PASS
- make test-battery: 157/157 PASS

This completes H6: remove fixed VAs, replacing hardcoded virtual
addresses with dynamic allocation to prevent collisions and improve
architectural flexibility.

7 weeks agotests: add security hardening tests for H2 and M8
Tulio A M Mendes [Thu, 11 Jun 2026 01:04:02 +0000 (22:04 -0300)]
tests: add security hardening tests for H2 and M8

- Add I7: /proc/dmesg root-only access test (H2)
- Add I8: /proc/cmdline root-only access test (H2)
- Add I9: /proc/PID/maps format verification test (H2)
- Add I10: /dev/random CSPRNG uniqueness test (M8)
- Update smoke_test.exp with new test patterns
- Update test_battery.exp with new test patterns

Validation:
- make test SMOKE_SMP=4: 131/131 PASS (was 127/127, +4 new tests)
- make test-battery: 157/157 PASS (was 153/153, +4 new tests)

Tests validate H2 (/proc hardening) and M8 (CSPRNG) implementations.

7 weeks agosecurity: implement central CSPRNG with real entropy (M8)
Tulio A M Mendes [Thu, 11 Jun 2026 00:56:29 +0000 (21:56 -0300)]
security: implement central CSPRNG with real entropy (M8)

- Create src/kernel/csprng.c with ChaCha20-based DRBG
- Entropy sources: RDTSC, timer ticks, interrupt timing, user input
- Add csprng_init() called at boot in kernel_main()
- Add csprng_get_bytes(), csprng_get_u32(), csprng_get_u64() APIs
- Add csprng_add_entropy() for /dev/random writes
- Update src/kernel/devfs.c:
  - Remove local PRNG (prng_state, prng_next)
  - Use csprng_get_bytes() in dev_random_read()
  - Use csprng_add_entropy() in dev_random_write()
- Spinlock protection for SMP safety
- Reseed mechanism every 256 entropy additions

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses M8 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agosecurity: add SMP spinlock protection to futex table (H5)
Tulio A M Mendes [Thu, 11 Jun 2026 00:52:51 +0000 (21:52 -0300)]
security: add SMP spinlock protection to futex table (H5)

- Add g_futex_lock spinlock to protect global futex_waiters table
- Protect futex_cleanup_process with spinlock
- Protect FUTEX_WAIT path with spinlock:
  - Slot allocation and registration
  - Timeout cleanup on early return
  - Cleanup after schedule() wakeup
- Protect FUTEX_WAKE path with spinlock:
  - Wakeup loop over waiters
- Existing shared keying by (addr_space, uaddr) preserved
- Prevents race conditions in SMP environments

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses H5 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agosecurity: harden /proc with access controls and hidepid (H2)
Tulio A M Mendes [Thu, 11 Jun 2026 00:50:48 +0000 (21:50 -0300)]
security: harden /proc with access controls and hidepid (H2)

- Protect /proc/dmesg: root-only access (euid == 0)
- Protect /proc/cmdline: root-only access (euid == 0)
- Implement hidepid mechanism with g_proc_hidepid global:
  - 0 = visible to all (default)
  - 1 = invisible to non-root, except own process (current default)
  - 2 = invisible to non-root, including own process
- Redact addresses in /proc/<pid>/maps for non-root users:
  - Show 0 instead of actual heap/brk/mmap addresses
  - Applies even to own process for security
- Update proc_root_readdir to respect hidepid for PID listing
- Update proc_root_finddir to respect hidepid for direct PID access

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses H2 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agosecurity: add tmpfs quotas and overflow hardening (H7)
Tulio A M Mendes [Thu, 11 Jun 2026 00:48:33 +0000 (21:48 -0300)]
security: add tmpfs quotas and overflow hardening (H7)

- Add global tmpfs quota (512MB) to prevent DoS via memory exhaustion
- Track total memory usage across all tmpfs instances with g_tmpfs_total_used
- Validate quota before allocation in tmpfs_write_impl, tmpfs_add_file, and tmpfs_create_file
- Decrement quota when freeing memory in tmpfs_unlink_impl and tmpfs_kill_sb
- Add overflow protection in tmpfs_write_impl new_cap *= 2 loop:
  - Cap per-file maximum at 256MB
  - Check for overflow before doubling
  - Return error if requested size exceeds max cap
- All quota operations protected by existing g_tmpfs_lock

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses H7 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agosecurity: fix inverted user_range_ok checks in socket syscalls (M5)
Tulio A M Mendes [Thu, 11 Jun 2026 00:46:26 +0000 (21:46 -0300)]
security: fix inverted user_range_ok checks in socket syscalls (M5)

- Fix SYSCALL_GETPEERNAME: user_range_ok == 0 means failure, not success
- Fix SYSCALL_GETSOCKNAME: user_range_ok == 0 means failure, not success
- Previously, the code incorrectly nested copy_to_user inside the
  user_range_ok == 0 check, which would only execute copy_to_user
  when the range check FAILED
- Now properly returns -EFAULT when user_range_ok fails, then
  calls copy_to_user when the range check succeeds

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses M5 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agosecurity: complete AIO validation (H1)
Tulio A M Mendes [Thu, 11 Jun 2026 00:44:47 +0000 (21:44 -0300)]
security: complete AIO validation (H1)

- Add fd mode validation in syscall_aio_rw_impl:
  - Reject aio_read on O_WRONLY fd (except char devices)
  - Reject aio_write on O_RDONLY fd (except char devices)
  - Reject aio_write on MS_RDONLY mount
- Reuse same policy as read/write/pread/pwrite syscalls
- Fix fulltest AIO test to use O_RDWR instead of O_WRONLY
  (test was incorrectly trying to read from write-only fd)

Validation:
- make -j12: PASS
- make test-host: PASS (111/111)
- make test SMOKE_SMP=4: PASS (127/127)
- make test-battery: PASS (153/153)
- make analyzer: PASS

Addresses H1 from docs/URGENT_SECURITY_STATUS_2026-06-09.md

7 weeks agodocs: add urgent security status checklist
Tulio A M Mendes [Tue, 9 Jun 2026 07:30:07 +0000 (04:30 -0300)]
docs: add urgent security status checklist

Add an updated security status document replacing the outdated phase 2-5 checklist as the immediate planning reference.

The document classifies each previously listed item as implemented, partial, or still pending based on direct source inspection, and highlights the urgent remaining work around AIO validation, /proc hardening, futex robustness, fixed virtual addresses, tmpfs hardening, socket copyout review, and kernel RNG quality.

7 weeks agoscheduler: harden SIGKILL SMP and clone semantics
Tulio A M Mendes [Tue, 9 Jun 2026 07:12:43 +0000 (04:12 -0300)]
scheduler: harden SIGKILL SMP and clone semantics

Fix the remote SIGKILL path so it no longer tears down a task on behalf of another CPU before that task reaches a safe exit point. SIGKILL is now queued as a fatal pending signal, forcibly unblocked, blocked/sleeping tasks are woken, and reschedule IPIs are sent so the target exits on its own CPU.

Fix CLONE_VM address-space accounting by using the global address-space refcount table to detect the first shared-mm clone and to decide teardown during reap. This closes the leak/counter skew when a non-leader thread creates another CLONE_VM thread.

Align clone semantics with the implementation by rejecting unsupported shared-state flags from the syscall interface, while still inheriting cwd, file references, descriptor flags, signal handlers, and signal mask by copy. Update pthread/fulltest users accordingly.

Also prevent userspace from changing SIGKILL/SIGSTOP disposition or blocking them, make default SIGKILL delivery fatal in usermode signal dispatch, and extend the kill regression test so the child tries to block SIGKILL before spinning.

7 weeks agoscheduler: fix SMP waitpid reap race and harden socket file init
Tulio A M Mendes [Tue, 9 Jun 2026 06:19:17 +0000 (03:19 -0300)]
scheduler: fix SMP waitpid reap race and harden socket file init

Prevent process_waitpid() from reaping a zombie child while it is still the current process on another CPU. This avoids freeing a live process struct and kernel stack during the exit-to-schedule handoff under SMP, which matched the intermittent invalid-opcode panic seen after the job-control path in fulltest.

Also zero-initialize struct file allocations in the socket() and accept() paths so mount_root and any future fields cannot inherit heap garbage.

Validation: make -j$(nproc), make test-host, make test SMOKE_SMP=4, make test-battery (153/153 PASS).

7 weeks agoChange: support for multitest
Tulio A M Mendes [Tue, 9 Jun 2026 02:59:42 +0000 (23:59 -0300)]
Change: support for multitest

7 weeks agofs: fix ext2 readdir visibility and ls single-file output
Tulio A M Mendes [Tue, 9 Jun 2026 02:59:34 +0000 (23:59 -0300)]
fs: fix ext2 readdir visibility and ls single-file output

Corrected:
- fix ext2 directory iteration so readdir accepts valid exact-fit ext2 dirents instead of rejecting entries where name_len == rec_len - 8
- restore visibility of pre-existing files on ext2 mounts when listing directories with ls/getdents
- fix the userland ls command so path arguments are stat'ed first and handled as either directories or standalone files
- make 'ls -l /disk/outro.txt' and 'ls -l /disk2/outro.txt' print the expected single-file output instead of treating regular files like directories and producing no output

Changed:
- refactor ls formatting through a shared print_entry() helper reused by both directory listings and direct file-path listings

Validation:
- ext2 directory listing regression reproduced from mounted host image and corrected in src/kernel/ext2.c
- make test passes after the changes

7 weeks agofs: fix mounted ext2/fat stat and dirent regressions
Tulio A M Mendes [Tue, 9 Jun 2026 01:24:40 +0000 (22:24 -0300)]
fs: fix mounted ext2/fat stat and dirent regressions

Corrected:
- align kernel struct stat with the userspace ABI and update fulltest's local struct stat so stat/fstat copy the expected fields on mounted filesystems
- make getdents emit variable-length userspace dirent records with d_reclen and correct d_type values, and update ulibc readdir to consume them
- fix ext2 directory entry validation for exact-fit names and replace several 4KB on-stack buffers in ext2 inode/block/bitmap/write paths with heap-backed buffers to avoid stack-related crashes while listing and writing /disk
- populate sensible FAT mode/uid/gid defaults so ls -l reports sane metadata on FAT mounts
- preserve overlay root/initrd lifetime by keeping the initrd root registered separately and using a no-op close handler for the overlay root wrapper

Changed:
- add fulltest coverage for open('/disk') + getdents + close and for overlay root lifecycle after getdents/close/exec
- extend smoke_test.exp and test_battery.exp with the new /disk readdir and overlay root lifecycle expectations
- teach the minimal ulibc stdio formatter to accept a single 'l' length modifier so formats such as %lu work in ls -l output

TODO:
- add more targeted ext2 create/write regression coverage beyond the current fulltest/smoke battery if a smaller dedicated harness is introduced
- keep an eye on remaining direct getdents consumers, but the current tree passes make test and make test-battery in this state

8 weeks agodocs: add rootfs handoff implementation plan
Tulio A M Mendes [Sat, 6 Jun 2026 19:39:09 +0000 (16:39 -0300)]
docs: add rootfs handoff implementation plan

8 weeks agofs: harden fat and ext2 mount validation
Tulio A M Mendes [Sat, 6 Jun 2026 18:44:22 +0000 (15:44 -0300)]
fs: harden fat and ext2 mount validation

8 weeks agovfs: route virtual mounts through fs registry
Tulio A M Mendes [Sat, 6 Jun 2026 18:35:43 +0000 (15:35 -0300)]
vfs: route virtual mounts through fs registry

8 weeks agovfs: fix cwd mount refs across kill and clone
Tulio A M Mendes [Sat, 6 Jun 2026 18:23:42 +0000 (15:23 -0300)]
vfs: fix cwd mount refs across kill and clone

8 weeks agomount: resolve partitions in boot and mount paths
Tulio A M Mendes [Sat, 6 Jun 2026 18:05:02 +0000 (15:05 -0300)]
mount: resolve partitions in boot and mount paths

8 weeks agobuild: fix analyzer target and scan-build warning
Tulio A M Mendes [Sat, 6 Jun 2026 17:54:38 +0000 (14:54 -0300)]
build: fix analyzer target and scan-build warning

8 weeks agoinit: recreate /disk before boot-time automount
Tulio A M Mendes [Sat, 6 Jun 2026 17:51:17 +0000 (14:51 -0300)]
init: recreate /disk before boot-time automount

8 weeks agobuild: fix sparse warning and host utility test builds
Tulio A M Mendes [Thu, 4 Jun 2026 07:17:07 +0000 (04:17 -0300)]
build: fix sparse warning and host utility test builds

8 weeks agosecurity: document getlogin/who as placeholder (Fase 5)
Tulio A M Mendes [Tue, 26 May 2026 05:30:53 +0000 (02:30 -0300)]
security: document getlogin/who as placeholder (Fase 5)

8 weeks agosecurity: return ENAMETOOLONG on path truncation (Fase 5)
Tulio A M Mendes [Tue, 26 May 2026 05:29:30 +0000 (02:29 -0300)]
security: return ENAMETOOLONG on path truncation (Fase 5)

8 weeks agosecurity: add explicit field width support to scanf (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:28:11 +0000 (02:28 -0300)]
security: add explicit field width support to scanf (Fase 3)

8 weeks agosecurity: fix fcntl/openat varargs handling (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:26:20 +0000 (02:26 -0300)]
security: fix fcntl/openat varargs handling (Fase 3)

8 weeks agosecurity: add retry loop to mkstemp for EEXIST collisions (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:24:42 +0000 (02:24 -0300)]
security: add retry loop to mkstemp for EEXIST collisions (Fase 3)

8 weeks agosecurity: add refcount to overlayfs wrapper nodes (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:22:48 +0000 (02:22 -0300)]
security: add refcount to overlayfs wrapper nodes (Fase 3)

8 weeks agosecurity: handle copy_to_user failures in socket syscalls (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:21:07 +0000 (02:21 -0300)]
security: handle copy_to_user failures in socket syscalls (Fase 3)

8 weeks agosecurity: remove truncate fallback, return ENOSYS for no backend (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:19:40 +0000 (02:19 -0300)]
security: remove truncate fallback, return ENOSYS for no backend (Fase 3)

8 weeks agosecurity: implement O_NOFOLLOW -ELOOP return (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:19:02 +0000 (02:19 -0300)]
security: implement O_NOFOLLOW -ELOOP return (Fase 3)

8 weeks agosecurity: implement POSIX access() with vfs_check_permission (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:17:56 +0000 (02:17 -0300)]
security: implement POSIX access() with vfs_check_permission (Fase 3)

8 weeks agosecurity: fix VFS permissions and execve execute check (Fase 3)
Tulio A M Mendes [Tue, 26 May 2026 05:17:11 +0000 (02:17 -0300)]
security: fix VFS permissions and execve execute check (Fase 3)

8 weeks agosecurity: fix rumpuser_free alignment handling with magic value (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:16:18 +0000 (02:16 -0300)]
security: fix rumpuser_free alignment handling with magic value (Fase 2)

8 weeks agosecurity: add SMP locking to tmpfs (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:14:58 +0000 (02:14 -0300)]
security: add SMP locking to tmpfs (Fase 2)

8 weeks agosecurity: remove hardcoded fixed VAs, use hal_mm_kernel_virt_base() (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:13:17 +0000 (02:13 -0300)]
security: remove hardcoded fixed VAs, use hal_mm_kernel_virt_base() (Fase 2)

8 weeks agosecurity: add user_range_ok validation for futex uaddr (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:11:26 +0000 (02:11 -0300)]
security: add user_range_ok validation for futex uaddr (Fase 2)

8 weeks agosecurity: add root privilege check for SOCK_RAW sockets (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:10:48 +0000 (02:10 -0300)]
security: add root privilege check for SOCK_RAW sockets (Fase 2)

8 weeks agosecurity: add complete POSIX permissions for SHM (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:09:59 +0000 (02:09 -0300)]
security: add complete POSIX permissions for SHM (Fase 2)

8 weeks agosecurity: add UID-based access control to /proc per-PID entries (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:08:37 +0000 (02:08 -0300)]
security: add UID-based access control to /proc per-PID entries (Fase 2)

8 weeks agosecurity: add AIO validation for aio_nbytes (Fase 2)
Tulio A M Mendes [Tue, 26 May 2026 05:07:33 +0000 (02:07 -0300)]
security: add AIO validation for aio_nbytes (Fase 2)

8 weeks agosecurity: add SETREUID/SETREGID syscalls for complete UID infrastructure (Fase 4)
Tulio A M Mendes [Tue, 26 May 2026 05:06:58 +0000 (02:06 -0300)]
security: add SETREUID/SETREGID syscalls for complete UID infrastructure (Fase 4)

2 months agosecurity: fix FAT BPB validation (C7)
Tulio A M Mendes [Tue, 26 May 2026 04:58:00 +0000 (01:58 -0300)]
security: fix FAT BPB validation (C7)

2 months agosecurity: fix ext2 superblock/GDT validation (C6)
Tulio A M Mendes [Tue, 26 May 2026 04:57:27 +0000 (01:57 -0300)]
security: fix ext2 superblock/GDT validation (C6)

2 months agosecurity: tighten mprotect ownership check (C5 partial)
Tulio A M Mendes [Tue, 26 May 2026 04:56:48 +0000 (01:56 -0300)]
security: tighten mprotect ownership check (C5 partial)

2 months agosecurity: fix pmm_boot.c Multiboot2 parsing with cursor/limit validation (C4)
Tulio A M Mendes [Tue, 26 May 2026 04:56:13 +0000 (01:56 -0300)]
security: fix pmm_boot.c Multiboot2 parsing with cursor/limit validation (C4)

2 months agosecurity: fix initrd TAR parser with size limits and checksum validation (C3)
Tulio A M Mendes [Tue, 26 May 2026 04:55:18 +0000 (01:55 -0300)]
security: fix initrd TAR parser with size limits and checksum validation (C3)

2 months agosecurity: apply NX by default to all user mappings (C2)
Tulio A M Mendes [Tue, 26 May 2026 04:54:19 +0000 (01:54 -0300)]
security: apply NX by default to all user mappings (C2)

2 months agosecurity: fix ELF loader p_filesz > p_memsz validation (C1)
Tulio A M Mendes [Tue, 26 May 2026 04:52:46 +0000 (01:52 -0300)]
security: fix ELF loader p_filesz > p_memsz validation (C1)

2 months agodocs: add security fix plan for 2026-05-26 reanalysis
Tulio A M Mendes [Tue, 26 May 2026 04:47:51 +0000 (01:47 -0300)]
docs: add security fix plan for 2026-05-26 reanalysis

2 months agotests: remove unused g_test_bdev2 variable
Tulio A M Mendes [Tue, 26 May 2026 04:45:27 +0000 (01:45 -0300)]
tests: remove unused g_test_bdev2 variable

2 months agotests: add partition layer unit tests (Etapa 7)
Tulio A M Mendes [Tue, 26 May 2026 04:10:34 +0000 (01:10 -0300)]
tests: add partition layer unit tests (Etapa 7)

- Added 10 unit tests for partition layer in test_utils.c
- Tests cover: register, find, find_by_device, refcount
- Added ASSERT_NEQ macro for not-equal assertions
- Added mock partition registry for testing
- Host tests: 73/73 PASS (63 + 10 new)
- Smoke tests: 124/124 PASS

2 months agoinit: integrate partition scanning after blockdev registration (Etapa 6)
Tulio A M Mendes [Tue, 26 May 2026 04:08:52 +0000 (01:08 -0300)]
init: integrate partition scanning after blockdev registration (Etapa 6)

- Added partition_scan_mbr() call for each ATA drive present
- Scans hda, hdb, hdc, hdd for MBR partitions
- Partitions are automatically registered during scan
- Tests: 124/124 PASS

2 months agoext2: add ext2_mount_partition helper (Etapa 5)
Tulio A M Mendes [Tue, 26 May 2026 04:05:55 +0000 (01:05 -0300)]
ext2: add ext2_mount_partition helper (Etapa 5)

- Added ext2_mount_partition(partition_t*) helper function
- Extracts parent block device and start_lba from partition
- Calls ext2_mount with extracted parameters
- Maintains compatibility with existing ext2_mount signature
- Tests: 124/124 PASS

2 months agofat: add fat_mount_partition helper (Etapa 4)
Tulio A M Mendes [Tue, 26 May 2026 04:02:13 +0000 (01:02 -0300)]
fat: add fat_mount_partition helper (Etapa 4)

- Added fat_mount_partition(partition_t*) helper function
- Extracts parent block device and start_lba from partition
- Calls fat_mount with extracted parameters
- Maintains compatibility with existing fat_mount signature
- Tests: 124/124 PASS

2 months agodevfs: add placeholder for partition device registration (Etapa 3)
Tulio A M Mendes [Tue, 26 May 2026 04:00:02 +0000 (01:00 -0300)]
devfs: add placeholder for partition device registration (Etapa 3)

- Added devfs_register_partitions() placeholder function
- Added declaration in devfs.h
- Placeholder for future dynamic partition node creation
- Tests: 124/124 PASS

2 months agopartition: add MBR parser (Etapa 2)
Tulio A M Mendes [Tue, 26 May 2026 03:56:35 +0000 (00:56 -0300)]
partition: add MBR parser (Etapa 2)

- Added mbr_partition_entry_t structure for 16-byte partition entries
- Implemented partition_scan_mbr() to read and parse MBR sector
- Validates MBR signature (0xAA55) at offset 510
- Parses 4 primary partition entries starting at offset 446
- Skips empty partitions (type 0)
- Generates partition names (e.g. hda1, vda2)
- Silently skips devices without valid MBR (no errors)
- Tests: 124/124 PASS

2 months agopartition: add partition_t structure and registry (Etapa 1)
Tulio A M Mendes [Tue, 26 May 2026 03:52:42 +0000 (00:52 -0300)]
partition: add partition_t structure and registry (Etapa 1)

- Created include/partition.h with partition_t structure
- Created src/kernel/partition.c with partition registry functions
- Implemented partition_register, partition_find, partition_find_by_device
- Implemented partition_claim, partition_release for refcounting
- Added partition_init_lock for spinlock initialization
- Tests: 124/124 PASS

2 months agodocs: add TODO for VFS umount root check (Item 11)
Tulio A M Mendes [Tue, 26 May 2026 03:44:08 +0000 (00:44 -0300)]
docs: add TODO for VFS umount root check (Item 11)

Check of root directory in umount is pending due to stability issues.
Two attempts failed:
- char root[128] caused memory corruption (alignment issues)
- fs_node_t* root_fs_node caused massive instability (55/125 tests)

Check of cwd is fully implemented and validated (124/124 tests passing).
Documented future implementation options:
- Per-process mount namespaces (most robust, 5-7 days)
- Fix alignment issues (medium, 2-3 days)
- Debug fs_node_t* approach (high, 3-4 days)

Recommendation: Keep cwd check only, implement root check when
chroot/pivot_root is actually needed or when implementing containers.

2 months agovfs: implement cwd busy check via mount refcount
Tulio A M Mendes [Tue, 26 May 2026 03:08:21 +0000 (00:08 -0300)]
vfs: implement cwd busy check via mount refcount

Implemented mount refcount-based busy check for umount to prevent
filesystem unmount when processes have cwd inside the mount.

Implementation uses mount refcount approach (same as Linux/BSD):
- Added vfs_mount_ref_by_path() and vfs_mount_unref_by_path()
- Functions use longest prefix match to find most specific mount
- chdir() updates refcounts (unref old cwd, ref new cwd)
- Process creation increments refcount for initial cwd
- Process exit decrements refcount for cwd
- vfs_umount_nolock() rejects if refcount > 0

This approach is O(1) for the check, avoids storing root as path
string (which caused struct alignment issues), and matches how
commercial OSes handle mount busy detection.

Test I20 (umount cwd) validates the implementation:
- Mounts tmpfs to /tmp/mnt_cwd
- Changes cwd into mount
- Verifies umount fails with -EBUSY
- Changes cwd back to /
- Verifies umount succeeds

Test results: 124/124 PASS

2 months agovfs: add cwd check to umount to prevent filesystem in use
Tulio A M Mendes [Tue, 26 May 2026 02:42:57 +0000 (23:42 -0300)]
vfs: add cwd check to umount to prevent filesystem in use

Added busy check in vfs_umount_nolock to reject unmount if any process
has its current working directory (cwd) within the mount being unmounted.

Implementation details:
- Checks current_process->cwd first (process executing umount)
- Iterates over ready_queue_head to check all other processes
- Uses path_is_mountpoint_prefix to determine if cwd is within mount
- Returns -EBUSY if any process has cwd in the mount
- Note: root directory check not implemented (would require vfs_getpath
  or storing root as path in process struct)

Also added test I20 (umount cwd) to fulltest.c:
- Mounts tmpfs to /tmp/mnt_cwd
- Changes cwd into the mount
- Verifies umount fails with -EBUSY
- Changes cwd back to /
- Verifies umount succeeds

Updated test harnesses (smoke_test.exp, test_battery.exp) to include
the new test pattern.

Test results:
- Smoke test: 124/124 PASS
- Zero regressions

2 months agovfs: add cwd check to umount to prevent filesystem in use
Tulio A M Mendes [Tue, 26 May 2026 02:20:43 +0000 (23:20 -0300)]
vfs: add cwd check to umount to prevent filesystem in use

Added busy check in vfs_umount_nolock to reject unmount if any process
has its current working directory (cwd) within the mount being unmounted.

Implementation details:
- Iterates over ready_queue_head under sched_lock
- Uses path_is_mountpoint_prefix to check if cwd is within mount
- Returns -EBUSY if any process has cwd in the mount
- Note: root directory check not implemented (root not stored as path in process struct)

This prevents crashes when processes attempt to access files after
their cwd filesystem has been unmounted.

Test results:
- Smoke test: 123/123 PASS
- Zero regressions

2 months agotests: add automated tests for VFS/mount bug fixes
Tulio A M Mendes [Tue, 26 May 2026 02:11:09 +0000 (23:11 -0300)]
tests: add automated tests for VFS/mount bug fixes

Added 4 new automated tests in fulltest.c:
- I16: MS_REMOUNT - verify remount updates flags correctly
- I17: Mount replace rejection - verify mount without MS_REMOUNT fails
- I18: ftruncate readonly - verify ftruncate respects MS_RDONLY
- I19: Mountpoint validation - verify mount fails on non-existent or non-directory mountpoints

Updated test harnesses:
- smoke_test.exp: added 4 new test patterns (119→123 tests)
- test_battery.exp: added 4 new test patterns (27→31 tests)

Added missing errno constants (EBUSY, ENOENT, ENOTDIR) to fulltest.c

Test results:
- Smoke test: 123/123 PASS
- Zero regressions

2 months agovfs: unify virtual filesystems in registry and add /dev/vda to devfs
Tulio A M Mendes [Tue, 26 May 2026 01:54:53 +0000 (22:54 -0300)]
vfs: unify virtual filesystems in registry and add /dev/vda to devfs

- Added tmpfs_mount/tmpfs_kill_sb to tmpfs.c with proper cleanup
- Added devfs_mount/devfs_kill_sb to devfs.c (static globals, no cleanup needed)
- Added procfs_mount/procfs_kill_sb to procfs.c (static globals, no cleanup needed)
- Registered tmpfs, devfs, and procfs in filesystem type registry in init.c
- Added /dev/vda block device node to devfs for consistency with virtio-blk
- Updated headers (tmpfs.h, devfs.h, procfs.h) with VFS mount interface declarations
- Added necessary includes (fs.h, blockdev.h) to virtual filesystem implementations

Test results:
- Smoke test: 119/119 PASS
- Zero regressions

2 months agovfs: fix MS_REMOUNT, mount validation, blockdev locking, and resource leaks
Tulio A M Mendes [Tue, 26 May 2026 01:51:06 +0000 (22:51 -0300)]
vfs: fix MS_REMOUNT, mount validation, blockdev locking, and resource leaks

High-severity fixes:
- MS_REMOUNT: pass full flags to VFS, store flags & ~MS_REMOUNT in remount branch
- Reject mount replacement with -EBUSY (except with MS_REMOUNT)
- Fix init_mount_fs leak: call kill_sb on failure after fst->mount
- Add MS_RDONLY check in SYSCALL_FTRUNCATE via f->mount_root

Medium-severity fixes:
- Centralize read-only check in vfs_link with vfs_require_writable_path
- Validate mountpoint in init_mount_fs and kconsole mount (must exist and be directory)
- Add spinlock to g_blockdevs with irqsave/irqrestore protection
- Remove const from blockdev_claim/release API (block_device_t* instead of const*)

Files modified:
- src/kernel/syscall.c: MS_REMOUNT fix, ftruncate readonly check
- src/kernel/fs.c: mount replacement rejection, vfs_link readonly check, bdev const removal
- src/kernel/init.c: mountpoint validation, init_mount_fs leak fix, blockdev_init_lock call
- src/kernel/kconsole.c: mountpoint validation
- include/blockdev.h: spinlock include, const removal from API
- src/kernel/blockdev.c: spinlock implementation, const removal from functions
- include/fs.h: const removal from bdev, mount function signatures
- include/ext2.h: const removal from bdev, mount signature
- include/fat.h: const removal from bdev, mount signature
- src/kernel/ext2.c: const removal from mount signature
- src/kernel/fat.c: const removal from mount signature
- src/drivers/virtio_blk.c: const removal from ops functions
- include/kernel/init.h: const removal from init_mount_fs signature

Test results:
- Smoke test: 119/119 PASS
- cppcheck: style-level warnings only (no errors)

2 months agosecurity: re-enable temporarily disabled security checks
Tulio A M Mendes [Mon, 25 May 2026 21:44:34 +0000 (18:44 -0300)]
security: re-enable temporarily disabled security checks

- Revert proc_find_pid_safe to simple version (remove disabled UID check)
- Revert shm.c comment to original NX flag message
- Remove commented-out SOCK_RAW privilege check in socket.c

These checks were temporarily disabled in commit 63566ad to investigate
test failures but were never re-enabled. With NX support properly
implemented in commit 5d72805, all checks can now be active.

Test: 119/119 PASS (SMP=4)

2 months agovfs: remove obsolete diskfs/persistfs comment (P5.3)
Tulio A M Mendes [Mon, 25 May 2026 21:21:48 +0000 (18:21 -0300)]
vfs: remove obsolete diskfs/persistfs comment (P5.3)

2 months agovfs: remove obsolete 'drive' field from fat_mount and ext2_mount (P5.2)
Tulio A M Mendes [Mon, 25 May 2026 21:19:21 +0000 (18:19 -0300)]
vfs: remove obsolete 'drive' field from fat_mount and ext2_mount (P5.2)

2 months agovfs: add vfs_mount_unref to process_close_all_files_locked (P5.1)
Tulio A M Mendes [Mon, 25 May 2026 21:15:20 +0000 (18:15 -0300)]
vfs: add vfs_mount_unref to process_close_all_files_locked (P5.1)

2 months agovfs: add vfs_require_writable_path checks to VFS mutator functions (P4.2)
Tulio A M Mendes [Mon, 25 May 2026 21:12:34 +0000 (18:12 -0300)]
vfs: add vfs_require_writable_path checks to VFS mutator functions (P4.2)

- Add MS_RDONLY check to vfs_create, vfs_mkdir, vfs_unlink, vfs_rmdir
- Add MS_RDONLY check to vfs_rename for both old_path and new_path
- vfs_truncate already has the check from previous session

2 months agovfs: add vfs_require_writable_path check to syscall_link_impl (P4.1)
Tulio A M Mendes [Mon, 25 May 2026 21:09:37 +0000 (18:09 -0300)]
vfs: add vfs_require_writable_path check to syscall_link_impl (P4.1)

2 months agovfs: remove g_fat_root global, allocate root per mount (P3.1, P3.2, P3.3)
Tulio A M Mendes [Mon, 25 May 2026 21:05:48 +0000 (18:05 -0300)]
vfs: remove g_fat_root global, allocate root per mount (P3.1, P3.2, P3.3)

- Remove g_fat_root global from fat.c
- Allocate root node dynamically in fat_mount() and ext2_mount()
- Add root field to vfs_superblock_t for cleanup on umount
- Update fat_kill_sb and ext2_kill_sb to free root node
- Remove g_fat_root check from fat_close_impl

2 months agovfs: add kill_sb callback to vfs_fs_type_t for filesystem cleanup (P2.3)
Tulio A M Mendes [Mon, 25 May 2026 21:01:29 +0000 (18:01 -0300)]
vfs: add kill_sb callback to vfs_fs_type_t for filesystem cleanup (P2.3)

- Add kill_sb function pointer to vfs_fs_type_t
- Update vfs_umount_nolock to call fstype->kill_sb instead of direct fat_umount/ext2_umount
- Implement fat_kill_sb and ext2_kill_sb callbacks in init.c
- Callbacks call filesystem-specific umount and free superblock

2 months agovfs: change mount API to return vfs_mount_result_t {root, sb} (P2.1)
Tulio A M Mendes [Mon, 25 May 2026 20:58:12 +0000 (17:58 -0300)]
vfs: change mount API to return vfs_mount_result_t {root, sb} (P2.1)

- Add vfs_mount_result_t structure with root and superblock
- Update vfs_fs_type_t.mount() to return vfs_mount_result_t
- Update fat_mount() and ext2_mount() to build and return superblock
- Update init_mount_fs() to handle vfs_mount_result_t and set fstype in sb
- Update vfs_mount_full() to accept sb parameter
- Update all vfs_mount_full() callers to pass sb (NULL for virtual FS)

2 months agovfs: separate new mount from MS_REMOUNT - reject replacement if mount is active ...
Tulio A M Mendes [Mon, 25 May 2026 20:50:18 +0000 (17:50 -0300)]
vfs: separate new mount from MS_REMOUNT - reject replacement if mount is active (refcount>0) unless MS_REMOUNT flag is set (P1.3)

2 months agovfs: zero removed mount slot after shifting to prevent stale data in reused slots...
Tulio A M Mendes [Mon, 25 May 2026 20:47:36 +0000 (17:47 -0300)]
vfs: zero removed mount slot after shifting to prevent stale data in reused slots (P1.2)

2 months agovfs: initialize refcount=0 for new mount entries to prevent inheriting stale values...
Tulio A M Mendes [Mon, 25 May 2026 20:45:08 +0000 (17:45 -0300)]
vfs: initialize refcount=0 for new mount entries to prevent inheriting stale values from reused slots (P1.1)

2 months agodocs: add security fix TODO implementation plan
Tulio A M Mendes [Mon, 25 May 2026 20:26:46 +0000 (17:26 -0300)]
docs: add security fix TODO implementation plan

- Document implementation plan for 3 remaining security items
- K12/K13/K23: /proc UID check (requires UID infrastructure)
- K15: raw socket privilege (requires UID infrastructure)
- K24: NX flag in SHM (needs additional testing)
- Includes phases, testing strategy, timeline estimates
- Total estimated effort: 9-14 days depending on approach

2 months agosecurity: audit completion and TODO documentation
Tulio A M Mendes [Mon, 25 May 2026 20:22:46 +0000 (17:22 -0300)]
security: audit completion and TODO documentation

- Verified 23/25 items from SECURITY_FIX_PLAN_2026-05-25.md are implemented
- Documented K12/K13/K23 (/proc UID check) as TODO - requires UID infrastructure
- Documented K15 (raw socket privilege) as TODO - requires UID infrastructure
- Documented K24 (NX in SHM) as TODO - needs additional testing
- K24 NX flag temporarily disabled in shm_at for safety
- Analysis shows 92% completion of security fix plan
- Remaining items depend on multi-user authentication infrastructure

2 months agokernel: implement NX (No-Execute) support via IA32_EFER.NXE
Tulio A M Mendes [Mon, 25 May 2026 19:57:13 +0000 (16:57 -0300)]
kernel: implement NX (No-Execute) support via IA32_EFER.NXE

Fix A01 (W^X/NX) which was deferred due to IA32_EFER.NXE MSR instability.
Root cause: NX bit was being set in PTEs without NXE enabled, causing
undefined behavior and kernel panic.

Changes:
- boot.S: Check CPUID.0x80000001:EDX bit 20 for NX support before enabling
- boot.S: Enable IA32_EFER.NXE (MSR 0xC0000080, bit 11) if NX supported
- vmm.c: Add g_nxe_enabled flag and check_nxe_enabled() function
- vmm.c: Conditionalize X86_PTE_NX usage based on g_nxe_enabled
- vmm.c: Print NX status in vmm_init()
- Makefile: Add -cpu qemu32,+nx to expose NX support in QEMU
- smoke_test.exp: Add -cpu qemu32,+nx for testing

Behavior:
- With NX support: NXE enabled, VMM uses NX bit for non-executable pages
- Without NX support: NXE not enabled, VMM ignores VMM_FLAG_NX
- W^X now works correctly for ELF loading, mmap/mprotect, etc.

Test: 119/119 PASS (SMP=4)