|
|
b40826 |
2010-10-22 Andreas Schwab <schwab@redhat.com>
|
|
|
b40826 |
|
|
|
b40826 |
* include/dlfcn.h (__RTLD_SECURE): Define.
|
|
|
b40826 |
* elf/dl-load.c (_dl_map_object): Remove preloaded parameter. Use
|
|
|
b40826 |
mode & __RTLD_SECURE instead.
|
|
|
b40826 |
(open_path): Remove preloaded parameter to secure.
|
|
|
b40826 |
* sysdeps/generic/ldsodefs.h (_dl_map_object): Adjust declaration.
|
|
|
b40826 |
* elf/dl-open.c (dl_open_worker): Adjust call to _dl_map_object.
|
|
|
b40826 |
* elf/dl-deps.c (openaux): Likewise.
|
|
|
b40826 |
* elf/rtld.c (struct map_args): Remove is_preloaded.
|
|
|
b40826 |
(map_doit): Don't use it.
|
|
|
b40826 |
(dl_main): Likewise.
|
|
|
b40826 |
(do_preload): Use __RTLD_SECURE instead of is_preloaded.
|
|
|
b40826 |
(dlmopen_doit): Add __RTLD_SECURE to mode bits.
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/elf/dl-deps.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-deps.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/elf/dl-deps.c
|
|
|
b40826 |
@@ -62,7 +62,7 @@ openaux (void *a)
|
|
|
b40826 |
{
|
|
|
b40826 |
struct openaux_args *args = (struct openaux_args *) a;
|
|
|
b40826 |
|
|
|
b40826 |
- args->aux = _dl_map_object (args->map, args->name, 0,
|
|
|
b40826 |
+ args->aux = _dl_map_object (args->map, args->name,
|
|
|
b40826 |
(args->map->l_type == lt_executable
|
|
|
b40826 |
? lt_library : args->map->l_type),
|
|
|
b40826 |
args->trace_mode, args->open_mode,
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
|
|
|
b40826 |
@@ -1811,7 +1811,7 @@ open_verify (const char *name, struct fi
|
|
|
b40826 |
if MAY_FREE_DIRS is true. */
|
|
|
b40826 |
|
|
|
b40826 |
static int
|
|
|
b40826 |
-open_path (const char *name, size_t namelen, int preloaded,
|
|
|
b40826 |
+open_path (const char *name, size_t namelen, int secure,
|
|
|
b40826 |
struct r_search_path_struct *sps, char **realname,
|
|
|
b40826 |
struct filebuf *fbp, struct link_map *loader, int whatcode,
|
|
|
b40826 |
bool *found_other_class)
|
|
|
b40826 |
@@ -1893,7 +1893,7 @@ open_path (const char *name, size_t name
|
|
|
b40826 |
/* Remember whether we found any existing directory. */
|
|
|
b40826 |
here_any |= this_dir->status[cnt] != nonexisting;
|
|
|
b40826 |
|
|
|
b40826 |
- if (fd != -1 && __builtin_expect (preloaded, 0)
|
|
|
b40826 |
+ if (fd != -1 && __builtin_expect (secure, 0)
|
|
|
b40826 |
&& INTUSE(__libc_enable_secure))
|
|
|
b40826 |
{
|
|
|
b40826 |
/* This is an extra security effort to make sure nobody can
|
|
|
b40826 |
@@ -1962,7 +1962,7 @@ open_path (const char *name, size_t name
|
|
|
b40826 |
|
|
|
b40826 |
struct link_map *
|
|
|
b40826 |
internal_function
|
|
|
b40826 |
-_dl_map_object (struct link_map *loader, const char *name, int preloaded,
|
|
|
b40826 |
+_dl_map_object (struct link_map *loader, const char *name,
|
|
|
b40826 |
int type, int trace_mode, int mode, Lmid_t nsid)
|
|
|
b40826 |
{
|
|
|
b40826 |
int fd;
|
|
|
b40826 |
@@ -2066,7 +2066,8 @@ _dl_map_object (struct link_map *loader,
|
|
|
b40826 |
for (l = loader; l; l = l->l_loader)
|
|
|
b40826 |
if (cache_rpath (l, &l->l_rpath_dirs, DT_RPATH, "RPATH"))
|
|
|
b40826 |
{
|
|
|
b40826 |
- fd = open_path (name, namelen, preloaded, &l->l_rpath_dirs,
|
|
|
b40826 |
+ fd = open_path (name, namelen, mode & __RTLD_SECURE,
|
|
|
b40826 |
+ &l->l_rpath_dirs,
|
|
|
b40826 |
&realname, &fb, loader, LA_SER_RUNPATH,
|
|
|
b40826 |
&found_other_class);
|
|
|
b40826 |
if (fd != -1)
|
|
|
b40826 |
@@ -2081,14 +2082,15 @@ _dl_map_object (struct link_map *loader,
|
|
|
b40826 |
&& main_map != NULL && main_map->l_type != lt_loaded
|
|
|
b40826 |
&& cache_rpath (main_map, &main_map->l_rpath_dirs, DT_RPATH,
|
|
|
b40826 |
"RPATH"))
|
|
|
b40826 |
- fd = open_path (name, namelen, preloaded, &main_map->l_rpath_dirs,
|
|
|
b40826 |
+ fd = open_path (name, namelen, mode & __RTLD_SECURE,
|
|
|
b40826 |
+ &main_map->l_rpath_dirs,
|
|
|
b40826 |
&realname, &fb, loader ?: main_map, LA_SER_RUNPATH,
|
|
|
b40826 |
&found_other_class);
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
/* Try the LD_LIBRARY_PATH environment variable. */
|
|
|
b40826 |
if (fd == -1 && env_path_list.dirs != (void *) -1)
|
|
|
b40826 |
- fd = open_path (name, namelen, preloaded, &env_path_list,
|
|
|
b40826 |
+ fd = open_path (name, namelen, mode & __RTLD_SECURE, &env_path_list,
|
|
|
b40826 |
&realname, &fb,
|
|
|
b40826 |
loader ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded,
|
|
|
b40826 |
LA_SER_LIBPATH, &found_other_class);
|
|
|
b40826 |
@@ -2097,12 +2099,12 @@ _dl_map_object (struct link_map *loader,
|
|
|
b40826 |
if (fd == -1 && loader != NULL
|
|
|
b40826 |
&& cache_rpath (loader, &loader->l_runpath_dirs,
|
|
|
b40826 |
DT_RUNPATH, "RUNPATH"))
|
|
|
b40826 |
- fd = open_path (name, namelen, preloaded,
|
|
|
b40826 |
+ fd = open_path (name, namelen, mode & __RTLD_SECURE,
|
|
|
b40826 |
&loader->l_runpath_dirs, &realname, &fb, loader,
|
|
|
b40826 |
LA_SER_RUNPATH, &found_other_class);
|
|
|
b40826 |
|
|
|
b40826 |
if (fd == -1
|
|
|
b40826 |
- && (__builtin_expect (! preloaded, 1)
|
|
|
b40826 |
+ && (__builtin_expect (! (mode & __RTLD_SECURE), 1)
|
|
|
b40826 |
|| ! INTUSE(__libc_enable_secure)))
|
|
|
b40826 |
{
|
|
|
b40826 |
/* Check the list of libraries in the file /etc/ld.so.cache,
|
|
|
b40826 |
@@ -2168,7 +2170,7 @@ _dl_map_object (struct link_map *loader,
|
|
|
b40826 |
&& ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL
|
|
|
b40826 |
|| __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1))
|
|
|
b40826 |
&& rtld_search_dirs.dirs != (void *) -1)
|
|
|
b40826 |
- fd = open_path (name, namelen, preloaded, &rtld_search_dirs,
|
|
|
b40826 |
+ fd = open_path (name, namelen, mode & __RTLD_SECURE, &rtld_search_dirs,
|
|
|
b40826 |
&realname, &fb, l, LA_SER_DEFAULT, &found_other_class);
|
|
|
b40826 |
|
|
|
b40826 |
/* Add another newline when we are tracing the library loading. */
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/elf/dl-open.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-open.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/elf/dl-open.c
|
|
|
b40826 |
@@ -252,7 +252,7 @@ dl_open_worker (void *a)
|
|
|
b40826 |
|
|
|
b40826 |
/* Load the named object. */
|
|
|
b40826 |
struct link_map *new;
|
|
|
b40826 |
- args->map = new = _dl_map_object (call_map, file, 0, lt_loaded, 0,
|
|
|
b40826 |
+ args->map = new = _dl_map_object (call_map, file, lt_loaded, 0,
|
|
|
b40826 |
mode | __RTLD_CALLMAP, args->nsid);
|
|
|
b40826 |
|
|
|
b40826 |
/* If the pointer returned is NULL this means the RTLD_NOLOAD flag is
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/elf/rtld.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/elf/rtld.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/elf/rtld.c
|
|
|
b40826 |
@@ -589,7 +589,6 @@ struct map_args
|
|
|
b40826 |
/* Argument to map_doit. */
|
|
|
b40826 |
char *str;
|
|
|
b40826 |
struct link_map *loader;
|
|
|
b40826 |
- int is_preloaded;
|
|
|
b40826 |
int mode;
|
|
|
b40826 |
/* Return value of map_doit. */
|
|
|
b40826 |
struct link_map *map;
|
|
|
b40826 |
@@ -627,16 +626,17 @@ static void
|
|
|
b40826 |
map_doit (void *a)
|
|
|
b40826 |
{
|
|
|
b40826 |
struct map_args *args = (struct map_args *) a;
|
|
|
b40826 |
- args->map = _dl_map_object (args->loader, args->str,
|
|
|
b40826 |
- args->is_preloaded, lt_library, 0, args->mode,
|
|
|
b40826 |
- LM_ID_BASE);
|
|
|
b40826 |
+ args->map = _dl_map_object (args->loader, args->str, lt_library, 0,
|
|
|
b40826 |
+ args->mode, LM_ID_BASE);
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
static void
|
|
|
b40826 |
dlmopen_doit (void *a)
|
|
|
b40826 |
{
|
|
|
b40826 |
struct dlmopen_args *args = (struct dlmopen_args *) a;
|
|
|
b40826 |
- args->map = _dl_open (args->fname, RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT,
|
|
|
b40826 |
+ args->map = _dl_open (args->fname,
|
|
|
b40826 |
+ (RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT
|
|
|
b40826 |
+ | __RTLD_SECURE),
|
|
|
b40826 |
dl_main, LM_ID_NEWLM, _dl_argc, INTUSE(_dl_argv),
|
|
|
b40826 |
__environ);
|
|
|
b40826 |
}
|
|
|
b40826 |
@@ -806,8 +806,7 @@ do_preload (char *fname, struct link_map
|
|
|
b40826 |
|
|
|
b40826 |
args.str = fname;
|
|
|
b40826 |
args.loader = main_map;
|
|
|
b40826 |
- args.is_preloaded = 1;
|
|
|
b40826 |
- args.mode = 0;
|
|
|
b40826 |
+ args.mode = __RTLD_SECURE;
|
|
|
b40826 |
|
|
|
b40826 |
unsigned int old_nloaded = GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
|
|
|
b40826 |
|
|
|
b40826 |
@@ -1054,7 +1053,6 @@ of this helper program; chances are you
|
|
|
b40826 |
|
|
|
b40826 |
args.str = rtld_progname;
|
|
|
b40826 |
args.loader = NULL;
|
|
|
b40826 |
- args.is_preloaded = 0;
|
|
|
b40826 |
args.mode = __RTLD_OPENEXEC;
|
|
|
b40826 |
(void) _dl_catch_error (&objname, &err_str, &malloced, map_doit,
|
|
|
b40826 |
&args);
|
|
|
b40826 |
@@ -1066,7 +1064,7 @@ of this helper program; chances are you
|
|
|
b40826 |
else
|
|
|
b40826 |
{
|
|
|
b40826 |
HP_TIMING_NOW (start);
|
|
|
b40826 |
- _dl_map_object (NULL, rtld_progname, 0, lt_library, 0,
|
|
|
b40826 |
+ _dl_map_object (NULL, rtld_progname, lt_library, 0,
|
|
|
b40826 |
__RTLD_OPENEXEC, LM_ID_BASE);
|
|
|
b40826 |
HP_TIMING_NOW (stop);
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/include/dlfcn.h
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/include/dlfcn.h
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/include/dlfcn.h
|
|
|
b40826 |
@@ -9,6 +9,7 @@
|
|
|
b40826 |
#define __RTLD_OPENEXEC 0x20000000
|
|
|
b40826 |
#define __RTLD_CALLMAP 0x10000000
|
|
|
b40826 |
#define __RTLD_AUDIT 0x08000000
|
|
|
b40826 |
+#define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */
|
|
|
b40826 |
|
|
|
b40826 |
#define __LM_ID_CALLER -2
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/generic/ldsodefs.h
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
|
|
|
b40826 |
@@ -824,11 +824,9 @@ extern void _dl_receive_error (receiver_
|
|
|
b40826 |
|
|
|
b40826 |
/* Open the shared object NAME and map in its segments.
|
|
|
b40826 |
LOADER's DT_RPATH is used in searching for NAME.
|
|
|
b40826 |
- If the object is already opened, returns its existing map.
|
|
|
b40826 |
- For preloaded shared objects PRELOADED is set to a non-zero
|
|
|
b40826 |
- value to allow additional security checks. */
|
|
|
b40826 |
+ If the object is already opened, returns its existing map. */
|
|
|
b40826 |
extern struct link_map *_dl_map_object (struct link_map *loader,
|
|
|
b40826 |
- const char *name, int preloaded,
|
|
|
b40826 |
+ const char *name,
|
|
|
b40826 |
int type, int trace_mode, int mode,
|
|
|
b40826 |
Lmid_t nsid)
|
|
|
b40826 |
internal_function attribute_hidden;
|