summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/channels.c
AgeCommit message (Collapse)Author
2024-10-13don't start the ObscureKeystrokeTiming mitigations if there has beenDamien Miller
traffic on a X11 forwarding channel recently. Should fix X11 forwarding performance problems when this setting is enabled. Patch from Antonio Larrosa via bz3655
2024-07-25Fix proxy multiplexing (-O proxy) bugDamien Miller
If a mux started with ControlPersist then later has a forwarding added using mux proxy connection and the forwarding was used, then when the mux proxy session terminates, the mux master process will send a channel close to the server with a bad channel ID and crash the connection. This was caused by my stupidly reusing c->remote_id for mux channel associations when I should have just added another member to struct channel. ok markus@
2024-05-17Start the process of splitting sshd into separate binaries. This stepDamien Miller
splits sshd into a listener and a session binary. More splits are planned. After this changes, the listener binary will validate the configuration, load the hostkeys, listen on port 22 and manage MaxStartups only. All session handling will be performed by a new sshd-session binary that the listener fork+execs. This reduces the listener process to the minimum necessary and sets us up for future work on the sshd-session binary. feedback/ok markus@ deraadt@ NB. if you're updating via source, please restart sshd after installing, otherwise you run the risk of locking yourself out.
2024-03-06fix memory leak in mux proxy mode when requesting forwarding.Damien Miller
found by RASU JSC, reported by Maks Mishin in GHPR#467
2024-01-09add a "global" ChannelTimeout type to ssh(1) and sshd(8) that watchesDamien Miller
all open channels and will close all open channels if there is no traffic on any of them for the specified interval. This is in addition to the existing per-channel timeouts added a few releases ago. This supports use-cases like having a session + x11 forwarding channel open where one may be idle for an extended period but the other is actively used. The global timeout would allow closing both channels when both have been idle for too long. ok dtucker@
2023-12-18stricter handling of channel window limitsDamien Miller
This makes ssh/sshd more strict in handling non-compliant peers that send more data than the advertised channel window allows. Previously the additional data would be silently discarded. This change will cause ssh/sshd to terminate the connection if the channel window is exceeded by more than a small grace allowance. ok markus@
2023-11-15when deciding whether to enable keystroke timing obfuscation,Damien Miller
only consider enabling it when a channel with a tty is open. Avoids turning on the obfucation when X11 forwarding only is in use, which slows it right down. Reported by Roger Marsh
2023-09-04make channel_output_poll() return a flag indicating whether channelDamien Miller
data was enqueued. Will be used to improve keystroke timing obfuscation. Problem spotted by / tested by naddy@
2023-07-04add support for unix domain sockets to ssh -WDavid Gwynne
ok djm@ dtucker@
2023-06-05Store timeouts as int, not u_int as they are limited to INT_MAX.Todd C. Miller
Fixes sign compare warnings systems with 32-bit time_t due to type promotion. OK djm@
2023-03-10Expliticly ignore return code from fcntl(.. FD_CLOEXEC) since there'sDarren Tucker
not much we can do anyway. From Coverity CID 291857, ok djm@
2023-03-07refactor to be more readable top to bottom. Prompted by Coverity CIDDamien Miller
405048 which was a false-positive fd leak; ok dtucker@
2023-03-04Use time_t instead of u_int for remaining x11 timeout checks for 64bitDarren Tucker
time_t safety. From Coverity CIDs 405197 and 405028, ok djm@
2023-01-18when restoring non-blocking mode to stdio fds, restore exactlyDamien Miller
the flags that ssh started with and don't just clobber them with zero, as this could also remove the append flag from the set; bz3523; ok dtucker@
2023-01-06Implement channel inactivity timeoutsDamien Miller
This adds a sshd_config ChannelTimeouts directive that allows channels that have not seen traffic in a configurable interval to be automatically closed. Different timeouts may be applied to session, X11, agent and TCP forwarding channels. Note: this only affects channels over an opened SSH connection and not the connection itself. Most clients close the connection when their channels go away, with a notable exception being ssh(1) in multiplexing mode. ok markus dtucker
2023-01-06Add channel_set_xtype()Damien Miller
This sets an "extended" channel type after channel creation (e.g. "session:subsystem:sftp") that will be used for setting channel inactivity timeouts. ok markus dtucker
2023-01-06tweak channel ctype namesDamien Miller
These are now used by sshd_config:ChannelTimeouts to specify timeouts by channel type, so force them all to use a similar format without whitespace. ok dtucker markus
2023-01-06Add channel_force_close()Damien Miller
This will forcibly close an open channel by simulating read/write errors, draining the IO buffers and calling the detach function. Previously the detach function was only ever called during channel garbage collection, but there was no way to signal the user of a channel (e.g. session.c) that its channel was being closed deliberately (vs. by the usual state-machine logic). So this adds an extra "force" argument to the channel cleanup callback to indicate this condition. ok markus dtucker
2023-01-06replace manual poll/ppoll timeout math with ptimeout APIDamien Miller
feedback markus / ok markus dtucker
2022-11-18In channel_request_remote_forwarding the parameters for permission_set_addMoritz Buhl
are leaked as they are also duplicated in the call. Found by CodeChecker. ok djm
2022-09-19better debugging for connect_next()Damien Miller
2022-05-05channel_new no longer frees remote_name. So update the commentDamien Miller
accordingly. As remote_name is not modified, it can be const as well. From Martin Vahlensieck
2022-05-04make sure stdout is non-blocking; ok djm@Markus Friedl
2022-04-20Try to continue running local I/O for channels in state OPEN duringDamien Miller
SSH transport rekeying. The most visible benefit is that it should make ~-escapes work in the client (e.g. to exit) if the connection happened to have stalled during a rekey event. Based work by and ok dtucker@
2022-04-11clear io_want/io_ready flags at start of poll() cycle;Damien Miller
avoids plausible spin during rekeying if channel io_want flags are reused across cycles. ok markus@ deraadt@
2022-03-30fix poll() spin when a channel's output fd closes without data in theDamien Miller
channel buffer. Introduce more exact packing of channel fds into the pollfd array. fixes bz3405 and bz3411; ok deraadt@ markus@
2022-03-15improve DEBUG_CHANNEL_POLL debugging messageDamien Miller
2022-02-17check for EINTR/EAGAIN failures in the rfd fast-path;Damien Miller
caught by dtucker's minix3 vm :) ok dtucker@
2022-01-22Use sshbuf_read() to read directly into the channel input bufferDamien Miller
rather than into a stack buffer that needs to be copied again; Improves performance by about 1% on cipher-speed.sh feedback dtucker@ ok markus@
2022-01-06convert ssh, sshd mainloops from select() to poll();Damien Miller
feedback & ok deraadt@ and markus@ has been in snaps for a few months
2022-01-06prepare for conversion of ssh, sshd mainloop from select() to poll()Damien Miller
by moving FD_SET construction out of channel handlers into separate functions. ok markus
2022-01-01spellingJonathan Gray
ok dtucker@
2021-09-14put back the mux_ctx memleak fix for SSH_CHANNEL_MUX_CLIENTmbuhl
OK mfriedl@
2021-05-19restore blocking status on stdio fds before closeDamien Miller
ssh(1) needs to set file descriptors to non-blocking mode to operate but it was not restoring the original state on exit. This could cause problems with fds shared with other programs via the shell, e.g. > $ cat > test.sh << _EOF > #!/bin/sh > { > ssh -Fnone -oLogLevel=verbose ::1 hostname > cat /usr/share/dict/words > } | sleep 10 > _EOF > $ ./test.sh > Authenticated to ::1 ([::1]:22). > Transferred: sent 2352, received 2928 bytes, in 0.1 seconds > Bytes per second: sent 44338.9, received 55197.4 > cat: stdout: Resource temporarily unavailable This restores the blocking status for fds 0,1,2 (stdio) before ssh(1) abandons/closes them. This was reported as bz3280 and GHPR246; ok dtucker@
2021-04-03highly polished whitespace, mostly fixing spaces-for-tab and badDamien Miller
indentation on continuation lines. Prompted by GHPR#185
2021-02-15ssh: add PermitRemoteOpen for remote dynamic forwarding with SOCKSMarkus Friedl
ok djm@, dtucker@
2021-01-27remove global variable used to stash compat flags and use theDamien Miller
purpose-built ssh->compat variable instead; feedback/ok markus@
2020-10-18use the new variant log macros instead of prepending __func__ andDamien Miller
appending ssh_err(r) manually; ok markus@
2020-09-20cap channel input buffer size at 16MB; avoids high memory use whenDamien Miller
peer advertises a large window but is slow to consume the data we send (e.g. because of a slow network) reported by Pierre-Yves David fix with & ok markus@
2020-07-03put back the mux_ctx memleak fix, but only for channels of typeDamien Miller
SSH_CHANNEL_MUX_LISTENER; Specifically SSH_CHANNEL_MUX_PROXY channels should not have this structure freed.
2020-07-03revert r1.399 - the lifetime of c->mux_ctx is more complex; simply freeingDamien Miller
it here causes other problems
2020-07-03fix memory leak of mux_ctx; patch from Sergiy Lozovsky via bz3189Damien Miller
ok dtucker
2020-04-25We've standardized on memset over bzero, replace a couple that had slippedDarren Tucker
in. ok deraadt markus djm.
2020-03-06fix uninitialized pointers for forward_cancel; ok djmMarkus Friedl
2020-02-26change explicit_bzero();free() to freezero()Jonathan Gray
While freezero() returns early if the pointer is NULL the tests for NULL in callers are left to avoid warnings about passing an uninitialised size argument across a function boundry. ok deraadt@ djm@
2020-01-25the GatewayPorts vs -R listen address selection logic is stillDamien Miller
confusing people, so add another comment explaining the special handling of "localhost"; bz#3258
2019-07-07Remove some set but never used variables. ok daraadt@Darren Tucker
2019-06-28When system calls indicate an error they return -1, not some arbitraryTheo de Raadt
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
2019-06-07Typo and spelling fixes in comments and error messages. Patch fromDarren Tucker
knweiss at gmail.com via -portable.
2019-05-10For PermitOpen violations add the remote host and port toFlorian Obser
be able to find out from where the request was comming. Add the same logging for PermitListen violations which where not logged at all. Pointed out by Robert Kisteleki (robert AT ripe.net) input markus OK deraadt