Strange behavior with Linux binaries
Posted: Mon Apr 27, 2009 7:06 am
Hello,
I was wondering if someone had already tried executing binaries that were originally compiled for Linux?
If so I've got a few questions
1) How is errno handled? By examining the Linux kernel code I'm about 90 % sure that when an error occurs, the errno value is returned negatively in the EAX register (and then errno is updated by the function which made the syscall) ; what makes me doubt is that official docs say for almost all functions "on error it should return -1 and update errno"
2) How does sys_brk work? According to the docs it should just store the parameter (ie. the end of the heap), returning -1 if the parameter is too large and 0 otherwise ; but with some experimentations I discovered that the Linux kernel doesn't update the value if it is null, and always returns the stored value
3) What docs do you use? Official manual seems to say incorrect things and the Linux kernel is really messy, I lose a lot of time looking for the function I want in the kernel. Variables and structs with non-explicit names doesn't help
I've already found some useful links:
http://foosec.pl/pub/info/syscalls_linux_2_2.html (did Linux 2.2 only have 190 syscalls? 2.6.29 has 332 ones)
http://webster.cs.ucr.edu/Page_Linux/LinuxSysCalls.pdf
http://linux-documentation.com/en/man/man2/
http://linux.die.net/include/asm/unistd.h
But none of them is really good
For example I'm currently stuck on what I should return for sys_mmap2 with length = 0
According to this page since 2.6.12 the call should fail if length = 0 but if I do so the program I'm trying to execute exits after printing an error message
I'm certainly going to solve this problem soon by myself, but I'm regularly stuck because of lack of actual documentation
I was wondering if someone had already tried executing binaries that were originally compiled for Linux?
If so I've got a few questions
1) How is errno handled? By examining the Linux kernel code I'm about 90 % sure that when an error occurs, the errno value is returned negatively in the EAX register (and then errno is updated by the function which made the syscall) ; what makes me doubt is that official docs say for almost all functions "on error it should return -1 and update errno"
2) How does sys_brk work? According to the docs it should just store the parameter (ie. the end of the heap), returning -1 if the parameter is too large and 0 otherwise ; but with some experimentations I discovered that the Linux kernel doesn't update the value if it is null, and always returns the stored value
3) What docs do you use? Official manual seems to say incorrect things and the Linux kernel is really messy, I lose a lot of time looking for the function I want in the kernel. Variables and structs with non-explicit names doesn't help
I've already found some useful links:
http://foosec.pl/pub/info/syscalls_linux_2_2.html (did Linux 2.2 only have 190 syscalls? 2.6.29 has 332 ones)
http://webster.cs.ucr.edu/Page_Linux/LinuxSysCalls.pdf
http://linux-documentation.com/en/man/man2/
http://linux.die.net/include/asm/unistd.h
But none of them is really good
For example I'm currently stuck on what I should return for sys_mmap2 with length = 0
According to this page since 2.6.12 the call should fail if length = 0 but if I do so the program I'm trying to execute exits after printing an error message
I'm certainly going to solve this problem soon by myself, but I'm regularly stuck because of lack of actual documentation