summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch')
-rw-r--r--meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch361
1 files changed, 361 insertions, 0 deletions
diff --git a/meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch b/meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch
new file mode 100644
index 0000000000..c6353d8ce0
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils/CVE-2017-9955_9.patch
@@ -0,0 +1,361 @@
1From 8e2f54bcee7e3e8315d4a39a302eaf8e4389e07d Mon Sep 17 00:00:00 2001
2From: "H.J. Lu" <hjl.tools@gmail.com>
3Date: Tue, 30 May 2017 06:34:05 -0700
4Subject: [PATCH] Add bfd_get_file_size to get archive element size
5
6We can't use stat() to get archive element size. Add bfd_get_file_size
7to get size for both normal files and archive elements.
8
9bfd/
10
11 PR binutils/21519
12 * bfdio.c (bfd_get_file_size): New function.
13 * bfd-in2.h: Regenerated.
14
15binutils/
16
17 PR binutils/21519
18 * objdump.c (dump_relocs_in_section): Replace get_file_size
19 with bfd_get_file_size to get archive element size.
20 * testsuite/binutils-all/objdump.exp (test_objdump_f): New
21 proc.
22 (test_objdump_h): Likewise.
23 (test_objdump_t): Likewise.
24 (test_objdump_r): Likewise.
25 (test_objdump_s): Likewise.
26 Add objdump tests on archive.
27
28Upstream-Status: Backport
29CVE: CVE-2017-9955
30Signed-off-by: Armin Kuster <akuster@mvista.com>
31
32---
33 bfd/ChangeLog | 6 +
34 bfd/bfd-in2.h | 2 +
35 bfd/bfdio.c | 23 ++++
36 binutils/ChangeLog | 13 ++
37 binutils/objdump.c | 2 +-
38 binutils/testsuite/binutils-all/objdump.exp | 178 +++++++++++++++++++---------
39 6 files changed, 170 insertions(+), 54 deletions(-)
40
41Index: git/bfd/bfd-in2.h
42===================================================================
43--- git.orig/bfd/bfd-in2.h
44+++ git/bfd/bfd-in2.h
45@@ -1241,6 +1241,8 @@ long bfd_get_mtime (bfd *abfd);
46
47 file_ptr bfd_get_size (bfd *abfd);
48
49+file_ptr bfd_get_file_size (bfd *abfd);
50+
51 void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
52 int prot, int flags, file_ptr offset,
53 void **map_addr, bfd_size_type *map_len);
54Index: git/bfd/bfdio.c
55===================================================================
56--- git.orig/bfd/bfdio.c
57+++ git/bfd/bfdio.c
58@@ -434,6 +434,29 @@ bfd_get_size (bfd *abfd)
59 return buf.st_size;
60 }
61
62+/*
63+FUNCTION
64+ bfd_get_file_size
65+
66+SYNOPSIS
67+ file_ptr bfd_get_file_size (bfd *abfd);
68+
69+DESCRIPTION
70+ Return the file size (as read from file system) for the file
71+ associated with BFD @var{abfd}. It supports both normal files
72+ and archive elements.
73+
74+*/
75+
76+file_ptr
77+bfd_get_file_size (bfd *abfd)
78+{
79+ if (abfd->my_archive != NULL
80+ && !bfd_is_thin_archive (abfd->my_archive))
81+ return arelt_size (abfd);
82+
83+ return bfd_get_size (abfd);
84+}
85
86 /*
87 FUNCTION
88Index: git/binutils/objdump.c
89===================================================================
90--- git.orig/binutils/objdump.c
91+++ git/binutils/objdump.c
92@@ -3310,7 +3310,7 @@ dump_relocs_in_section (bfd *abfd,
93 }
94
95 if ((bfd_get_file_flags (abfd) & (BFD_IN_MEMORY | BFD_LINKER_CREATED)) == 0
96- && relsize > get_file_size (bfd_get_filename (abfd)))
97+ && relsize > bfd_get_file_size (abfd))
98 {
99 printf (" (too many: 0x%x)\n", section->reloc_count);
100 bfd_set_error (bfd_error_file_truncated);
101Index: git/binutils/testsuite/binutils-all/objdump.exp
102===================================================================
103--- git.orig/binutils/testsuite/binutils-all/objdump.exp
104+++ git/binutils/testsuite/binutils-all/objdump.exp
105@@ -64,96 +64,168 @@ if [regexp $want $got] then {
106 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
107 return
108 }
109+if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest2.o]} then {
110+ return
111+}
112 if [is_remote host] {
113 set testfile [remote_download host tmpdir/bintest.o]
114+ set testfile2 [remote_download host tmpdir/bintest2.o]
115 } else {
116 set testfile tmpdir/bintest.o
117+ set testfile2 tmpdir/bintest2.o
118+}
119+
120+if { ![istarget "alpha-*-*"] || [is_elf_format] } then {
121+ remote_file host file delete tmpdir/bintest.a
122+ set got [binutils_run $AR "rc tmpdir/bintest.a $testfile2"]
123+ if ![string match "" $got] then {
124+ fail "bintest.a"
125+ remote_file host delete tmpdir/bintest.a
126+ } else {
127+ if [is_remote host] {
128+ set testarchive [remote_download host tmpdir/bintest.a]
129+ } else {
130+ set testarchive tmpdir/bintest.a
131+ }
132+ }
133+ remote_file host delete tmpdir/bintest2.o
134 }
135
136 # Test objdump -f
137
138-set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"]
139+proc test_objdump_f { testfile dumpfile } {
140+ global OBJDUMP
141+ global OBJDUMPFLAGS
142+ global cpus_regex
143
144-set want "$testfile:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS"
145+ set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"]
146
147-if ![regexp $want $got] then {
148- fail "objdump -f"
149-} else {
150- pass "objdump -f"
151+ set want "$dumpfile:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS"
152+
153+ if ![regexp $want $got] then {
154+ fail "objdump -f ($testfile, $dumpfile)"
155+ } else {
156+ pass "objdump -f ($testfile, $dumpfile)"
157+ }
158+}
159+
160+test_objdump_f $testfile $testfile
161+if { [ remote_file host exists $testarchive ] } then {
162+ test_objdump_f $testarchive bintest2.o
163 }
164
165 # Test objdump -h
166
167-set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"]
168+proc test_objdump_h { testfile dumpfile } {
169+ global OBJDUMP
170+ global OBJDUMPFLAGS
171
172-set want "$testfile:\[ \]*file format.*Sections.*\[0-9\]+\[ \]+\[^ \]*(text|TEXT|P|\\\$CODE\\\$)\[^ \]*\[ \]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ \]+\[^ \]*(\\.data|DATA|D_1)\[^ \]*\[ \]*(\[0-9a-fA-F\]+)"
173+ set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"]
174
175-if ![regexp $want $got all text_name text_size data_name data_size] then {
176- fail "objdump -h"
177-} else {
178- verbose "text name is $text_name size is $text_size"
179- verbose "data name is $data_name size is $data_size"
180- set ets 8
181- set eds 4
182- # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1
183- if [istarget *c4x*-*-*] then {
184- set ets 2
185- set eds 1
186- }
187- # c54x section sizes are in bytes, not octets; adjust accordingly
188- if [istarget *c54x*-*-*] then {
189- set ets 4
190- set eds 2
191- }
192- if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then {
193- send_log "sizes too small\n"
194- fail "objdump -h"
195+ set want "$dumpfile:\[ \]*file format.*Sections.*\[0-9\]+\[ \]+\[^ \]*(text|TEXT|P|\\\$CODE\\\$)\[^ \]*\[ \]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ \]+\[^ \]*(\\.data|DATA|D_1)\[^ \]*\[ \]*(\[0-9a-fA-F\]+)"
196+
197+ if ![regexp $want $got all text_name text_size data_name data_size] then {
198+ fail "objdump -h ($testfile, $dumpfile)"
199 } else {
200- pass "objdump -h"
201+ verbose "text name is $text_name size is $text_size"
202+ verbose "data name is $data_name size is $data_size"
203+ set ets 8
204+ set eds 4
205+ # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1
206+ if [istarget *c4x*-*-*] then {
207+ set ets 2
208+ set eds 1
209+ }
210+ # c54x section sizes are in bytes, not octets; adjust accordingly
211+ if [istarget *c54x*-*-*] then {
212+ set ets 4
213+ set eds 2
214+ }
215+ if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then {
216+ send_log "sizes too small\n"
217+ fail "objdump -h ($testfile, $dumpfile)"
218+ } else {
219+ pass "objdump -h ($testfile, $dumpfile)"
220+ }
221 }
222 }
223
224+test_objdump_h $testfile $testfile
225+if { [ remote_file host exists $testarchive ] } then {
226+ test_objdump_h $testarchive bintest2.o
227+}
228+
229 # Test objdump -t
230
231-set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"]
232+proc test_objdump_t { testfile} {
233+ global OBJDUMP
234+ global OBJDUMPFLAGS
235+
236+ set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"]
237+
238+ if [info exists vars] then { unset vars }
239+ while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} {
240+ set vars($symbol) 1
241+ set got $rest
242+ }
243
244-if [info exists vars] then { unset vars }
245-while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} {
246- set vars($symbol) 1
247- set got $rest
248+ if {![info exists vars(text_symbol)] \
249+ || ![info exists vars(data_symbol)] \
250+ || ![info exists vars(common_symbol)] \
251+ || ![info exists vars(external_symbol)]} then {
252+ fail "objdump -t ($testfile)"
253+ } else {
254+ pass "objdump -t ($testfile)"
255+ }
256 }
257
258-if {![info exists vars(text_symbol)] \
259- || ![info exists vars(data_symbol)] \
260- || ![info exists vars(common_symbol)] \
261- || ![info exists vars(external_symbol)]} then {
262- fail "objdump -t"
263-} else {
264- pass "objdump -t"
265+test_objdump_t $testfile
266+if { [ remote_file host exists $testarchive ] } then {
267+ test_objdump_t $testarchive
268 }
269
270 # Test objdump -r
271
272-set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"]
273+proc test_objdump_r { testfile dumpfile } {
274+ global OBJDUMP
275+ global OBJDUMPFLAGS
276
277-set want "$testfile:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol"
278+ set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"]
279
280-if [regexp $want $got] then {
281- pass "objdump -r"
282-} else {
283- fail "objdump -r"
284+ set want "$dumpfile:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol"
285+
286+ if [regexp $want $got] then {
287+ pass "objdump -r ($testfile, $dumpfile)"
288+ } else {
289+ fail "objdump -r ($testfile, $dumpfile)"
290+ }
291+}
292+
293+test_objdump_r $testfile $testfile
294+if { [ remote_file host exists $testarchive ] } then {
295+ test_objdump_r $testarchive bintest2.o
296 }
297
298 # Test objdump -s
299
300-set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"]
301+proc test_objdump_s { testfile dumpfile } {
302+ global OBJDUMP
303+ global OBJDUMPFLAGS
304
305-set want "$testfile:\[ \]*file format.*Contents.*(text|TEXT|P|\\\$CODE\\\$)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000001|01000000|00000100).*Contents.*(data|DATA|D_1)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000002|02000000|00000200)"
306+ set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"]
307
308-if [regexp $want $got] then {
309- pass "objdump -s"
310-} else {
311- fail "objdump -s"
312+ set want "$dumpfile:\[ \]*file format.*Contents.*(text|TEXT|P|\\\$CODE\\\$)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000001|01000000|00000100).*Contents.*(data|DATA|D_1)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000002|02000000|00000200)"
313+
314+ if [regexp $want $got] then {
315+ pass "objdump -s ($testfile, $dumpfile)"
316+ } else {
317+ fail "objdump -s ($testfile, $dumpfile)"
318+ }
319+}
320+
321+test_objdump_s $testfile $testfile
322+if { [ remote_file host exists $testarchive ] } then {
323+ test_objdump_s $testarchive bintest2.o
324 }
325
326 # Test objdump -s on a file that contains a compressed .debug section
327Index: git/bfd/ChangeLog
328===================================================================
329--- git.orig/bfd/ChangeLog
330+++ git/bfd/ChangeLog
331@@ -1,3 +1,9 @@
332+2017-05-30 H.J. Lu <hongjiu.lu@intel.com>
333+
334+ PR binutils/21519
335+ * bfdio.c (bfd_get_file_size): New function.
336+ * bfd-in2.h: Regenerated.
337+
338 2017-06-27 Alan Modra <amodra@gmail.com>
339
340 PR binutils/21665
341Index: git/binutils/ChangeLog
342===================================================================
343--- git.orig/binutils/ChangeLog
344+++ git/binutils/ChangeLog
345@@ -1,3 +1,16 @@
346+2017-05-30 H.J. Lu <hongjiu.lu@intel.com>
347+
348+ PR binutils/21519
349+ * objdump.c (dump_relocs_in_section): Replace get_file_size
350+ with bfd_get_file_size to get archive element size.
351+ * testsuite/binutils-all/objdump.exp (test_objdump_f): New
352+ proc.
353+ (test_objdump_h): Likewise.
354+ (test_objdump_t): Likewise.
355+ (test_objdump_r): Likewise.
356+ (test_objdump_s): Likewise.
357+ Add objdump tests on archive.
358+
359 2017-07-01 Alan Modra <amodra@gmail.com>
360
361 PR binutils/21665