From: Tom Hughes Date: Wed, 17 Apr 2013 10:08:04 +0000 (+0000) Subject: Pay attention to PT_GNU_STACK when deciding what permissions to X-Git-Tag: svn/VALGRIND_3_9_0~316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11234a940796a250cd3eaf70667940ce99463409;p=thirdparty%2Fvalgrind.git Pay attention to PT_GNU_STACK when deciding what permissions to use for the client stack. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13368 --- diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c index f9a68a6715..653ce1a9e8 100644 --- a/coregrind/m_initimg/initimg-linux.c +++ b/coregrind/m_initimg/initimg-linux.c @@ -557,7 +557,7 @@ Addr setup_client_stack( void* init_sp, res = VG_(am_mmap_anon_fixed_client)( anon_start -inner_HACK, anon_size +inner_HACK, - VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC + info->stack_prot ); } if ((!ok) || sr_isError(res)) { diff --git a/coregrind/m_ume/elf.c b/coregrind/m_ume/elf.c index 3fae44390b..03b0102d59 100644 --- a/coregrind/m_ume/elf.c +++ b/coregrind/m_ume/elf.c @@ -354,6 +354,7 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info) info->phnum = e->e.e_phnum; info->entry = e->e.e_entry + ebase; info->phdr = 0; + info->stack_prot = VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC; for (i = 0; i < e->e.e_phnum; i++) { ESZ(Phdr) *ph = &e->p[i]; @@ -416,6 +417,12 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info) } break; + case PT_GNU_STACK: + if ((ph->p_flags & PF_X) == 0) info->stack_prot &= ~VKI_PROT_EXEC; + if ((ph->p_flags & PF_W) == 0) info->stack_prot &= ~VKI_PROT_WRITE; + if ((ph->p_flags & PF_R) == 0) info->stack_prot &= ~VKI_PROT_READ; + break; + default: // do nothing break; diff --git a/coregrind/pub_core_ume.h b/coregrind/pub_core_ume.h index e1ab47ba28..2ac4600324 100644 --- a/coregrind/pub_core_ume.h +++ b/coregrind/pub_core_ume.h @@ -52,6 +52,7 @@ typedef #if !defined(VGO_darwin) Addr phdr; // OUT: address phdr was mapped at Int phnum; // OUT: number of phdrs + UInt stack_prot; // OUT: stack permissions Addr interp_base; // OUT: where interpreter (ld.so) was mapped #else Addr stack_start; // OUT: address of start of stack segment (hot)