From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 72808 invoked by alias); 4 Oct 2017 19:18:31 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 72797 invoked by uid 89); 4 Oct 2017 19:18:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.8 required=5.0 tests=BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=HX-Envelope-From:sk:Christi, smashing, sk:i686w6, testtestx X-HELO: mailout01.t-online.de Received: from mailout01.t-online.de (HELO mailout01.t-online.de) (194.25.134.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Oct 2017 19:18:29 +0000 Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout01.t-online.de (Postfix) with SMTP id 0367542AC4B2 for ; Wed, 4 Oct 2017 21:18:27 +0200 (CEST) Received: from [192.168.2.101] (rAlaceZYgh1OCoGH4VFieB+uwzdvG41lPuBacgpIh0jrftY6bYpZIvKRcN0nGKgZva@[91.57.244.199]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1dzpBX-1T9R8y0; Wed, 4 Oct 2017 21:18:23 +0200 From: Christian Franke Subject: Re: problem with i686-w64-mingw32-gcc -fstack-protector-all To: cygwin@cygwin.com References: Message-ID: <1d6ce5fb-ea05-b830-8096-98d839cc6e02@t-online.de> Date: Wed, 04 Oct 2017 19:18:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0 SeaMonkey/2.50 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-10/txt/msg00041.txt.bz2 Lee wrote: > 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" > ... > > 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 BTW: There is no need to link with -lssp if the related code generation option -fstack-protector* is also used during link. > + ./ssp.exe testtestx > ./doit: line 11: 9128 Illegal instruction ./ssp.exe testtestx > + echo -e '\n\n' > The *** stack smashing detected *** message from MinGW runtime is only visible if stdio is attached to a Windows console. Works for me if one more overflow char is added: Cygwin mintty: $ ./ssp testtestx main: argv[1]=testtestx doit: s="testtestx" buf="12345678" i=1 doit: s="testtestx" buf="testtestx" i=1 main: exit $ ./ssp testtestxx Illegal instruction Cygwin in Windows console (cygwin.bat): $ ./ssp testtestxx main: argv[1]=testtestxx doit: s="testtestxx" buf="12345678" i=1 doit: s="testtestxx" buf="testtestxx" i=1 *** stack smashing detected ***: terminated Illegal instruction cmd.exe in Windows console: C:\cygwin\tmp>.\ssp.exe testtestxx main: argv[1]=testtestxx doit: s="testtestxx" buf="12345678" i=1 doit: s="testtestxx" buf="testtestxx" i=1 *** stack smashing detected ***: terminated [Windows Message Box: Debug/Abort Program ?] Christian -- 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