[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Fix boundschecking for signal/sigaction/fork

From: Herman ten Brugge
Subject: [Tinycc-devel] Fix boundschecking for signal/sigaction/fork
Date: Thu, 17 Sep 2020 21:23:38 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0


I have recently added code to redirect fork/sigaction to the bound checking
code. I also implemented limited thread local storage support.

See also commit Fix boundschecking for signal/sigaction/fork

The radare2 project (https://github.com/radareorg/radare2) has very high
load for fork/sigaction and bound checking failed.
For bound checking and tcc to work I had to do patches and sent them to a
maintainer for the radare2 project. The patches I sent probably need some
review and are not present in the radare2 git repository yet.
After the above commit and the changes to radare2 project to compile
with "tcc -b" the result was the same as compiled with gcc.

The implementation of thread local storage is just enough to link the
gcc compiled code of bcheck.c on i386/x86_64. It does not mean that
thread local storage is now supported and static linking still fails.

There is still one problem. fork() is not compatible with -run and SELINUX.
You can see this when doing:
tcc -b -run tests/tests2/114_bound_signal.c

The problem is that MAP_SHARED is used. This means the parent and child
still share the same memory after fork().
The patch below fixes this.
Can I apply this patch or is there a better solution?


diff --git a/tccrun.c b/tccrun.c
index 17f1eeb..7057e44 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -88,8 +88,12 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
     ftruncate(fd, size);
+#if 0 /* does not work with fork */
     ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
     prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
+    ptr = prx = mmap (NULL, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, fd, 0);
     if (ptr == MAP_FAILED || prx == MAP_FAILED)
        tcc_error("tccrun: could not map memory");
     dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size);
diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
index f7f4791..93e4062 100644
--- a/tests/tests2/Makefile
+++ b/tests/tests2/Makefile
@@ -94,7 +94,6 @@ GEN-ALWAYS =
 114_bound_signal.test: FLAGS += -b
-114_bound_signal.test: NORUN = true # tcc -run does not support fork and -b and SELINUX
 115_bound_setjmp.test: FLAGS += -b
 116_bound_setjmp2.test: FLAGS += -b
 117_builtins.test: T1 = ( $(TCC) -run $1 && $(TCC) -b -run $1 )

reply via email to

[Prev in Thread] Current Thread [Next in Thread]