1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 13:25:10 +00:00
serenity/Libraries/LibC
Tom c8d9f1b9c9 Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps
for us, we don't really need to attempt to do this. Doing it
ourselves doesn't really work very reliably, because we'd have to
account for other processors modifying virtual memory, and we'd
have to account for e.g. pages not being able to be allocated
due to insufficient resources.

So change the copy_to/from_user (and associated helper functions)
to use the new safe_memcpy, which will return whether it succeeded
or not. The only manual validation step needed (which the CPU
can't perform for us) is making sure the pointers provided by user
mode aren't pointing to kernel mappings.

To make it easier to read/write from/to either kernel or user mode
data add the UserOrKernelBuffer helper class, which will internally
either use copy_from/to_user or directly memcpy, or pass the data
through directly using a temporary buffer on the stack.

Last but not least we need to keep syscall params trivial as we
need to copy them from/to user mode using copy_from/to_user.
2020-09-13 21:19:15 +02:00
..
arpa LibC: Add inet_aton, based on inet_pton 2020-05-11 09:50:42 +02:00
bits Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
net Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
netinet LibC: Add sa_family_t and in_port_t types 2020-08-11 21:13:18 +02:00
sys LibC: Add settimeofday 2020-09-06 21:50:55 +02:00
alloca.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
assert.cpp LibC: Remove endless loop after abort() call 2020-05-26 14:35:10 +02:00
assert.h LibC: Make sure assert() expands to *something* in non-DEBUG builds 2020-08-11 20:29:14 +02:00
byteswap.h Meta: Add missing copyright headers 2020-04-06 11:09:01 +02:00
CMakeLists.txt Build: Add some -Wno-unknown-warning-option flags to CXXFLAGS 2020-09-01 12:00:53 +02:00
crt0.cpp LibC: Avoid ninja-imports of system functions 2020-08-12 20:40:59 +02:00
crti.S Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
crtn.S Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
ctype.cpp Revert "LibC: Implement isblank()" 2020-02-16 10:47:54 +01:00
ctype.h LibC: Don't let ctype isfoo() helpers access array out of bounds 2020-05-17 22:35:25 +02:00
cxxabi.cpp LibC: Move C++ABI functions to cxxabi.cpp, typecheck cxa_atexit 2020-08-12 20:40:59 +02:00
dirent.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
dirent.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
dlfcn.cpp AK: Rename FileSystemPath -> LexicalPath 2020-05-26 14:35:10 +02:00
dlfcn.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
endian.h LibC: Fix big endian definitions 2020-02-19 16:08:28 +01:00
errno.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
errno_numbers.h Kernel+LibC: Remove ESUCCESS 2020-04-10 13:09:35 +02:00
fcntl.cpp LibC: Missing varargs cleanup in fcntl 2020-08-17 09:17:57 +02:00
fcntl.h Kernel+LibC: Switch isatty() to use a fcntl() 2020-05-20 08:31:31 +02:00
fd_set.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
float.h Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
getopt.cpp LibC: Don't include things required for getopt_long in unistd.h 2020-09-06 21:36:36 +02:00
getopt.h LibC: Don't include things required for getopt_long in unistd.h 2020-09-06 21:36:36 +02:00
grp.cpp LibC: Use AK::String-backed buffers instead of static buffers 2020-08-30 17:35:27 +02:00
grp.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
iconv.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
inttypes.h LibC: Add some missing macros to inttypes.h 2020-02-20 06:51:16 +01:00
ioctl.cpp LibC: Missing varargs cleanup in ioctl 2020-08-17 09:17:57 +02:00
libcinit.cpp LibC: Move C++ABI functions to cxxabi.cpp, typecheck cxa_atexit 2020-08-12 20:40:59 +02:00
libgen.cpp Meta: Claim copyright for files created by me 2020-01-24 15:15:16 +01:00
libgen.h Meta: Claim copyright for files created by me 2020-01-24 15:15:16 +01:00
limits.h LibC: Use more flexible digit parsing code, deduplicate 2020-05-11 10:52:24 +02:00
locale.cpp Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
locale.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
malloc.cpp malloc: Keep some stats and dump them at process exit if LIBC_DUMP_MALLOC_STATS is set 2020-08-17 09:43:23 +02:00
mallocdefs.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
memory.h Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
mman.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
mman.h Kernel+LibC: Add minherit() and MAP_INHERIT_ZERO 2020-04-12 20:22:26 +02:00
mntent.cpp Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
mntent.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
netdb.cpp LibC: Avoid generating calls to__cxa_guard_* functions in netdb.cpp 2020-09-06 21:36:36 +02:00
netdb.h LibC: getprotoent() family of functions 2020-04-18 10:11:55 +02:00
poll.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
poll.h LibC+Kernel: Implement ppoll 2020-06-23 14:12:20 +02:00
pwd.cpp LibC: Use AK::String-backed buffers instead of static buffers 2020-08-30 17:35:27 +02:00
pwd.h LibC: Implement putpwent() 2020-02-02 10:58:45 +01:00
qsort.cpp LibC: Remove unused data member in the qsort() implementation 2020-08-24 18:22:09 +02:00
scanf.cpp LibC: Replace some strncpy() calls with memcpy() 2020-08-30 17:35:27 +02:00
sched.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
sched.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
serenity.cpp Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
serenity.h Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
setjmp.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
setjmp.S Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
signal.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
signal.h LibC: Declare pthread_sigmask() in signal.h. 2020-06-16 09:34:00 +02:00
signal_numbers.h Kernel+LibC+UE: Introduce SIGINFO (generated with ^T) 2020-09-09 21:10:23 +02:00
spawn.cpp LibC: In posix_spawn(), use _exit instead of exit on child error 2020-06-20 14:43:27 +02:00
spawn.h Add manpages for posix_spawn 2020-07-06 10:01:14 +02:00
stat.cpp LibC: Move stat(), lstat() and fstat() to <sys/stat.h> 2020-08-11 20:29:14 +02:00
stdarg.h Kernel: Absorb LibBareMetal back into the kernel 2020-05-16 12:00:04 +02:00
stdbool.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
stddef.h LibC: Move ssize_t from <stddef.h> to <sys/types.h> 2020-05-23 17:03:41 +02:00
stdint.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
stdio.cpp LibC: Partially implement 'freopen' 2020-08-31 09:14:11 +02:00
stdio.h Kernel+LibC: Fix various build issues introduced by ssize_t 2020-05-23 15:27:33 +02:00
stdlib.cpp Meta: Force semi-colon after MAKE_AK_NONXXXABLE() 2020-08-27 10:12:04 +02:00
stdlib.h malloc: Keep some stats and dump them at process exit if LIBC_DUMP_MALLOC_STATS is set 2020-08-17 09:43:23 +02:00
string.cpp LibC: Implement strlcpy 2020-08-24 00:45:03 +02:00
string.h LibC: Don't advertise wrong functions 2020-09-12 13:46:15 +02:00
strings.cpp Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
strings.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
syslog.cpp AK: Add a forward declaration header 2020-02-14 23:31:18 +01:00
syslog.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
termcap.cpp LibC: Deprecate strcpy(), strncpy(), strcat() and strncat() :^) 2020-08-30 17:35:27 +02:00
termcap.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
termios.cpp LibC: Implement tcflush(3) 2020-07-11 11:33:33 +02:00
termios.h LibC: Implement cf{g,s}et{i,o}speed 2020-07-04 10:49:36 +02:00
time.cpp LibC: Add settimeofday 2020-09-06 21:50:55 +02:00
time.h LibC: Add timegm() 2020-08-21 12:11:48 +02:00
times.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
ulimit.cpp LibC: Log calls to getrusage 2020-05-07 23:32:11 +02:00
ulimit.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
unistd.cpp Kernel: Make copy_to/from_user safe and remove unnecessary checks 2020-09-13 21:19:15 +02:00
unistd.h LibC: Don't include things required for getopt_long in unistd.h 2020-09-06 21:36:36 +02:00
utime.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
utime.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
utmp.h LibC: Add missing <sys/time.h> include in <utmp.h> 2020-05-11 09:50:42 +02:00
utsname.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
wchar.cpp Meta: Add license header to source files 2020-01-18 09:45:54 +01:00
wchar.h Meta: Add license header to source files 2020-01-18 09:45:54 +01:00