1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-14 23:07:36 +00:00
serenity/Kernel/Syscalls
Ben Wiederhake 501952852c Kernel: Fix pointer over/underflow in create_thread
The expression
    (u8*)params.m_stack_location + stack_size
… causes UBSan to spit out the warning
    KUBSAN: addition of unsigned offset to 0x00000002 overflowed to 0xb0000003
… even though there is no actual overflow happening here.
This can be reproduced by running:
    $ syscall create_thread 0 [ 0 0 0 0 0xb0000001 2 ]
Technically, this is a true-positive: The C++-reference is incredibly strict
about pointer-arithmetic:
    > A pointer to non-array object is treated as a pointer to the first element
    > of an array with size 1. […] [A]ttempts to generate a pointer that isn't
    > pointing at an element of the same array or one past the end invoke
    > undefined behavior.
    https://en.cppreference.com/w/cpp/language/operator_arithmetic
Frankly, this feels silly. So let's just use FlatPtr instead.

Found by fuzz-syscalls. Undocumented bug.

Note that FlatPtr is an unsigned type, so
    user_esp.value() - 4
is defined even if we end up with a user_esp of 0 (this can happen for example
when params.m_stack_size = 0 and params.m_stack_location = 0). The result would
be a Kernelspace-pointer, which would then be immediately flagged by
'MM.validate_user_stack' as invalid, as intended.
2021-03-07 17:31:25 +01:00
..
abort.cpp Kernel: Don't disable interrupts while dealing with a process crash 2021-02-25 19:36:36 +01:00
access.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
alarm.cpp Kernel: Make TimeManagement use AK::Time internally 2021-03-02 08:36:08 +01:00
anon_create.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
beep.cpp Kernel: Make Thread use AK::Time internally 2021-03-02 08:36:08 +01:00
chdir.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
chmod.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
chown.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
chroot.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
clock.cpp Kernel: Make kgettimeofday use AK::Time 2021-03-02 08:36:08 +01:00
debug.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
disown.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
dup2.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
execve.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
exit.cpp Kernel: Don't disable interrupts while exiting a thread or process 2021-02-25 19:36:36 +01:00
fcntl.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
fork.cpp Kernel: Skip TLB flushes while cloning regions in sys$fork() 2021-03-03 22:57:45 +01:00
ftruncate.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
futex.cpp Kernel: Make Thread use AK::Time internally 2021-03-02 08:36:08 +01:00
get_dir_entries.cpp Kernel: Use Userspace<T> in sys$get_dir_entries() 2021-03-01 15:04:31 +01:00
get_stack_bounds.cpp Kernel: Use Userspace<T> in sys$get_stack_bounds() 2021-03-01 14:50:36 +01:00
getrandom.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
getuid.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
hostname.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
ioctl.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
keymap.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
kill.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
link.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
lseek.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
mkdir.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
mknod.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
mmap.cpp Kernel+Profiler: Capture metadata about all profiled processes 2021-03-02 22:38:06 +01:00
module.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
mount.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
open.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
perf_event.cpp Kernel: Better handling of allocation failure in profiling 2021-03-02 22:38:06 +01:00
pipe.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
pledge.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
prctl.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
process.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
profiling.cpp Kernel: Start work on full system profiling :^) 2021-03-02 22:38:06 +01:00
ptrace.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
purge.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
read.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
readlink.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
realpath.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
rename.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
rmdir.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
sched.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
select.cpp Kernel: Avoid transient kmalloc heap allocations in sys$select() 2021-03-03 20:37:23 +01:00
sendfd.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
setpgid.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
setuid.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
shutdown.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
sigaction.cpp Kernel: Use Userspace<T> in sys$sigaction() 2021-03-01 14:06:20 +01:00
socket.cpp Kernel: Make sockets use AK::Time 2021-03-02 08:36:08 +01:00
stat.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
sync.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
sysconf.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
thread.cpp Kernel: Fix pointer over/underflow in create_thread 2021-03-07 17:31:25 +01:00
times.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
ttyname.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
umask.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
uname.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
unlink.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
unveil.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
utime.cpp Kernel: Make kgettimeofday use AK::Time 2021-03-02 08:36:08 +01:00
waitid.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
watch_file.cpp Kernel: Make all syscall functions return KResultOr<T> 2021-03-01 13:54:32 +01:00
write.cpp Kernel: Fix build with IO_DEBUG 2021-03-01 16:07:50 +01:00