FreeBSD src
Go to file
Maxim Sobolev 18a2ccd22d Fix bug in the readpassphrase(3) function, which can be exposed
by application closing its stdin (i.e. STDIN_FILENO) prior to
calling readpassphrase WITHOUT setting RPP_STDIN. What happens
then is that the readpassphrase would open /dev/tty, and since
file descriptors are reused, the call would return first unused
fd, which is 0 which is also STDIN_FILENO. Then due to the usage
of "input != STDIN_FILENO" in the code to do its logic, that
would result in noecho flags not set on that file descriptor,
which was original issue I've been trying to fix.

In addition to that, the readpassphrase() would leak file
descriptor on its way out, so fix that one as well.

This problem can be tested with:

 $ ssh-add - < /tmp/myprivate.key

The password will not be hidden as it should and ktrace will
show:

 53326 ssh-add  CALL  open(0x80142443c,0x100002<O_RDWR|O_CLOEXEC>,<unused>0x165f030)
 53326 ssh-add  NAMI  "/dev/tty"
 53326 ssh-add  RET   open 0
 53326 ssh-add  CALL  sigprocmask(SIG_SETMASK,0x802eb1324,0x7fffffffd5e0)
 53326 ssh-add  RET   sigprocmask 0
 53326 ssh-add  CALL  sigaction(SIGALRM,0x7fffffffd630,0x7fffffffd610)

Instead of:

 57690 ssh-add  CALL  open(0x80142443c,0x100002<O_RDWR|O_CLOEXEC>,<unused>0x165f030)
 57690 ssh-add  NAMI  "/dev/tty"
 57690 ssh-add  RET   open 4
 57690 ssh-add  CALL  ioctl(0x4,TIOCGETA,0x7fffffffd860)
 57690 ssh-add  RET   ioctl 0
 57690 ssh-add  CALL  ioctl(0x4,TIOCSETAF,0x7fffffffd680)
 57690 ssh-add  RET   ioctl 0
 57690 ssh-add  CALL  sigprocmask(SIG_SETMASK,0x802eb1324,0x7fffffffd620)
 57690 ssh-add  RET   sigprocmask 0
 57690 ssh-add  CALL  sigaction(SIGALRM,0x7fffffffd670,0x7fffffffd650)

For the case when the key is read from the file.

Technically this can also be workaround'ed at the application side
by not closing the STDIN_FILENO in the first place, but readpassphrase(3)
doesn't need to make any assumptions about that. Plus the file descriptor
leak confirms that this is an oversight, rather than a deliberate behaviour.

MFC after:	1 week
2016-01-24 22:20:13 +00:00
bin sh: Remove a global variable from cd.c. 2016-01-24 17:01:34 +00:00
cddl Remove a dead local variable, missed in r274565. 2016-01-14 00:34:37 +00:00
contrib Add config for RISC-V ISA. 2016-01-24 15:12:49 +00:00
crypto r294563 was incomplete; re-add the client-side options as well. 2016-01-22 14:22:11 +00:00
etc Do not generate RSA1 or DSA keys by default. 2016-01-22 12:14:08 +00:00
gnu Use MAN= to specify that no man page is provided 2016-01-22 21:33:27 +00:00
include Provide new socket option TCP_CCALGOOPT, which stands for TCP congestion 2016-01-22 02:07:48 +00:00
kerberos5 DIRDEPS_BUILD: Update dependencies. 2015-12-07 23:53:01 +00:00
lib Fix bug in the readpassphrase(3) function, which can be exposed 2016-01-24 22:20:13 +00:00
libexec Follow r293066 adding a generalized exec hook for RISC-V as well. 2016-01-23 11:46:52 +00:00
release Increase efiboot.img size used in ISO creation 2016-01-13 14:47:13 +00:00
rescue Fix the build after ifconfig was converted over to lib80211 in r291470 2015-11-30 16:34:13 +00:00
sbin Add "kldstat -h"; showing module sizes in hex is rather weird. 2016-01-23 12:10:16 +00:00
secure Upgrade to OpenSSH 7.0p1. 2016-01-20 22:57:10 +00:00
share Bump copyright for change from fbt to syscall 2016-01-24 21:18:54 +00:00
sys Remove an extra newline that crept in. 2016-01-24 19:12:16 +00:00
targets Add in DIRDEPS_BUILD support. 2016-01-07 00:19:30 +00:00
tests PID file support hasn't been committed for ggated(8) yet. Unbreak running 2016-01-14 07:39:05 +00:00
tools Use different ports in the TCP/UDP testcases with the first set and 2016-01-23 22:51:22 +00:00
usr.bin We don't support a.out executables on RISC-V. 2016-01-24 15:15:57 +00:00
usr.sbin The <libutil.h> is an ordinary header file; should sort just like any other. 2016-01-24 18:11:36 +00:00
.arcconfig Add repository.callsign, to help arcanist figure out what repo it's 2015-07-02 22:23:52 +00:00
.arclint phabricator related changes: 2015-04-20 20:33:22 +00:00
COPYRIGHT Bump copyright year. 2015-12-31 11:21:45 +00:00
LOCKS Explicitly require Security Officer's approval for kernel PRNG bits. 2013-09-17 14:19:05 +00:00
MAINTAINERS Add interests/maintainerships + notes 2015-12-28 19:29:05 +00:00
Makefile Import mdocml CVS snapshot 20160116 2016-01-15 23:08:59 +00:00
Makefile.inc1 Correct a comment. 2016-01-11 20:27:05 +00:00
ObsoleteFiles.inc Remove leading slashes added to ObsoleteFiles.inc in r294113. 2016-01-17 00:52:28 +00:00
README README: changes and fixups 2015-04-19 07:16:44 +00:00
UPDATING Enable DSA keys by default. They were disabled in OpenSSH 6.9p1. 2016-01-21 11:10:14 +00:00

This is the top level of the FreeBSD source directory.  This file
was last revised on:
$FreeBSD$

For copyright information, please see the file COPYRIGHT in this
directory (additional copyright information also exists for some
sources in this tree - please see the specific source directories for
more information).

The Makefile in this directory supports a number of targets for
building components (or all) of the FreeBSD source tree.  See build(7)
and http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/makeworld.html
for more information, including setting make(1) variables.

The `buildkernel` and `installkernel` targets build and install
the kernel and the modules (see below).  Please see the top of
the Makefile in this directory for more information on the
standard build targets and compile-time flags.

Building a kernel is a somewhat more involved process.  See build(7), config(8),
and http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig.html
for more information.

Note: If you want to build and install the kernel with the
`buildkernel` and `installkernel` targets, you might need to build
world before.  More information is available in the handbook.

The kernel configuration files reside in the sys/<arch>/conf
sub-directory.  GENERIC is the default configuration used in release builds.
NOTES contains entries and documentation for all possible
devices, not just those commonly used.


Source Roadmap:
---------------

bin		System/user commands.

cddl		Various commands and libraries under the Common Development
		and Distribution License.

contrib		Packages contributed by 3rd parties.

crypto		Cryptography stuff (see crypto/README).

etc		Template files for /etc.

games		Amusements.

gnu		Various commands and libraries under the GNU Public License.
		Please see gnu/COPYING* for more information.

include		System include files.

kerberos5	Kerberos5 (Heimdal) package.

lib		System libraries.

libexec		System daemons.

release		Release building Makefile & associated tools.

rescue		Build system for statically linked /rescue utilities.

sbin		System commands.

secure		Cryptographic libraries and commands.

share		Shared resources.

sys		Kernel sources.

tests		Regression tests which can be run by Kyua.  See tests/README
		for additional information.

tools		Utilities for regression testing and miscellaneous tasks.

usr.bin		User commands.

usr.sbin	System administration commands.


For information on synchronizing your source tree with one or more of
the FreeBSD Project's development branches, please see:

  http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/synching.html