I am trying to use Python for an embedded application on an Arm processor running Linux (CPython 2.7.3, cross-compiled from X86 / Linux). It worked very well until I started protecting the device to prevent tampering. At first, I made rootfs read-only to prevent damage to root computers in the event of a sudden loss of power and to prevent unauthorized users from making changes to our main code. However, python and our ctypes libraries continued to work as usual. The / tmp directory maps to tmpfs (ramdrive). Another simplification step is to set the noexec flag on the tmpfs section so that users cannot load any code in any way that could lead to a local root exploit. If both of these options are set, importing ctypes causes immediate segfault:
root@ATX4 :~# python Python 2.7.3 (default, Jul 16 2013, 17:15:57) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes Segmentation fault
Interestingly, any of the changes below allow ctypes to work correctly:
- Rebooting rootfs as read / write
- Rebooting tmpfs without noexec
- Reboot / dev / shm without noexec
Any idea what causes this? At the moment, I created / dev / shm mount without noexec and just limit it to the least possible users.
source share