mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 20:40:05 +00: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:
parent
0b98a87487
commit
eff687e846
@ -17,7 +17,9 @@
|
|||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <link.h>
|
||||||
#include <ldsodefs.h>
|
#include <ldsodefs.h>
|
||||||
|
#include <dl-machine.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
_dl_audit_activity_map (struct link_map *l, int action)
|
_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;
|
reloc_result->flags = flags;
|
||||||
*value = DL_FIXUP_ADDR_VALUE (sym.st_value);
|
*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);
|
||||||
|
}
|
||||||
|
@ -320,78 +320,7 @@ _dl_profile_fixup (
|
|||||||
#ifdef SHARED
|
#ifdef SHARED
|
||||||
/* Auditing checkpoint: report the PLT entering and allow the
|
/* Auditing checkpoint: report the PLT entering and allow the
|
||||||
auditors to change the value. */
|
auditors to change the value. */
|
||||||
if (GLRO(dl_naudit) > 0
|
_dl_audit_pltenter (l, reloc_result, &value, regs, &framesize);
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Store the frame size information. */
|
/* Store the frame size information. */
|
||||||
|
@ -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 _dl_audit_symbind_alt (struct link_map *l, const ElfW(Sym) *ref,
|
||||||
void **value, lookup_t result);
|
void **value, lookup_t result);
|
||||||
rtld_hidden_proto (_dl_audit_symbind_alt)
|
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 */
|
#endif /* SHARED */
|
||||||
|
|
||||||
#if PTHREAD_IN_LIBC && defined SHARED
|
#if PTHREAD_IN_LIBC && defined SHARED
|
||||||
|
Loading…
Reference in New Issue
Block a user