This is an automated email from the git hooks/post-receive script.

aurel32 pushed a commit to branch jessie
in repository glibc.

commit 412b811106810505e4095bf8fdd9788714a75886
Author: Aurelien Jarno <aurel...@aurel32.net>
Date:   Sat Jun 17 00:51:33 2017 +0200

    debian/patches/any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff, 
debian/patches/any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff, 
debian/patches/any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff: add patches to 
protect the dynamic linker against stack clashes (CVE-2017-1000366).
---
 debian/changelog                                   |  10 +
 .../any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff  | 205 +++++++++++++++++++++
 ...ocal-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff |  33 ++++
 .../local-CVE-2017-1000366-rtld-LD_PRELOAD.diff    | 111 +++++++++++
 debian/patches/series                              |   3 +
 5 files changed, 362 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index d7d6931..bbb1223 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+glibc (2.19-18+deb8u10) jessie-security; urgency=medium
+
+  * debian/patches/any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff,
+    debian/patches/any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff,
+    debian/patches/any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff: add
+    patches to protect the dynamic linker against stack clashes
+    (CVE-2017-1000366).
+
+ -- Aurelien Jarno <aure...@debian.org>  Fri, 16 Jun 2017 23:13:21 +0200
+
 glibc (2.19-18+deb8u9) stable; urgency=medium
 
   * Remove patches/any/cvs-resolv-internal-qtype.diff, it breaks the
diff --git a/debian/patches/any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff 
b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff
new file mode 100644
index 0000000..a8ede37
--- /dev/null
+++ b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff
@@ -0,0 +1,205 @@
+From ba67ba3275d47e0080f0e5f09d9f5102c000c97e Mon Sep 17 00:00:00 2001
+Message-Id: 
<ba67ba3275d47e0080f0e5f09d9f5102c000c97e.1495998948.git.fwei...@redhat.com>
+In-Reply-To: <cover.1495998948.git.fwei...@redhat.com>
+References: <cover.1495998948.git.fwei...@redhat.com>
+From: Florian Weimer <fwei...@redhat.com>
+Date: Sun, 28 May 2017 20:44:52 +0200
+Subject: [PATCH 3/3] rtld: Reject overly long LD_AUDIT path elements
+To: libc-al...@sourceware.org
+
+Also only process the last LD_AUDIT entry.
+---
+ elf/rtld.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
+ 1 file changed, 95 insertions(+), 15 deletions(-)
+
+diff --git a/elf/rtld.c b/elf/rtld.c
+index 30f0cae..89d8573 100644
+--- a/elf/rtld.c
++++ b/elf/rtld.c
+@@ -116,13 +116,91 @@ dso_name_valid_for_suid (const char *p)
+   return *p != '\0';
+ }
+ 
+-/* List of auditing DSOs.  */
++/* LD_AUDIT variable contents.  Must be processed before the
++   audit_list below.  */
++const char *audit_list_string;
++
++/* Cyclic list of auditing DSOs.  audit_list->next is the first
++   element.  */
+ static struct audit_list
+ {
+   const char *name;
+   struct audit_list *next;
+ } *audit_list;
+ 
++/* Iterator for audit_list_string followed by audit_list.  */
++struct audit_list_iter
++{
++  /* Tail of audit_list_string still needing processing, or NULL.  */
++  const char *audit_list_tail;
++
++  /* The list element returned in the previous iteration.  NULL before
++     the first element.  */
++  struct audit_list *previous;
++
++  /* Scratch buffer for returning a name which is part of
++     audit_list_string.  */
++  char fname[PATH_MAX];
++};
++
++/* Initialize an audit list iterator.  */
++static void
++audit_list_iter_init (struct audit_list_iter *iter)
++{
++  iter->audit_list_tail = audit_list_string;
++  iter->previous = NULL;
++}
++
++/* Iterate through both audit_list_string and audit_list.  */
++static const char *
++audit_list_iter_next (struct audit_list_iter *iter)
++{
++  if (iter->audit_list_tail != NULL)
++    {
++      /* First iterate over audit_list_string.  */
++      while (*iter->audit_list_tail != '\0')
++      {
++        /* Split audit list at colon.  */
++        size_t len = strcspn (iter->audit_list_tail, ":");
++        if (len > 0 && len < PATH_MAX)
++          {
++            memcpy (iter->fname, iter->audit_list_tail, len);
++            iter->fname[len] = '\0';
++          }
++        else
++          /* Do not return this name to the caller.  */
++          iter->fname[0] = '\0';
++
++        /* Skip over the substring and the following delimiter.  */
++        iter->audit_list_tail += len;
++        if (*iter->audit_list_tail == ':')
++          ++iter->audit_list_tail;
++
++        /* If the name is valid, return it.  */
++        if (dso_name_valid_for_suid (iter->fname))
++          return iter->fname;
++        /* Otherwise, wrap around and try the next name.  */
++      }
++      /* Fall through to the procesing of audit_list.  */
++    }
++
++  if (iter->previous == NULL)
++    {
++      if (audit_list == NULL)
++      /* No pre-parsed audit list.  */
++      return NULL;
++      /* Start of audit list.  The first list element is at
++       audit_list->next (cyclic list).  */
++      iter->previous = audit_list->next;
++      return iter->previous->name;
++    }
++  if (iter->previous == audit_list)
++    /* Cyclic list wrap-around.  */
++    return NULL;
++  iter->previous = iter->previous->next;
++  return iter->previous->name;
++}
++
+ #ifndef HAVE_INLINED_SYSCALLS
+ /* Set nonzero during loading and initialization of executable and
+    libraries, cleared before the executable's entry point runs.  This
+@@ -1290,11 +1368,13 @@ of this helper program; chances are you did not intend 
to run this program.\n\
+     GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
+ 
+   /* If we have auditing DSOs to load, do it now.  */
+-  if (__builtin_expect (audit_list != NULL, 0))
++  bool need_security_init = true;
++  if (__builtin_expect (audit_list != NULL, 0)
++      || __builtin_expect (audit_list_string != NULL, 0))
+     {
+-      /* Iterate over all entries in the list.  The order is important.  */
+       struct audit_ifaces *last_audit = NULL;
+-      struct audit_list *al = audit_list->next;
++      struct audit_list_iter al_iter;
++      audit_list_iter_init (&al_iter);
+ 
+       /* Since we start using the auditing DSOs right away we need to
+        initialize the data structures now.  */
+@@ -1305,9 +1385,14 @@ of this helper program; chances are you did not intend 
to run this program.\n\
+        use different values (especially the pointer guard) and will
+        fail later on.  */
+       security_init ();
++      need_security_init = false;
+ 
+-      do
++      while (true)
+       {
++        const char *name = audit_list_iter_next (&al_iter);
++        if (name == NULL)
++          break;
++
+         int tls_idx = GL(dl_tls_max_dtv_idx);
+ 
+         /* Now it is time to determine the layout of the static TLS
+@@ -1316,7 +1401,7 @@ of this helper program; chances are you did not intend 
to run this program.\n\
+            no DF_STATIC_TLS bit is set.  The reason is that we know
+            glibc will use the static model.  */
+         struct dlmopen_args dlmargs;
+-        dlmargs.fname = al->name;
++        dlmargs.fname = name;
+         dlmargs.map = NULL;
+ 
+         const char *objname;
+@@ -1329,7 +1414,7 @@ of this helper program; chances are you did not intend 
to run this program.\n\
+           not_loaded:
+             _dl_error_printf ("\
+ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; 
ignored.\n",
+-                              al->name, err_str);
++                              name, err_str);
+             if (malloced)
+               free ((char *) err_str);
+           }
+@@ -1433,10 +1518,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit 
interface: %s; ignored.\n",
+                 goto not_loaded;
+               }
+           }
+-
+-        al = al->next;
+       }
+-      while (al != audit_list->next);
+ 
+       /* If we have any auditing modules, announce that we already
+        have two objects loaded.  */
+@@ -1700,7 +1782,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit 
interface: %s; ignored.\n",
+   if (tcbp == NULL)
+     tcbp = init_tls ();
+ 
+-  if (__builtin_expect (audit_list == NULL, 1))
++  if (__builtin_expect (need_security_init, true))
+     /* Initialize security features.  But only if we have not done it
+        earlier.  */
+     security_init ();
+@@ -2331,9 +2413,7 @@ process_dl_audit (char *str)
+   char *p;
+ 
+   while ((p = (strsep) (&str, ":")) != NULL)
+-    if (p[0] != '\0'
+-      && (__builtin_expect (! INTUSE(__libc_enable_secure), 1)
+-          || strchr (p, '/') == NULL))
++    if (dso_name_valid_for_suid (p))
+       {
+       /* This is using the local malloc, not the system malloc.  The
+          memory can never be freed.  */
+@@ -2397,7 +2477,7 @@ process_envvars (enum mode *modep)
+             break;
+           }
+         if (memcmp (envline, "AUDIT", 5) == 0)
+-          process_dl_audit (&envline[6]);
++          audit_list_string = &envline[6];
+         break;
+ 
+       case 7:
+-- 
+2.9.4
+
diff --git 
a/debian/patches/any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff 
b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff
new file mode 100644
index 0000000..88b1925
--- /dev/null
+++ b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff
@@ -0,0 +1,33 @@
+From 4d009d39ac9ede0369e268554a181b428f177a80 Mon Sep 17 00:00:00 2001
+Message-Id: 
<4d009d39ac9ede0369e268554a181b428f177a80.1495998948.git.fwei...@redhat.com>
+In-Reply-To: <cover.1495998948.git.fwei...@redhat.com>
+References: <cover.1495998948.git.fwei...@redhat.com>
+From: Florian Weimer <fwei...@redhat.com>
+Date: Sun, 28 May 2017 20:37:40 +0200
+Subject: [PATCH 1/3] rtld: Completely ignore LD_LIBRARY_PATH for AT_SECURE=1
+ programs
+To: libc-al...@sourceware.org
+
+LD_LIBRARY_PATH can only be used to reorder system search paths, which
+is not useful functionality.
+---
+ elf/rtld.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/elf/rtld.c b/elf/rtld.c
+index 319ef06..824b6cf 100644
+--- a/elf/rtld.c
++++ b/elf/rtld.c
+@@ -2419,7 +2419,8 @@ process_envvars (enum mode *modep)
+ 
+       case 12:
+         /* The library search path.  */
+-        if (memcmp (envline, "LIBRARY_PATH", 12) == 0)
++        if (!__libc_enable_secure
++            && memcmp (envline, "LIBRARY_PATH", 12) == 0)
+           {
+             library_path = &envline[13];
+             break;
+-- 
+2.9.4
+
diff --git a/debian/patches/any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff 
b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff
new file mode 100644
index 0000000..a71a4d4
--- /dev/null
+++ b/debian/patches/any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff
@@ -0,0 +1,111 @@
+From 65ff0b7a085b85271ec8fde99f542281b495e3bc Mon Sep 17 00:00:00 2001
+Message-Id: 
<65ff0b7a085b85271ec8fde99f542281b495e3bc.1495998948.git.fwei...@redhat.com>
+In-Reply-To: <cover.1495998948.git.fwei...@redhat.com>
+References: <cover.1495998948.git.fwei...@redhat.com>
+From: Florian Weimer <fwei...@redhat.com>
+Date: Sun, 28 May 2017 20:57:40 +0200
+Subject: [PATCH 2/3] rtld: Reject overly long LD_PRELOAD path elements
+To: libc-al...@sourceware.org
+
+---
+ elf/rtld.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---------------
+ 1 file changed, 53 insertions(+), 16 deletions(-)
+
+diff --git a/elf/rtld.c b/elf/rtld.c
+index 824b6cf..30f0cae 100644
+--- a/elf/rtld.c
++++ b/elf/rtld.c
+@@ -99,6 +99,22 @@ uintptr_t __pointer_chk_guard_local
+ strong_alias (__pointer_chk_guard_local, __pointer_chk_guard)
+ #endif
+ 
++/* Check that AT_SECURE=0, or that the passed name does not contain
++   directories and is not overly long.  Reject empty names
++   unconditionally.  */
++static bool
++dso_name_valid_for_suid (const char *p)
++{
++  if (__glibc_unlikely (__libc_enable_secure))
++    {
++      /* Ignore pathnames with directories for AT_SECURE=1
++       programs, and also skip overlong names.  */
++      size_t len = strlen (p);
++      if (len >= NAME_MAX || memchr (p, '/', len) != NULL)
++      return false;
++    }
++  return *p != '\0';
++}
+ 
+ /* List of auditing DSOs.  */
+ static struct audit_list
+@@ -716,6 +732,42 @@ static const char *preloadlist attribute_relro;
+ /* Nonzero if information about versions has to be printed.  */
+ static int version_info attribute_relro;
+ 
++/* The LD_PRELOAD environment variable gives list of libraries
++   separated by white space or colons that are loaded before the
++   executable's dependencies and prepended to the global scope list.
++   (If the binary is running setuid all elements containing a '/' are
++   ignored since it is insecure.)  Return the number of preloads
++   performed.  */
++unsigned int
++handle_ld_preload (const char *preloadlist, struct link_map *main_map)
++{
++  unsigned int npreloads = 0;
++  const char *p = preloadlist;
++  char fname[PATH_MAX];
++
++  while (*p != '\0')
++    {
++      /* Split preload list at space/colon.  */
++      size_t len = strcspn (p, " :");
++      if (len > 0 && len < PATH_MAX)
++      {
++        memcpy (fname, p, len);
++        fname[len] = '\0';
++      }
++      else
++      fname[0] = '\0';
++
++      /* Skip over the substring and the following delimiter.  */
++      p += len;
++      if (*p == ' ' || *p == ':')
++      ++p;
++
++      if (dso_name_valid_for_suid (fname))
++      npreloads += do_preload (fname, main_map, "LD_PRELOAD");
++    }
++  return npreloads;
++}
++
+ static void
+ dl_main (const ElfW(Phdr) *phdr,
+        ElfW(Word) phnum,
+@@ -1462,23 +1514,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit 
interface: %s; ignored.\n",
+ 
+   if (__builtin_expect (preloadlist != NULL, 0))
+     {
+-      /* The LD_PRELOAD environment variable gives list of libraries
+-       separated by white space or colons that are loaded before the
+-       executable's dependencies and prepended to the global scope
+-       list.  If the binary is running setuid all elements
+-       containing a '/' are ignored since it is insecure.  */
+-      char *list = strdupa (preloadlist);
+-      char *p;
+-
+       HP_TIMING_NOW (start);
+-
+-      /* Prevent optimizing strsep.  Speed is not important here.  */
+-      while ((p = (strsep) (&list, " :")) != NULL)
+-      if (p[0] != '\0'
+-          && (__builtin_expect (! INTUSE(__libc_enable_secure), 1)
+-              || strchr (p, '/') == NULL))
+-        npreloads += do_preload (p, main_map, "LD_PRELOAD");
+-
++      npreloads += handle_ld_preload (preloadlist, main_map);
+       HP_TIMING_NOW (stop);
+       HP_TIMING_DIFF (diff, start, stop);
+       HP_TIMING_ACCUM_NT (load_time, diff);
+-- 
+2.9.4
+
diff --git a/debian/patches/series b/debian/patches/series
index 746f71c..ade96a1 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -274,3 +274,6 @@ any/cvs-wscanf.diff
 any/cvs-ldconfig-aux-cache.diff
 any/cvs-grantpt-pty-owner.diff
 any/cvs-hesiod-resolver.diff
+any/local-CVE-2017-1000366-rtld-LD_LIBRARY_PATH.diff
+any/local-CVE-2017-1000366-rtld-LD_PRELOAD.diff
+any/local-CVE-2017-1000366-rtld-LD_AUDIT.diff

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-glibc/glibc.git

Reply via email to