From f1bab6b74d84b972a9e817e5028b8e438bf5e83d Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 15 Aug 2024 21:29:54 +0200 Subject: kernel: disallow NUL bytes in paths --- src/kernel/syscalls.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/kernel') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index e94f886..a6c807c 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -73,6 +73,14 @@ hid_t _sys_open(const char __user *path, long len, int flags) { goto fail; } + /* I used to allow NUL in paths. Now I don't, but I want to keep the same + * API -- so let's reject paths with NUL in them. */ + for (long i = 0; i < len; i++) { + if (path_buf[i] == '\0') { + goto fail; + } + } + len = path_simplify(path_buf, path_buf, len); if (len == 0) goto fail; -- cgit v1.2.3