]> sourceware.org Git - glibc.git/commitdiff
elf: Add _dl_audit_pltenter
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 22 Jul 2021 20:45:33 +0000 (17:45 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Dec 2021 11:40:38 +0000 (08:40 -0300)
It consolidates the code required to call la_pltenter audit
callback.

Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
elf/dl-audit.c
elf/dl-runtime.c
sysdeps/generic/ldsodefs.h

index 0b6fac8e48877c93f4662a8020d74001f578d7d4..15250c67e8ac1658e2886911c95240946e94c035 100644 (file)
@@ -17,7 +17,9 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <assert.h>
+#include <link.h>
 #include <ldsodefs.h>
+#include <dl-machine.h>
 
 void
 _dl_audit_activity_map (struct link_map *l, int action)
@@ -243,3 +245,78 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
   reloc_result->flags = flags;
   *value = DL_FIXUP_ADDR_VALUE (sym.st_value);
 }
+
+void
+_dl_audit_pltenter (struct link_map *l, struct reloc_result *reloc_result,
+                   DL_FIXUP_VALUE_TYPE *value, void *regs, long int *framesize)
+{
+  /* Don't do anything if no auditor wants to intercept this call.  */
+  if (GLRO(dl_naudit) == 0
+      || (reloc_result->enterexit & LA_SYMB_NOPLTENTER))
+    return;
+
+  /* Sanity check:  DL_FIXUP_VALUE_CODE_ADDR (value) should have been
+     initialized earlier in this function or in another thread.  */
+  assert (DL_FIXUP_VALUE_CODE_ADDR (*value) != 0);
+  ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound,
+                                           l_info[DT_SYMTAB])
+                      + reloc_result->boundndx);
+
+  /* Set up the sym parameter.  */
+  ElfW(Sym) sym = *defsym;
+  sym.st_value = DL_FIXUP_VALUE_ADDR (*value);
+
+  /* Get the symbol name.  */
+  const char *strtab = (const void *) D_PTR (reloc_result->bound,
+                                            l_info[DT_STRTAB]);
+  const char *symname = strtab + sym.st_name;
+
+  /* Keep track of overwritten addresses.  */
+  unsigned int flags = reloc_result->flags;
+
+  struct audit_ifaces *afct = GLRO(dl_audit);
+  for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+    {
+      if (afct->ARCH_LA_PLTENTER != NULL
+         && (reloc_result->enterexit
+             & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0)
+       {
+         long int new_framesize = -1;
+         struct auditstate *l_state = link_map_audit_state (l, cnt);
+         struct auditstate *bound_state
+           = link_map_audit_state (reloc_result->bound, cnt);
+         uintptr_t new_value
+           = afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx,
+                                     &l_state->cookie, &bound_state->cookie,
+                                     regs, &flags, symname, &new_framesize);
+         if (new_value != (uintptr_t) sym.st_value)
+           {
+             flags |= LA_SYMB_ALTVALUE;
+             sym.st_value = new_value;
+           }
+
+         /* Remember the results for every audit library and store a summary
+            in the first two bits.  */
+         reloc_result->enterexit |= ((flags & (LA_SYMB_NOPLTENTER
+                                               | LA_SYMB_NOPLTEXIT))
+                                     << (2 * (cnt + 1)));
+
+         if ((reloc_result->enterexit & (LA_SYMB_NOPLTEXIT
+                                         << (2 * (cnt + 1))))
+             == 0 && new_framesize != -1 && *framesize != -2)
+           {
+             /* If this is the first call providing information, use it.  */
+             if (*framesize == -1)
+               *framesize = new_framesize;
+             /* If two pltenter calls provide conflicting information, use
+                the larger value.  */
+             else if (new_framesize != *framesize)
+               *framesize = MAX (new_framesize, *framesize);
+           }
+       }
+
+      afct = afct->next;
+    }
+
+  *value = DL_FIXUP_ADDR_VALUE (sym.st_value);
+}
index c4413c9165cec8cb4e4dd49a14609e1d3ce2c667..dfedeaf2dd1c725303f9322f5fca214519c2e378 100644 (file)
@@ -320,78 +320,7 @@ _dl_profile_fixup (
 #ifdef SHARED
   /* Auditing checkpoint: report the PLT entering and allow the
      auditors to change the value.  */
-  if (GLRO(dl_naudit) > 0
-      /* Don't do anything if no auditor wants to intercept this call.  */
-      && (reloc_result->enterexit & LA_SYMB_NOPLTENTER) == 0)
-    {
-      /* Sanity check:  DL_FIXUP_VALUE_CODE_ADDR (value) should have been
-        initialized earlier in this function or in another thread.  */
-      assert (DL_FIXUP_VALUE_CODE_ADDR (value) != 0);
-      ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound,
-                                               l_info[DT_SYMTAB])
-                          + reloc_result->boundndx);
-
-      /* Set up the sym parameter.  */
-      ElfW(Sym) sym = *defsym;
-      sym.st_value = DL_FIXUP_VALUE_ADDR (value);
-
-      /* Get the symbol name.  */
-      const char *strtab = (const void *) D_PTR (reloc_result->bound,
-                                                l_info[DT_STRTAB]);
-      const char *symname = strtab + sym.st_name;
-
-      /* Keep track of overwritten addresses.  */
-      unsigned int flags = reloc_result->flags;
-
-      struct audit_ifaces *afct = GLRO(dl_audit);
-      for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
-       {
-         if (afct->ARCH_LA_PLTENTER != NULL
-             && (reloc_result->enterexit
-                 & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0)
-           {
-             long int new_framesize = -1;
-             struct auditstate *l_state = link_map_audit_state (l, cnt);
-             struct auditstate *bound_state
-               = link_map_audit_state (reloc_result->bound, cnt);
-             uintptr_t new_value
-               = afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx,
-                                         &l_state->cookie,
-                                         &bound_state->cookie,
-                                         regs, &flags, symname,
-                                         &new_framesize);
-             if (new_value != (uintptr_t) sym.st_value)
-               {
-                 flags |= LA_SYMB_ALTVALUE;
-                 sym.st_value = new_value;
-               }
-
-             /* Remember the results for every audit library and
-                store a summary in the first two bits.  */
-             reloc_result->enterexit
-               |= ((flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT))
-                   << (2 * (cnt + 1)));
-
-             if ((reloc_result->enterexit & (LA_SYMB_NOPLTEXIT
-                                             << (2 * (cnt + 1))))
-                 == 0 && new_framesize != -1 && framesize != -2)
-               {
-                 /* If this is the first call providing information,
-                    use it.  */
-                 if (framesize == -1)
-                   framesize = new_framesize;
-                 /* If two pltenter calls provide conflicting information,
-                    use the larger value.  */
-                 else if (new_framesize != framesize)
-                   framesize = MAX (new_framesize, framesize);
-               }
-           }
-
-         afct = afct->next;
-       }
-
-      value = DL_FIXUP_ADDR_VALUE (sym.st_value);
-    }
+  _dl_audit_pltenter (l, reloc_result, &value, regs, &framesize);
 #endif
 
   /* Store the frame size information.  */
index 9a67e296a8c141022dda3a97842e06eceabb53b9..cf9f58d6f548af0337bb32c763ade06a2504b2da 100644 (file)
@@ -1434,6 +1434,10 @@ void _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result,
 void _dl_audit_symbind_alt (struct link_map *l, const ElfW(Sym) *ref,
                            void **value, lookup_t result);
 rtld_hidden_proto (_dl_audit_symbind_alt)
+void _dl_audit_pltenter (struct link_map *l, struct reloc_result *reloc_result,
+                        DL_FIXUP_VALUE_TYPE *value, void *regs,
+                        long int *framesize)
+  attribute_hidden;
 #endif /* SHARED */
 
 #if PTHREAD_IN_LIBC && defined SHARED
This page took 0.044479 seconds and 5 git commands to generate.