Repository navigation
Fix five privately reported issues: reverse tunnels, Unix socket ops, reconnect - #924
Merged
Merged
Conversation
A reverse tunnel in the InitialPayload with neither a source nor an environment variable reached STFATAL in PortForwardHandler::createSource(), so any user who could start a session could abort etserver and end every user's sessions. A failed mkdtemp() also built a std::string from NULL. Reject such a tunnel before creating the directory, and turn the mkdtemp, chmod and chown failures into runtime_errors, which the existing catch reports to the client. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Michel Lind <[email protected]>
listenAtPath() called fchmod() on the socket descriptor after listen(). On Linux that changes the socket inode, not the bound path, so the path kept umask-derived permissions and the chmod() fallback never ran. With a permissive umask, other local users could connect to a reverse tunnel's socket. chmod() the path to 0700 after bind() and before listen(), fail if that does not work, and remove the path on failure. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Michel Lind <[email protected]>
Since MisterTea#784, runAsUser() calls setgroups(1, &gid) with only the primary group, so forwarding to a socket the user can reach only through a group (docker.sock via the docker group, group-shared directories) fails with EACCES. Resolve the group list in the parent with getpwuid_r() and getgrouplist(), since NSS is not safe in a child forked from a threaded process, cap it at NGROUPS_MAX, and pass it to setgroups() in the child. If the user cannot be looked up, keep only the primary group, as before. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Michel Lind <[email protected]>
connectAtPath() did a blocking connect(). On Linux a listener whose backlog is full and which never accepts blocks it forever, hanging the session's thread in connectUnixAsUser and later etserver shutdown, which joins that thread. PipeSocketHandler::connect() used to give up after 3 s. Connect non-blocking with a 3 s deadline, retrying on EAGAIN, which is what Linux returns for a full backlog (nothing is left in progress). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Michel Lind <[email protected]>
When recover() fails, recoverClient() restored the old socket with BackedReader::revive(), which clears partialMessage. If the live socket was part way through a packet, the next read started mid-frame and the client was disconnected. With the legacy handshake, a peer that knows only the client id could trigger this. Add BackedReader::reattach(), which restores the socket and keeps the partial packet; a failed recover() never calls reader->revive(), so the reader is otherwise unchanged. Also restore the writer under its recoverMutex, as recover() does. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Michel Lind <[email protected]>
michel-slm
force-pushed
the
fix/7.1.1-hardening
branch
from
November 16, 2026 17:25
77267bf to
375143e
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #924 +/- ##
==========================================
- Coverage 77.92% 77.88% -0.05%
==========================================
Files 206 206
Lines 30447 30696 +249
Branches 19986 20153 +167
==========================================
+ Hits 23727 23908 +181
- Misses 3979 4027 +48
- Partials 2741 2761 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The Fedora job failed to build BackedIOTest.cpp under -Werror: BackedIOTest.cpp:420: array subscript 'ErrnoReadHandler[0]' is partly outside array bounds of 'unsigned char [80]' The BackedReader reattach test read the framed packet back with a virtual handler->read() on an InMemorySocketHandler. GCC speculatively devirtualized that call to ErrnoReadHandler::read, the only other read() override in the file, and then warned that its err member lies past the end of the smaller InMemorySocketHandler allocation. Read the bytes back with a non-virtual InMemorySocketHandler::drain() instead. Co-authored-by: Cursor <[email protected]>
recoverClient() detaches the writer before recover() takes its mutex. A packet written in that window, or after a failed recover() releases the mutex and before the old socket is restored, was only buffered: it took a sequence number and a nonce but was never sent. Restoring the old socket with revive() dropped it, so the client failed to decrypt the next packet and had to reconnect. Add BackedWriter::reattach(), which restores the socket and sends the packets buffered while it was detached, in order, under the recover mutex. Co-authored-by: Cursor <[email protected]>
If connect() reports EINPROGRESS, connectAtPath() polled for a fresh CONNECT_TIMEOUT_MS after already retrying EAGAIN for up to that long, so the call could take twice the intended 3 s. Poll only for what is left of the deadline. Co-authored-by: Cursor <[email protected]>
runAsUser() looked up the session user's groups (getpwuid_r and getgrouplist, which can go to LDAP or sssd) on every forwarded Unix connection, on the thread serving the session. Remember the result per uid and gid for 60 s, looking up outside the cache lock so one slow user does not stall the others. A group membership change takes effect within a minute. Co-authored-by: Cursor <[email protected]>
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.
AI assistance: an AI code review (Claude Code, claude-opus-5-5) found
these issues while I was backporting the 7.1.x security fixes to 6.2.11 for
Fedora and EPEL (#923). The fixes and tests were written with the same
assistant; I checked each issue against the code and reviewed the changes.
These are the issues I reported privately; you said a public PR is fine.
If you'd rather fix any of them your own way, feel free to close this.
One commit per issue:
nor an environment variable reached
STFATALinPortForwardHandler::createSource(), so any user who could start asession could abort etserver. It is now rejected and reported to the
client, as are
mkdtemp/chmod/chownfailures.fchmod()on the socketdescriptor does not change the bound path on Linux, so the path kept
umask-derived permissions. The path is now chmod 0700 between
bind()and
listen().primary group, so forwarding to e.g.
docker.sockvia the docker groupfails with
EACCES. The group list is now resolved in the parent(NSS is not fork-safe in a threaded process), capped at
NGROUPS_MAX.connectAtPath()blocked forever on alistener with a full backlog that never accepts. It now uses a 3 s
deadline, as
PipeSocketHandler::connect()used to.recoverClient()restored the old socket with
BackedReader::revive(), which drops apartly read packet. A new
reattach()keeps it; the writer is restoredunder its
recoverMutex.Before and after
Each new test run alone (60 s limit) on
master(730db79) with only thenew tests added, and with this series. Fedora rawhide, GCC 16, aarch64,
in mock.
connect()read()fails mid-frameThe connect-deadline test runs on Linux only: the hang doesn't happen on macOS.
Every commit builds without warnings and passes the
[UserSocketOps],[PortForwardHandler],[BackedIO]and[ClientConnection]tests on its own.Full
ctestwith the whole series: 673 of 675 pass; the other two (theControl-mode PTYHTM e2e tests) failed only because the chroot had nopgrep, failed the same way onmaster, and pass once procps-ng isinstalled.
To rerun one:
./build/et-test "PortForwardHandler rejects a tunnel with no source or name"Not changed here
child stuck elsewhere (e.g. resolving a path on a hung FUSE mount) still
blocks it.
chmod()afterbind()follows a symlink if the socket's directory iswritable by others.