blob: daadec76c7123f6b4a5cb89b1b9b8d4b83072c98 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From fdc8a33ac2c81a0237b8a6d8b1aac7f1cdbb46af 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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004Subject: [PATCH] nativesdk-glibc: Fix buffer overrun with a relocated SDK
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6When ld-linux-*.so.2 is relocated to a path that is longer than the
7original fixed location, the dynamic loader will crash in open_path
8because it implicitly assumes that max_dirnamelen is a fixed size that
9never changes.
10
11The allocated buffer will not be large enough to contain the directory
12path string which is larger than the fixed location provided at build
13time.
14
15Upstream-Status: Inappropriate [OE SDK specific]
16
17Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
18Signed-off-by: Khem Raj <raj.khem@gmail.com>
19---
20 elf/dl-load.c | 12 ++++++++++++
21 1 file changed, 12 insertions(+)
22
23diff --git a/elf/dl-load.c b/elf/dl-load.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080024index 44bbb69dc4..74e2e5e962 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025--- a/elf/dl-load.c
26+++ b/elf/dl-load.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027@@ -1785,7 +1785,19 @@ open_path (const char *name, size_t namelen, int mode,
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 given on the command line when rtld is run directly. */
29 return -1;
30
31+ do
32+ {
33+ struct r_search_path_elem *this_dir = *dirs;
34+ if (this_dir->dirnamelen > max_dirnamelen)
35+ {
36+ max_dirnamelen = this_dir->dirnamelen;
37+ }
38+ }
39+ while (*++dirs != NULL);
40+
41 buf = alloca (max_dirnamelen + max_capstrlen + namelen);
42+
43+ dirs = sps->dirs;
44 do
45 {
46 struct r_search_path_elem *this_dir = *dirs;