Skip to content

Server: support Linux abstract sockets for unixsocket via the @ prefix - #15575

Open
mgravell wants to merge 1 commit into
redis:unstablefrom
mgravell:marc/uds-abstract-server
Open

Server: support Linux abstract sockets for unixsocket via the @ prefix#15575
mgravell wants to merge 1 commit into
redis:unstablefrom
mgravell:marc/uds-abstract-server

Conversation

@mgravell

@mgravell mgravell commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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:

  • 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.


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 unixsocket when the configured name starts with @ (socat/systemd convention), so listeners need no filesystem socket file or cleanup.

anetUnixAddr centralizes sockaddr construction and exact socklen_t for 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 / chmod are skipped for abstract sockets; unlink is not run before bind (unix.c) or on shutdown (server.c). redis.conf documents 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.

Comment thread src/unix.c Outdated
Comment thread src/anet.c Outdated
@mgravell
mgravell force-pushed the marc/uds-abstract-server branch from 2e33b7f to 7ebc5d0 Compare August 2, 2026 19:03
@mgravell
mgravell marked this pull request as draft August 2, 2026 19:12
@mgravell

mgravell commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Crossref: #15572

@mgravell
mgravell force-pushed the marc/uds-abstract-server branch from 7ebc5d0 to 4e66d4b Compare August 2, 2026 19:43
@mgravell
mgravell force-pushed the marc/uds-abstract-server branch from 4e66d4b to f99034f Compare August 3, 2026 06:42
@mgravell mgravell changed the title Support Linux abstract sockets for unixsocket via the @ prefix Server: support Linux abstract sockets for unixsocket via the @ prefix Aug 3, 2026
@mgravell
mgravell marked this pull request as ready for review August 3, 2026 07:15
Comment thread src/anet.c
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
mgravell force-pushed the marc/uds-abstract-server branch from f99034f to 4a46b37 Compare August 3, 2026 07:31

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4a46b37. Configure here.

Comment thread tests/unit/networking.tcl
@sundb

sundb commented Aug 5, 2026

Copy link
Copy Markdown
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.
Then we can use rebase merge for this PR.

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants