Commit Graph

1311 Commits

Author SHA1 Message Date
Matheus 26cd12e7c6 kernel: add missing sym table generation steps
Adds missing symbol table generation steps that were not commited
alongside previous work. Also bumps astral.
2026-10-09 02:21:18 -03:00
Matheus 5360edb9c7 pipe2: properly clean up vnode references on error
Currently, pipe2 both closes the fds and releases references to the pipe
vnode on failure. However, closing the fds already causes the vnode
references to be dropped.

Make pipe2 only release the vnode references when the respective file_t
were not closed.

Found by syzkaller fuzzing.
2026-10-09 02:11:50 -03:00
Matheus 47ce33935f mknodat: refuse to create symlinks
The current mknodat code creates symlinks when requested. Not only does
this break POSIX, it also causes a kernel crash (NULL-deref on
tmpfs_readlink).

Refuse to create symlinks with mknodat.

Found by syzkaller fuzzing.
2026-10-09 02:10:12 -03:00
Matheus ac6addd527 dbg: map addresses to file+function+offset
Add support for mapping kernel .text addresses into file + function +
offset for debugging purposes. Make the backtrace use this new feature.
2026-10-09 01:46:15 -03:00
Matheus b52882f3f7 syscalls: fix vnode cleanup in some *at syscalls
Some *at functions have a cleanup goto which could use an uninitialized
vnode. Fix this by defining the vnodes earlier.

Found by syzkaller fuzzing.
2026-10-09 01:41:48 -03:00
Matheus c6c74396d6 syscall: be explicit about abs in #gpf jump
The jump to the #GPF handler has an implicit abs reference, which gives a
NASM warning. Be explicit about it being absolute.
2026-10-08 23:43:33 -03:00
Matheus 7ac6681ea8 kernel: generate symbol tables
In preparation for printing file+function names in backtraces, add
support for generating and linking three tables into the kernel:

- dbg_sym_table: a table consisting of <uint32_t addr_offset, uint32_t
  function_name_offset, uint32_t file_name_offset>, being ordered by
  offset.
- dbg_fn_name_table: a table consisting of packed NULL terminated
  strings, which the dbg_sym_table points into.
- dbg_file_name_table: a table consisting of packed NULL terminated
  strings, which the dbg_sym_table points into.
2026-10-08 23:36:37 -03:00
Matheus 91ec85d8ca panic: print backtrace on panic
Panics currently lack backtraces, which are a very useful thing to
have. Make the profiling backtrace function generic and print backtraces
using it.
2026-10-08 22:14:46 -03:00
Matheus 9b8c81a2cf tcp: signal POLLOUT when transmitting
Current tcp senders can wait forever for buffer space as POLLOUT is not
signaled when transmitting data. Signal POLLOUT when transmitting out of
a full tx buffer.
2026-10-08 18:42:26 -03:00
Matheus 9a9740469f kcov: move thread attach from open to start
The current kcov code attaches a kcov object to the thread which opened
it. This is not desirable, as syzkaller opens /dev/kcov in a parent
process and passes it down to the child.

Move the thread attachment from open() time to start time.
2026-10-08 18:42:25 -03:00
Matheus d999ab7de2 mm: fix NULL deref on vnode inactive
An oversight on vnode inactivation when the last reference was a dirty
page causes a NULL-deref due to VOP_RELEASE set-NULL behavior.

Use a temporary variable in this case as the backing can still be
accesed by a truncation on vnode inactive.
2026-10-08 18:42:26 -03:00
Matheus e25008b80b Merge pull request #36 from jvbronzeado/rewrite
Optimize page fault handling by caching last accessed range
2026-10-08 15:39:12 -03:00
jvbronzeado 185b33e719 mm: added page fault range caching for each mm_space_t
mm: added last_pagefault handling when mm_space_t is unmapped

mm: fixed styling inconsistencies, fixed last pagefault range removal

mm: fix unitialized last_pagefault member in slab data
2026-10-08 15:28:56 -03:00
Matheus de3633f5e1 Merge pull request #48 from wnsntgs/Kernel/Lib/ListOptimizations
Optimize kernel lists a bit
2026-10-07 18:10:27 -03:00
wnstngs bb555d0620 dpc: make dpc queues FIFO 2026-10-07 23:00:21 +03:00
wnstngs 8b9fcf54bb kernel: use LIST_DEFINE and list_drain 2026-10-07 23:00:01 +03:00
wnstngs 5180e693d9 list: add list definition and drain operation 2026-10-07 21:33:49 +03:00
wnstngs 91491d825b kernel: remove the list_t alias since it's just a typedef for node 2026-10-07 14:08:36 +03:00
wnstngs 9cffe521f3 kernel: use circular lists in various places 2026-10-07 10:32:08 +03:00
wnstngs 513faa92c7 kernel: use list.h for scheduling run queues 2026-10-07 10:24:50 +03:00
wnstngs 3894be1a15 kernel: use list.h for DPC queues 2026-10-07 10:23:18 +03:00
wnstngs 90cbe1d6aa list: switch lists to circular lists 2026-10-07 10:21:50 +03:00
wnstngs 9972aa9eea kernel: opportunistic spin on contended push locks 2026-10-06 19:51:19 +03:00
Matheus 416e305a19 Merge pull request #46 from wnsntgs/Kernel/Lib/PushLockBackoff
Back off shared push lock retries
2026-10-06 11:57:20 -03:00
Matheus e4a4896b4b kcov: initial implementation
Implement a device (/dev/kcov) that exposes coverage info for the
kernel. This will be especially useful for coverage-based fuzzing (e.g.
syzkaller).

Exclude a lot of functions which would crash/otherwise interfere in the
coverage, including only processing coverage callbacks when not handling
an irq.
2026-10-06 11:51:02 -03:00
Matheus 111a8696d8 mmu: move tlb shootdown to IPL_MAX
Currently, with IPL_IGNORE, tlb shootdown is not being treated as an
irq and thus does not contribute to the irq depth. Move it to the
highest possible IPL.
2026-10-06 11:51:02 -03:00
Matheus 011309d43d cpu: add irq depth counting
Add a way of checking if a cpu is in the middle of handling an irq and
how deep it is into it. This will allow for future code to conditionally
run only in/outside interrupts.
2026-10-06 11:51:01 -03:00
Matheus 6c65a90a5f mm: properly fork shared file mappings
mm_fork_context() currently maps shared chdev mappings 1:1 when forking
a range. The issue with this approach is that chdev mappings are not
guaranteed to be backed by physical memory, and thus cannot safely be
refcounted. This can lead to issues on devices with more complex buffer
lifetimes.

To allow for internal book-keeping, do not map shared chdev memory on
fork and instead allow it to go through the entire fault-in process
again.
2026-10-06 11:51:01 -03:00
Matheus 0cdd03eba8 smp: fix race between cpu exposure and smp init
The SMP code exposes that a cpu woke up before it is properly
initialized in sched_ap_entry(). Fix this by initializing it first,
exposing it and then stopping the bootstrap thread.
2026-10-06 11:51:01 -03:00
Matheus 1ed159489d scheduler: only run load balance when appropriate
Prevent the load balancer from balancing when running uniprocessor
machines and when not all CPUs are online yet.

This prevents a race between ap initialization and load balancing.
2026-10-06 11:51:00 -03:00
Matheus d214326e8e print: add nouserprint argument
For some usecases, silencing syscall_print()s is ideal. A good example
of that is syzkaller, which uses logs to detect crashes and a badly
timed syscall_print() could interfere.

Add a nouserprint argument which skips printing on syscall_print().
2026-10-06 11:51:00 -03:00
Matheus 77520c00c5 pty: use new anonymous devfs operations
Switch the old hacky way of registering a new pty master into using the
new anonymous api.
2026-10-06 11:51:00 -03:00
Matheus 1c65a2c891 devfs: add anonymous variants to register/remove
The current devfs code requires registered devices to have a name on
creation. This makes temporary/hidden devices like pty master ends
appear for a split second on the devfs tree.

Add a way of registering/removing devfs nodes which do not have a name
on the tree.
2026-10-06 11:50:59 -03:00
Matheus d1765b22b5 tty: fix lifetime issue in tty_unregister()
The tty_unregister code removes the tty's vnode from the devfs mappings.
This causes a reference to be dropped, which can then cause the tty to
be freed and the remaining code in tty_unregister does a UAF.

Fix this by holding a reference across the unregister operation.
2026-10-06 11:50:59 -03:00
Matheus cc069554ae vfs: fix UAF on VOP_RELEASE 2026-10-06 11:50:59 -03:00
Matheus e8da0eba6a statvfs: handle vnodes without a vfs 2026-10-06 11:50:58 -03:00
Matheus eda6bca466 tmpfs: remove bad print 2026-10-06 11:50:58 -03:00
Matheus efe699bd2f x86_64 cpu: always inline asm helpers 2026-10-06 11:50:57 -03:00
Matheus 9e028dc059 tcp: copy port to listening tcb chilren 2026-10-06 11:50:57 -03:00
Matheus bf7a4a9d72 vionet: fix transmit publication ordering 2026-10-06 11:50:56 -03:00
Matheus 2867889202 vfs: fix possible use-after-free 2026-10-06 11:50:56 -03:00
Matheus 4500f1f3ec kernel: add nofblog option 2026-10-06 11:50:56 -03:00
wnstngs 5d1a35fdc6 kernel: back off shared push lock cmpcxhg retries 2026-10-06 15:05:34 +03:00
Matheus f7052a78c1 Merge pull request #41 from wnsntgs/Kernel/Lib/PushLockOptimizations
Avoid repeated push lock waiter queue walks
2026-09-28 16:39:43 -03:00
wnstngs 2db436c700 kernel: guard pushlock assertions with DEBUG_LOCKS 2026-09-28 22:35:13 +03:00
wnstngs 4eab391004 kernel: avoid repeated push lock waiter queue walks 2026-09-24 23:17:53 +03:00
Matheus ad1740738b Merge pull request #42 from wnsntgs/Kernel/Lib/SemaphoreWakeupFix
Fix semaphore wakeup race
2026-09-23 15:11:05 -03:00
Matheus 68af759f20 Merge pull request #43 from wnsntgs/Kernel/Sched/NanosleepTimerFix
Fix timer cleanup in interrupted nanosleep
2026-09-23 15:09:28 -03:00
Matheus 6ac80173b4 Merge pull request #44 from wnsntgs/Kernel/Lib/EventDetachFix
Detach all event listener attachments
2026-09-23 15:07:41 -03:00
wnstngs 3a952c96b1 kernel: fix semaphore wakeup race 2026-09-23 20:48:29 +03:00