Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4906154yba; Mon, 13 May 2019 01:42:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAwMzzKYhAmN/rGhYIcvwI2qYrAlPyPguX+kvnetXrkVpj/8nz8lEHS9ZsHkevNMfSRkzW X-Received: by 2002:aa7:93bb:: with SMTP id x27mr31030742pff.104.1557736924990; Mon, 13 May 2019 01:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557736924; cv=none; d=google.com; s=arc-20160816; b=HtMI040vuTbMR0NxsXHZO4WitAX/e0PaSIhv2Gyt0z4Djww93vyBtorgqMwrbihtoE ZOe6l21cJrujdoFGj2sQM51Ey/g0NFLgy42NgcvId0LbIesfuCD3jfNejsGxfbJN/EF+ tDK2CnM9GiU2EjLgzVp34rrkLldbfXIrptw1ZphmMbHmCDbJIlnJzBBbl3edPH/Kz0Ih x6UeNxl9Yj/qMOVBCh1OLshqiqqfPV1XTBRvH65QD6I5zFJxJPif0cZkAeuNnbyfsb5v sLVx6xDQO0bvbS/ss1b+12E65fGCx7jGJGPxBZbVbR06qJxxQbfgJv27pqt4rRO5cjzC PecQ== 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=KnyNPpS3/IuZil8Uli/e5qg23u6Dh+UGd1Izdvt9Xl4=; b=XvzRErZaLdHSDVpLkyVCCXpKZkaon0S4/TgpOVY5WW6FVm/A4sNAXq23Wc2alOhb9K sFpevm5GqlzO2v7oOSrV4ggi5O074HMbIBhOgfMyf+i70V/Urk7HPSy8rOF1tA2bqqSz MHsnoHuJEJgWEe/V1Lapo0cGM3Zzq4QTVXSjq+XRXjSlixu634NZW0qAC1uo7o7Qa5Jj AtLpq32IbFG6CHjVbgAxUYEjKWX/nRGg0DnWvPf05CnJmyFDKMszK61PNQG7WM3CoEq/ DKsl9HGfZUuBONkekEuLLP0IPjy8bU4pHIbE9bJrdbhySzqQmdNMCgdLPARNO7PKzJd/ pUnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ryFblFXj; 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 d2si16623231pln.43.2019.05.13.01.41.47; Mon, 13 May 2019 01:42:04 -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=ryFblFXj; 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 S1728210AbfEMIPV (ORCPT + 99 others); Mon, 13 May 2019 04:15:21 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:56524 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727355AbfEMIPV (ORCPT ); Mon, 13 May 2019 04:15:21 -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=KnyNPpS3/IuZil8Uli/e5qg23u6Dh+UGd1Izdvt9Xl4=; b=ryFblFXjlXk+SBg6r2yrKzeaE oNV1g8kuLX0GcGWBlWRn4+AGoZfop572rLjUfVXK2G5b8+oF57G4YLNQ3nTamzPjdSky5aPd7q74f 855iziskHlTtfgJZVmHqUHQFgsUyUVLw6q/Rz5qQ0fHSGAyw6Gbx5AO9zyp4lOyz/M2y5ij6/71J+ KjEK3HOHjMa85n313NabRj9GoTRj9eTaZz8e637X50fcPmaMnC9cd934Yd1SnWb5uE+LNBz8t3z6O zO/avz/svOREVoXFSULdd5XfrmuJtEvANn8pk6XeYKVJZgcolRn3KmkxR6V9uxMc8OZmZwNIeawR+ LCBLlT/tA==; 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 1hQ670-000470-DV; Mon, 13 May 2019 08:15:06 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DCF902029FD7A; Mon, 13 May 2019 10:15:03 +0200 (CEST) Date: Mon, 13 May 2019 10:15:03 +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: <20190513081503.GK2623@hirez.programming.kicks-ass.net> References: <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> <20190510124054.GV2589@hirez.programming.kicks-ass.net> <20190511095655.405147cde331cd1da539d0e8@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190511095655.405147cde331cd1da539d0e8@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 Sat, May 11, 2019 at 09:56:55AM +0900, Masami Hiramatsu wrote: > On Fri, 10 May 2019 14:40:54 +0200 > Peter Zijlstra wrote: > > > 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. > > Is that really possible? On x86-64, most parameters are passed by registers, > but x86-32 (and x86-64 in rare case) some parameters can be passed by stack. > If we change the stack layout in the function prologue, the code in > function body can not access those parameters on stack. Ooh, I see what you mean... yes that might be trouble indeed. Damn..