Commit Graph

648 Commits

Author SHA1 Message Date
guenther@openbsd.org 51875897b8
upstream: Delete obsolete /* ARGSUSED */ lint comments.
ok miod@ millert@

OpenBSD-Commit-ID: 7be168a570264d59e96a7d2d22e927d45fee0e4c
2023-03-08 17:26:53 +11:00
dtucker@openbsd.org 9641753e0f
upstream: Refactor creation of KEX proposal.
This adds kex_proposal_populate_entries (and corresponding free) which
populates the KEX proposal array with dynamically allocated strings.
This replaces the previous mix of static and dynamic that has been the
source of previous leaks and bugs.  Remove unused compat functions.
With & ok djm@.

OpenBSD-Commit-ID: f2f99da4aae2233cb18bf9c749320c5e040a9c7b
2023-03-06 23:31:52 +11:00
dtucker@openbsd.org 93291bd723
upstream: Check return values of dup2. Spotted by Coverity, ok djm@
OpenBSD-Commit-ID: 19fb1b53072826d00c67df677731d2f6c1dd602b
2023-03-03 14:49:14 +11:00
djm@openbsd.org 18938d11a9
upstream: add a `sshd -G` option that parses and prints the
effective configuration without attempting to load private keys and perform
other checks. This allows usage of the option before keys have been
generated.

bz3460 feedback/ok dtucker@

OpenBSD-Commit-ID: 774504f629023fc25a559ab1d95401adb3a7fb29
2023-02-10 16:12:42 +11:00
millert@openbsd.org 7d17ea151c
upstream: Add a -V (version) option to sshd like the ssh client
has. OK markus@ deraadt@

OpenBSD-Commit-ID: abe990ec3e636fb040132aab8cbbede98f0c413e
2023-01-18 13:21:00 +11:00
djm@openbsd.org 2d1ff2b943
upstream: Implement channel inactivity timeouts
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

OpenBSD-Commit-ID: ae8bba3ed9d9f95ff2e2dc8dcadfa36b48e6c0b8
2023-01-06 16:23:16 +11:00
djm@openbsd.org 93f2ce8c05
upstream: Clear signal mask early in main(); sshd may have been
started with one or more signals masked (sigprocmask(2) is not cleared
on fork/exec) and this could interfere with various things, e.g. the
login grace timer.

Execution environments that fail to clear the signal mask before running
sshd are clearly broken, but apparently they do exist.

Reported by Sreedhar Balasubramanian; ok dtucker@

OpenBSD-Commit-ID: 77078c0b1c53c780269fc0c416f121d05e3010ae
2023-01-03 17:53:05 +11:00
cheloha@openbsd.org b85c3581c1
upstream: remove '?' from getopt(3) loops
userspace: remove vestigial '?' cases from top-level getopt(3) loops

getopt(3) returns '?' when it encounters a flag not present in the in
the optstring or if a flag is missing its option argument.  We can
handle this case with the "default" failure case with no loss of
legibility.  Hence, remove all the redundant "case '?':" lines.

Prompted by dlg@.  With help from dlg@ and millert@.

Link: https://marc.info/?l=openbsd-tech&m=167011979726449&w=2

ok naddy@ millert@ dlg@

OpenBSD-Commit-ID: b2f89346538ce4f5b33ab8011a23e0626a67e66e
2022-12-09 11:36:12 +11:00
Darren Tucker 5372db7e79
Remove seed passing over reexec.
This was added for the benefit of platforms using ssh-rand-helper to
prevent a delay on each connection as sshd reseeded itself.

ssh-random-helper is long gone, and since the re-exec happens before the
chroot the re-execed sshd can reseed itself normally. ok djm@
2022-11-10 12:44:51 +11:00
Darren Tucker cf1a9852d7
Defer seed_rng until after closefrom call.
seed_rng will initialize OpenSSL, and some engine providers (eg Intel's
QAT) will open descriptors for their own use.  bz#3483, patch from
joel.d.schuetze at intel.com, ok djm@
2022-11-09 09:23:47 +11:00
djm@openbsd.org 2519a7077a
upstream: refactor sshkey_private_serialize_opt()
feedback/ok markus@

OpenBSD-Commit-ID: 61e0fe989897901294efe7c3b6d670cefaf44cbd
2022-10-28 12:47:01 +11:00
djm@openbsd.org 1875042c52
upstream: Add RequiredRSASize for sshd(8); RSA keys that fall
beneath this limit will be ignored for user and host-based authentication.

Feedback deraadt@ ok markus@

OpenBSD-Commit-ID: 187931dfc19d51873df5930a04f2d972adf1f7f1
2022-09-17 20:39:02 +10:00
dtucker@openbsd.org 322964f8f2 upstream: Remove leftover line.
Remove extra line leftover from merge conflict. ok djm@

OpenBSD-Commit-ID: 460e2290875d7ae64971a7e669c244b1d1c0ae2e
2022-07-01 16:00:17 +10:00
dtucker@openbsd.org 6c31ba10e9 upstream: Don't leak the strings allocated by order_hostkeyalgs()
and list_hostkey_types() that are passed to compat_pkalg_proposal(). Part of
github PR#324 from ZoltanFridrich, ok djm@

This is a roll-forward of the previous rollback now that the required
changes in compat.c have been done.

OpenBSD-Commit-ID: c7cd93730b3b9f53cdad3ae32462922834ef73eb
2022-07-01 13:41:16 +10:00
dtucker@openbsd.org 2369a28101 upstream: Roll back previous KEX changes as they aren't safe until
compat_pkalg_proposal and friends always allocate their returned strings.
Reported by Qualys.

OpenBSD-Commit-ID: 1c7a88a0d5033f42f88ab9bec58ef1cf72c81ad0
2022-06-28 07:43:15 +10:00
dtucker@openbsd.org 646686136c upstream: Don't leak the strings allocated by order_hostkeyalgs()
and list_hostkey_types() that are passed to compat_pkalg_proposal(). Part of
github PR#324 from ZoltanFridrich, ok djm@

OpenBSD-Commit-ID: b2f6e5f60f2bba293b831654328a8a0035ef4a1b
2022-06-28 07:43:15 +10:00
dtucker@openbsd.org ad1762173b upstream: Log an error if pipe() fails while accepting a
connection.  bz#3447, from vincent-openssh at vinc17 net, ok djm@

OpenBSD-Commit-ID: 9d59f19872b94900a5c79da2d57850241ac5df94
2022-06-24 14:28:29 +10:00
djm@openbsd.org 731087d261 upstream: don't try to resolve ListenAddress directives in the sshd
re-exec path - we're never going to use the result and if the operation fails
then it can prevent connections from being accepted. Reported by Aaron
Poffenberger; with / ok dtucker@

OpenBSD-Commit-ID: 44c53a43909a328e2f5ab26070fdef3594eded60
2022-03-20 19:54:35 +11:00
djm@openbsd.org 379b30120d upstream: pack pollfd array before server_accept_loop() ppoll()
call, and terminate sshd if ppoll() returns errno==EINVAL

avoids spin in ppoll when MaxStartups > RLIMIT_NOFILE, reported by
Daniel Micay

feedback/ok deraadt

OpenBSD-Commit-ID: dbab1c24993ac977ec24d83283b8b7528f7c2c15
2022-03-01 13:01:01 +11:00
Darren Tucker b30698662b Move SSHD_ACQUIRES_CTTY workaround into compat.
On some (most? all?) SysV based systems with STREAMS based ptys,
sshd could acquire a controlling terminal during pty setup when
it pushed the "ptem" module, due to what is probably a bug in
the STREAMS driver that's old enough to vote.  Because it was the
privileged sshd's controlling terminal, it was not available for
the user's session, which ended up without one.  This is known to
affect at least Solaris <=10, derivatives such as OpenIndiana and
several other SysV systems.  See bz#245 for the backstory.

In the we past worked around that by not calling setsid in the
privileged sshd child, which meant it was not a session or process
group leader.  This solved controlling terminal problem because sshd
was not eligble to acquire one, but had other side effects such as
not cleaning up helper subprocesses in the SIGALRM handler since it
was not PG leader.  Recent cleanups in the signal handler uncovered
this, resulting in the LoginGraceTime timer not cleaning up privsep
unprivileged processes.

This change moves the workaround into the STREAMS pty allocation code,
by allocating a sacrificial pty to act as sshd's controlling terminal
before allocating user ptys, so those are still available for users'
sessions.

On the down side:
 - this will waste a pty per ssh connection on affected platforms.

On the up side:
 - it makes the process group behaviour consistent between platforms.

 - it puts the workaround nearest the code that actually causes the
   problem and competely out of the mainline code.

 - the workaround is only activated if you use the STREAMS code.  If,
   say, Solaris 11 has the bug but also a working openpty() it doesn't
   matter that we defined SSHD_ACQUIRES_CTTY.

 - the workaround is only activated when the fist pty is allocated,
   ie in the post-auth privsep monitor.  This means there's no risk
   of fd leaks to the unprivileged processes, and there's no effect on
   sessions that do not allocate a pty.

Based on analysis and work by djm@, ok djm@
2022-02-11 21:00:35 +11:00
dtucker@openbsd.org 4e62c13ab4 upstream: Remove explicit kill of privsep preauth child's PID in
SIGALRM handler. It's no longer needed since the child will get terminated by
the SIGTERM to the process group that cleans up any auth helpers, it
simplifies the signal handler and removes the risk of a race when updating
the PID. Based on analysis by HerrSpace in github PR#289, ok djm@

OpenBSD-Commit-ID: 2be1ffa28b4051ad9e33bb4371e2ec8a31d6d663
2022-02-01 19:20:30 +11:00
Darren Tucker b544ce1ad4 Put poll.h inside ifdef HAVE_POLL_H. 2021-11-18 23:06:35 +11:00
djm@openbsd.org 36b5e37030 upstream: fd leak in sshd listen loop error path; from Gleb
Smirnoff

OpenBSD-Commit-ID: a7a2be27a690a74bf2381bc16cea38e265657412
2021-11-18 14:11:38 +11:00
djm@openbsd.org b99498d0c9 upstream: check for POLLHUP as well as POLLIN in sshd listen loop;
ok deraadt millert

OpenBSD-Commit-ID: a4f1244c5a9c2b08dac4f3b1dc22e9d1dc60c587
2021-11-18 14:11:38 +11:00
djm@openbsd.org fd7e7de4dd upstream: set num_listen_socks to 0 on close-all instead of -1,
which interferes with the new poll()-based listen loop; spotted and debugged
by anton@+deraadt@

OpenBSD-Commit-ID: f7ab8ab124f615a2e0c45fee14c38d2f2abbabbd
2021-11-18 09:14:22 +11:00
deraadt@openbsd.org fd9343579a upstream: use ppoll() instead of pselect() with djm
OpenBSD-Commit-ID: 980f87c9564d5d2ad55722b7a6f44f21284cd215
2021-11-18 09:14:22 +11:00
dtucker@openbsd.org 1cc1fd0953 upstream: Id sync only, -portable already has this.
Put dh_set_moduli_file call inside ifdef WITH_OPENSSL. Fixes
build with OPENSSL=no.

OpenBSD-Commit-ID: af54abbebfb12bcde6219a44d544e18204defb15
2021-07-19 13:04:52 +10:00
Darren Tucker 53237ac789 Sync remaining ChallengeResponse removal.
These were omitted from commit 88868fd131.
2021-07-03 19:23:28 +10:00
dtucker@openbsd.org 73f6f191f4 upstream: Continue accept loop when pselect
returns -1, eg if it was interrupted by a signal.  This should prevent
the hang discovered by sthen@ wherein sshd receives a SIGHUP while it has
an unauthenticated child and goes on to a blocking read on a notify_pipe.
feedback deraadt@, ok djm@

OpenBSD-Commit-ID: 0243c1c5544fca0974dae92cd4079543a3fceaa0
2021-06-10 19:48:53 +10:00
djm@openbsd.org 530739d42f upstream: Match host certificates against host public keys, not private
keys. Allows use of certificates with private keys held in a ssh-agent.
Reported by Miles Zhou in bz3524; ok dtucker@

OpenBSD-Commit-ID: 25f5bf70003126d19162862d9eb380bf34bac22a
2021-06-06 21:35:29 +10:00
dtucker@openbsd.org 771f57a862 upstream: Switch the listening select loop from select() to
pselect() and mask signals while checking signal flags, umasking for pselect
and restoring afterwards. Also restore signals before sighup_restart so they
don't remain blocked after restart.

This prevents a race where a SIGTERM or SIGHUP can arrive between
checking the flag and calling select (eg if sshd is processing a
new connection) resulting in sshd not shutting down until the next
time it receives a new connection.  bz#2158, with & ok djm@

OpenBSD-Commit-ID: bf85bf880fd78e00d7478657644fcda97b9a936f
2021-06-04 15:13:14 +10:00
djm@openbsd.org e3c032333b upstream: don't sigdie() in signal handler in privsep child process;
this can end up causing sandbox violations per bz3286; ok dtucker@

OpenBSD-Commit-ID: a7f40b2141dca4287920da68ede812bff7ccfdda
2021-05-10 10:57:58 +10:00
djm@openbsd.org 31d8d231eb upstream: highly polished whitespace, mostly fixing spaces-for-tab
and bad indentation on continuation lines. Prompted by GHPR#185

OpenBSD-Commit-ID: e5c81f0cbdcc6144df1ce468ec1bac366d8ad6e9
2021-04-03 17:23:02 +11:00
Darren Tucker 5ca8a92165 Only call dh_set_moduli_file if using OpenSSL.
Fixes link failure when configuring --without-openssl since dh.c is not
linked in.
2021-03-13 14:40:43 +11:00
dtucker@openbsd.org 88057eb6df upstream: Add ModuliFile keyword to sshd_config to specify the
location of the "moduli" file containing the groups for DH-GEX.  This will
allow us to run tests against arbitrary moduli files without having to
install them. ok djm@

OpenBSD-Commit-ID: 8df99d60b14ecaaa28f3469d01fc7f56bff49f66
2021-03-13 13:14:13 +11:00
dtucker@openbsd.org a35d3e911e upstream: Remove debug message from sigchld handler. While this
works on OpenBSD it can cause problems on other platforms.  From kircherlike
at outlook.com via bz#3259, ok djm@

OpenBSD-Commit-ID: 3e241d7ac1ee77e3de3651780b5dc47b283a7668
2021-02-05 13:38:57 +11:00
djm@openbsd.org 39be3dc209 upstream: make ssh->kex->session_id a sshbuf instead of u_char*/size_t
and use that instead of global variables containing copies of it. feedback/ok
markus@

OpenBSD-Commit-ID: a4b1b1ca4afd2e37cb9f64f737b30a6a7f96af68
2021-01-27 21:10:57 +11:00
djm@openbsd.org 4ca6a1fac3 upstream: remove global variable used to stash compat flags and use the
purpose-built ssh->compat variable instead; feedback/ok markus@

OpenBSD-Commit-ID: 7c4f200e112dae6bcf99f5bae1a5629288378a06
2021-01-27 20:28:25 +11:00
dtucker@openbsd.org 3a92312953 upstream: Add PerSourceMaxStartups and PerSourceNetBlockSize
options which provide more fine grained MaxStartups limits.  Man page help
jmc@, feedback & ok djm@

OpenBSD-Commit-ID: e2f68664e3d02c0895b35aa751c48a2af622047b
2021-01-11 15:04:12 +11:00
djm@openbsd.org 2c71cec020 upstream: Update/replace the experimental post-quantim hybrid key
exchange method based on Streamlined NTRU Prime (coupled with X25519).

The previous sntrup4591761x25519-sha512@tinyssh.org method is
replaced with sntrup761x25519-sha512@openssh.com. Per the authors,
sntrup4591761 was replaced almost two years ago by sntrup761.

The sntrup761 implementaion, like sntrup4591761 before it, is public
domain code extracted from the SUPERCOP cryptography benchmark
suite (https://bench.cr.yp.to/supercop.html).

Thanks for Daniel J Bernstein for guidance on algorithm selection.
Patch from Tobias Heider; feedback & ok markus@ and myself

(note this both the updated method and the one that it replaced are
disabled by default)

OpenBSD-Commit-ID: 2bf582b772d81ee24e911bb6f4b2aecfd39338ae
2020-12-29 12:38:53 +11:00
dtucker@openbsd.org 4d94b031ff upstream: Replace WITH_OPENSSL ifdefs in log calls with a macro.
The log calls are themselves now macros, and preprocessor directives inside
macro arguments are undefined behaviour which some compilers (eg old GCCs)
choke on.  It also makes the code tidier.  ok deraadt@

OpenBSD-Commit-ID: cc12a9029833d222043aecd252d654965c351a69
2020-11-09 00:02:27 +11:00
djm@openbsd.org 816036f142 upstream: use the new variant log macros instead of prepending
__func__ and appending ssh_err(r) manually; ok markus@

OpenBSD-Commit-ID: 1f14b80bcfa85414b2a1a6ff714fb5362687ace8
2020-10-18 23:46:29 +11:00
djm@openbsd.org 793b583d09 upstream: LogVerbose keyword for ssh and sshd
Allows forcing maximum debug logging by file/function/line pattern-
lists.

ok markus@

OpenBSD-Commit-ID: c294c25732d1b4fe7e345cb3e044df00531a6356
2020-10-17 00:43:17 +11:00
djm@openbsd.org 396d32f3a1 upstream: There are lots of place where we want to redirect stdin,
stdout and/or stderr to /dev/null. Factor all these out to a single
stdfd_devnull() function that allows selection of which of these to redirect.
ok markus@

OpenBSD-Commit-ID: 3033ba5a4c47cacfd5def020d42cabc52fad3099
2020-10-03 19:34:24 +10:00
djm@openbsd.org 9b8ad93824 upstream: support for user-verified FIDO keys
FIDO2 supports a notion of "user verification" where the user is
required to demonstrate their identity to the token before particular
operations (e.g. signing). Typically this is done by authenticating
themselves using a PIN that has been set on the token.

This adds support for generating and using user verified keys where
the verification happens via PIN (other options might be added in the
future, but none are in common use now). Practically, this adds
another key generation option "verify-required" that yields a key that
requires a PIN before each authentication.

feedback markus@ and Pedro Martelletto; ok markus@

OpenBSD-Commit-ID: 57fd461e4366f87c47502c5614ec08573e6d6a15
2020-08-27 11:28:36 +10:00
markus@openbsd.org b0c1e8384d upstream: update setproctitle after re-exec; ok djm
OpenBSD-Commit-ID: bc92d122f9184ec2a9471ade754b80edd034ce8b
2020-07-15 15:06:44 +10:00
markus@openbsd.org cd119a5ec2 upstream: keep ignoring HUP after fork+exec; ok djm
OpenBSD-Commit-ID: 7679985a84ee5ceb09839905bb6f3ddd568749a2
2020-07-15 15:06:44 +10:00
markus@openbsd.org 8af4a74369 upstream: don't exit the listener on send_rexec_state errors; ok
djm

OpenBSD-Commit-ID: 57cbd757d130d3f45b7d41310b3a15eeec137d5c
2020-07-15 15:06:44 +10:00
djm@openbsd.org 7775819c6d upstream: check public host key matches private; ok markus@ (as
part of previous diff)

OpenBSD-Commit-ID: 65a4f66436028748b59fb88b264cb8c94ce2ba63
2020-06-19 15:51:04 +10:00
djm@openbsd.org 3a7f654d5b upstream: unbreak "sshd -ddd" - close of config passing fd happened too
early. ok markus@

OpenBSD-Commit-ID: 49346e945c6447aca3e904e65fc400128d2f8ed0
2020-06-05 16:20:09 +10:00