mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-05 09:01:07 +00:00
[BZ #1346]
2005-09-20 Roland McGrath <roland@redhat.com> [BZ #1346] * elf/dl-load.c (_dl_map_object_from_fd) [HAVE_Z_RELRO]: Do relro magic on __stack_prot only if [SHARED]. Skip mprotect if __stack_prot lies outside the page-rounded-down relro region.
This commit is contained in:
parent
ab209d3a5c
commit
e751d28209
@ -1354,24 +1354,38 @@ cannot allocate TLS data structures for initial thread");
|
|||||||
|
|
||||||
if (__builtin_expect ((stack_flags &~ GL(dl_stack_flags)) & PF_X, 0))
|
if (__builtin_expect ((stack_flags &~ GL(dl_stack_flags)) & PF_X, 0))
|
||||||
{
|
{
|
||||||
|
if (__builtin_expect (__check_caller (RETURN_ADDRESS (0), allow_ldso),
|
||||||
|
0) != 0)
|
||||||
|
{
|
||||||
|
errstring = N_("invalid caller");
|
||||||
|
goto call_lose;
|
||||||
|
}
|
||||||
|
|
||||||
/* The stack is presently not executable, but this module
|
/* The stack is presently not executable, but this module
|
||||||
requires that it be executable. We must change the
|
requires that it be executable. We must change the
|
||||||
protection of the variable which contains the flags used in
|
protection of the variable which contains the flags used in
|
||||||
the mprotect calls. */
|
the mprotect calls. */
|
||||||
#ifdef HAVE_Z_RELRO
|
#if defined HAVE_Z_RELRO && defined SHARED
|
||||||
if ((mode & (__RTLD_DLOPEN | __RTLD_AUDIT)) == __RTLD_DLOPEN)
|
if ((mode & (__RTLD_DLOPEN | __RTLD_AUDIT)) == __RTLD_DLOPEN)
|
||||||
{
|
{
|
||||||
uintptr_t p = ((uintptr_t) &__stack_prot) & ~(GLRO(dl_pagesize) - 1);
|
const uintptr_t p = (uintptr_t) &__stack_prot & -GLRO(dl_pagesize);
|
||||||
size_t s = (uintptr_t) &__stack_prot - p + sizeof (int);
|
const size_t s = (uintptr_t) (&__stack_prot + 1) - p;
|
||||||
|
|
||||||
|
struct link_map *const m = &GL(dl_rtld_map);
|
||||||
|
const uintptr_t relro_end = ((m->l_addr + m->l_relro_addr
|
||||||
|
+ m->l_relro_size)
|
||||||
|
& -GLRO(dl_pagesize));
|
||||||
|
if (__builtin_expect (p + s <= relro_end, 1))
|
||||||
|
{
|
||||||
|
/* The variable lies in the region protected by RELRO. */
|
||||||
__mprotect ((void *) p, s, PROT_READ|PROT_WRITE);
|
__mprotect ((void *) p, s, PROT_READ|PROT_WRITE);
|
||||||
if (__builtin_expect (__check_caller (RETURN_ADDRESS (0),
|
|
||||||
allow_ldso) == 0,
|
|
||||||
0))
|
|
||||||
__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
|
__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
|
||||||
__mprotect ((void *) p, s, PROT_READ);
|
__mprotect ((void *) p, s, PROT_READ);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
|
__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user