00db10
#* CVE-2013-2207 Incorrectly granting access to another user's pseudo-terminal
00db10
#  has been fixed by disabling the use of pt_chown (Bugzilla #15755).
00db10
#  Distributions can re-enable building and using pt_chown via the new configure
00db10
#  option `--enable-pt_chown'.  Enabling the use of pt_chown carries with it
00db10
#  considerable security risks and should only be used if the distribution
00db10
#  understands and accepts the risks.
00db10
#
00db10
#2013-07-21  Siddhesh Poyarekar  <siddhesh@redhat.com>
00db10
#	    Andreas Schwab  <schwab@suse.de>
00db10
#	    Roland McGrath  <roland@hack.frob.com>
00db10
#	    Joseph Myers  <joseph@codesourcery.com>
00db10
#	    Carlos O'Donell  <carlos@redhat.com>
00db10
#
00db10
#	[BZ #15755]
00db10
#	* config.h.in: Define HAVE_PT_CHOWN.
00db10
#	* config.make.in (build-pt-chown): New variable.
00db10
#	* configure.in (--enable-pt_chown): New configure option.
00db10
#	* configure: Regenerate.
00db10
#	* login/Makefile: Include Makeconfig.  Build pt_chown only if
00db10
#	build-pt-chown is enabled.
00db10
#	* sysdeps/unix/grantpt.c (grantpt) [HAVE_PT_CHOWN]: Spawn
00db10
#	pt_chown to fix pty ownership.
00db10
#	* sysdeps/unix/sysv/linux/grantpt.c [HAVE_PT_CHOWN]: Define
00db10
#	CLOSE_ALL_FDS.
00db10
#	* manual/install.texi (Configuring and compiling): Mention
00db10
#	--enable-pt_chown. Add @findex for grantpt.
00db10
#	* INSTALL: Regenerate.
00db10
#
00db10
diff -Nru glibc-2.17-c758a686/config.h.in glibc-2.17-c758a686/config.h.in
00db10
--- glibc-2.17-c758a686/config.h.in	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/config.h.in	2013-07-24 00:20:07.651301252 -0400
00db10
@@ -232,4 +232,7 @@
00db10
 /* The ARM hard-float ABI is being used.  */
00db10
 #undef HAVE_ARM_PCS_VFP
00db10
 
00db10
+/* The pt_chown binary is being built and used by grantpt.  */
00db10
+#undef HAVE_PT_CHOWN
00db10
+
00db10
 #endif
00db10
diff -Nru glibc-2.17-c758a686/config.make.in glibc-2.17-c758a686/config.make.in
00db10
--- glibc-2.17-c758a686/config.make.in	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/config.make.in	2013-07-24 00:21:15.244176098 -0400
00db10
@@ -101,6 +101,7 @@ force-install = @force_install@
00db10
 link-obsolete-rpc = @link_obsolete_rpc@
00db10
 build-nscd = @build_nscd@
00db10
 use-nscd = @use_nscd@
00db10
+build-pt-chown = @build_pt_chown@
00db10
 
00db10
 # Build tools.
00db10
 CC = @CC@
00db10
diff -Nru glibc-2.17-c758a686/configure glibc-2.17-c758a686/configure
00db10
--- glibc-2.17-c758a686/configure	2013-07-24 00:25:10.090174244 -0400
00db10
+++ glibc-2.17-c758a686/configure	2013-07-24 00:20:07.769174345 -0400
00db10
@@ -653,6 +653,7 @@ multi_arch
00db10
 base_machine
00db10
 add_on_subdirs
00db10
 add_ons
00db10
+build_pt_chown
00db10
 build_nscd
00db10
 link_obsolete_rpc
00db10
 libc_cv_nss_crypt
00db10
@@ -759,6 +760,7 @@ enable_obsolete_rpc
00db10
 enable_systemtap
00db10
 enable_build_nscd
00db10
 enable_nscd
00db10
+enable_pt_chown
00db10
 with_cpu
00db10
 '
00db10
       ac_precious_vars='build_alias
00db10
@@ -1419,6 +1421,7 @@ Optional Features:
00db10
   --enable-systemtap      enable systemtap static probe points [default=no]
00db10
   --disable-build-nscd    disable building and installing the nscd daemon
00db10
   --disable-nscd          library functions will not contact the nscd daemon
00db10
+  --enable-pt_chown       Enable building and installing pt_chown
00db10
 
00db10
 Optional Packages:
00db10
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
00db10
@@ -3934,6 +3937,19 @@ else
00db10
 fi
00db10
 
00db10
 
00db10
+# Check whether --enable-pt_chown was given.
00db10
+if test "${enable_pt_chown+set}" = set; then :
00db10
+  enableval=$enable_pt_chown; build_pt_chown=$enableval
00db10
+else
00db10
+  build_pt_chown=no
00db10
+fi
00db10
+
00db10
+
00db10
+if test $build_pt_chown = yes; then
00db10
+  $as_echo "#define HAVE_PT_CHOWN 1" >>confdefs.h
00db10
+
00db10
+fi
00db10
+
00db10
 # The way shlib-versions is used to generate soversions.mk uses a
00db10
 # fairly simplistic model for name recognition that can't distinguish
00db10
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
00db10
diff -Nru glibc-2.17-c758a686/configure.in glibc-2.17-c758a686/configure.in
00db10
--- glibc-2.17-c758a686/configure.in	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/configure.in	2013-07-24 00:20:07.658298658 -0400
00db10
@@ -315,6 +315,16 @@ AC_ARG_ENABLE([nscd],
00db10
 	      [use_nscd=$enableval],
00db10
 	      [use_nscd=yes])
00db10
 
00db10
+AC_ARG_ENABLE([pt_chown],
00db10
+	      [AS_HELP_STRING([--enable-pt_chown],
00db10
+	       [Enable building and installing pt_chown])],
00db10
+	      [build_pt_chown=$enableval],
00db10
+	      [build_pt_chown=no])
00db10
+AC_SUBST(build_pt_chown)
00db10
+if test $build_pt_chown = yes; then
00db10
+  AC_DEFINE(HAVE_PT_CHOWN)
00db10
+fi
00db10
+
00db10
 # The way shlib-versions is used to generate soversions.mk uses a
00db10
 # fairly simplistic model for name recognition that can't distinguish
00db10
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
00db10
diff -Nru glibc-2.17-c758a686/INSTALL glibc-2.17-c758a686/INSTALL
00db10
--- glibc-2.17-c758a686/INSTALL	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/INSTALL	2013-07-24 00:20:07.650300624 -0400
00db10
@@ -128,6 +128,18 @@ will be used, and CFLAGS sets optimizati
00db10
      this can be prevented though there generally is no reason since it
00db10
      creates compatibility problems.
00db10
 
00db10
+`--enable-pt_chown'
00db10
+     The file `pt_chown' is a helper binary for `grantpt' (*note
00db10
+     Pseudo-Terminals: Allocation.) that is installed setuid root to
00db10
+     fix up pseudo-terminal ownership.  It is not built by default
00db10
+     because systems using the Linux kernel are commonly built with the
00db10
+     `devpts' filesystem enabled and mounted at `/dev/pts', which
00db10
+     manages pseudo-terminal ownership automatically.  By using
00db10
+     `--enable-pt_chown', you may build `pt_chown' and install it
00db10
+     setuid and owned by `root'.  The use of `pt_chown' introduces
00db10
+     additional security risks to the system and you should enable it
00db10
+     only if you understand and accept those risks.
00db10
+
00db10
 `--build=BUILD-SYSTEM'
00db10
 `--host=HOST-SYSTEM'
00db10
      These options are for cross-compiling.  If you specify both
00db10
diff -Nru glibc-2.17-c758a686/login/Makefile glibc-2.17-c758a686/login/Makefile
00db10
--- glibc-2.17-c758a686/login/Makefile	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/login/Makefile	2013-07-24 00:20:07.660298670 -0400
00db10
@@ -29,9 +29,15 @@ routines := getutent getutent_r getutid 
00db10
 
00db10
 CFLAGS-grantpt.c = -DLIBEXECDIR='"$(libexecdir)"'
00db10
 
00db10
-others = utmpdump pt_chown
00db10
+others = utmpdump
00db10
+
00db10
+include ../Makeconfig
00db10
+
00db10
+ifeq (yes,$(build-pt-chown))
00db10
+others += pt_chown
00db10
 others-pie = pt_chown
00db10
 install-others-programs = $(inst_libexecdir)/pt_chown
00db10
+endif
00db10
 
00db10
 subdir-dirs = programs
00db10
 vpath %.c programs
00db10
diff -Nru glibc-2.17-c758a686/manual/install.texi glibc-2.17-c758a686/manual/install.texi
00db10
--- glibc-2.17-c758a686/manual/install.texi	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/manual/install.texi	2013-07-24 00:20:07.662298261 -0400
00db10
@@ -155,6 +155,20 @@ if the used tools support it.  By using 
00db10
 prevented though there generally is no reason since it creates
00db10
 compatibility problems.
00db10
 
00db10
+@pindex pt_chown
00db10
+@findex grantpt
00db10
+@item --enable-pt_chown
00db10
+The file @file{pt_chown} is a helper binary for @code{grantpt}
00db10
+(@pxref{Allocation, Pseudo-Terminals}) that is installed setuid root to
00db10
+fix up pseudo-terminal ownership.  It is not built by default because
00db10
+systems using the Linux kernel are commonly built with the @code{devpts}
00db10
+filesystem enabled and mounted at @file{/dev/pts}, which manages
00db10
+pseudo-terminal ownership automatically.  By using
00db10
+@samp{--enable-pt_chown}, you may build @file{pt_chown} and install it
00db10
+setuid and owned by @code{root}.  The use of @file{pt_chown} introduces
00db10
+additional security risks to the system and you should enable it only if
00db10
+you understand and accept those risks.
00db10
+
00db10
 @item --build=@var{build-system}
00db10
 @itemx --host=@var{host-system}
00db10
 These options are for cross-compiling.  If you specify both options and
00db10
diff -Nru glibc-2.17-c758a686/sysdeps/unix/grantpt.c glibc-2.17-c758a686/sysdeps/unix/grantpt.c
00db10
--- glibc-2.17-c758a686/sysdeps/unix/grantpt.c	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/unix/grantpt.c	2013-07-24 00:20:07.663299235 -0400
00db10
@@ -173,9 +173,10 @@ grantpt (int fd)
00db10
   retval = 0;
00db10
   goto cleanup;
00db10
 
00db10
-  /* We have to use the helper program.  */
00db10
+  /* We have to use the helper program if it is available.  */
00db10
  helper:;
00db10
 
00db10
+#ifdef HAVE_PT_CHOWN
00db10
   pid_t pid = __fork ();
00db10
   if (pid == -1)
00db10
     goto cleanup;
00db10
@@ -190,9 +191,9 @@ grantpt (int fd)
00db10
 	if (__dup2 (fd, PTY_FILENO) < 0)
00db10
 	  _exit (FAIL_EBADF);
00db10
 
00db10
-#ifdef CLOSE_ALL_FDS
00db10
+# ifdef CLOSE_ALL_FDS
00db10
       CLOSE_ALL_FDS ();
00db10
-#endif
00db10
+# endif
00db10
 
00db10
       execle (_PATH_PT_CHOWN, basename (_PATH_PT_CHOWN), NULL, NULL);
00db10
       _exit (FAIL_EXEC);
00db10
@@ -231,6 +232,7 @@ grantpt (int fd)
00db10
 	    assert(! "getpt: internal error: invalid exit code from pt_chown");
00db10
 	  }
00db10
     }
00db10
+#endif
00db10
 
00db10
  cleanup:
00db10
   if (buf != _buf)
00db10
diff -Nru glibc-2.17-c758a686/sysdeps/unix/sysv/linux/grantpt.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/grantpt.c
00db10
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/grantpt.c	2012-12-24 22:02:13.000000000 -0500
00db10
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/grantpt.c	2013-07-24 00:20:07.664298465 -0400
00db10
@@ -11,7 +11,7 @@
00db10
 
00db10
 #include "pty-private.h"
00db10
 
00db10
-
00db10
+#if HAVE_PT_CHOWN
00db10
 /* Close all file descriptors except the one specified.  */
00db10
 static void
00db10
 close_all_fds (void)
00db10
@@ -38,6 +38,7 @@ close_all_fds (void)
00db10
       __dup2 (STDOUT_FILENO, STDERR_FILENO);
00db10
     }
00db10
 }
00db10
-#define CLOSE_ALL_FDS() close_all_fds()
00db10
+# define CLOSE_ALL_FDS() close_all_fds()
00db10
+#endif
00db10
 
00db10
 #include <sysdeps/unix/grantpt.c>