blob: 473b89449dfe24d5d23f818e0842bdaf8de631d4 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001From 179dc5f1e13c3ff96d5f21a2a78c089cf120ceb8 Mon Sep 17 00:00:00 2001
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 18 Mar 2015 01:50:00 +0000
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05004Subject: [PATCH 02/24] nativesdk-glibc: Fix buffer overrun with a relocated
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005 SDK
6
7When ld-linux-*.so.2 is relocated to a path that is longer than the
8original fixed location, the dynamic loader will crash in open_path
9because it implicitly assumes that max_dirnamelen is a fixed size that
10never changes.
11
12The allocated buffer will not be large enough to contain the directory
13path string which is larger than the fixed location provided at build
14time.
15
16Upstream-Status: Inappropriate [OE SDK specific]
17
18Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
19Signed-off-by: Khem Raj <raj.khem@gmail.com>
20---
21 elf/dl-load.c | 12 ++++++++++++
22 1 file changed, 12 insertions(+)
23
24diff --git a/elf/dl-load.c b/elf/dl-load.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050025index ee3d1e6..c4a42e9 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026--- a/elf/dl-load.c
27+++ b/elf/dl-load.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028@@ -1793,7 +1793,19 @@ open_path (const char *name, size_t namelen, int mode,
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 given on the command line when rtld is run directly. */
30 return -1;
31
32+ do
33+ {
34+ struct r_search_path_elem *this_dir = *dirs;
35+ if (this_dir->dirnamelen > max_dirnamelen)
36+ {
37+ max_dirnamelen = this_dir->dirnamelen;
38+ }
39+ }
40+ while (*++dirs != NULL);
41+
42 buf = alloca (max_dirnamelen + max_capstrlen + namelen);
43+
44+ dirs = sps->dirs;
45 do
46 {
47 struct r_search_path_elem *this_dir = *dirs;
48--
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500492.6.4
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050