Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1 | From aa8393bff257e4badfd208b88473ead175c69362 Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 18 Mar 2015 01:50:00 +0000 |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 4 | Subject: [PATCH] nativesdk-glibc: Fix buffer overrun with a relocated SDK |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | When ld-linux-*.so.2 is relocated to a path that is longer than the |
| 7 | original fixed location, the dynamic loader will crash in open_path |
| 8 | because it implicitly assumes that max_dirnamelen is a fixed size that |
| 9 | never changes. |
| 10 | |
| 11 | The allocated buffer will not be large enough to contain the directory |
| 12 | path string which is larger than the fixed location provided at build |
| 13 | time. |
| 14 | |
| 15 | Upstream-Status: Inappropriate [OE SDK specific] |
| 16 | |
| 17 | Signed-off-by: Jason Wessel <jason.wessel@windriver.com> |
| 18 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 19 | --- |
| 20 | elf/dl-load.c | 12 ++++++++++++ |
| 21 | 1 file changed, 12 insertions(+) |
| 22 | |
| 23 | diff --git a/elf/dl-load.c b/elf/dl-load.c |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 24 | index ad01674027..f455207e79 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 25 | --- a/elf/dl-load.c |
| 26 | +++ b/elf/dl-load.c |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 27 | @@ -1871,7 +1871,19 @@ open_path (const char *name, size_t namelen, int mode, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 28 | 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; |