Commit Graph

17 Commits

Author SHA1 Message Date
Darren Tucker df93529dd7 Test if sshd accidentally acquires controlling tty
When SSHD_ACQUIRES_CTTY is defined, test for the problematic behaviour
in the STREAMS code before activating the workaround.  ok djm@
2022-02-14 14:19:40 +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
Darren Tucker 945bf52c3c Fix a couple of mysig_t leftovers. 2020-01-23 21:06:45 +11:00
dtucker@openbsd.org 3bf2a6ac79 upstream: Replace all calls to signal(2) with a wrapper around
sigaction(2). This wrapper blocks all other signals during the handler
preventing races between handlers, and sets SA_RESTART which should reduce
the potential for short read/write operations.

OpenBSD-Commit-ID: 5e047663fd77a40d7b07bdabe68529df51fd2519
2020-01-23 18:51:25 +11:00
Darren Tucker b7b8334914 Don't install duplicate STREAMS modules on Solaris
Check if STREAMS modules are already installed on pty before installing
since when compiling with XPG>=4 they will likely be installed already.
Prevents hangs and duplicate lines on the terminal.  bz#2945 and bz#2998,
patch from djm@
2019-04-26 18:06:34 +10:00
Darren Tucker bc3f80e4d1 Remove UNICOS code missed during removal.
Fixes compile error on AIX.
2018-03-26 13:24:28 +11:00
Darren Tucker ddc0f38148 Remove UNICOS support.
The code required to support it is quite invasive to the mainline
code that is synced with upstream and is an ongoing maintenance burden.
Both the hardware and software are literal museum pieces these days and
we could not find anyone still running OpenSSH on one.
2018-02-15 20:04:02 +11:00
Darren Tucker c20dccb561 Strip trailing whitespace.
Mechanically strip trailing whitespace on files not synced with OpenBSD
(or in the case of bsd-snprint.c, rsync).
2016-08-02 09:44:25 +10:00
Darren Tucker f80f5ec81b - (dtucker) [openbsd-compat/bsd-openpty.c] Include for ioctl(2). 2006-08-24 19:52:30 +10:00
Darren Tucker f78fb54412 - (dtucker) [openbsd-compat/{bsd-asprintf.c,bsd-openpty.c,bsd-snprintf.c,
glob.c}] Include stdlib.h for malloc and friends in compat code.
2006-08-06 21:25:24 +10:00
Damien Miller 62da44f064 - (djm) [openbsd-compat/basename.c openbsd-compat/bsd-closefrom.c]
[openbsd-compat/bsd-cray.c openbsd-compat/bsd-openpty.c]
   [openbsd-compat/bsd-snprintf.c openbsd-compat/fake-rfc2553.c]
   [openbsd-compat/port-aix.c openbsd-compat/port-irix.c]
   [openbsd-compat/rresvport.c]
   These look to need string.h and/or unistd.h (based on a grep for function
   names)
2006-07-24 15:08:35 +10:00
Darren Tucker 44c828fe29 - (dtucker) [configure.ac ssh-keygen.c openbsd-compat/bsd-openpty.c
openbsd-compat/daemon.c] Add includes needed by open(2).  Conditionally
   include paths.h.  Fixes build error on Solaris.
2006-07-11 18:00:06 +10:00
Damien Miller 6645e7a70d - (djm) [auth-pam.c clientloop.c includes.h monitor.c session.c]
[sftp-client.c ssh-keysign.c ssh.c sshconnect.c sshconnect2.c]
   [sshd.c openbsd-compat/bsd-misc.c openbsd-compat/bsd-openpty.c]
   [openbsd-compat/glob.c openbsd-compat/mktemp.c]
   [openbsd-compat/readpassphrase.c] Lots of include fixes for
   OpenSolaris
2006-03-15 14:42:54 +11:00
Darren Tucker 34233830a1 - (dtucker) [openbsd-compat/bsd-openpty.c openbsd-compat/inet_ntop.c]
Remove two obsolete Cygwin #ifdefs.  Patch from vinschen at redhat.com.
2005-02-26 10:04:28 +11:00
Damien Miller 98225c2950 - (djm) Simplify the license on code I have written. No code changes. 2004-02-17 16:49:41 +11:00
Damien Miller 6814411b3e - (djm) Typo in openbsd-compat/bsd-openpty.c; from wendyp AT cray.com 2004-01-24 13:50:39 +11:00
Damien Miller f4da3bb6ca - deraadt@cvs.openbsd.org 2004/01/11 21:55:06
[sshpty.c]
     for pty opening, only use the openpty() path.  the other stuff only needs
     to be in openssh-p; markus ok
 - (djm) [openbsd-compat/bsd-openpty.c] Rework old sshpty.c code into an
   openpty() replacement
2004-01-21 17:07:16 +11:00