Skip to content

Fix five privately reported issues: reverse tunnels, Unix socket ops, reconnect - #924

Merged
MisterTea merged 9 commits into
MisterTea:masterfrom
michel-slm:fix/7.1.1-hardening
Nov 17, 2026
Merged

MisterTea merged 9 commits into
MisterTea:masterfrom
michel-slm:fix/7.1.1-hardening

Conversation

@michel-slm

@michel-slm michel-slm commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Abort on a malformed reverse tunnel. A tunnel with neither a source
    nor an environment variable reached STFATAL in
    PortForwardHandler::createSource(), so any user who could start a
    session could abort etserver. It is now rejected and reported to the
    client, as are mkdtemp/chmod/chown failures.
  2. Reverse-tunnel socket permissions. fchmod() on the socket
    descriptor 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().
  3. Supplementary groups. Since Fix four pre-auth and privilege-escalation issues from security notices. #784 the privilege drop keeps only the
    primary group, so forwarding to e.g. docker.sock via the docker group
    fails with EACCES. The group list is now resolved in the parent
    (NSS is not fork-safe in a threaded process), capped at NGROUPS_MAX.
  4. Blocking Unix connect. connectAtPath() blocked forever on a
    listener with a full backlog that never accepts. It now uses a 3 s
    deadline, as PipeSocketHandler::connect() used to.
  5. Failed reconnect desynchronises the session. recoverClient()
    restored the old socket with BackedReader::revive(), which drops a
    partly read packet. A new reattach() keeps it; the writer is restored
    under its recoverMutex.

Before and after

Each new test run alone (60 s limit) on master (730db79) with only the
new tests added, and with this series. Fedora rawhide, GCC 16, aarch64,
in mock.

Issue Test master this PR
1 PortForwardHandler rejects a tunnel with no source or name SIGABRT pass
2 UserSocketOps listenAtPath restricts the socket to its owner mode is not 0700 pass
3 UserSocketOps supplementaryGroups includes the primary group (new helper, needs the fix) pass
4 UserSocketOps connectAtPath gives up on a listener that never accepts killed at 60 s, still in connect() pass
5 ServerClientConnection recoverClient failure keeps a partly read packet read() fails mid-frame pass
5 BackedReader reattach keeps a partly read packet (new method, needs the fix) pass

The 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 ctest with the whole series: 673 of 675 pass; the other two (the
Control-mode PTY HTM e2e tests) failed only because the chroot had no
pgrep, failed the same way on master, and pass once procps-ng is
installed.

To rerun one: ./build/et-test "PortForwardHandler rejects a tunnel with no source or name"

Not changed here

  • The parent's wait for the child's result has no timeout of its own, so a
    child stuck elsewhere (e.g. resolving a path on a hung FUSE mount) still
    blocks it.
  • chmod() after bind() follows a symlink if the socket's directory is
    writable by others.

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]>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.28517% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.88%. Comparing base (730db79) to head (7868f5f).

Files with missing lines Patch % Lines
src/base/UserSocketOpsUnix.cpp 40.69% 37 Missing and 14 partials ⚠️
src/terminal/forwarding/PortForwardHandler.cpp 46.15% 5 Missing and 2 partials ⚠️
test/unit_tests/UserSocketOpsTest.cpp 94.64% 1 Missing and 2 partials ⚠️
src/base/BackedWriter.cpp 86.66% 1 Missing and 1 partial ⚠️
src/base/BackedReader.hpp 66.66% 0 Missing and 1 partial ⚠️
test/unit_tests/ClientConnectionTest.cpp 97.22% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jasongauci-webai and others added 4 commits November 16, 2026 14:07
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]>
@MisterTea
MisterTea merged commit bba566b into MisterTea:master Nov 17, 2026
35 checks passed
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.

3 participants