Browse code

glibc : Fix CVE-2017-16997

Change-Id: Ia50d26676d59c7a703db1102e06b350737c52116
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4620
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Divya Thaluru <dthaluru@vmware.com>

xiaolin-vmware authored on 2018/01/09 10:02:15
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,117 @@
0
+From f24c345bf5486cc8d659f7a17463adcae402ec8e Mon Sep 17 00:00:00 2001
1
+From: Aurelien Jarno <aurelien@aurel32.net>
2
+Date: Sat, 30 Dec 2017 10:54:23 +0100
3
+Subject: [PATCH] elf: Check for empty tokens before dynamic string token
4
+ expansion [BZ #22625]
5
+
6
+The fillin_rpath function in elf/dl-load.c loops over each RPATH or
7
+RUNPATH tokens and interprets empty tokens as the current directory
8
+("./"). In practice the check for empty token is done *after* the
9
+dynamic string token expansion. The expansion process can return an
10
+empty string for the $ORIGIN token if __libc_enable_secure is set
11
+or if the path of the binary can not be determined (/proc not mounted).
12
+
13
+Fix that by moving the check for empty tokens before the dynamic string
14
+token expansion. In addition, check for NULL pointer or empty strings
15
+return by expand_dynamic_string_token.
16
+
17
+The above changes highlighted a bug in decompose_rpath, an empty array
18
+is represented by the first element being NULL at the fillin_rpath
19
+level, but by using a -1 pointer in decompose_rpath and other functions.
20
+
21
+Changelog:
22
+	[BZ #22625]
23
+	* elf/dl-load.c (fillin_rpath): Check for empty tokens before dynamic
24
+	string token expansion. Check for NULL pointer or empty string possibly
25
+	returned by expand_dynamic_string_token.
26
+	(decompose_rpath): Check for empty path after dynamic string
27
+	token expansion.
28
+(cherry picked from commit 3e3c904daef69b8bf7d5cc07f793c9f07c3553ef)
29
+---
30
+ ChangeLog     | 10 ++++++++++
31
+ NEWS          |  4 ++++
32
+ elf/dl-load.c | 49 +++++++++++++++++++++++++++++++++----------------
33
+ 3 files changed, 47 insertions(+), 16 deletions(-)
34
+
35
+ The following bugs are resolved with this release:
36
+ 
37
+   [20790] Fix rpcgen buffer overrun
38
+diff --git a/elf/dl-load.c b/elf/dl-load.c
39
+index 75a1700..1f774e1 100644
40
+--- a/elf/dl-load.c
41
+@@ -434,31 +434,40 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
42
+ {
43
+   char *cp;
44
+   size_t nelems = 0;
45
+-  char *to_free;
46
+ 
47
+   while ((cp = __strsep (&rpath, sep)) != NULL)
48
+     {
49
+       struct r_search_path_elem *dirp;
50
++      char *to_free = NULL;
51
++      size_t len = 0;
52
+ 
53
+-      to_free = cp = expand_dynamic_string_token (l, cp, 1);
54
++      /* `strsep' can pass an empty string.  */
55
++      if (*cp != '\0')
56
++	{
57
++	  to_free = cp = expand_dynamic_string_token (l, cp, 1);
58
+ 
59
+-      size_t len = strlen (cp);
60
++	  /* expand_dynamic_string_token can return NULL in case of empty
61
++	     path or memory allocation failure.  */
62
++	  if (cp == NULL)
63
++	    continue;
64
+ 
65
+-      /* `strsep' can pass an empty string.  This has to be
66
+-	 interpreted as `use the current directory'. */
67
+-      if (len == 0)
68
+-	{
69
+-	  static const char curwd[] = "./";
70
+-	  cp = (char *) curwd;
71
+-	}
72
++	  /* Compute the length after dynamic string token expansion and
73
++	     ignore empty paths.  */
74
++	  len = strlen (cp);
75
++	  if (len == 0)
76
++	    {
77
++	      free (to_free);
78
++	      continue;
79
++	    }
80
+ 
81
+-      /* Remove trailing slashes (except for "/").  */
82
+-      while (len > 1 && cp[len - 1] == '/')
83
+-	--len;
84
++	  /* Remove trailing slashes (except for "/").  */
85
++	  while (len > 1 && cp[len - 1] == '/')
86
++	    --len;
87
+ 
88
+-      /* Now add one if there is none so far.  */
89
+-      if (len > 0 && cp[len - 1] != '/')
90
+-	cp[len++] = '/';
91
++	  /* Now add one if there is none so far.  */
92
++	  if (len > 0 && cp[len - 1] != '/')
93
++	    cp[len++] = '/';
94
++	}
95
+ 
96
+       /* Make sure we don't use untrusted directories if we run SUID.  */
97
+       if (__glibc_unlikely (check_trusted) && !is_trusted_path (cp, len))
98
+@@ -622,6 +631,14 @@ decompose_rpath (struct r_search_path_struct *sps,
99
+      necessary.  */
100
+   free (copy);
101
+ 
102
++  /* There is no path after expansion.  */
103
++  if (result[0] == NULL)
104
++    {
105
++      free (result);
106
++      sps->dirs = (struct r_search_path_elem **) -1;
107
++      return false;
108
++    }
109
++
110
+   sps->dirs = result;
111
+   /* The caller will change this value if we haven't used a real malloc.  */
112
+   sps->malloced = 1;
113
+-- 
114
+2.9.3
115
+
... ...
@@ -6,7 +6,7 @@
6 6
 Summary:        Main C library
7 7
 Name:           glibc
8 8
 Version:        2.22
9
-Release:        17%{?dist}
9
+Release:        18%{?dist}
10 10
 License:        LGPLv2+
11 11
 URL:            http://www.gnu.org/software/libc
12 12
 Group:          Applications/System
... ...
@@ -45,6 +45,7 @@ Patch18:        glibc-fix-CVE-2017-15804.patch
45 45
 Patch19:        glibc-fix-CVE-2015-5180.patch
46 46
 #https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=patch;h=5e7fdabd7df1fc6c56d104e61390bf5a6b526c38
47 47
 Patch20:        glibc-2.22-CVE-2016-5417.patch
48
+Patch21:        glibc-fix-CVE-2017-16997.patch
48 49
 Provides:       rtld(GNU_HASH)
49 50
 Requires:       filesystem
50 51
 %description
... ...
@@ -91,6 +92,7 @@ sed -i 's/\\$$(pwd)/`pwd`/' timezone/Makefile
91 91
 %patch18 -p1
92 92
 %patch19 -p1
93 93
 %patch20 -p1
94
+%patch21 -p1
94 95
 install -vdm 755 %{_builddir}/%{name}-build
95 96
 # do not try to explicitly provide GLIBC_PRIVATE versioned libraries
96 97
 %define __find_provides %{_builddir}/%{name}-%{version}/find_provides.sh
... ...
@@ -217,6 +219,8 @@ popd
217 217
 %{_datarootdir}/locale/locale.alias
218 218
 
219 219
 %changelog
220
+*   Mon Jan 08 2018 Xiaolin Li <xiaolinl@vmware.com> 2.22-18
221
+-   Fix CVE-2017-16997
220 222
 *   Tue Dec 5 2017 Anish Swaminathan <anishs@vmware.com> 2.22-17
221 223
 -   Fix CVE-2016-5417
222 224
 *   Tue Nov 14 2017 Xiaolin Li <xiaolinl@vmware.com> 2.22-16