|
|
b9ba6d |
2011-03-14 Andreas Schwab <schwab@redhat.com>
|
|
|
b9ba6d |
|
|
|
b9ba6d |
* elf/dl-load.c (is_dst): Remove parameter secure, all callers
|
|
|
b9ba6d |
changed. Don't check for isolated use.
|
|
|
b9ba6d |
(_dl_dst_substitute): Ignore rpath elements containing
|
|
|
b9ba6d |
non-isolated use of $ORIGIN when privileged.
|
|
|
b9ba6d |
|
|
|
b9ba6d |
* elf/dl-load.c (_dl_dst_substitute): When skipping the first
|
|
|
b9ba6d |
rpath element also skip the following colon.
|
|
|
b9ba6d |
(expand_dynamic_string_token): Add is_path parameter and pass
|
|
|
b9ba6d |
down to DL_DST_REQUIRED and _dl_dst_substitute.
|
|
|
b9ba6d |
(decompose_rpath): Call expand_dynamic_string_token with
|
|
|
b9ba6d |
non-zero is_path. Ignore empty rpaths.
|
|
|
b9ba6d |
(_dl_map_object_from_fd): Call expand_dynamic_string_token
|
|
|
b9ba6d |
with zero is_path.
|
|
|
b9ba6d |
|
|
|
b9ba6d |
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
|
|
|
b9ba6d |
===================================================================
|
|
|
b9ba6d |
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
|
|
|
b9ba6d |
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
|
|
|
b9ba6d |
@@ -169,8 +169,7 @@ local_strdup (const char *s)
|
|
|
b9ba6d |
|
|
|
b9ba6d |
|
|
|
b9ba6d |
static size_t
|
|
|
b9ba6d |
-is_dst (const char *start, const char *name, const char *str,
|
|
|
b9ba6d |
- int is_path, int secure)
|
|
|
b9ba6d |
+is_dst (const char *start, const char *name, const char *str, int is_path)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
size_t len;
|
|
|
b9ba6d |
bool is_curly = false;
|
|
|
b9ba6d |
@@ -199,11 +198,6 @@ is_dst (const char *start, const char *n
|
|
|
b9ba6d |
&& (!is_path || name[len] != ':'))
|
|
|
b9ba6d |
return 0;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- if (__builtin_expect (secure, 0)
|
|
|
b9ba6d |
- && ((name[len] != '\0' && (!is_path || name[len] != ':'))
|
|
|
b9ba6d |
- || (name != start + 1 && (!is_path || name[-2] != ':'))))
|
|
|
b9ba6d |
- return 0;
|
|
|
b9ba6d |
-
|
|
|
b9ba6d |
return len;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
@@ -218,13 +212,10 @@ _dl_dst_count (const char *name, int is_
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
size_t len;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- /* $ORIGIN is not expanded for SUID/GUID programs (except if it
|
|
|
b9ba6d |
- is $ORIGIN alone) and it must always appear first in path. */
|
|
|
b9ba6d |
++name;
|
|
|
b9ba6d |
- if ((len = is_dst (start, name, "ORIGIN", is_path,
|
|
|
b9ba6d |
- INTUSE(__libc_enable_secure))) != 0
|
|
|
b9ba6d |
- || (len = is_dst (start, name, "PLATFORM", is_path, 0)) != 0
|
|
|
b9ba6d |
- || (len = is_dst (start, name, "LIB", is_path, 0)) != 0)
|
|
|
b9ba6d |
+ if ((len = is_dst (start, name, "ORIGIN", is_path)) != 0
|
|
|
b9ba6d |
+ || (len = is_dst (start, name, "PLATFORM", is_path)) != 0
|
|
|
b9ba6d |
+ || (len = is_dst (start, name, "LIB", is_path)) != 0)
|
|
|
b9ba6d |
++cnt;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
name = strchr (name + len, '$');
|
|
|
b9ba6d |
@@ -256,9 +247,16 @@ _dl_dst_substitute (struct link_map *l,
|
|
|
b9ba6d |
size_t len;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
++name;
|
|
|
b9ba6d |
- if ((len = is_dst (start, name, "ORIGIN", is_path,
|
|
|
b9ba6d |
- INTUSE(__libc_enable_secure))) != 0)
|
|
|
b9ba6d |
+ if ((len = is_dst (start, name, "ORIGIN", is_path)) != 0)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
+ /* $ORIGIN is not expanded for SUID/GUID programs
|
|
|
b9ba6d |
+ (except if it is $ORIGIN alone) and it must always
|
|
|
b9ba6d |
+ appear first in path. */
|
|
|
b9ba6d |
+ if (__builtin_expect (INTUSE(__libc_enable_secure), 0)
|
|
|
b9ba6d |
+ && ((name[len] != '\0' && (!is_path || name[len] != ':'))
|
|
|
b9ba6d |
+ || (name != start + 1 && (!is_path || name[-2] != ':'))))
|
|
|
b9ba6d |
+ repl = (const char *) -1;
|
|
|
b9ba6d |
+ else
|
|
|
b9ba6d |
#ifndef SHARED
|
|
|
b9ba6d |
if (l == NULL)
|
|
|
b9ba6d |
repl = _dl_get_origin ();
|
|
|
b9ba6d |
@@ -266,9 +264,9 @@ _dl_dst_substitute (struct link_map *l,
|
|
|
b9ba6d |
#endif
|
|
|
b9ba6d |
repl = l->l_origin;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
- else if ((len = is_dst (start, name, "PLATFORM", is_path, 0)) != 0)
|
|
|
b9ba6d |
+ else if ((len = is_dst (start, name, "PLATFORM", is_path)) != 0)
|
|
|
b9ba6d |
repl = GLRO(dl_platform);
|
|
|
b9ba6d |
- else if ((len = is_dst (start, name, "LIB", is_path, 0)) != 0)
|
|
|
b9ba6d |
+ else if ((len = is_dst (start, name, "LIB", is_path)) != 0)
|
|
|
b9ba6d |
repl = DL_DST_LIB;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
if (repl != NULL && repl != (const char *) -1)
|
|
|
b9ba6d |
@@ -284,6 +282,10 @@ _dl_dst_substitute (struct link_map *l,
|
|
|
b9ba6d |
name += len;
|
|
|
b9ba6d |
while (*name != '\0' && (!is_path || *name != ':'))
|
|
|
b9ba6d |
++name;
|
|
|
b9ba6d |
+ /* Also skip following colon if this is the first rpath
|
|
|
b9ba6d |
+ element, but keep an empty element at the end. */
|
|
|
b9ba6d |
+ if (wp == result && is_path && *name == ':' && name[1] != '\0')
|
|
|
b9ba6d |
+ ++name;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
else
|
|
|
b9ba6d |
/* No DST we recognize. */
|
|
|
b9ba6d |
@@ -310,7 +312,7 @@ _dl_dst_substitute (struct link_map *l,
|
|
|
b9ba6d |
belonging to the map is loaded. In this case the path element
|
|
|
b9ba6d |
containing $ORIGIN is left out. */
|
|
|
b9ba6d |
static char *
|
|
|
b9ba6d |
-expand_dynamic_string_token (struct link_map *l, const char *s)
|
|
|
b9ba6d |
+expand_dynamic_string_token (struct link_map *l, const char *s, int is_path)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* We make two runs over the string. First we determine how large the
|
|
|
b9ba6d |
resulting string is and then we copy it over. Since this is no
|
|
|
b9ba6d |
@@ -321,7 +323,7 @@ expand_dynamic_string_token (struct link
|
|
|
b9ba6d |
char *result;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Determine the number of DST elements. */
|
|
|
b9ba6d |
- cnt = DL_DST_COUNT (s, 1);
|
|
|
b9ba6d |
+ cnt = DL_DST_COUNT (s, is_path);
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* If we do not have to replace anything simply copy the string. */
|
|
|
b9ba6d |
if (__builtin_expect (cnt, 0) == 0)
|
|
|
b9ba6d |
@@ -335,7 +337,7 @@ expand_dynamic_string_token (struct link
|
|
|
b9ba6d |
if (result == NULL)
|
|
|
b9ba6d |
return NULL;
|
|
|
b9ba6d |
|
|
|
b9ba6d |
- return _dl_dst_substitute (l, s, result, 1);
|
|
|
b9ba6d |
+ return _dl_dst_substitute (l, s, result, is_path);
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
|
|
|
b9ba6d |
@@ -551,13 +553,21 @@ decompose_rpath (struct r_search_path_st
|
|
|
b9ba6d |
|
|
|
b9ba6d |
/* Make a writable copy. At the same time expand possible dynamic
|
|
|
b9ba6d |
string tokens. */
|
|
|
b9ba6d |
- copy = expand_dynamic_string_token (l, rpath);
|
|
|
b9ba6d |
+ copy = expand_dynamic_string_token (l, rpath, 1);
|
|
|
b9ba6d |
if (copy == NULL)
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
errstring = N_("cannot create RUNPATH/RPATH copy");
|
|
|
b9ba6d |
goto signal_error;
|
|
|
b9ba6d |
}
|
|
|
b9ba6d |
|
|
|
b9ba6d |
+ /* Ignore empty rpaths. */
|
|
|
b9ba6d |
+ if (*copy == 0)
|
|
|
b9ba6d |
+ {
|
|
|
b9ba6d |
+ free (copy);
|
|
|
b9ba6d |
+ sps->dirs = (char *) -1;
|
|
|
b9ba6d |
+ return false;
|
|
|
b9ba6d |
+ }
|
|
|
b9ba6d |
+
|
|
|
b9ba6d |
/* Count the number of necessary elements in the result array. */
|
|
|
b9ba6d |
nelems = 0;
|
|
|
b9ba6d |
for (cp = copy; *cp != '\0'; ++cp)
|
|
|
b9ba6d |
@@ -2176,7 +2186,7 @@ _dl_map_object (struct link_map *loader,
|
|
|
b9ba6d |
{
|
|
|
b9ba6d |
/* The path may contain dynamic string tokens. */
|
|
|
b9ba6d |
realname = (loader
|
|
|
b9ba6d |
- ? expand_dynamic_string_token (loader, name)
|
|
|
b9ba6d |
+ ? expand_dynamic_string_token (loader, name, 0)
|
|
|
b9ba6d |
: local_strdup (name));
|
|
|
b9ba6d |
if (realname == NULL)
|
|
|
b9ba6d |
fd = -1;
|