I would like to execute arbitrary (potentially dangerous) binaries on my server. Therefore, I have used objcopy
to rename the "main" symbol to "other_main" so that I could link in my own small main function that sets an appropriate value for RLIMIT_CPU
and toggles the SECCOMP
flag before calling other_main. I am quite happy with this solution so far.
The problem now is, that the 3rd party program code might contain some calls to malloc that might kill the program instantly (sbrk isn't allowed). Therefore I would like to pre-allocate some reasonable sized array (e.g. 20MB) before setting SECCOMP
that should be used by malloc / realloc / calloc / free. Unfortunately, I don't know how to archive the last step. Do I have to implement all those 4 functions on my own? How can I inject my own functions to the stdlib (e.g., what happens when printf calls malloc internally?).