History

Use mmap instead of exec mem for Selinux machines. Fixes crash on Fedora.

Henry Kroll III committed 16 years ago

Commit be7e3391 parent a64a6f32 files · +41 −5Browse files

Unified · Split

2 files
  1. configure +8 −1
  2. tccrun.c +33 −4
configure+8−1
@@ -130,6 +130,8 @@ for opt do · 129 unmodified lines
130130 ;;
131131 --with-libgcc) use_libgcc="yes"
132132 ;;
133+ --with-selinux) have_selinux="yes"
134+ ;;
133135 --help|-h) show_help="yes"
134136 ;;
135137 esac
@@ -229,7 +231,8 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" · 93 unmodified lines
229231 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
230232 echo " --cc=CC use C compiler CC [$cc]"
231233 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
232−echo ""
234+echo " --with-selinux use mmap instead of exec mem"
235+echo " [requires write access to /tmp]"echo ""
233236 #echo "NOTE: The object files are build at the place where configure is launched"
234237 exit 1
235238 fi
@@ -357,6 +360,10 @@ if test "$use_libgcc" = "yes" ; then · 121 unmodified lines
357360 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
358361 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
359362 fi
363+if test "$have_selinux" = "yes" ; then
364+ echo "#define HAVE_SELINUX" >> $TMPH
365+ echo "HAVE_SELINUX=yes" >> config.mak
366+fi
360367 version=`head $source_path/VERSION`
361368 echo "VERSION=$version" >>config.mak
362369 echo "#define TCC_VERSION \"$version\"" >> $TMPH
tccrun.c+33−4
@@ -50,10 +50,34 @@ int tcc_relocate(TCCState *s1) · 49 unmodified lines
5050 int tcc_run(TCCState *s1, int argc, char **argv)
5151 {
5252 int (*prog_main)(int, char **);
53−
53+ int ret;
54+#ifdef HAVE_SELINUX
55+ int rret;
56+ void *ptr,*writep;
57+ char tmpfname[] = "/tmp/.tccrunXXXXXX";
58+ int fd = mkstemp (tmpfname);
59+ unlink (tmpfname);
60+ ftruncate (fd, 1000);
61+ if ((rret= tcc_relocate_ex(s1,NULL)) < 0)
62+ return -1;
63+ /* Use mmap instead of malloc for Selinux */
64+ writep = mmap (NULL, rret, PROT_READ|PROT_WRITE,
65+ MAP_SHARED, fd, 0);
66+ if(writep == MAP_FAILED){
67+ error("/tmp not writeable");
68+ return -1;
69+ }
70+ ptr = mmap (NULL, rret, PROT_READ|PROT_EXEC,
71+ MAP_SHARED, fd, 0);
72+ if(ptr == MAP_FAILED){
73+ error("/tmp not executable");
74+ return -1;
75+ }
76+ tcc_relocate_ex(s1, writep);
77+#else
5478 if (tcc_relocate(s1) < 0)
5579 return -1;
56−
80+#endif
5781 prog_main = tcc_get_symbol_err(s1, "main");
5882
5983 #ifdef CONFIG_TCC_BACKTRACE
@@ -65,7 +89,6 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines
6589 if (s1->do_bounds_check) {
6690 void (*bound_init)(void);
6791 void (*bound_exit)(void);
68− int ret;
6992 /* set error function */
7093 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
7194 rt_prog_main = prog_main;
@@ -85,7 +108,13 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 13 unmodified lines
85108 if (p) *p = 0;
86109 }
87110 #endif
88− return (*prog_main)(argc, argv);
111+ ret=(*prog_main)(argc, argv);
112+#ifdef HAVE_SELINUX
113+ munmap (writep, rret);
114+ munmap (ptr, rret);
115+
116+#endif
117+ return ret;
89118 }
90119
91120

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t