-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Description:
This issue tracks the refactoring of sockaddr handling and addresses the problems encountered with accept_syscall.
Background:
Currently, sockaddr is initialized using the default Unix GenSockaddr borrowed from RustPOSIX, which has the largest memory space. This may cause issues with getpeername, as IPv4/IPv6 shouldn't have a path field.
It's been observed that byte-level operations should be preferred over struct-type checks.
In Linux, there are various sockaddr structures, such as sockaddr_in for IPv4 and sockaddr_in6 for IPv6. However, tracing through the PostgreSQL source code shows that PostgreSQL uses sockaddr_storage, which is cast to sockaddr when necessary. The key difference between sockaddr and sockaddr_storage is size, with sockaddr_storage being large enough to accommodate all sockaddr types.
PostgreSQL's accept syscall passes a sockaddr->family=0 with sock_len=128, making it impossible to determine the family based on size alone.
Problem:
When using accept, recvfrom, getsockname, or getpeername, issues arise because the wrong sockaddr family is being inferred. The system receives a NULL sockaddr, and the copy_out function from RustPOSIX doesn't perform any operations.
Current Patch
I made a temporary modification to accept_syscall to make RawPOSIX work for now:
- Initialize a default
GenSockaddrstruct based on thesockaddrfamily received at the dispatcher stage. - Handle the UNIX path conversion within the syscall itself.
- Additionally, in the
copy_outfunction, the number of bytes to copy will be determined by comparinginitaddrlenwith the actual length of the structure (taking the minimum value), ensuring that no more than the reserved space is copied.
Proposed Further Solution:
To resolve this, I suggest:
- Refining the
GenSockAddrdata structure. Directly allocate a buffer of size 128 bytes for syscalls likeaccept,recvfrom,getsockname, andgetpeername. - Implement a new function: Pass pointers to avoid
NULLvalues being sent to syscalls.