Ticket #1185: glibc-2.26-glob_exploit-1.patch

File glibc-2.26-glob_exploit-1.patch, 8.5 KB (added by William Harrington, 6 years ago)

GLIBC 2.26 GLOB TILDE exploit fixes

  • ChangeLog

    Submitted by: William Harrington (kb0iic at clfs dot ort)
    Date: 2018-01-05
    Initial Package Version: 2.26
    Origin: https://sourceware.org/bugzilla/show_bug.cgi?id=22320
            https://sourceware.org/bugzilla/show_bug.cgi?id=22325
            https://sourceware.org/bugzilla/show_bug.cgi?id=22332
    
    Description: Fixes Memory leak in glob with GLOB_TILDE
                 Fixes Buffer overflow in glob with GLOB_TILDE in unescaping
    
    diff -Naur glibc-2.26.orig/ChangeLog glibc-2.26/ChangeLog
    old new  
     12017-10-22  Paul Eggert <eggert@cs.ucla.edu>
     2
     3       [BZ #22332]
     4       * posix/glob.c (__glob): Fix buffer overflow during GLOB_TILDE
     5       unescaping.
     6
     72017-10-21  Florian Weimer  <fweimer@redhat.com>
     8
     9        * posix/Makefile (tests): Add tst-glob-tilde.
     10        (tests-special): Add tst-glob-tilde-mem.out
     11        (tst-glob-tilde-ENV): Set MALLOC_TRACE.
     12        (tst-glob-tilde-mem.out): Add mtrace check.
     13        * posix/tst-glob-tilde.c: New file.
     14
     152017-10-20  Paul Eggert <eggert@cs.ucla.edu>
     16
     17       [BZ #22320]
     18       CVE-2017-15670
     19       * posix/glob.c (__glob): Fix one-byte overflow.
     20
    1212017-08-02  Siddhesh Poyarekar  <siddhesh@sourceware.org>
    222
    323        * version.h (RELEASE): Set to "stable"
  • glibc-2.26

    diff -Naur glibc-2.26.orig/NEWS glibc-2.26/NEWS
    old new  
    206206* A use-after-free vulnerability in clntudp_call in the Sun RPC system has been
    207207  fixed (CVE-2017-12133).
    208208
     209  CVE-2017-15670: The glob function, when invoked with GLOB_TILDE,
     210  suffered from a one-byte overflow during ~ operator processing (either
     211  on the stack or the heap, depending on the length of the user name).
     212  Reported by Tim RÃŒhsen.
     213
    209214The following bugs are resolved with this release:
    210215
    211216  [984] network: Respond to changed resolv.conf in gethostbyname
  • posix/Makefile

    diff -Naur glibc-2.26.orig/posix/Makefile glibc-2.26/posix/Makefile
    old new  
    9393                   tst-fnmatch3 bug-regex36 tst-getaddrinfo5 \
    9494                   tst-posix_spawn-fd tst-posix_spawn-setsid \
    9595                   tst-posix_fadvise tst-posix_fadvise64 \
    96                    tst-sysconf-empty-chroot
     96                   tst-sysconf-empty-chroot tst-glob-tilde
    9797tests-internal  := bug-regex5 bug-regex20 bug-regex33 \
    9898                   tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3
    9999xtests          := bug-ga2
     
    141141                 $(objpfx)tst-rxspencer-no-utf8-mem.out $(objpfx)tst-pcre-mem.out \
    142142                 $(objpfx)tst-boost-mem.out $(objpfx)tst-getconf.out \
    143143                 $(objpfx)bug-glob2-mem.out $(objpfx)tst-vfork3-mem.out \
    144                  $(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out
     144                 $(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out \
     145                 $(objpfx)tst-glob-tilde-mem.out
    145146xtests-special += $(objpfx)bug-ga2-mem.out
    146147endif
    147148
     
    350351        $(common-objpfx)malloc/mtrace $(objpfx)bug-glob2.mtrace > $@; \
    351352        $(evaluate-test)
    352353
     354tst-glob-tilde-ENV = MALLOC_TRACE=$(objpfx)tst-glob-tilde.mtrace
     355
     356$(objpfx)tst-glob-tilde-mem.out: $(objpfx)tst-glob-tilde.out
     357        $(common-objpfx)malloc/mtrace $(objpfx)tst-glob-tilde.mtrace > $@; \
     358        $(evaluate-test)
     359
    353360$(inst_libexecdir)/getconf: $(inst_bindir)/getconf \
    354361                            $(objpfx)getconf.speclist FORCE
    355362        $(addprefix $(..)./scripts/mkinstalldirs ,\
  • posix/glob.c

    diff -Naur glibc-2.26.orig/posix/glob.c glibc-2.26/posix/glob.c
    old new  
    843843                  *p = '\0';
    844844                }
    845845              else
    846                 *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
     846                *((char *) mempcpy (newp, dirname + 1, end_name - dirname - 1))
    847847                  = '\0';
    848848              user_name = newp;
    849849            }
  • posix/tst-glob-tilde.c

    diff -Naur glibc-2.26.orig/posix/tst-glob-tilde.c glibc-2.26/posix/tst-glob-tilde.c
    old new  
     1/* Check for GLOB_TIDLE heap allocation issues (bugs 22320, 22325, 22332).
     2   Copyright (C) 2017 Free Software Foundation, Inc.
     3   This file is part of the GNU C Library.
     4
     5   The GNU C Library is free software; you can redistribute it and/or
     6   modify it under the terms of the GNU Lesser General Public
     7   License as published by the Free Software Foundation; either
     8   version 2.1 of the License, or (at your option) any later version.
     9
     10   The GNU C Library is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   Lesser General Public License for more details.
     14
     15   You should have received a copy of the GNU Lesser General Public
     16   License along with the GNU C Library; if not, see
     17   <http://www.gnu.org/licenses/>.  */
     18
     19#include <glob.h>
     20#include <mcheck.h>
     21#include <nss.h>
     22#include <pwd.h>
     23#include <stdlib.h>
     24#include <string.h>
     25#include <support/check.h>
     26#include <support/support.h>
     27
     28/* Flag which indicates whether to pass the GLOB_ONLYDIR flag.  */
     29static int do_onlydir;
     30
     31/* Flag which indicates whether to pass the GLOB_NOCHECK flag.  */
     32static int do_nocheck;
     33
     34/* Flag which indicates whether to pass the GLOB_MARK flag.  */
     35static int do_mark;
     36
     37/* Flag which indicates whether to pass the GLOB_NOESCAPE flag.  */
     38static int do_noescape;
     39
     40static void
     41one_test (const char *prefix, const char *middle, const char *suffix)
     42{
     43  char *pattern = xasprintf ("%s%s%s", prefix, middle, suffix);
     44  int flags = GLOB_TILDE;
     45  if (do_onlydir)
     46    flags |= GLOB_ONLYDIR;
     47  if (do_nocheck)
     48    flags |= GLOB_NOCHECK;
     49  if (do_mark)
     50    flags |= GLOB_MARK;
     51  if (do_noescape)
     52    flags |= GLOB_NOESCAPE;
     53  glob_t gl;
     54  /* This glob call might result in crashes or memory leaks.  */
     55  if (glob (pattern, flags, NULL, &gl) == 0)
     56    globfree (&gl);
     57  free (pattern);
     58}
     59
     60enum
     61  {
     62    /* The largest base being tested.  */
     63    largest_base_size = 500000,
     64
     65    /* The actual size is the base size plus a variable whose absolute
     66       value is not greater than this.  This helps malloc to trigger
     67       overflows.  */
     68    max_size_skew = 16,
     69
     70    /* The maximum string length supported by repeating_string
     71       below.  */
     72    repeat_size = largest_base_size + max_size_skew,
     73  };
     74
     75/* Used to construct strings which repeat a single character 'x'.  */
     76static char *repeat;
     77
     78/* Return a string of SIZE characters.  */
     79const char *
     80repeating_string (int size)
     81{
     82  TEST_VERIFY (size >= 0);
     83  TEST_VERIFY (size <= repeat_size);
     84  const char *repeated_shifted = repeat + repeat_size - size;
     85  TEST_VERIFY (strlen (repeated_shifted) == size);
     86  return repeated_shifted;
     87}
     88
     89static int
     90do_test (void)
     91{
     92  /* Avoid network-based NSS modules and initialize nss_files with a
     93     dummy lookup.  This has to come before mtrace because NSS does
     94     not free all memory.  */
     95  __nss_configure_lookup ("passwd", "files");
     96  (void) getpwnam ("root");
     97
     98  mtrace ();
     99
     100  repeat = xmalloc (repeat_size + 1);
     101  memset (repeat, 'x', repeat_size);
     102  repeat[repeat_size] = '\0';
     103
     104  /* These numbers control the size of the user name.  The values
     105     cover the minimum (0), a typical size (8), a large
     106     stack-allocated size (100000), and a somewhat large
     107     heap-allocated size (largest_base_size).  */
     108  static const int base_sizes[] = { 0, 8, 100, 100000, largest_base_size, -1 };
     109
     110  for (do_onlydir = 0; do_onlydir < 2; ++do_onlydir)
     111    for (do_nocheck = 0; do_nocheck < 2; ++do_nocheck)
     112      for (do_mark = 0; do_mark < 2; ++do_mark)
     113        for (do_noescape = 0; do_noescape < 2; ++do_noescape)
     114          for (int base_idx = 0; base_sizes[base_idx] >= 0; ++base_idx)
     115            {
     116              for (int size_skew = -max_size_skew; size_skew <= max_size_skew;
     117                   ++size_skew)
     118                {
     119                  int size = base_sizes[base_idx] + size_skew;
     120                  if (size < 0)
     121                    continue;
     122
     123                  const char *user_name = repeating_string (size);
     124                  one_test ("~", user_name, "/a/b");
     125                  one_test ("~", user_name, "x\\x\\x////x\\a");
     126                }
     127
     128              const char *user_name = repeating_string (base_sizes[base_idx]);
     129              one_test ("~", user_name, "");
     130              one_test ("~", user_name, "/");
     131              one_test ("~", user_name, "/a");
     132              one_test ("~", user_name, "/*/*");
     133              one_test ("~", user_name, "\\/");
     134              one_test ("/~", user_name, "");
     135              one_test ("*/~", user_name, "/a/b");
     136            }
     137
     138  free (repeat);
     139
     140  return 0;
     141}
     142
     143#include <support/test-driver.c>