From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933362AbbGGWfa (ORCPT ); Tue, 7 Jul 2015 18:35:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43455 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933170AbbGGWfX (ORCPT ); Tue, 7 Jul 2015 18:35:23 -0400 Date: Tue, 7 Jul 2015 17:35:19 -0500 From: Josh Poimboeuf To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: Michal Marek , Peter Zijlstra , Andy Lutomirski , Borislav Petkov , Linus Torvalds , Andi Kleen , Pedro Alves , x86@kernel.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Martin Jambor , Jiri Kosina , Segher Boessenkool Subject: Re: [PATCH v6 0/4] Compile-time stack validation Message-ID: <20150707223519.GA31294@treble.redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 07, 2015 at 09:54:09AM -0500, Josh Poimboeuf wrote: > I did some more looking and it turns out that inline assembly doesn't > play nicely with frame pointers at all. If the inline asm is at the > beginning of the function, gcc sometimes emits the inline asm code > before setting up the frame pointer. That can break stack traces > when the inline asm has a call instruction. > > That turns out to be a very common problem. Stackvalidate found 37 C > object files which break frame pointer rules, thanks to inline asm. > > I don't know of a solution to this problem yet. Basically I think we > need a way to ensure that gcc emits the frame pointer setup before > inserting any inline asm (particularly when the inline asm has a call > instruction). A solution to this problem was posted by Segher Boessenkool in a related thread on the gcc mailing list: https://gcc.gnu.org/ml/gcc/2015-07/msg00080.html The suggestion is to use something like: register void *sp asm("%sp"); asm volatile("call func" : "+r"(sp)); I can confirm that it seems to fix the issue. (I had tried something like this before, but I guess I wasn't able to get the incantation just right.) Thanks to Jiri for the pointer to the thread, and Martin for raising the issue on the gcc list. -- Josh