Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/usr/include/unistd.h:603:13: error: conflicting types for '_exit' #1

Closed
unixfreaxjp opened this issue May 30, 2018 · 5 comments
Closed

Comments

@unixfreaxjp
Copy link

unixfreaxjp commented May 30, 2018

Good work on the method for injection with fPIE compilation ELF!

I am not so sure why I have problem with the build, as per seen in the the title or in the error snip below.
It seems that the macro (for arch recognition) is having a problem or icrt_syscall.h has been conflicted with /usr/include/unistd.h ?
If you would be kind to upload the mandiblue you compiled for the both architecture in the repo or onto virus total etc, it would be very helpful. I am onto reproduction the method your described.
I use Debian for the purpose, and doing plenty of build on the other apps without problem.. Thank you.

On x32:

$ make x86
rm -rf mandibule target toinject
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -pie -fPIE -fno-builtin -nostdlib -m32 -o mandibule mandibule.c
In file included from /usr/include/i386-linux-gnu/sys/user.h:25:0,
                 from code/ptinject.h:15,
                 from mandibule.c:28:
/usr/include/unistd.h:603:13: error: conflicting types for '_exit'
 extern void _exit (int __status) __attribute__ ((__noreturn__));
             ^
In file included from icrt/icrt.h:15:0,
                 from mandibule.c:25:
icrt/icrt_syscall.h:169:25: note: previous definition of '_exit' was here
 _syscall1(SYS_exit,     _exit,      int,        int);
                         ^
icrt/icrt_syscall.h:149:23: note: in definition of macro '_syscall1'
 static inline rettype sys_name(t1 a1)                                       \
                       ^
Makefile:25: recipe for target 'x86' failed
make: *** [x86] Error 1

On x64:

$ make x86_64
rm -rf mandibule target toinject
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -pie -fPIE -fno-builtin -nostdlib -o mandibule mandibule.c
In file included from /usr/include/x86_64-linux-gnu/sys/user.h:25:0,
                 from code/ptinject.h:15,
                 from mandibule.c:28:
/usr/include/unistd.h:603:13: error: conflicting types for '_exit'
 extern void _exit (int __status) __attribute__ ((__noreturn__));
             ^
In file included from icrt/icrt.h:15:0,
                 from mandibule.c:25:
icrt/icrt_syscall.h:169:25: note: previous definition of '_exit' was here
 _syscall1(SYS_exit,     _exit,      int,        int);
                         ^
icrt/icrt_syscall.h:149:23: note: in definition of macro '_syscall1'
 static inline rettype sys_name(t1 a1)                                       \
                       ^
Makefile:32: recipe for target 'x86_64' failed
make: *** [x86_64] Error 1

end of issue

@ixty
Copy link
Owner

ixty commented May 30, 2018

Hello,
Thanks for trying out mandibule and writing this report.
Can you please tell me what you have in CC (and its version) and CFLAGS?

In the meantime you can try to change
icrt/icrt_syscall.h:169:25: _syscall1(SYS_exit, _exit, void, int);
That might fix the problem.

Im going to compile with -Werror -Wpedantic -Wall ... on my end to fix that kind of issues.

@ixty
Copy link
Owner

ixty commented May 30, 2018

I just pushed a commit fixing a few warnings when compiling with -Wall -Wpedantic i also pushed a small edit for _exit which should fix your problem.

Can you pull & try the compilation again?

@unixfreaxjp
Copy link
Author

unixfreaxjp commented May 31, 2018

Firstly thank you for your answer and code adjustment effort.
In 32bit there are still some errors, I am trimming its bug source now,
but in 64bit just a warning and compilation is successfully done as per snipped below:

$ make x86_64
rm -rf mandibule target toinject
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -pie -fPIE -fno-builtin -nostdlib -o mandibule mandibule.c
In file included from icrt/icrt.h:15:0,
                 from mandibule.c:25:
/usr/include/unistd.h: In function '_exit':
icrt/icrt_syscall.h:170:1: warning: 'noreturn' function does return
 void _exit(int c) { __exit(c); }
 ^
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -pie -fPIE -fno-builtin -o toinject samples/toinject.c
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -o target samples/target.c
$  file mandibule target toinject 
mandibule: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=26e4d6ad5402b7a2afaa74193174946eb9443fb0, not stripped
target:    ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=d9e02b9978525438aeb4c4e6b91e328813f7a5b6, not stripped
toinject:  ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c148db991287dbb06f381735b4ae284c286ebe5a, not stripped

I will get back on the x86 (32bit) report with more details in CC version CFLAGS.

@unixfreaxjp
Copy link
Author

unixfreaxjp commented May 31, 2018

For the x86 people will meet the bug in the assembly coding for C in volatile mode,
the problem is residing in the icrt/icrt_syscall.h:30:9, as per snipped below:

#ifdef __i386__
    #define _syscall_do(sys_nbr, rettype)                                   \
    {                                                                       \
        rettype ret = 0;                                                    \
        asm volatile                                                        \
        (                                                                   \
            "int $0x80;"                                                    \
            : "=a" (ret)                                                    \
            : "0"(sys_nbr), "bx"(a1), "cx"(a2),                             \
              "dx"(a3),     "S"(a4),  "D"(a5), "bp"(a6)                     \
        );                                                                  \
        return ret;                                                         \
    }

[ EDIT ]
I think this is the assembly code writing matter for 32bit (register adjust)

Error message for the fail compilation with CC -v4.9.2 x86, or [ EDIT ] the other versions too appears the same error state:

icrt/icrt_syscall.h: In function '_getpid':
icrt/icrt_syscall.h:30:9: error: inconsistent operand constraints in an 'asm'
         asm volatile                                                        \
         ^

And this is the full log of compilation with the error message intact.

$ 
$ cc --version
cc (Debian 4.9.2-10 deb8u1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ 
$ make x86
rm -rf mandibule target toinject
cc -D_GNU_SOURCE -std=gnu99 -static-libgcc -lgcc -I icrt/ -I code/ -fno-common -fno-stack-protector -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -pie -fPIE -fno-builtin -nostdlib -m32 -o mandibule mandibule.c
In file included from icrt/icrt.h:15:0,
                 from mandibule.c:25:
/usr/include/unistd.h: In function '_exit':
icrt/icrt_syscall.h:170:1: warning: 'noreturn' function does return
 void _exit(int c) { __exit(c); }
 ^
icrt/icrt_syscall.h: In function '_getpid':
icrt/icrt_syscall.h:30:9: error: inconsistent operand constraints in an 'asm'
         asm volatile                                                        \
         ^
icrt/icrt_syscall.h:159:5: note: in expansion of macro '_syscall_do'
     _syscall_do(sys_nbr, rettype)                                           \
     ^
icrt/icrt_syscall.h:167:1: note: in expansion of macro '_syscall0'
 _syscall0(SYS_getpid,   _getpid,    int)
 ^
Makefile:26: recipe for target 'x86' failed
make: *** [x86] Error 1
$ 
$ 

the best way I can advise for this matter is avoiding volatile mode and just convert the code into basic asm, for example:

        asm ( "int $0x80;" 
                 "mov %1, %0;"
                 "add $1, %0;"
                    : "=a" (ret)    
                    :

Please refer to https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.htmlv
But talking is always be easier than doing it, thank you for the x86_64 fix!!!

@ixty ixty closed this as completed in 31e95dd May 31, 2018
@ixty
Copy link
Owner

ixty commented May 31, 2018

rewrote the x86 syscall wrapper to be compatible with older gcc (4.9).
works on my debian jessie chroot with gcc version 4.9.2 (Debian 4.9.2-10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants