Skip to content

[io_uring] Fix Unix domain socket support for abstract namespace sockets#15876

Merged
normanmaurer merged 2 commits into
netty:4.2from
j-bahr:domain-socket-fix
Nov 19, 2025
Merged

[io_uring] Fix Unix domain socket support for abstract namespace sockets#15876
normanmaurer merged 2 commits into
netty:4.2from
j-bahr:domain-socket-fix

Conversation

@j-bahr
Copy link
Copy Markdown
Contributor

@j-bahr j-bahr commented Nov 18, 2025

Motivation:

The current implementation of SockaddrIn.setUds() only supports file path based Unix domain sockets. It incorrectly adds a null terminator for all sockets and always passes SIZEOF_SOCKADDR_UN as the address length to io_uring operations. This breaks abstract namespace sockets, which are distinguished by having a null byte as the first character and must not have an additional null terminator appended and included in the address_len. According to unix(7), abstract sockets require a precise address length of offsetof(sun_path) + actual_name_length, while pathname sockets require offsetof(sun_path) + strlen(path) + 1.

Modifications:

Modified SockaddrIn.setUds() to:

  • Detect abstract namespace sockets by checking if the path starts with '\0'
  • Only append null terminator for pathname sockets, not abstract sockets
  • Calculate and return the correct address length based on socket type

Modified AbstractIoUringChannel.submitConnect(DomainSocketAddress) to:

  • Capture the address length returned by setUds()
  • Pass the actual address length to IoUringIoOps.newConnect() instead of the hardcoded SIZEOF_SOCKADDR_UN

Result:

Both pathname-based and abstract namespace Unix domain sockets are now properly supported. Abstract sockets will correctly connect without spurious null bytes, and the kernel will receive the precise address length required for each socket type.

…kets

 Motivation:

  The current implementation of `SockaddrIn.setUds()` only supports
  file path-based Unix domain sockets. It incorrectly adds a null
  terminator for all sockets and always passes `SIZEOF_SOCKADDR_UN`
  as the address length to io_uring operations. This breaks abstract
  namespace sockets, which are distinguished by having a null byte as                                                                                                                   ⧉ 1 line selected
  the first character and must not have an additional null terminator
  appended. According to unix(7), abstract sockets require a precise
  address length of `offsetof(sun_path) + actual_name_length`, while
  pathname sockets require `offsetof(sun_path) + strlen(path) + 1`.

  Modifications:

  Modified `SockaddrIn.setUds()` to:
  - Detect abstract namespace sockets by checking if the path starts
    with '\0'
  - Only append null terminator for pathname sockets, not abstract
    sockets
  - Calculate and return the correct address length based on socket type
  - Added comprehensive documentation explaining both socket types

  Modified `AbstractIoUringChannel.submitConnect(DomainSocketAddress)` to:
  - Capture the address length returned by `setUds()`
  - Pass the actual address length to `IoUringIoOps.newConnect()`
    instead of the hardcoded `SIZEOF_SOCKADDR_UN`

  Result:

  Both pathname-based and abstract namespace Unix domain sockets are
  now properly supported. Abstract sockets will correctly connect without
  spurious null bytes, and the kernel will receive the precise address
  length required for each socket type.
@normanmaurer
Copy link
Copy Markdown
Member

@j-bahr nice! Let me check in detail ... do we also need a fix for epoll ?

@normanmaurer normanmaurer added this to the 4.2.8.Final milestone Nov 18, 2025
@j-bahr
Copy link
Copy Markdown
Contributor Author

j-bahr commented Nov 18, 2025

@j-bahr nice! Let me check in detail ... do we also need a fix for epoll ?

Our epoll implementation on top of abstract namespace sockets appears to work fine. We only see issues after changing to io_uring. I did a quick inspection and found that epoll appears to do the same calculation we're doing for io_uring.

#define _UNIX_ADDR_LENGTH(path_len) ((uintptr_t) offsetof(struct sockaddr_un, sun_path) + (uintptr_t) path_len)

@j-bahr j-bahr requested a review from normanmaurer November 18, 2025 16:16
Copy link
Copy Markdown
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one nit...

@normanmaurer normanmaurer merged commit a3f581e into netty:4.2 Nov 19, 2025
18 of 19 checks passed
@normanmaurer
Copy link
Copy Markdown
Member

@j-bahr thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants