1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

elf: Add _dl_audit_pltenter

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>
This commit is contained in:
Adhemerval Zanella
2021-07-22 17:45:33 -03:00
parent 0b98a87487
commit eff687e846
3 changed files with 82 additions and 72 deletions

View 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);
}