]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Pay attention to PT_GNU_STACK when deciding what permissions to
authorTom Hughes <tom@compton.nu>
Wed, 17 Apr 2013 10:08:04 +0000 (10:08 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 17 Apr 2013 10:08:04 +0000 (10:08 +0000)
use for the client stack.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13368

coregrind/m_initimg/initimg-linux.c
coregrind/m_ume/elf.c
coregrind/pub_core_ume.h

index f9a68a6715520c22f402f3c05e0c20e174cd98bf..653ce1a9e8ef2073d30873c7c76ba3a1cd87ffe6 100644 (file)
@@ -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)) {
index 3fae44390b656efbc564435f6accdbb39aae2173..03b0102d593f09bdc03dc43adbf4d183170ca3a6 100644 (file)
@@ -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;
index e1ab47ba28055aa7cfc35994fa5428e5239076a3..2ac46003249bafd2a280cd0736cd89adc580339d 100644 (file)
@@ -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)