summaryrefslogtreecommitdiff
path: root/jail/elf.c
Commit message (Collapse)AuthorAgeFilesLines
* jail: ignore missing .dynamic sectYuteng Zhong2022-11-101-8/+8
| | | | | | | | | | A static-linked binary doesn't have a .dynamic section, but when starting ujail with -r or -w will automatically search for PT_DYNAMIC in ELF and exit with failure if it is not found. github issue: https://github.com/openwrt/openwrt/issues/10933 Signed-off-by: Yuteng Zhong <zonyitoo@qq.com>
* jail: elf: Remove MIPS 64 warningHauke Mehrtens2021-11-011-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Revert commit 33b799b ("ujail: elf: work around GCC bug on MIPS64") The procd jails are working fine on MIPS64 too now. I saw this error message when add_path_and_deps() was called which calls elf_load_deps() again under some conditions. This is happening because gcc_mips64_bug_work_around is stored in the data segment. We have a call trace like this: elf_load_deps() gcc_mips64_bug_work_around = 1; call add_path_and_deps() call elf_load_deps() gcc_mips64_bug_work_around = 1; error if gcc_mips64_bug_work_around =! 1 gcc_mips64_bug_work_around = 0; return; return; error if gcc_mips64_bug_work_around =! 1 return; I got the same error messages on MIPS 32 BE, when I removed the compile check. This was tested in qemu on MIPS 64 BE and MIPS64 LE. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* jail: elf: Use 64 bit variables for elf offsetsHauke Mehrtens2021-11-011-8/+8
| | | | | | | | | | | | | | | | | | | | | | The members p_offset, p_filesz and p_vaddr of the structure Elf64_Phdr are all uint64_t. This structure is used for 64 bit applications. Without this change we would convert the 64 bit values into 32 bit values and an overflow could happen in this conversion. On MIPS 64 BE the variable load_vaddr has the value 0x120000000 which sets the 32th bit which will overflow when converted to a 32 bit value. On 32 bit systems Elf32_Phdr is used with uint32_t, converting this to 64 bit values too should not cause problems as this is not in the hot path. Without this fix I am getting error messages like this at bootup on MIPS 64 BE: [ 16.622602] do_page_fault(): sending SIGSEGV to ujail for invalid read access from 00000100f37251e3 [ 16.622907] epc = 000000aaab4ed0e0 in ujail[aaab4e0000+18000] [ 16.623237] ra = 000000aaab4ed694 in ujail[aaab4e0000+18000] Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* jail: leak less memoryDaniel Golle2020-11-271-0/+12
| | | | | | | Always free everything before exiting, clean up dynamic structures, add missing free() calls in various places, ... Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* ujail: elf: work around GCC bug on MIPS64Daniel Golle2020-10-231-0/+12
| | | | | | | | | | | | | | Work-around gcc bug which leads to segfault parsing ELF on MIPS64. The codepath added in this commit gets triggered when parsing /lib/ld-musl-mips64-sf.so.1 (a symlink to /lib/libc.so) on MIPS64 (built with gcc-8.4.0 and musl 1.1.24) in qemu-system-mips64 on the malta/be64 target. Include work-around outputting an error message, but preventing segfault when building for MIPS64. Tested-by: Roman Kuzmitskii <damex.pp@icloud.com> [tested on edgerouter 4 and edgerouter lite] Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* ujail: add O_CLOEXEC flag to open() callEtienne CHAMPETIER2015-12-111-1/+1
| | | | | | | if we forget to close() in the future, this prevent fd leak Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: add ELF interpreter (DT_INTERP) to the jailEtienne CHAMPETIER2015-11-271-0/+5
| | | | | | | | | | | | | this is needed by musl (openwrt DD) uClibc/glibc is working without this this partly fixes https://dev.openwrt.org/ticket/20785 we still don't handle DT_RPATH, DT_RUNPATH, nodeflib, ... see http://man7.org/linux/man-pages/man8/ld.so.8.html Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: rework fs jail partEtienne CHAMPETIER2015-11-271-74/+24
| | | | | | | | | | | | | | | | Change functions to work with full paths (do less split and concat of path) Store "soname" as key and the fullpath as path in "libraries" Remove "extras" list and replace it with "mounts" avl_tree ("mounts" also store fullpath) Add add_path_and_deps() function to handle file/lib openning and mmaping Check if file is an elf (magic number) before passing it to elf_load_deps() elf_load_deps() now only handle elf parsing part next commit adds script (#!) handling Use add_path_and_deps() with -r and -w args to automatically add dependencies Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: DT_STRTAB uses d_ptr in d_un union (not d_val)Etienne CHAMPETIER2015-11-271-2/+2
| | | | | | | see https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-42444/index.html Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: remove some debug/dev hackEtienne CHAMPETIER2015-11-271-6/+1
| | | | | | this code is present since first ujail commit (dfcfcca7) Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: add init_library_search()Etienne CHAMPETIER2015-11-271-2/+11
| | | | | | | | | move all libraries search initialisation stuff into elf.c / init_library_search() for now we don't handle musl specific files Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: use PATH_MAX for path related buffersEtienne CHAMPETIER2015-11-271-4/+5
| | | | Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: remove "#include log.h" from elf.hEtienne CHAMPETIER2015-11-271-0/+1
| | | | | | headers must include all there dependencies, no more, no less Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: add <stdio.h> to log.hEtienne CHAMPETIER2015-11-271-1/+0
| | | | | | | headers must include all there dependencies, no more, no less (it uses fprintf) Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: use more const in elf.*Etienne CHAMPETIER2015-11-271-13/+15
| | | | Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* ujail: don't add non existant library_pathEtienne CHAMPETIER2015-11-271-4/+4
| | | | Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* jail: cleanup includeEtienne CHAMPETIER2015-10-071-14/+0
| | | | Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* add initial version of ujail and utraceJohn Crispin2015-03-231-0/+369
Signed-off-by: John Crispin <blogic@openwrt.org>