From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752246AbeFEVTy (ORCPT ); Tue, 5 Jun 2018 17:19:54 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:35063 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751635AbeFEVTx (ORCPT ); Tue, 5 Jun 2018 17:19:53 -0400 X-Google-Smtp-Source: ADUXVKI3s1/biCQidUZsGZ0AsDUNjC3IimMsk1RBIAzySBRnaVB0Ag/MgXNDYWt2+jOVERBH3QuA+dvMTg78QfdCf/c= MIME-Version: 1.0 References: <20180529221625.33541-1-thgarnie@google.com> <20180529221625.33541-22-thgarnie@google.com> <20180604161612.6d48d8d2@gandalf.local.home> <20180604174431.4aabfbf1@gandalf.local.home> In-Reply-To: From: Thomas Garnier Date: Tue, 5 Jun 2018 14:19:40 -0700 Message-ID: Subject: Re: [PATCH v4 21/27] x86/ftrace: Adapt function tracing for PIE support To: Steven Rostedt Cc: Kernel Hardening , Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" , "the arch/x86 maintainers" , Francis Deslauriers , Greg KH , Andrew Morton , Peter Zijlstra , Guenter Roeck , nixiaoming , James Hogan , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 5, 2018 at 9:56 AM Thomas Garnier wrote: > > On Mon, Jun 4, 2018 at 2:44 PM Steven Rostedt wrote: > > > > On Mon, 4 Jun 2018 14:06:03 -0700 > > Thomas Garnier wrote: > > > > > On Mon, Jun 4, 2018 at 1:16 PM Steven Rostedt wrote: > > > > > > > > On Tue, 29 May 2018 15:15:22 -0700 > > > > Thomas Garnier wrote: > > > > > > > > > When using -fPIE/PIC with function tracing, the compiler generates a > > > > > call through the GOT (call *__fentry__@GOTPCREL). This instruction > > > > > takes 6 bytes instead of 5 on the usual relative call. > > > > > > > > > > If PIE is enabled, replace the 6th byte of the GOT call by a 1-byte nop > > > > > so ftrace can handle the previous 5-bytes as before. > > > > > > > > > > Position Independent Executable (PIE) support will allow to extend the > > > > > KASLR randomization range 0xffffffff80000000. > > > > > > > > I thought you were going to write a update to recordmcount.c to handle > > > > this at compile time? > > > > > > I can correctly calculate the start of the call instruction with > > > recordmcount (no need for addr-1) but I still need to handle the > > > different size of the instructions. I don't think I can completely > > > replace the GOT call with a relative call. Maybe I am missing > > > something on the way recordmcount is used? Should it replace all > > > mcount locations with a nop slide? Why is it done at runtime too then? > > > > Because we need to figure out the "ideal nop" thus we need to change it > > regardless. > > I see what you mean looking at the different ideal_nops based on configurations. > > > > > We could have recordmcount.c replace everything with the default nop > > (I've thought of that before), and then we could update with the ideal > > nop at run time, if that helps with this. > > I don't think that's necessary. In proposed implementation of PIE, > kernel modules would not use a GOT call. In the current implementation > the __fentry__ call is always GOT based (6-bytes). I will simplify the > runtime implementation in the next patch set to just swap the expected > size and ideal_nop when PIE is enabled. Actually moving the logic from 5-bytes to 6-bytes is much more complicated, that's why I went with this approach before. I don't think it can be improved much more beyond creating a nop slide in mrecordcount but that's a different approach. I will clean-up the code a bit for the next iteration but that's about it. Let me know what you think. > > > > > -- Steve > > > > -- > Thomas -- Thomas