c5d972
commit bfb5ed5df3dd4d9507b4922248dc445b690d19c0
c5d972
Author: H.J. Lu <hjl.tools@gmail.com>
c5d972
Date:   Fri Oct 15 10:44:49 2021 -0700
c5d972
c5d972
    elf: Also try DT_RUNPATH for LD_AUDIT dlopen [BZ #28455]
c5d972
    
c5d972
    DT_RUNPATH is only used to find the immediate dependencies of the
c5d972
    executable or shared object containing the DT_RUNPATH entry.  Update
c5d972
    LD_AUDIT dlopen call to try the DT_RUNPATH entry of the executable.
c5d972
    
c5d972
    Add tst-audit14a, which is copied from tst-audit14, to DT_RUNPATH and
c5d972
    build tst-audit14 with -Wl,--disable-new-dtags to test DT_RPATH.
c5d972
    
c5d972
    This partially fixes BZ #28455.
c5d972
c5d972
Conflicts:
c5d972
	elf/Makefile
c5d972
		Rewrite test inclusion to use older stdout pattern.
c5d972
c5d972
diff --git a/elf/Makefile b/elf/Makefile
c5d972
index 914cb5ad2f2c3aea..4ec4e9a049156755 100644
c5d972
--- a/elf/Makefile
c5d972
+++ b/elf/Makefile
c5d972
@@ -227,6 +227,7 @@ tests += \
c5d972
   tst-audit12 \
c5d972
   tst-audit13 \
c5d972
   tst-audit14 \
c5d972
+  tst-audit14a \
c5d972
   tst-audit15 \
c5d972
   tst-audit16 \
c5d972
   tst-audit17 \
c5d972
@@ -1788,9 +1789,11 @@ $(objpfx)tst-auditmany.out: $(objpfx)tst-auditmanymod1.so \
c5d972
 tst-auditmany-ENV = \
c5d972
   LD_AUDIT=tst-auditmanymod1.so:tst-auditmanymod2.so:tst-auditmanymod3.so:tst-auditmanymod4.so:tst-auditmanymod5.so:tst-auditmanymod6.so:tst-auditmanymod7.so:tst-auditmanymod8.so:tst-auditmanymod9.so
c5d972
 
c5d972
-LDFLAGS-tst-audit14 = -Wl,--audit=tst-auditlogmod-1.so
c5d972
+LDFLAGS-tst-audit14 = -Wl,--audit=tst-auditlogmod-1.so,--disable-new-dtags
c5d972
 $(objpfx)tst-auditlogmod-1.so: $(libsupport)
c5d972
 $(objpfx)tst-audit14.out: $(objpfx)tst-auditlogmod-1.so
c5d972
+LDFLAGS-tst-audit14a = -Wl,--audit=tst-auditlogmod-1.so,--enable-new-dtags
c5d972
+$(objpfx)tst-audit14a.out: $(objpfx)tst-auditlogmod-1.so
c5d972
 LDFLAGS-tst-audit15 = \
c5d972
   -Wl,--audit=tst-auditlogmod-1.so,--depaudit=tst-auditlogmod-2.so
c5d972
 $(objpfx)tst-auditlogmod-2.so: $(libsupport)
c5d972
diff --git a/elf/dl-load.c b/elf/dl-load.c
c5d972
index 1613217a236c7fc3..0b45e6e3db31c70d 100644
c5d972
--- a/elf/dl-load.c
c5d972
+++ b/elf/dl-load.c
c5d972
@@ -2042,6 +2042,21 @@ _dl_map_object (struct link_map *loader, const char *name,
c5d972
 			    &main_map->l_rpath_dirs,
c5d972
 			    &realname, &fb, loader ?: main_map, LA_SER_RUNPATH,
c5d972
 			    &found_other_class);
c5d972
+
c5d972
+	  /* Also try DT_RUNPATH in the executable for LD_AUDIT dlopen
c5d972
+	     call.  */
c5d972
+	  if (__glibc_unlikely (mode & __RTLD_AUDIT)
c5d972
+	      && fd == -1 && !did_main_map
c5d972
+	      && main_map != NULL && main_map->l_type != lt_loaded)
c5d972
+	    {
c5d972
+	      struct r_search_path_struct l_rpath_dirs;
c5d972
+	      l_rpath_dirs.dirs = NULL;
c5d972
+	      if (cache_rpath (main_map, &l_rpath_dirs,
c5d972
+			       DT_RUNPATH, "RUNPATH"))
c5d972
+		fd = open_path (name, namelen, mode, &l_rpath_dirs,
c5d972
+				&realname, &fb, loader ?: main_map,
c5d972
+				LA_SER_RUNPATH, &found_other_class);
c5d972
+	    }
c5d972
 	}
c5d972
 
c5d972
       /* Try the LD_LIBRARY_PATH environment variable.  */
c5d972
diff --git a/elf/tst-audit14a.c b/elf/tst-audit14a.c
c5d972
new file mode 100644
c5d972
index 0000000000000000..c6232eacf2946e4e
c5d972
--- /dev/null
c5d972
+++ b/elf/tst-audit14a.c
c5d972
@@ -0,0 +1 @@
c5d972
+#include "tst-audit14.c"