diff options
author | Catalin Popeanga <Catalin.Popeanga@enea.com> | 2014-10-09 14:23:24 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-10-13 11:18:38 +0100 |
commit | f7dba9940cf6067f4a26de0151c0d5cc029a04f8 (patch) | |
tree | 5aa6de35e7527afedf3b7b574b6d13d708dd9502 /meta/recipes-extended/bash/bash-3.2.48 | |
parent | 634b753f8458c34b0df971084d6cb71ff8e62815 (diff) | |
download | poky-f7dba9940cf6067f4a26de0151c0d5cc029a04f8.tar.gz |
bash: Fix for exported function namespace change
This is a followup patch to incomplete CVE-2014-6271 fix code execution via
specially-crafted environment
This patch changes the encoding bash uses for exported functions to avoid
clashes with shell variables and to avoid depending only on an environment
variable's contents to determine whether or not to interpret it as a shell
function.
(From OE-Core daisy rev: 6c51cc96d03df26d1c10867633e7a10dfbec7c45)
(From OE-Core rev: af1f65b57dbfcaf5fc7c254dce80ac55f3a632cb)
Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com>
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-extended/bash/bash-3.2.48')
-rw-r--r-- | meta/recipes-extended/bash/bash-3.2.48/Fix-for-bash-exported-function-namespace-change.patch | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/meta/recipes-extended/bash/bash-3.2.48/Fix-for-bash-exported-function-namespace-change.patch b/meta/recipes-extended/bash/bash-3.2.48/Fix-for-bash-exported-function-namespace-change.patch new file mode 100644 index 0000000000..c087016eee --- /dev/null +++ b/meta/recipes-extended/bash/bash-3.2.48/Fix-for-bash-exported-function-namespace-change.patch | |||
@@ -0,0 +1,158 @@ | |||
1 | Fix for exported function namespace change | ||
2 | |||
3 | Upstream-Status: Backport | ||
4 | |||
5 | Downloaded from: http://ftp.gnu.org/gnu/bash/bash-3.2-patches/bash32-054 | ||
6 | |||
7 | Author: Chet Ramey <chet.ramey@case.edu> | ||
8 | Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com> | ||
9 | |||
10 | |||
11 | BASH PATCH REPORT | ||
12 | ================= | ||
13 | |||
14 | Bash-Release: 3.2 | ||
15 | Patch-ID: bash32-054 | ||
16 | |||
17 | Bug-Reported-by: Florian Weimer <fweimer@redhat.com> | ||
18 | Bug-Reference-ID: | ||
19 | Bug-Reference-URL: | ||
20 | |||
21 | Bug-Description: | ||
22 | |||
23 | This patch changes the encoding bash uses for exported functions to avoid | ||
24 | clashes with shell variables and to avoid depending only on an environment | ||
25 | variable's contents to determine whether or not to interpret it as a shell | ||
26 | function. | ||
27 | --- | ||
28 | --- a/variables.c 2014-09-16 19:10:39.000000000 -0400 | ||
29 | +++ b/variables.c 2014-09-27 21:02:08.000000000 -0400 | ||
30 | @@ -75,4 +75,9 @@ | ||
31 | #define ifsname(s) ((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && (s)[3] == '\0') | ||
32 | |||
33 | +#define BASHFUNC_PREFIX "BASH_FUNC_" | ||
34 | +#define BASHFUNC_PREFLEN 10 /* == strlen(BASHFUNC_PREFIX */ | ||
35 | +#define BASHFUNC_SUFFIX "%%" | ||
36 | +#define BASHFUNC_SUFFLEN 2 /* == strlen(BASHFUNC_SUFFIX) */ | ||
37 | + | ||
38 | extern char **environ; | ||
39 | |||
40 | @@ -242,5 +247,5 @@ | ||
41 | static void dispose_temporary_env __P((sh_free_func_t *)); | ||
42 | |||
43 | -static inline char *mk_env_string __P((const char *, const char *)); | ||
44 | +static inline char *mk_env_string __P((const char *, const char *, int)); | ||
45 | static char **make_env_array_from_var_list __P((SHELL_VAR **)); | ||
46 | static char **make_var_export_array __P((VAR_CONTEXT *)); | ||
47 | @@ -310,19 +315,30 @@ | ||
48 | /* If exported function, define it now. Don't import functions from | ||
49 | the environment in privileged mode. */ | ||
50 | - if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4)) | ||
51 | + if (privmode == 0 && read_but_dont_execute == 0 && | ||
52 | + STREQN (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) && | ||
53 | + STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) && | ||
54 | + STREQN ("() {", string, 4)) | ||
55 | { | ||
56 | + size_t namelen; | ||
57 | + char *tname; /* desired imported function name */ | ||
58 | + | ||
59 | + namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN; | ||
60 | + | ||
61 | + tname = name + BASHFUNC_PREFLEN; /* start of func name */ | ||
62 | + tname[namelen] = '\0'; /* now tname == func name */ | ||
63 | + | ||
64 | string_length = strlen (string); | ||
65 | - temp_string = (char *)xmalloc (3 + string_length + char_index); | ||
66 | + temp_string = (char *)xmalloc (namelen + string_length + 2); | ||
67 | |||
68 | - strcpy (temp_string, name); | ||
69 | - temp_string[char_index] = ' '; | ||
70 | - strcpy (temp_string + char_index + 1, string); | ||
71 | + memcpy (temp_string, tname, namelen); | ||
72 | + temp_string[namelen] = ' '; | ||
73 | + memcpy (temp_string + namelen + 1, string, string_length + 1); | ||
74 | |||
75 | /* Don't import function names that are invalid identifiers from the | ||
76 | environment. */ | ||
77 | - if (legal_identifier (name)) | ||
78 | - parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
79 | + if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname))) | ||
80 | + parse_and_execute (temp_string, tname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
81 | |||
82 | - if (temp_var = find_function (name)) | ||
83 | + if (temp_var = find_function (tname)) | ||
84 | { | ||
85 | VSETATTR (temp_var, (att_exported|att_imported)); | ||
86 | @@ -330,5 +346,8 @@ | ||
87 | } | ||
88 | else | ||
89 | - report_error (_("error importing function definition for `%s'"), name); | ||
90 | + report_error (_("error importing function definition for `%s'"), tname); | ||
91 | + | ||
92 | + /* Restore original suffix */ | ||
93 | + tname[namelen] = BASHFUNC_SUFFIX[0]; | ||
94 | } | ||
95 | #if defined (ARRAY_VARS) | ||
96 | @@ -2208,5 +2227,5 @@ | ||
97 | |||
98 | INVALIDATE_EXPORTSTR (var); | ||
99 | - var->exportstr = mk_env_string (name, value); | ||
100 | + var->exportstr = mk_env_string (name, value, 0); | ||
101 | |||
102 | array_needs_making = 1; | ||
103 | @@ -2999,19 +3018,40 @@ | ||
104 | |||
105 | static inline char * | ||
106 | -mk_env_string (name, value) | ||
107 | +mk_env_string (name, value, isfunc) | ||
108 | const char *name, *value; | ||
109 | + int isfunc; | ||
110 | { | ||
111 | - int name_len, value_len; | ||
112 | - char *p; | ||
113 | + size_t name_len, value_len; | ||
114 | + char *p, *q; | ||
115 | |||
116 | name_len = strlen (name); | ||
117 | value_len = STRLEN (value); | ||
118 | - p = (char *)xmalloc (2 + name_len + value_len); | ||
119 | - strcpy (p, name); | ||
120 | - p[name_len] = '='; | ||
121 | + | ||
122 | + /* If we are exporting a shell function, construct the encoded function | ||
123 | + name. */ | ||
124 | + if (isfunc && value) | ||
125 | + { | ||
126 | + p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + value_len + 2); | ||
127 | + q = p; | ||
128 | + memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN); | ||
129 | + q += BASHFUNC_PREFLEN; | ||
130 | + memcpy (q, name, name_len); | ||
131 | + q += name_len; | ||
132 | + memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN); | ||
133 | + q += BASHFUNC_SUFFLEN; | ||
134 | + } | ||
135 | + else | ||
136 | + { | ||
137 | + p = (char *)xmalloc (2 + name_len + value_len); | ||
138 | + memcpy (p, name, name_len); | ||
139 | + q = p + name_len; | ||
140 | + } | ||
141 | + | ||
142 | + q[0] = '='; | ||
143 | if (value && *value) | ||
144 | - strcpy (p + name_len + 1, value); | ||
145 | + memcpy (q + 1, value, value_len + 1); | ||
146 | else | ||
147 | - p[name_len + 1] = '\0'; | ||
148 | + q[1] = '\0'; | ||
149 | + | ||
150 | return (p); | ||
151 | } | ||
152 | @@ -3088,5 +3128,5 @@ | ||
153 | using the cached exportstr... */ | ||
154 | list[list_index] = USE_EXPORTSTR ? savestring (value) | ||
155 | - : mk_env_string (var->name, value); | ||
156 | + : mk_env_string (var->name, value, function_p (var)); | ||
157 | |||
158 | if (USE_EXPORTSTR == 0) | ||