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
130 ;;130 ;;
131 --with-libgcc) use_libgcc="yes"131 --with-libgcc) use_libgcc="yes"
132 ;;132 ;;
133 --with-selinux) have_selinux="yes"
134 ;;
133 --help|-h) show_help="yes"135 --help|-h) show_help="yes"
134 ;;136 ;;
135 esac137 esac
@@ -229,7 +231,8 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" · 93 unmodified lines
229echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"231echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
230echo " --cc=CC use C compiler CC [$cc]"232echo " --cc=CC use C compiler CC [$cc]"
231echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"233echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
232echo ""234echo " --with-selinux use mmap instead of exec mem"
235echo " [requires write access to /tmp]"echo ""
233#echo "NOTE: The object files are build at the place where configure is launched"236#echo "NOTE: The object files are build at the place where configure is launched"
234exit 1237exit 1
235fi238fi
@@ -357,6 +360,10 @@ if test "$use_libgcc" = "yes" ; then · 121 unmodified lines
357 echo "#define CONFIG_USE_LIBGCC" >> $TMPH360 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
358 echo "CONFIG_USE_LIBGCC=yes" >> config.mak361 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
359fi362fi
363if test "$have_selinux" = "yes" ; then
364 echo "#define HAVE_SELINUX" >> $TMPH
365 echo "HAVE_SELINUX=yes" >> config.mak
366fi
360version=`head $source_path/VERSION`367version=`head $source_path/VERSION`
361echo "VERSION=$version" >>config.mak368echo "VERSION=$version" >>config.mak
362echo "#define TCC_VERSION \"$version\"" >> $TMPH369echo "#define TCC_VERSION \"$version\"" >> $TMPH
tccrun.c+33−4
@@ -50,10 +50,34 @@ int tcc_relocate(TCCState *s1) · 49 unmodified lines
50int tcc_run(TCCState *s1, int argc, char **argv)50int tcc_run(TCCState *s1, int argc, char **argv)
51{51{
52 int (*prog_main)(int, char **);52 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
54 if (tcc_relocate(s1) < 0)78 if (tcc_relocate(s1) < 0)
55 return -1;79 return -1;
56 80#endif
57 prog_main = tcc_get_symbol_err(s1, "main");81 prog_main = tcc_get_symbol_err(s1, "main");
58 82
59#ifdef CONFIG_TCC_BACKTRACE83#ifdef CONFIG_TCC_BACKTRACE
@@ -65,7 +89,6 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines
65 if (s1->do_bounds_check) {89 if (s1->do_bounds_check) {
66 void (*bound_init)(void);90 void (*bound_init)(void);
67 void (*bound_exit)(void);91 void (*bound_exit)(void);
68 int ret;
69 /* set error function */92 /* set error function */
70 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");93 rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg");
71 rt_prog_main = prog_main;94 rt_prog_main = prog_main;
@@ -85,7 +108,13 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 13 unmodified lines
85 if (p) *p = 0;108 if (p) *p = 0;
86 }109 }
87#endif110#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;
89}118}
90 119
91 120

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