Server: support Linux abstract sockets for unixsocket via the @ prefix - #15575
Open
mgravell wants to merge 1 commit into
Open
Server: support Linux abstract sockets for unixsocket via the @ prefix#15575mgravell wants to merge 1 commit into
mgravell wants to merge 1 commit into
Conversation
mgravell
force-pushed
the
marc/uds-abstract-server
branch
from
August 2, 2026 19:03
2e33b7f to
7ebc5d0
Compare
mgravell
marked this pull request as draft
August 2, 2026 19:12
Contributor
Author
|
Crossref: #15572 |
mgravell
force-pushed
the
marc/uds-abstract-server
branch
from
August 2, 2026 19:43
7ebc5d0 to
4e66d4b
Compare
mgravell
force-pushed
the
marc/uds-abstract-server
branch
from
August 3, 2026 06:42
4e66d4b to
f99034f
Compare
mgravell
marked this pull request as ready for review
August 3, 2026 07:15
The server's Unix-socket bind (anetUnixServer) copies the path with redis_strlcpy and binds with sizeof(sockaddr_un), so the abstract namespace -- whose addresses begin with a NUL byte -- has never been reachable. This maps a leading '@' to the abstract namespace, following the convention established by socat and systemd, on Linux only. One shared helper (anetUnixAddr) builds the address for both anetUnixServer and anetUnixGenericConnect, so the "is this socket already in use" probe in connUnixListen keeps working for abstract names too. The subtle half is the address length: for pathname sockets trailing padding is ignored, but for abstract sockets every byte up to the given length is part of the name, so the address must be bound and dialed with EXACTLY offsetof(sun_path) + 1 + strlen(name). Lifecycle differences handled where they arise rather than special-cased later: - no chmod: abstract sockets have no filesystem presence, so unixsocketperm cannot apply (anetListen skips it when sun_path[0] is NUL); - no unlink, before bind (connUnixListen) or at shutdown (server.c): there is no file, and the name vanishes with the listener. redis.conf documents the form. Client-side support for the same convention (redis-cli/redis-benchmark via hiredis) is the sibling branch marc/uds-abstract-sockets; the two compose but do not depend on each other.
mgravell
force-pushed
the
marc/uds-abstract-server
branch
from
August 3, 2026 07:31
f99034f to
4a46b37
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 4a46b37. Configure here.
Collaborator
|
@mgravell, what about handling https://github.com/redis/redis/pull/15572/changes together in this PR? otherwise the daily will fail after this PR is merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Support Linux abstract sockets for unixsocket via the @ prefix
This is the server half of #15577
Note tests are dependent on the client half, #15572
The server's Unix-socket bind (anetUnixServer) copies the path with redis_strlcpy and binds with sizeof(sockaddr_un), so the abstract namespace -- whose addresses begin with a NUL byte -- has never been reachable. This maps a leading '@' to the abstract namespace, following the convention established by socat and systemd, on Linux only.
One shared helper (anetUnixAddr) builds the address for both anetUnixServer and anetUnixGenericConnect, so the "is this socket already in use" probe in connUnixListen keeps working for abstract names too. The subtle half is the address length: for pathname sockets trailing padding is ignored, but for abstract sockets every byte up to the given length is part of the name, so the address must be bound and dialed with EXACTLY offsetof(sun_path) + 1 + strlen(name).
Lifecycle differences handled where they arise rather than special-cased later:
redis.conf documents the form. Client-side support for the same convention (redis-cli/redis-benchmark via hiredis) is the sibling branch marc/uds-abstract-sockets; the two compose but do not depend on each other.
Note
Medium Risk
Changes low-level Unix socket bind/connect behavior and listen/shutdown lifecycle; abstract sockets weaken filesystem-based access control compared to pathname sockets with
unixsocketperm.Overview
Adds Linux abstract Unix domain sockets for
unixsocketwhen the configured name starts with@(socat/systemd convention), so listeners need no filesystem socket file or cleanup.anetUnixAddrcentralizes sockaddr construction and exactsocklen_tfor bind/connect (critical for abstract names, where padding would change the socket identity). Connect/bind now enforce name length limits that pathname sockets previously lacked on the connect path.Lifecycle:
unixsocketperm/chmodare skipped for abstract sockets;unlinkis not run before bind (unix.c) or on shutdown (server.c).redis.confdocuments behavior and security (no file permissions—rely on ACLs/network namespace). Linux integration tests cover PING, no filesystem entry, and collision detection.Reviewed by Cursor Bugbot for commit 4a46b37. Bugbot is set up for automated code reviews on this repo. Configure here.