Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3514782yba; Tue, 7 May 2019 02:29:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4ilA6GFTbn/PDrEiLvMYPGQeWj7ipB+x/gc5BdIgw2nY6ui+fzdTWmEE1eUk0fhHlAMlA X-Received: by 2002:a17:902:860c:: with SMTP id f12mr4959951plo.127.1557221355127; Tue, 07 May 2019 02:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557221355; cv=none; d=google.com; s=arc-20160816; b=Rf1vhvkKdEHHsbfLcZYOdz1TpwnpAM74eO320U5MmWTueJ5gA9AwrwQbzcxCsJGo7y dWffRU7SAguMAjAgj1vp+ppv1Ye3MVaG5jnZXt4NQ3zZCl5CCj8Lphd6CwegghAjc5UC /lbsHn77d2G6MTjEPrUBuAI3ijisPb6AuBvrk3WwYZBfq1bl36eIKlt8YuonolLBFSGF K9OZkHk5tB+wckWHHzAEewzknC4sWpqdDAU4krfoRr4aJSWSdJC9omG/3eyRKZYZT1G7 MSAiepuYmnU8kf+4fwVKrEF/H+WlX5F34Xd/kgZJvKpWtJYtsewElPTtdRqwkvXTWenH cWmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=K74zIJWVTADuSIeC0XGT8F72POWkdJPeuuL+utrmqlI=; b=q2MXkdtSVFYT+GHP8smiPDKresIrmrnl24gdz7p7wjL2567QvwxpOcs6sYR9ZrJNvk 6jIm9mW1tYk6ZjseVEiA8kW3vmxe59ztV8gwD03Zz2TgIEHazTEoLEQaJPMBM3tkDuer xSqGZibsvxBxmt9O8ywRd/vbjtXmuvkdnH+cIls8qbDjTLNjUkKifPNfceiTzNBRRPWg y6n7q/BlNFyCy5WVb7QzFdoo6rvZyxMyoEGdQ5pU+qMdtt3xAWuhu98SAu0/fO4XQPAS P3o6REkazl8GGclVbnoHv8Q7meqgYbz38PeaCFVaalbZk2DvTKskGRCZKIYoH5irj+9L P77Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=X+FkTbzU; 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 g127si18250220pgc.135.2019.05.07.02.28.59; Tue, 07 May 2019 02:29:15 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=X+FkTbzU; 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 S1726738AbfEGJ2E (ORCPT + 99 others); Tue, 7 May 2019 05:28:04 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50762 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726394AbfEGJ2D (ORCPT ); Tue, 7 May 2019 05:28:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=K74zIJWVTADuSIeC0XGT8F72POWkdJPeuuL+utrmqlI=; b=X+FkTbzUvH17w4p9cdF0zY8Lj z6mvwSURsgoU9jZNM7JsIZkBBkQG+d+bLW17Dp4Yp9sQg+zPplRVE8UIxiC1ILSqiEGILP19Hx7M8 P+0mCwuZ7ldUxusHH2FqbBQ1crOSmnAteH6lVo+sMIdAbCS9N+QhsNjuWxRXM5Vi4mT31Fxbgk3G2 7+HWX/nyUSdgFlIdYdwc6c84w7qsgHu8aFyj/mTQws57Wn52FNW6WZ0JdacRQ+jGxPyY3nZxQcERn ysnUZztpngc6ZTNpHwFbHjVCxUvuYok1HGJ2n1qNas+WlKwXJyb8qZ0LA4CT2FAzJ5ZghGYrgnRix nMIDyk9hA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hNwNo-00016k-Li; Tue, 07 May 2019 09:27:32 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1BF2A2023ADB7; Tue, 7 May 2019 11:27:31 +0200 (CEST) Date: Tue, 7 May 2019 11:27:31 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Andy Lutomirski , Steven Rostedt , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Andy Lutomirski , Nicolai Stange , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , the arch/x86 maintainers , Josh Poimboeuf , 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 Subject: Re: [RFC][PATCH 1/2] x86: Allow breakpoints to emulate call functions Message-ID: <20190507092731.GH2650@hirez.programming.kicks-ass.net> References: <20190502202146.GZ2623@hirez.programming.kicks-ass.net> <20190502185225.0cdfc8bc@gandalf.local.home> <20190502193129.664c5b2e@gandalf.local.home> <20190502195052.0af473cf@gandalf.local.home> <20190503092959.GB2623@hirez.programming.kicks-ass.net> <20190503092247.20cc1ff0@gandalf.local.home> <2045370D-38D8-406C-9E94-C1D483E232C9@amacapital.net> <20190506081951.GJ2606@hirez.programming.kicks-ass.net> <20190507085753.GO2606@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190507085753.GO2606@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) 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 10:57:53AM +0200, Peter Zijlstra wrote: > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c > index 9e4fa2484d10..28d8ba3b9add 100644 > --- a/arch/x86/kernel/kprobes/core.c > +++ b/arch/x86/kernel/kprobes/core.c > @@ -731,29 +731,27 @@ asm( > ".global kretprobe_trampoline\n" > ".type kretprobe_trampoline, @function\n" > "kretprobe_trampoline:\n" > -#ifdef CONFIG_X86_64 > /* We don't bother saving the ss register */ > +#ifdef CONFIG_X86_64 > " pushq %rsp\n" > " pushfq\n" > SAVE_REGS_STRING > " movq %rsp, %rdi\n" > " call trampoline_handler\n" > /* Replace saved sp with true return address. */ > - " movq %rax, 152(%rsp)\n" > + " movq %rax, 19*8(%rsp)\n" > RESTORE_REGS_STRING > " popfq\n" > #else > - " pushf\n" > + " pushl %esp\n" > + " pushfl\n" > SAVE_REGS_STRING > " movl %esp, %eax\n" > " call trampoline_handler\n" > - /* Move flags to cs */ > - " movl 56(%esp), %edx\n" > - " movl %edx, 52(%esp)\n" > - /* Replace saved flags with true return address. */ > - " movl %eax, 56(%esp)\n" > + /* Replace saved sp with true return address. */ > + " movl %eax, 15*4(%esp)\n" > RESTORE_REGS_STRING > - " popf\n" > + " popfl\n" > #endif > " ret\n" > ".size kretprobe_trampoline, .-kretprobe_trampoline\n" > diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c > index f14262952015..c1010207d036 100644 > --- a/arch/x86/kernel/kprobes/opt.c > +++ b/arch/x86/kernel/kprobes/opt.c > @@ -115,14 +115,15 @@ asm ( > "optprobe_template_call:\n" > ASM_NOP5 > /* Move flags to rsp */ > - " movq 144(%rsp), %rdx\n" > - " movq %rdx, 152(%rsp)\n" > + " movq 18*8(%rsp), %rdx\n" > + " movq %rdx, 19*8(%rsp)\n" > RESTORE_REGS_STRING > /* Skip flags entry */ > " addq $8, %rsp\n" > " popfq\n" > #else /* CONFIG_X86_32 */ > - " pushf\n" > + " pushl %esp\n" > + " pushfl\n" > SAVE_REGS_STRING > " movl %esp, %edx\n" > ".global optprobe_template_val\n" > @@ -131,9 +132,13 @@ asm ( > ".global optprobe_template_call\n" > "optprobe_template_call:\n" > ASM_NOP5 > + /* Move flags into esp */ > + " movl 14*4(%esp), %edx\n" > + " movl %edx, 15*4(%esp)\n" > RESTORE_REGS_STRING > - " addl $4, %esp\n" /* skip cs */ > - " popf\n" > + /* Skip flags entry */ > + " addl $4, %esp\n" > + " popfl\n" > #endif > ".global optprobe_template_end\n" > "optprobe_template_end:\n" FWIW, both these trampolines assume a kprobe will not int3_emulate_{push/call}(), for both bitnesses. But then; I'm thinking kprobes should be inspection only and not modify things. So that might just be good enough.