I can't explain why this code doesn't work.
#include <stdio.h>
int main() {
char *command[] = { "/bin/sh", NULL };
asm volatile(
"movl $11, %%eax\n"
"movl %0, %%ebx\n"
"movl $0, %%ecx\n"
"xorl %%edx, %%edx\n"
"int $0x80\n"
:
: "g"(command)
: "%eax", "%ebx", "%ecx", "%edx"
);
perror("execve failed");
return 1;
}
I wrote this code to make a call to execve and get a shell but when I run it, I get
execve failed: Success
so no errno was entered. And while running in gdb I got the return value, 0xfffffffe -> -2 but in the man page write that if failed -1 is returned and errno is set
"On success, execve() does not return, on error -1 is returned, and errno is set appropriately"
Does someone have any idea what going on?
comepiled with gcc -m32 -o test test.c
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04.1)