Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2169320ybm; Thu, 23 May 2019 12:30:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyCbgab2mfpFUhtGHbgOnauAKtoIbbNZ18w4lsZbPfLZqUqRABMgT81/sDVVYlf5h1SMW9 X-Received: by 2002:a63:e706:: with SMTP id b6mr6804871pgi.90.1558639811515; Thu, 23 May 2019 12:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558639811; cv=none; d=google.com; s=arc-20160816; b=beFNIMGgEKC5CeXvYAGwuwZtVBOVvXyR0cp/a9u627pmKy8i86Xl/S7TCp7pPGMiRb zSwN70CFieGvQrPuoIFfnOiGyKhJHSPHh5WE4OkD7sMwP8QkMX1uGXwEsJesUb15A9RH W88RntNmcMhyAzzgOGgdZAt6lAxO9r4k3EoZzddpER9+54g/eCnqVfgcpgHIwazYtKTW QXaCBKOlAhSGa/EiQA50kGa5uxKcNqiDU+aZtEwOgh8wJ/X/VCFkL00+h1FBbBQcEIrY 1peeATyrukAOQ4ArtWYz2YSSt4R9FHBFCOpwp7rMYFouxIJFSu9yWQ16F5tjA95YxCrP rqkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z3NsRVfaaYK3W7GDTgNG6wtV96KLyNyAM4VXCgyfsLU=; b=GH6cCOLxlfm8DSXhyql5Rm/r++YgZzslzEFkgphb45iZjsVYZSsZOzPC9IUsNr9vRD 39f03p/OYEgN+hHN//cf8KpjmoeEwqGx9QUpLtRuOscFPPnHWLVKmkWCC0B761CYhXjH C1KFQfyAV7W8JKDXFGGFdvYyjO2FFA/g27g3JsOAlnlTfiSxPGrDJ1cu31ms27qA9pMZ MHQay9CgyA+iMGkvbOGrCjqszwjCRzP44BMnCpzQX5EeZptmRzu3HqiVHoLE41bFRNyr cruDZ/unHQ3KHkNyPH4Ebyj7/cUxzVt3wAhoP5h7xg10Ysc5ubt6rjZS3rORWhveYmGa WB6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y9DGbpD1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15si302671pfq.169.2019.05.23.12.29.56; Thu, 23 May 2019 12:30:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y9DGbpD1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391831AbfEWT2x (ORCPT + 99 others); Thu, 23 May 2019 15:28:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:41568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391826AbfEWT2t (ORCPT ); Thu, 23 May 2019 15:28:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95CF120879; Thu, 23 May 2019 19:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639729; bh=Q/5OzBM4VQEOBvCfeonOdIK9aQC1KWHPkJclcmFLRO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9DGbpD1XXp2QnDG9WWp26CI8inIc59H9vziPEOTE6o8HJ8Z0FIVroH4Pnd7WMW07 7rdxniBEEiOnxuT4BvsF4z7JrQ5hWbj0tM5gcYLT1qrbIRd7DfGmIvWi91Nfq489Eo tpF3bKxUV0RzRQx2m+kRMkAc6TfLIkZwwlj9OAlU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolai Stange , Masami Hiramatsu , Josh Poimboeuf , "Steven Rostedt (VMware)" Subject: [PATCH 5.1 073/122] x86_64: Add gap to int3 to allow for call emulation Date: Thu, 23 May 2019 21:06:35 +0200 Message-Id: <20190523181714.436949335@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josh Poimboeuf commit 2700fefdb2d9751c416ad56897e27d41e409324a upstream. 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") Tested-by: Nicolai Stange Reviewed-by: Nicolai Stange Reviewed-by: Masami Hiramatsu Signed-off-by: Josh Poimboeuf Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -881,7 +881,7 @@ apicinterrupt IRQ_WORK_VECTOR irq_work * @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 @@ -901,6 +901,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 + * int3 handler to emulate a call instruction. + */ + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_no_gap_\@ + .rept 6 + pushq 5*8(%rsp) + .endr + UNWIND_HINT_IRET_REGS offset=8 +.Lfrom_usermode_no_gap_\@: + .endif + .if \paranoid call paranoid_entry .else @@ -1132,7 +1146,7 @@ apicinterrupt3 HYPERV_STIMER0_VECTOR \ #endif /* CONFIG_HYPERV */ idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK -idtentry int3 do_int3 has_error_code=0 +idtentry int3 do_int3 has_error_code=0 create_gap=1 idtentry stack_segment do_stack_segment has_error_code=1 #ifdef CONFIG_XEN_PV