mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
Kernel: open() and openat() should ignore non-permission bits in mode
This commit is contained in:
parent
d310cf3b49
commit
e1d4b19461
Notes:
sideshowbarker
2024-07-19 10:15:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e1d4b19461b
@ -1652,6 +1652,9 @@ int Process::sys$open(const Syscall::SC_open_params* user_params)
|
||||
if (!validate_read(params.path, params.path_length))
|
||||
return -EFAULT;
|
||||
|
||||
// Ignore everything except permission bits.
|
||||
mode &= 04777;
|
||||
|
||||
String path = copy_string_from_user(params.path, params.path_length);
|
||||
int fd = alloc_fd();
|
||||
#ifdef DEBUG_IO
|
||||
@ -1681,6 +1684,9 @@ int Process::sys$openat(const Syscall::SC_openat_params* user_params)
|
||||
int options = params.options;
|
||||
u16 mode = params.mode;
|
||||
|
||||
// Ignore everything except permission bits.
|
||||
mode &= 04777;
|
||||
|
||||
if (params.path_length <= 0)
|
||||
return -EINVAL;
|
||||
if (!validate_read(params.path, params.path_length))
|
||||
|
@ -156,6 +156,24 @@ void test_procfs_read_past_end()
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void test_open_create_device()
|
||||
{
|
||||
int fd = open("/tmp/fakedevice", (O_RDWR | O_CREAT), (S_IFCHR | 0600));
|
||||
ASSERT(fd >= 0);
|
||||
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) < 0) {
|
||||
perror("stat");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (st.st_mode != 0100600) {
|
||||
fprintf(stderr, "Expected mode 0100600 after attempt to create a device node with open(O_CREAT), mode=%o\n", st.st_mode);
|
||||
}
|
||||
unlink("/tmp/fakedevice");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int rc;
|
||||
@ -177,6 +195,7 @@ int main(int, char**)
|
||||
test_mmap_directory();
|
||||
test_tmpfs_read_past_end();
|
||||
test_procfs_read_past_end();
|
||||
test_open_create_device();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user