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
GenSockaddr struct based on the sockaddr family received at the dispatcher stage.
- Handle the UNIX path conversion within the syscall itself.
- Additionally, in the
copy_out function, the number of bytes to copy will be determined by comparing initaddrlen with 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
GenSockAddr data structure. Directly allocate a buffer of size 128 bytes for syscalls like accept, recvfrom, getsockname, and getpeername.
- Implement a new function: Pass pointers to avoid
NULL values being sent to syscalls.
Description:
This issue tracks the refactoring of sockaddr handling and addresses the problems encountered with
accept_syscall.Background:
Currently,
sockaddris initialized using the default UnixGenSockaddrborrowed from RustPOSIX, which has the largest memory space. This may cause issues withgetpeername, 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
sockaddrstructures, such assockaddr_infor IPv4 andsockaddr_in6for IPv6. However, tracing through the PostgreSQL source code shows that PostgreSQL uses sockaddr_storage, which is cast tosockaddrwhen necessary. The key difference betweensockaddrandsockaddr_storageis size, withsockaddr_storagebeing large enough to accommodate allsockaddrtypes.PostgreSQL's
acceptsyscall passes asockaddr->family=0withsock_len=128, making it impossible to determine the family based on size alone.Problem:
When using
accept,recvfrom,getsockname, orgetpeername, issues arise because the wrongsockaddrfamily is being inferred. The system receives aNULLsockaddr,and thecopy_outfunction from RustPOSIX doesn't perform any operations.Current Patch
I made a temporary modification to
accept_syscallto make RawPOSIX work for now:GenSockaddrstruct based on thesockaddrfamily received at the dispatcher stage.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:
GenSockAddrdata structure. Directly allocate a buffer of size 128 bytes for syscalls likeaccept,recvfrom,getsockname, andgetpeername.NULLvalues being sent to syscalls.