From a65c385057a2cf6f73a836af5177056c72c57bce Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 17 Apr 2024 18:09:21 -0600 Subject: [PATCH] Kernel: Don't try to copy empty Vector in sys$recvmsg If there's no fds to copy in a message with proper space for an SCM_RIGHTS set of cmsg headers, then don't try to copy them. This avoids a Kernel panic when recvmsg-ing, as copy_to_user(p, 0, 0) hits a VERIFY. --- Kernel/Syscalls/socket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index 389f212cfba..d363de419ce 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -322,7 +322,8 @@ ErrorOr Process::sys$recvmsg(int sockfd, Userspace user m_fds.with_exclusive([&](auto& fds) { fds[fd_allocation.fd].set(*description, 0); }); fdnums.append(fd_allocation.fd); } - TRY(try_add_cmsg(SOL_SOCKET, SCM_RIGHTS, fdnums.data(), fdnums.size() * sizeof(int))); + if (!fdnums.is_empty()) + TRY(try_add_cmsg(SOL_SOCKET, SCM_RIGHTS, fdnums.data(), fdnums.size() * sizeof(int))); } TRY(copy_to_user(&user_msg.unsafe_userspace_ptr()->msg_controllen, ¤t_cmsg_len));