Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2059106yba; Fri, 10 May 2019 05:45:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3MQbRrwmXfslVp8KY2U5tphT6EbGahZiVELbJD+jTiTlf/kuzm3Rw5Nnq7wHjqYSMZuBn X-Received: by 2002:a17:902:42a5:: with SMTP id h34mr12310214pld.146.1557492307371; Fri, 10 May 2019 05:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557492307; cv=none; d=google.com; s=arc-20160816; b=OfHBm23cIxOTZL06XDUB+FLimlN3u16bH1OXohraOXB3zb6kX4lVuChyi0Bs1hDPGz fagS5griqg2RGKFnBMjEES5qKNfOIIVqNLgWoMX9Jb00cKzF+JSLMY7NPgE/uktuemXs V1Ant3QvPNSRXzxlZXT5zaPh+Jn5Ys6dSutFUgIgQuLkaVvZ3DTTJNi6o3rixDWykRry Mr76XJKHP1zcorRT28KtIfXz9dy2OEr/+IF/OtAX4Jk5qjxxuUaocIsqPy/SAF+i5IfO 53skkeTct/k7xvaOmILIo4UuKtOZHPug+cvMjJOMbjIeWYQ7dpnnxdCIy8Qoye3TGXtd 7fWQ== 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=PaEjONaV4ijDf76gOJrIlqa3RKQO2ZCV9SzvcjnY5M0=; b=YhHvsYJhwwBA/y9jxLV2kGe9Hc1yVRNr/e7FDwf1/5NOPS9Wty95k7IWERJOKW5PC4 L2elf8kauzLEXZ+vdJOFcy6G7Wretev5ishhc+xWfAUVnbg/9Dl/52kslVntq+pocchY o024Tf/DcCuTqW8g/lSJKuysgc61V+2xXimSdCfyEDCBEy4T3GwDtAr//5ityaiBGe8g VUNVlGfQOa4E+PUncuB/KMDHd2NVXtr5xPH7YOMhmwv1QYzwJYXD5zTI087gR6kJshml qGcMqwImMv3FWHeyKCgufxPTa8+JvoraSohouK1yhpXaOp+lhKiYXIWa5JP8xqnsMQMX 3ESA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=yHtmhqSg; 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 d19si7160685pls.221.2019.05.10.05.44.51; Fri, 10 May 2019 05:45:07 -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=merlin.20170209 header.b=yHtmhqSg; 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 S1727465AbfEJMlO (ORCPT + 99 others); Fri, 10 May 2019 08:41:14 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38298 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727222AbfEJMlN (ORCPT ); Fri, 10 May 2019 08:41:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=PaEjONaV4ijDf76gOJrIlqa3RKQO2ZCV9SzvcjnY5M0=; b=yHtmhqSgjr4d5cvy4Y4dw1EsF z3vUHhM76TmVgxToU5nVl8LQ3pVtp+6snuWTKySSED8fZIg/zmOTrIwK/SOD1f6d7yaDSEdDNKICX 9/2nzHmmfa+f3okzZ1hhRojX9VJ6TPC8kF8Ma074li+ZW32rm8OIASznKAu/gh4AVw3xDh6N/QSW2 lax1Du0IO3CTJfRktTffqiSWGQ+YvpFSChEA4n6iZtP/9heSCSUAMK0HvUAZQqAzgqvKllH4e1s8W Gh+uGdiKuw4+cbtTPoDlw3keRGhjc8ZqirzDu7ha6XZUBmqbIVLNHE2SLHTFFHt1v2vcsijXjssYB WgsWcslsw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hP4pc-0005gz-8E; Fri, 10 May 2019 12:40:56 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B5D4A2029FD7A; Fri, 10 May 2019 14:40:54 +0200 (CEST) Date: Fri, 10 May 2019 14:40:54 +0200 From: Peter Zijlstra To: Masami Hiramatsu Cc: Josh Poimboeuf , linux-kernel@vger.kernel.org, Linus Torvalds , Ingo Molnar , Andrew Morton , Andy Lutomirski , Nicolai Stange , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, 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 , linux-kselftest@vger.kernel.org Subject: Re: [PATCH 2/4] x86/kprobes: Fix frame pointer annotations Message-ID: <20190510124054.GV2589@hirez.programming.kicks-ass.net> References: <20190508115416.nblx7c2kocidpytm@treble> <20190508120416.GL2589@hirez.programming.kicks-ass.net> <20190508124248.u5ukpbhnh4wpiccq@treble> <20190508153907.GM2589@hirez.programming.kicks-ass.net> <20190508184848.qerg3flv3ej3xsev@treble> <20190509102030.dfa62e058f09d0d8cbdd6053@kernel.org> <20190509081431.GO2589@hirez.programming.kicks-ass.net> <20190509230106.3551b08553440d125e437f66@kernel.org> <20190509171416.GY2623@hirez.programming.kicks-ass.net> <20190510135831.c4ad309c68fc254f819194fc@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190510135831.c4ad309c68fc254f819194fc@kernel.org> 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 Fri, May 10, 2019 at 01:58:31PM +0900, Masami Hiramatsu wrote: > On Thu, 9 May 2019 19:14:16 +0200 > Peter Zijlstra wrote: > > > > --- a/arch/x86/kernel/kprobes/core.c > > > > +++ b/arch/x86/kernel/kprobes/core.c > > > > @@ -731,29 +731,8 @@ asm( > > > > ".global kretprobe_trampoline\n" > > > > ".type kretprobe_trampoline, @function\n" > > > > "kretprobe_trampoline:\n" > > > Here, we need a gap for storing ret-ip, because kretprobe_trampoline is > > > the address which is returned from the target function. We have no > > > "ret-ip" here at this point. So something like > > > > > > + "push $0\n" /* This is a gap, will be filled with real return address*/ > > > > The trampoline already provides a gap, trampoline_handler() will need to > > use int3_emulate_push() if it wants to inject something on the return > > stack. > > I guess you mean the int3 case. This trampoline is used as a return destination. > When the target function is called, kretprobe interrupts the first instruction, > and replace the return address with this trampoline. When a "ret" instruction > is done, it returns to this trampoline. Thus the stack frame start with > previous context here. As you described above, I would prefer to change that to inject an extra return address, instead of replacing it. With the new exception stuff we can actually do that. So on entry we then go from: RET-IP to RET-IP return-trampoline So when the function returns, it falls into the trampoline instead. > > > > + * On entry the stack looks like: > > > > + * > > > > + * 2*4(%esp) > > > > + * 1*4(%esp) RET-IP > > > > + * 0*4(%esp) func > > From this trampoline call, the stack looks like: > > * 1*4(%esp) > * 0*4(%esp) func > > So we need one more push. And then the stack looks just right at this point. > > > > + "push trampoline_handler\n" > > > > + "jmp call_to_exception_trampoline\n" > > > > ".size kretprobe_trampoline, .-kretprobe_trampoline\n" > > > > ); > > > > NOKPROBE_SYMBOL(kretprobe_trampoline);