diff options
author | Anton Kling <anton@kling.gg> | 2023-11-23 17:01:55 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-23 17:01:55 +0100 |
commit | 6757803629574fe46e9047be8567e0c7e0522973 (patch) | |
tree | cf31247efa27997b0b43bfed559ffbb42bfb8f3e /kernel | |
parent | b8da260dd01175529feb57d5a73570f469decb08 (diff) |
Kernel/LibC: Add randomfill() syscall.
This syscall aims to fill the given buffer with cryptographically secure
random data. If the syscall returns and does not cause a page fault it
will **always** have filled the buffer with random data and never gives
back any error value.
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 4 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 1 | ||||
-rw-r--r-- | kernel/includes/syscalls.h | 2 | ||||
-rw-r--r-- | kernel/syscalls/randomfill.c | 7 |
4 files changed, 12 insertions, 2 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 0542b49..99ab586 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,7 +1,7 @@ CC="i686-sb-gcc" AS="i686-sb-as" -OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o cpu/int_syscall.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o -CFLAGS = -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL +OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o cpu/int_syscall.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o halts.o syscalls/ppoll.o syscalls/ftruncate.o kubsan.o syscalls/mmap.o drivers/serial.o syscalls/accept.o syscalls/bind.o syscalls/socket.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o syscalls/shm.o elf.o ksbrk.o sched/scheduler.o syscalls/stat.o libc/string/copy.o libc/string/strncpy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o syscalls/msleep.o syscalls/uptime.o syscalls/mkdir.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o syscalls/recvfrom.o math.o syscalls/sendto.o signal.o syscalls/kill.o syscalls/sigaction.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o syscalls/chdir.o syscalls/getcwd.o syscalls/isatty.o syscalls/randomfill.o +CFLAGS = -O3 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL INCLUDE=-I./includes/ -I../include/ -I./libc/include/ all: myos.iso diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 7001d63..2a67235 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -155,6 +155,7 @@ void (*syscall_functions[])() = { (void(*))syscall_sendto, (void(*))syscall_kill, (void(*))syscall_sigaction, (void(*))syscall_chdir, (void(*))syscall_getcwd, (void(*))syscall_isatty, + (void(*))syscall_randomfill, }; void syscall_function_handler(u32 eax, u32 arg1, u32 arg2, u32 arg3, u32 arg4, diff --git a/kernel/includes/syscalls.h b/kernel/includes/syscalls.h index 6642fea..ee7efec 100644 --- a/kernel/includes/syscalls.h +++ b/kernel/includes/syscalls.h @@ -16,6 +16,8 @@ typedef struct SYS_ACCEPT_PARAMS { int syscall_accept(SYS_ACCEPT_PARAMS *args); +void syscall_randomfill(void *buffer, u32 size); + typedef struct SYS_BIND_PARAMS { int sockfd; const struct sockaddr *addr; diff --git a/kernel/syscalls/randomfill.c b/kernel/syscalls/randomfill.c new file mode 100644 index 0000000..41f3ef0 --- /dev/null +++ b/kernel/syscalls/randomfill.c @@ -0,0 +1,7 @@ +#include <random.h> +#include <typedefs.h> + +// This syscall will never fail. At worst a page fault will occur but if +// the syscall returns the buffer will have been filled with random +// data. +void syscall_randomfill(void *buffer, u32 size) { get_random(buffer, size); } |