diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-07-01 11:29:28 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-03 01:56:31 +0430 |
commit | b9f30c6f2a69b0c07d9a61e5dd81f439a1eafc8f (patch) | |
tree | e46fd572856b1be2280348ad03af3853fa6fc183 /Kernel/Syscalls/socket.cpp | |
parent | 45a82b2a5bd64eb73bb68f1b8a156303edbd29fe (diff) | |
download | serenity-b9f30c6f2a69b0c07d9a61e5dd81f439a1eafc8f.zip |
Everywhere: Fix some alignment issues
When creating uninitialized storage for variables, we need to make sure
that the alignment is correct. Fixes a KUBSAN failure when running
kernels compiled with Clang.
In `Syscalls/socket.cpp`, we can simply use local variables, as
`sockaddr_un` is a POD type.
Along with moving the `alignas` specifier to the correct member,
`AK::Optional`'s internal buffer has been made non-zeroed by default.
GCC emitted bogus uninitialized memory access warnings, so we now use
`__builtin_launder` to tell the compiler that we know what we are doing.
This might disable some optimizations, but judging by how GCC failed to
notice that the memory's initialization is dependent on `m_has_value`,
I'm not sure that's a bad thing.
Diffstat (limited to 'Kernel/Syscalls/socket.cpp')
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index 108e3967f1..f6f15384e5 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -119,10 +119,10 @@ KResultOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_para VERIFY(accepted_socket); if (user_address) { - u8 address_buffer[sizeof(sockaddr_un)]; + sockaddr_un address_buffer; address_size = min(sizeof(sockaddr_un), static_cast<size_t>(address_size)); - accepted_socket->get_peer_address((sockaddr*)address_buffer, &address_size); - if (!copy_to_user(user_address, address_buffer, address_size)) + accepted_socket->get_peer_address((sockaddr*)&address_buffer, &address_size); + if (!copy_to_user(user_address, &address_buffer, address_size)) return EFAULT; if (!copy_to_user(user_address_size, &address_size)) return EFAULT; @@ -311,13 +311,13 @@ int Process::get_sock_or_peer_name(const Params& params) auto& socket = *description->socket(); REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); - u8 address_buffer[sizeof(sockaddr_un)]; + sockaddr_un address_buffer; addrlen_value = min(sizeof(sockaddr_un), static_cast<size_t>(addrlen_value)); if constexpr (sockname) - socket.get_local_address((sockaddr*)address_buffer, &addrlen_value); + socket.get_local_address((sockaddr*)&address_buffer, &addrlen_value); else - socket.get_peer_address((sockaddr*)address_buffer, &addrlen_value); - if (!copy_to_user(params.addr, address_buffer, addrlen_value)) + socket.get_peer_address((sockaddr*)&address_buffer, &addrlen_value); + if (!copy_to_user(params.addr, &address_buffer, addrlen_value)) return EFAULT; if (!copy_to_user(params.addrlen, &addrlen_value)) return EFAULT; |