[mupen64plus] 129/262: Don't enable executable stack by default

Sven Eckelmann ecsv-guest at moszumanska.debian.org
Thu Nov 26 05:59:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

ecsv-guest pushed a commit to branch master
in repository mupen64plus.

commit f552fbdd4a73744c6650d306a329a09cc225bc7c
Author: Sven Eckelmann <sven.eckelmann at gmx.de>
Date:   Mon Sep 21 13:24:17 2009 +0200

    Don't enable executable stack by default
    
    A non executable stack is asecurity feature on modern platforms to
    protect against an attack made possble by a flaws that allows an
    attacker to fill stack memory with executable code.
    As mupen64plus needs executable pages store its recompiled code the code
    blocks and wrapper blocks must be allocated page aligned to change the
    protection bits to executable of pages which belong to that memory
    block.
---
 debian/changelog                 |   2 +
 debian/patches/noexecstack.patch | 208 +++++++++++++++++++++++++++++++++++++++
 debian/patches/series            |   1 +
 3 files changed, 211 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 49b6cdb..0ad302e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,8 @@ mupen64plus (1.5+dfsg1-5) UNRELEASED; urgency=low
     - Remove number before patches as order is given by debian/patches/series
     - Add gtk-open-filter.patch, Show files with .n64 and .v64 extension in
       filtered open file dialog (Closes: #546046)
+    - Add noexecstack.patch, Don't enable executable stack by default
+      (Closes: #547644)
 
  -- Sven Eckelmann <sven.eckelmann at gmx.de>  Fri, 11 Sep 2009 00:37:19 +0200
 
diff --git a/debian/patches/noexecstack.patch b/debian/patches/noexecstack.patch
new file mode 100644
index 0000000..b9fd381
--- /dev/null
+++ b/debian/patches/noexecstack.patch
@@ -0,0 +1,208 @@
+Description: Don't enable executable stack by default
+ A non executable stack is asecurity feature on modern platforms to protect
+ against an attack made possble by a flaws that allows an attacker to fill stack
+ memory with executable code.
+ As mupen64plus needs executable pages store its recompiled code the code blocks
+ and wrapper blocks must be allocated page aligned to change the protection bits
+ to executable of pages which belong to that memory block.
+Bug: http://code.google.com/p/mupen64plus/issues/detail?id=268
+Bug-Debian: http://bugs.debian.org/547644
+Author: Sven Eckelmann <sven.eckelmann at gmx.de>
+
+---
+diff --git a/Makefile b/Makefile
+index 01493e6e7f70fcd49ec784b97b54882404dbb599..2368afa38816069f4fd176c1936c23f40d277095 100644
+--- a/Makefile
++++ b/Makefile
+@@ -33,13 +33,6 @@ ifeq ($(OS), LINUX)
+   LDFLAGS += -Wl,-export-dynamic
+ endif
+ 
+-# set executable stack as a linker option for X86 architecture, for dynamic recompiler
+-ifeq ($(CPU), X86)
+-  ifeq ($(OS), LINUX)
+-    LDFLAGS += -z execstack
+-  endif
+-endif
+-
+ # set options
+ ifeq ($(DBG), 1)
+   CFLAGS += -DDBG
+diff --git a/r4300/recomp.c b/r4300/recomp.c
+index 876fc55213fde588365ec948abaf60abb56f07f6..d3672f30f52ed9fbd0391d434c660b0bfd45d774 100644
+--- a/r4300/recomp.c
++++ b/r4300/recomp.c
+@@ -20,6 +20,10 @@
+  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ 
+ #include <stdlib.h>
++#if defined(__GNUC__)
++#include <malloc.h>
++#include <sys/mman.h>
++#endif
+ 
+ #include "recomp.h"
+ #include "recomph.h" //include for function prototypes
+@@ -2168,7 +2172,7 @@ void init_block(int *source, precomp_block *block)
+   if (!block->block)
+   {
+     long memsize = ((length+1)+(length>>2)) * sizeof(precomp_instr);
+-    block->block = malloc(memsize);
++    block->block = malloc_exec(memsize);
+     memset(block->block, 0, memsize);
+     already_exist = 0;
+   }
+@@ -2178,12 +2182,12 @@ void init_block(int *source, precomp_block *block)
+     if (!block->code)
+     {
+ #if defined(PROFILE_R4300)
+-      block->code = malloc(524288); /* allocate so much code space that we'll never have to realloc(), because this may */
+-      max_code_length = 524288;     /* cause instruction locations to move, and break our profiling data                */
++      max_code_length = 524288; /* allocate so much code space that we'll never have to realloc(), because this may */
++                                /* cause instruction locations to move, and break our profiling data                */
+ #else
+-      block->code = malloc(32768);
+       max_code_length = 32768;
+ #endif
++      block->code = malloc_exec(max_code_length);
+     }
+     else
+     {
+@@ -2574,3 +2578,35 @@ void prefetch_opcode(unsigned int op)
+    recomp_ops[((src >> 26) & 0x3F)]();
+ }
+ 
++/**********************************************************************
++ ************** allocate memory with executable bit set ***************
++ **********************************************************************/
++void *malloc_exec(size_t size)
++{
++#if defined(__GNUC__)
++   void* block = valloc(size);
++   if (block != NULL)
++      mprotect(block, size, PROT_READ | PROT_WRITE | PROT_EXEC);
++   return block;
++#else
++   return malloc(size);
++#endif
++}
++
++/**********************************************************************
++ ************* reallocate memory with executable bit set **************
++ **********************************************************************/
++void *realloc_exec(void *ptr, size_t size, size_t newsize)
++{
++   void* block = malloc_exec(newsize);
++   if (block != NULL) {
++      size_t copysize;
++      if (size < newsize)
++         copysize = size;
++      else
++         copysize = newsize;
++      memcpy(block, ptr, copysize);
++   }
++   free(ptr);
++   return block;
++}
+diff --git a/r4300/recomp.h b/r4300/recomp.h
+index d286bef27a9b107e0c5da36ca444a59ed7b9cf8d..1b2c859c7bcdf189d2d75cb8d6e2626f461a2852 100644
+--- a/r4300/recomp.h
++++ b/r4300/recomp.h
+@@ -22,6 +22,7 @@
+ #ifndef RECOMP_H
+ #define RECOMP_H
+ 
++#include <stddef.h>
+ #if defined(__x86_64__)
+   #include "x86_64/assemble.h"
+ #else
+@@ -92,6 +93,8 @@ void prefetch_opcode(unsigned int op);
+ void dyna_jump();
+ void dyna_start(void (*code)());
+ void dyna_stop();
++void *malloc_exec(size_t size);
++void *realloc_exec(void *ptr, size_t size, size_t newsize);
+ 
+ extern precomp_instr *dst; /* precomp_instr structure for instruction being recompiled */
+ 
+diff --git a/r4300/x86/assemble.c b/r4300/x86/assemble.c
+index dd99314637a35e5058b8e5b9e9cc6dc944433686..4f6203a2213f8ac22e2f37d6ec257ef18a2f3be6 100644
+--- a/r4300/x86/assemble.c
++++ b/r4300/x86/assemble.c
+@@ -78,8 +78,8 @@ static void put8(unsigned char octet)
+    code_length++;
+    if (code_length == max_code_length)
+      {
+-    max_code_length += 1000;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
++    max_code_length += 8192;
+      }
+ }
+ 
+@@ -87,8 +87,8 @@ static void put16(unsigned short word)
+ {
+    if ((code_length+2) >= max_code_length)
+      {
+-    max_code_length += 1000;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
++    max_code_length += 8192;
+      }
+    *((unsigned short *)(&(*inst_pointer)[code_length])) = word;
+    code_length+=2;
+@@ -98,8 +98,8 @@ static void put32(unsigned int dword)
+ {
+    if ((code_length+4) >= max_code_length)
+      {
+-    max_code_length += 1000;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
++    max_code_length += 8192;
+      }
+    *((unsigned int *)(&(*inst_pointer)[code_length])) = dword;
+    code_length+=4;
+diff --git a/r4300/x86_64/assemble.c b/r4300/x86_64/assemble.c
+index 443f3355241bd94e0421878b018e46646b969558..bb9fdf14f392e230d3430d29d007c50b15d8626c 100644
+--- a/r4300/x86_64/assemble.c
++++ b/r4300/x86_64/assemble.c
+@@ -195,8 +195,8 @@ static void put8(unsigned char octet)
+   code_length++;
+   if (code_length == max_code_length)
+   {
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
+     max_code_length += 8192;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
+   }
+ }
+ 
+@@ -204,8 +204,8 @@ static void put16(unsigned short word)
+ {
+   if ((code_length + 2) >= max_code_length)
+   {
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
+     max_code_length += 8192;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
+   }
+   *((unsigned short *) (*inst_pointer + code_length)) = word;
+   code_length += 2;
+@@ -215,8 +215,8 @@ static void put32(unsigned int dword)
+ {
+   if ((code_length + 4) >= max_code_length)
+   {
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
+     max_code_length += 8192;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
+   }
+   *((unsigned int *) (*inst_pointer + code_length)) = dword;
+   code_length += 4;
+@@ -226,8 +226,8 @@ static void put64(unsigned long long qword)
+ {
+   if ((code_length + 8) >= max_code_length)
+   {
++    *inst_pointer = realloc_exec(*inst_pointer, max_code_length, max_code_length+8192);
+     max_code_length += 8192;
+-    *inst_pointer = realloc(*inst_pointer, max_code_length);
+   }
+   *((unsigned long long *) (*inst_pointer + code_length)) = qword;
+   code_length += 8;
diff --git a/debian/patches/series b/debian/patches/series
index 559d110..ab3d2a8 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -22,3 +22,4 @@ ftbfs-glibc210.patch
 version-string.patch
 default-optimisations.patch
 gtk-open-filter.patch
+noexecstack.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/mupen64plus.git



More information about the Pkg-games-commits mailing list