From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_NEOMUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0598BC04AAD for ; Tue, 7 May 2019 17:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC37820825 for ; Tue, 7 May 2019 17:57:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727236AbfEGR5K (ORCPT ); Tue, 7 May 2019 13:57:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49604 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726797AbfEGR5K (ORCPT ); Tue, 7 May 2019 13:57:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D7013001821; Tue, 7 May 2019 17:57:09 +0000 (UTC) Received: from treble (ovpn-123-166.rdu2.redhat.com [10.10.123.166]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7588B60BF4; Tue, 7 May 2019 17:56:58 +0000 (UTC) Date: Tue, 7 May 2019 12:56:55 -0500 From: Josh Poimboeuf To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Peter Zijlstra , Andy Lutomirski , Ingo Molnar , Andrew Morton , Andy Lutomirski , Nicolai Stange , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , the arch/x86 maintainers , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Konrad Rzeszutek Wilk , Tim Chen , Sebastian Andrzej Siewior , Mimi Zohar , Juergen Gross , Nick Desaulniers , Nayna Jain , Masahiro Yamada , Joerg Roedel , "open list:KERNEL SELFTEST FRAMEWORK" , stable , Masami Hiramatsu Subject: Re: [RFC][PATCH 1/3] x86_64: Add gap to int3 to allow for call emulation Message-ID: <20190507175655.u3kcvedpfao4rchj@treble> References: <20190507174227.673261270@goodmis.org> <20190507174400.064350937@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190507174400.064350937@goodmis.org> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 07 May 2019 17:57:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 07, 2019 at 01:42:28PM -0400, Steven Rostedt wrote: > From: Josh Poimboeuf > > To allow an int3 handler to emulate a call instruction, it must be able to > push a return address onto the stack. Add a gap to the stack to allow the > int3 handler to push the return address and change the return from int3 to > jump straight to the emulated called function target. > > Link: http://lkml.kernel.org/r/20181130183917.hxmti5josgq4clti@treble > Link: http://lkml.kernel.org/r/20190502162133.GX2623@hirez.programming.kicks-ass.net > > [ > Note, this is needed to allow Live Kernel Patching to not miss calling a > patched function when tracing is enabled. -- Steven Rostedt > ] > > Cc: stable@vger.kernel.org > Fixes: b700e7f03df5 ("livepatch: kernel: add support for live patching") > Signed-off-by: Josh Poimboeuf > Signed-off-by: Steven Rostedt (VMware) > --- > arch/x86/entry/entry_64.S | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index 1f0efdb7b629..00df6b135ab1 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -879,7 +879,7 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt > * @paranoid == 2 is special: the stub will never switch stacks. This is for > * #DF: if the thread stack is somehow unusable, we'll still get a useful OOPS. > */ > -.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 > +.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 create_gap=0 > ENTRY(\sym) > UNWIND_HINT_IRET_REGS offset=\has_error_code*8 > > @@ -899,6 +899,20 @@ ENTRY(\sym) > jnz .Lfrom_usermode_switch_stack_\@ > .endif > > + .if \create_gap == 1 > + /* > + * If coming from kernel space, create a 6-word gap to allow the static > + * call #BP handler to emulate a call instruction. Might as well refer to it as the int3 handler, since that's what the rest of the code calls it. Also, no static calls yet :-) So: s/static call #BP handler/int3 handler/ -- Josh