problem with i686-w64-mingw32-gcc -fstack-protector-all

Lee ler762@gmail.com
Tue Oct 3 18:26:00 GMT 2017


Maybe I'm just Doing It Wrong, but
  gcc -fstack-protector-all
seems to be working correctly &
  i686-w64-mingw32-gcc -fstack-protector-all
seems to be broken - eg:

$./ssp testtestx
Illegal instruction

printf's that happen before the stack over-write don't show up & no
"*** stack smashing detected ***" msg is printed before the "Illegal
instruction"

STC:

$cat doit
#!/bin/sh
LIB="-lssp"
set -x

cat main-ssp.c
cat func-ssp.c

i686-w64-mingw32-gcc -c -fstack-protector-all   func-ssp.c -o func-ssp.o
i686-w64-mingw32-gcc -c -fstack-protector-all   main-ssp.c -o main-ssp.o
i686-w64-mingw32-gcc -static -o ssp.exe func-ssp.o main-ssp.o $LIB
./ssp.exe testtestx

echo -e '\n\n'

gcc -c -fstack-protector-all   func-ssp.c -o cyg-func-ssp.o
gcc -c -fstack-protector-all   main-ssp.c -o cyg-main-ssp.o
gcc -static -o cyg-ssp.exe cyg-func-ssp.o cyg-main-ssp.o $LIB
./cyg-ssp.exe testtestx


$./doit
+ cat main-ssp.c
/* stack smashing protection
  i686-w64-mingw32-gcc -c -fstack-protector-all -o func-ssp.o func-ssp.c
  i686-w64-mingw32-gcc -c -fstack-protector-all -o main-ssp.o main-ssp.c
  i686-w64-mingw32-gcc -o ssp.exe  main-ssp.o func-ssp.o
  ./ssp testtestx
    *** should die ***
 */

#include <stdio.h>
#include <string.h>

extern int doit(char *s );

int main(int argc, char *argv[])
{
 int status=0;
 printf("main: argv[1]=%s\n", argv[1] );
 status = doit(argv[1]);
 if ( status != 1 ) printf("OhNoes!! doit returned %d\n", status );
 printf("main: exit\n" );
 return 0;
}

+ cat func-ssp.c
/* stack smashing protection test */

#include <stdio.h>
#include <string.h>

extern
int doit(char *s ) {
  char buf[]="12345678";
  int i=0;
  if ( *s != '\0' ) i = 1;  /* return true */
  printf("doit: s=\"%s\"   buf=\"%s\"  i=%d\n", s, buf, i );
  strcpy(buf, s);
    /* buffer overflow into return status(int i) if strlen(s) > 8 */
  printf("doit: s=\"%s\"   buf=\"%s\"  i=%d\n", s, buf, i );
  return i;
}

+ i686-w64-mingw32-gcc -c -fstack-protector-all func-ssp.c -o func-ssp.o
+ i686-w64-mingw32-gcc -c -fstack-protector-all main-ssp.c -o main-ssp.o
+ i686-w64-mingw32-gcc -static -o ssp.exe func-ssp.o main-ssp.o -lssp
+ ./ssp.exe testtestx
./doit: line 11:  9128 Illegal instruction     ./ssp.exe testtestx
+ echo -e '\n\n'



+ gcc -c -fstack-protector-all func-ssp.c -o cyg-func-ssp.o
+ gcc -c -fstack-protector-all main-ssp.c -o cyg-main-ssp.o
+ gcc -static -o cyg-ssp.exe cyg-func-ssp.o cyg-main-ssp.o -lssp
+ ./cyg-ssp.exe testtestx
main: argv[1]=testtestx
doit: s="testtestx"   buf="12345678"  i=1
doit: s="testtestx"   buf="testtestx"  i=1
*** stack smashing detected ***:  terminated
./doit: line 18:  2336 Illegal instruction     (core dumped)
./cyg-ssp.exe testtestx

$

$ gcc --version
gcc (GCC) 6.4.0
Copyright (C) 2017 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.

$ i686-w64-mingw32-gcc --version
i686-w64-mingw32-gcc (GCC) 6.3.0
Copyright (C) 2016 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.


Thanks,
Lee

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list