diff options
Diffstat (limited to 'meta/recipes-core/eglibc/eglibc-2.19/CVE-2014-7817-wordexp-fails-to-honour-WRDE_NOCMD.patch')
-rw-r--r-- | meta/recipes-core/eglibc/eglibc-2.19/CVE-2014-7817-wordexp-fails-to-honour-WRDE_NOCMD.patch | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/meta/recipes-core/eglibc/eglibc-2.19/CVE-2014-7817-wordexp-fails-to-honour-WRDE_NOCMD.patch b/meta/recipes-core/eglibc/eglibc-2.19/CVE-2014-7817-wordexp-fails-to-honour-WRDE_NOCMD.patch new file mode 100644 index 0000000000..6dc6b9ef16 --- /dev/null +++ b/meta/recipes-core/eglibc/eglibc-2.19/CVE-2014-7817-wordexp-fails-to-honour-WRDE_NOCMD.patch | |||
@@ -0,0 +1,164 @@ | |||
1 | From a39208bd7fb76c1b01c127b4c61f9bfd915bfe7c Mon Sep 17 00:00:00 2001 | ||
2 | From: Carlos O'Donell <carlos@redhat.com> | ||
3 | Date: Wed, 19 Nov 2014 11:44:12 -0500 | ||
4 | Subject: [PATCH] CVE-2014-7817: wordexp fails to honour WRDE_NOCMD. | ||
5 | |||
6 | The function wordexp() fails to properly handle the WRDE_NOCMD | ||
7 | flag when processing arithmetic inputs in the form of "$((... ``))" | ||
8 | where "..." can be anything valid. The backticks in the arithmetic | ||
9 | epxression are evaluated by in a shell even if WRDE_NOCMD forbade | ||
10 | command substitution. This allows an attacker to attempt to pass | ||
11 | dangerous commands via constructs of the above form, and bypass | ||
12 | the WRDE_NOCMD flag. This patch fixes this by checking for WRDE_NOCMD | ||
13 | in exec_comm(), the only place that can execute a shell. All other | ||
14 | checks for WRDE_NOCMD are superfluous and removed. | ||
15 | |||
16 | We expand the testsuite and add 3 new regression tests of roughly | ||
17 | the same form but with a couple of nested levels. | ||
18 | |||
19 | On top of the 3 new tests we add fork validation to the WRDE_NOCMD | ||
20 | testing. If any forks are detected during the execution of a wordexp() | ||
21 | call with WRDE_NOCMD, the test is marked as failed. This is slightly | ||
22 | heuristic since vfork might be used in the future, but it provides a | ||
23 | higher level of assurance that no shells were executed as part of | ||
24 | command substitution with WRDE_NOCMD in effect. In addition it doesn't | ||
25 | require libpthread or libdl, instead we use the public implementation | ||
26 | namespace function __register_atfork (already part of the public ABI | ||
27 | for libpthread). | ||
28 | |||
29 | Tested on x86_64 with no regressions. | ||
30 | --- | ||
31 | posix/wordexp-test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ | ||
32 | posix/wordexp.c | 16 ++++------------ | ||
33 | |||
34 | Index: git/posix/wordexp-test.c | ||
35 | =================================================================== | ||
36 | --- git.orig/posix/wordexp-test.c | ||
37 | +++ git/posix/wordexp-test.c | ||
38 | @@ -27,6 +27,25 @@ | ||
39 | |||
40 | #define IFS " \n\t" | ||
41 | |||
42 | +extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden"))); | ||
43 | +extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *); | ||
44 | + | ||
45 | +static int __app_register_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void)) | ||
46 | +{ | ||
47 | + return __register_atfork (prepare, parent, child, | ||
48 | + &__dso_handle == NULL ? NULL : __dso_handle); | ||
49 | +} | ||
50 | + | ||
51 | +/* Number of forks seen. */ | ||
52 | +static int registered_forks; | ||
53 | + | ||
54 | +/* For each fork increment the fork count. */ | ||
55 | +static void | ||
56 | +register_fork (void) | ||
57 | +{ | ||
58 | + registered_forks++; | ||
59 | +} | ||
60 | + | ||
61 | struct test_case_struct | ||
62 | { | ||
63 | int retval; | ||
64 | @@ -206,6 +225,12 @@ struct test_case_struct | ||
65 | { WRDE_SYNTAX, NULL, "$((2+))", 0, 0, { NULL, }, IFS }, | ||
66 | { WRDE_SYNTAX, NULL, "`", 0, 0, { NULL, }, IFS }, | ||
67 | { WRDE_SYNTAX, NULL, "$((010+4+))", 0, 0, { NULL }, IFS }, | ||
68 | + /* Test for CVE-2014-7817. We test 3 combinations of command | ||
69 | + substitution inside an arithmetic expression to make sure that | ||
70 | + no commands are executed and error is returned. */ | ||
71 | + { WRDE_CMDSUB, NULL, "$((`echo 1`))", WRDE_NOCMD, 0, { NULL, }, IFS }, | ||
72 | + { WRDE_CMDSUB, NULL, "$((1+`echo 1`))", WRDE_NOCMD, 0, { NULL, }, IFS }, | ||
73 | + { WRDE_CMDSUB, NULL, "$((1+$((`echo 1`))))", WRDE_NOCMD, 0, { NULL, }, IFS }, | ||
74 | |||
75 | { -1, NULL, NULL, 0, 0, { NULL, }, IFS }, | ||
76 | }; | ||
77 | @@ -258,6 +283,15 @@ main (int argc, char *argv[]) | ||
78 | return -1; | ||
79 | } | ||
80 | |||
81 | + /* If we are not allowed to do command substitution, we install | ||
82 | + fork handlers to verify that no forks happened. No forks should | ||
83 | + happen at all if command substitution is disabled. */ | ||
84 | + if (__app_register_atfork (register_fork, NULL, NULL) != 0) | ||
85 | + { | ||
86 | + printf ("Failed to register fork handler.\n"); | ||
87 | + return -1; | ||
88 | + } | ||
89 | + | ||
90 | for (test = 0; test_case[test].retval != -1; test++) | ||
91 | if (testit (&test_case[test])) | ||
92 | ++fail; | ||
93 | @@ -367,6 +401,9 @@ testit (struct test_case_struct *tc) | ||
94 | |||
95 | printf ("Test %d (%s): ", ++tests, tc->words); | ||
96 | |||
97 | + if (tc->flags & WRDE_NOCMD) | ||
98 | + registered_forks = 0; | ||
99 | + | ||
100 | if (tc->flags & WRDE_APPEND) | ||
101 | { | ||
102 | /* initial wordexp() call, to be appended to */ | ||
103 | @@ -378,6 +415,13 @@ testit (struct test_case_struct *tc) | ||
104 | } | ||
105 | retval = wordexp (tc->words, &we, tc->flags); | ||
106 | |||
107 | + if ((tc->flags & WRDE_NOCMD) | ||
108 | + && (registered_forks > 0)) | ||
109 | + { | ||
110 | + printf ("FAILED fork called for WRDE_NOCMD\n"); | ||
111 | + return 1; | ||
112 | + } | ||
113 | + | ||
114 | if (tc->flags & WRDE_DOOFFS) | ||
115 | start_offs = sav_we.we_offs; | ||
116 | |||
117 | Index: git/posix/wordexp.c | ||
118 | =================================================================== | ||
119 | --- git.orig/posix/wordexp.c | ||
120 | +++ git/posix/wordexp.c | ||
121 | @@ -893,6 +893,10 @@ exec_comm (char *comm, char **word, size | ||
122 | pid_t pid; | ||
123 | int noexec = 0; | ||
124 | |||
125 | + /* Do nothing if command substitution should not succeed. */ | ||
126 | + if (flags & WRDE_NOCMD) | ||
127 | + return WRDE_CMDSUB; | ||
128 | + | ||
129 | /* Don't fork() unless necessary */ | ||
130 | if (!comm || !*comm) | ||
131 | return 0; | ||
132 | @@ -2082,9 +2086,6 @@ parse_dollars (char **word, size_t *word | ||
133 | } | ||
134 | } | ||
135 | |||
136 | - if (flags & WRDE_NOCMD) | ||
137 | - return WRDE_CMDSUB; | ||
138 | - | ||
139 | (*offset) += 2; | ||
140 | return parse_comm (word, word_length, max_length, words, offset, flags, | ||
141 | quoted? NULL : pwordexp, ifs, ifs_white); | ||
142 | @@ -2196,9 +2197,6 @@ parse_dquote (char **word, size_t *word_ | ||
143 | break; | ||
144 | |||
145 | case '`': | ||
146 | - if (flags & WRDE_NOCMD) | ||
147 | - return WRDE_CMDSUB; | ||
148 | - | ||
149 | ++(*offset); | ||
150 | error = parse_backtick (word, word_length, max_length, words, | ||
151 | offset, flags, NULL, NULL, NULL); | ||
152 | @@ -2357,12 +2355,6 @@ wordexp (const char *words, wordexp_t *p | ||
153 | break; | ||
154 | |||
155 | case '`': | ||
156 | - if (flags & WRDE_NOCMD) | ||
157 | - { | ||
158 | - error = WRDE_CMDSUB; | ||
159 | - goto do_error; | ||
160 | - } | ||
161 | - | ||
162 | ++words_offset; | ||
163 | error = parse_backtick (&word, &word_length, &max_length, words, | ||
164 | &words_offset, flags, pwordexp, ifs, | ||