Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2154081ybm; Thu, 23 May 2019 12:15:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwAgLh7J8h+ERj7m++b74dke+pxLf84bm1qTenJEv4uSTvuhEWcCy2kP5tWSL53dKKsvOq X-Received: by 2002:aa7:8b57:: with SMTP id i23mr24856319pfd.54.1558638901220; Thu, 23 May 2019 12:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558638901; cv=none; d=google.com; s=arc-20160816; b=y8kG6sO4gzoqW2c6MzmSADSypXlxY6EdIYf+KZ6VCBBNpaY50PBw0oxkuyDEQrIhV6 /xwqnuM7WzKYb7YG2llWHonB0yzLqkp67pwFVqzcLyJZhmR4aqTT7XQ1EqrgsKVhUUlj NqrPH/s7XoYA0G2/pY+sG3TNQvn7mzgFmRc3NQIu1r2N06sUZE2roE6av8yeseh24nYG QTt6xz9bJ5saSkOp2q4ENPkOUj84ymm/CITz96zK4D7Jx4d+Sir80jv9iyCQZgHkBe0U jX9uho+IUjIi3AodutTObzq+OwK5QuE1wqsFygLNtrtKocYZ38jo6iDlyFjALqGCF51B +8AA== 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=ZZKROrxJ4rQB9F9blQhp5jn8tTY6jqvUfcK/DCb39RI=; b=K/lEt1/90Za6go480h0RuZ7EmybByL+1vMq4hmALEz+FSL0TiPnWV4Wdne2stnOtZ8 A24BXUltcqmJROoT50qtq6QUA3SqAvvG5gpTVtk+sk5BrT5UVpnDQKVfdtEIHu3I73vn 9UqbtEscDMHyzzCWTYNMP7Sfh2nuKHoHqSLrngpHGQXveWkucJrUAazTxdXbjZjSMj+3 ICz0GvK+YYiWriSrL9GtodE7OGko3kAFiNmeYnIIlU4cK+03mKKBXoc2J6/AIiSV9dBp 8uYbtQqigFcrib2lOpDpNuQI9KWhjolYJAiXjw/ZApkbw0wkNJH2YcQwf5ix7EgC1DQS b2/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M2tMVCpN; 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 bx8si320518pjb.79.2019.05.23.12.14.46; Thu, 23 May 2019 12:15:01 -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=M2tMVCpN; 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 S2388254AbfEWTLp (ORCPT + 99 others); Thu, 23 May 2019 15:11:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:45094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387592AbfEWTLk (ORCPT ); Thu, 23 May 2019 15:11:40 -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 3F00E21841; Thu, 23 May 2019 19:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638699; bh=oZAIRCschdBz2pGcCRVQcMK8gQPdmgEcWj9TysrAgvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M2tMVCpNKAtK4of7FMssFCJeXaHAGOwjp9uk0VP5ZWhPNj8a9E9FaQ6a7xoyAKKlm R3ZNQiIGgKKSWDT4Mf/O3gc8YE6ejy/iwmxatvQndokxHvyLqQDC4nDJR5QBk3K/HR JGfmZUx+i3m5zYjAfofwc8I8Y6G3Zl1t7ImIXXxA= 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 4.14 32/77] x86_64: Add gap to int3 to allow for call emulation Date: Thu, 23 May 2019 21:05:50 +0200 Message-Id: <20190523181724.654423650@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@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 @@ -853,7 +853,7 @@ ENTRY(switch_to_thread_stack) ret END(switch_to_thread_stack) -.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 @@ -873,6 +873,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 @@ -1093,7 +1107,7 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTO #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