ce426f
#
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
# Release date is RHEL 7.1 RC.
ce426f
# CVE-2014-8121:
ce426f
# Unexpected closing of nss_files databases after lookups causes denial of service 
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
# EMARGOED!!! -- EMBARGOED!!! -- EMBARGOED!!!
ce426f
#
ce426f
diff -up glibc-2.17-c758a686/nss/Makefile.rh1165192 glibc-2.17-c758a686/nss/Makefile
ce426f
--- glibc-2.17-c758a686/nss/Makefile.rh1165192	2015-01-14 21:22:57.558006945 +0100
ce426f
+++ glibc-2.17-c758a686/nss/Makefile	2015-01-14 21:44:59.657777124 +0100
ce426f
@@ -38,7 +38,7 @@ install-bin             := getent makedb
ce426f
 makedb-modules = xmalloc hash-string
ce426f
 extra-objs		+= $(makedb-modules:=.o)
ce426f
 
ce426f
-tests			= test-netdb tst-nss-test1 bug17079
ce426f
+tests			= test-netdb tst-nss-test1 bug17079 tst-nss-getpwent
ce426f
 xtests			= bug-erange
ce426f
 
ce426f
 include ../Makeconfig
ce426f
diff -up glibc-2.17-c758a686/nss/nss_files/files-XXX.c.rh1165192 glibc-2.17-c758a686/nss/nss_files/files-XXX.c
ce426f
--- glibc-2.17-c758a686/nss/nss_files/files-XXX.c.rh1165192	2015-01-14 21:22:14.630721754 +0100
ce426f
+++ glibc-2.17-c758a686/nss/nss_files/files-XXX.c	2015-01-14 21:22:15.072725814 +0100
ce426f
@@ -135,7 +135,7 @@ CONCAT(_nss_files_set,ENTNAME) (int stay
ce426f
 
ce426f
   __libc_lock_lock (lock);
ce426f
 
ce426f
-  status = internal_setent (stayopen);
ce426f
+  status = internal_setent (1);
ce426f
 
ce426f
   if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0)
ce426f
     {
ce426f
diff -up glibc-2.17-c758a686/nss/tst-nss-getpwent.c.rh1165192 glibc-2.17-c758a686/nss/tst-nss-getpwent.c
ce426f
--- glibc-2.17-c758a686/nss/tst-nss-getpwent.c.rh1165192	2015-01-14 21:23:50.003236107 +0100
ce426f
+++ glibc-2.17-c758a686/nss/tst-nss-getpwent.c	2015-01-14 21:46:39.912194368 +0100
ce426f
@@ -0,0 +1,116 @@
ce426f
+/* Copyright (C) 2015 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <pwd.h>
ce426f
+#include <stdbool.h>
ce426f
+#include <stdio.h>
ce426f
+#include <stdlib.h>
ce426f
+#include <string.h>
ce426f
+
ce426f
+int
ce426f
+do_test (void)
ce426f
+{
ce426f
+  /* Count the number of entries in the password database, and fetch
ce426f
+     data from the first and last entries.  */
ce426f
+  size_t count = 0;
ce426f
+  struct passwd * pw;
ce426f
+  char *first_name = NULL;
ce426f
+  uid_t first_uid = 0;
ce426f
+  char *last_name = NULL;
ce426f
+  uid_t last_uid = 0;
ce426f
+  setpwent ();
ce426f
+  while ((pw  = getpwent ()) != NULL)
ce426f
+    {
ce426f
+      if (first_name == NULL)
ce426f
+	{
ce426f
+	  first_name = strdup (pw->pw_name);
ce426f
+	  if (first_name == NULL)
ce426f
+	    {
ce426f
+	      printf ("strdup: %m\n");
ce426f
+	      return 1;
ce426f
+	    }
ce426f
+	  first_uid = pw->pw_uid;
ce426f
+	}
ce426f
+      
ce426f
+      free (last_name);
ce426f
+      last_name = strdup (pw->pw_name);
ce426f
+      if (last_name == NULL)
ce426f
+	{
ce426f
+	  printf ("strdup: %m\n");
ce426f
+	  return 1;
ce426f
+	}
ce426f
+      last_uid = pw->pw_uid;
ce426f
+      ++count;
ce426f
+    }
ce426f
+  endpwent ();
ce426f
+
ce426f
+  if (count == 0)
ce426f
+    {
ce426f
+      printf ("No entries in the password database.\n");
ce426f
+      return 0;
ce426f
+    }
ce426f
+
ce426f
+  /* Try again, this time interleaving with name-based and UID-based
ce426f
+     lookup operations.  The counts do not match if the interleaved
ce426f
+     lookups affected the enumeration.  */
ce426f
+  size_t new_count = 0;
ce426f
+  setpwent ();
ce426f
+  while ((pw  = getpwent ()) != NULL)
ce426f
+    {
ce426f
+      if (new_count == count)
ce426f
+	{
ce426f
+	  printf ("Additional entry in the password database.\n");
ce426f
+	  return 1;
ce426f
+	}
ce426f
+      ++new_count;
ce426f
+      struct passwd *pw2 = getpwnam (first_name);
ce426f
+      if (pw2 == NULL)
ce426f
+	{
ce426f
+	  printf ("getpwnam (%s) failed: %m\n", first_name);
ce426f
+	  return 1;
ce426f
+	}
ce426f
+      pw2 = getpwnam (last_name);
ce426f
+      if (pw2 == NULL)
ce426f
+	{
ce426f
+	  printf ("getpwnam (%s) failed: %m\n", last_name);
ce426f
+	  return 1;
ce426f
+	}
ce426f
+      pw2 = getpwuid (first_uid);
ce426f
+      if (pw2 == NULL)
ce426f
+	{
ce426f
+	  printf ("getpwuid (%llu) failed: %m\n", (unsigned long long) first_uid);
ce426f
+	  return 1;
ce426f
+	}
ce426f
+      pw2 = getpwuid (last_uid);
ce426f
+      if (pw2 == NULL)
ce426f
+	{
ce426f
+	  printf ("getpwuid (%llu) failed: %m\n", (unsigned long long) last_uid);
ce426f
+	  return 1;
ce426f
+	}
ce426f
+    }
ce426f
+  endpwent ();
ce426f
+  if (new_count < count)
ce426f
+    {
ce426f
+      printf ("Missing entry in the password database.\n");
ce426f
+      return 1;
ce426f
+    }
ce426f
+  
ce426f
+  return 0;
ce426f
+}
ce426f
+
ce426f
+#define TEST_FUNCTION do_test ()
ce426f
+#include "../test-skeleton.c"