Remote Dynamic forwarding with unix socket
Charles Mirabile
cmirabil at redhat.com
Mon Nov 16 16:35:51 AEDT 2026
Hi all—
I recently tried to do reverse dynamic forwarding where the remote
listener was a unix socket instead of a tcp host/port (i.e. `-R
/tmp/proxy.sock`) on Linux. It wasn't documented in the man page, but
seemed like a natural extension of the existing syntax and it was
accepted by my client and the server (i.e. no error message locally
and the socket does get created on the remote machine).
However trying to actually use the remote socket as a proxy didn't
work (e.g. `curl --proxy=socks5h://localhost/tmp/proxy.sock
https://example.com` on the remote machine causes ssh to print
"connect_to socks: unknown host (Name or service not known)").
After rooting around in the code for a while but not really getting
anywhere, I asked gemini (forgive me) and it confirmed my suspicions,
suggesting that this behavior was a limitation of the client: while it
could parse the option and was sending the right thing to the server
something wasn't hooked up internally locally and it was treating it
like a remote unix to local tcp forward and trying to connect locally
to a fake hostname "socks". It suggested various workarounds (i.e.
running a dedicated proxy on a specific local port and forwarding that
port to the remote machine).
I asked it whether I could patch my client, and while it hallucinated
the actual code substantially, I guess enough of the openssh code was
in its pre-training that it was able to point me to the functions
`channel_connect_by_listen_address` and
`channel_connect_by_listen_path` in channels.c where I saw the former
has a check for `port_to_connect` being zero in which case it calls
`rdynamic_connect_prepare` while the latter has no such check.
I copied the if statement from one function into the other and
recompiled and the resulting client was able to perform this kind of
forwarding. I have attached a patch with that modification to
`channel_connect_by_listen_path`, and also a small edit to the man
page to document this usage (though I do not know troff and again
merely copied another block and edited it lightly so do please check
it over).
Perhaps this patch is worth including? I'd also be happy to file a
formal bug. I am not very familiar with the OpenBSD development
process, but I do think that this would be applicable to the upstream
and not merely to the portable version. I also only subscribed to the
list to send this and will probably unsubscribe so please make sure to
reply to me directly. Thanks in advance for your attention (and for
creating this great program in the first place)!
Best—Charlie
Charles Mirabile
Senior Software Engineer
ARM & RISC-V Kernel Hardware Team
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reverse_dynamic_unix_sockets.patch
Type: text/x-patch
Size: 921 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261116/19ed6bcc/attachment.bin>
More information about the openssh-unix-dev
mailing list