Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3799512imm; Mon, 8 Oct 2018 09:41:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV60hrqIbtNjjYPzZTGAW1CH3NlsFIDdM2T2Hz2JgsDb9JFfen3e+xf2FGgH6DJ4rwTKcqarD X-Received: by 2002:a62:4803:: with SMTP id v3-v6mr26659317pfa.89.1539016868878; Mon, 08 Oct 2018 09:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539016868; cv=none; d=google.com; s=arc-20160816; b=chR3Y1sm7YVvpIuvRHXqd5YSNzxDEmTbMViySAZ0i+1QaeJGGekVp1R9zwHhYjvxP3 thFd9tOCwwp7Z1J1xUWipHBkLEjbAHNLxed3z+i1GbIx3IzZ7NBaEdGij3T7ugHhmt+2 zQkZpxmz+392T3Um9iTq4+zTYNbYnWV6iptTLQZl1KkCRVJAayvUiLEJ78diKAwIDrQf K3kFuqOPnO8L1lb9JXqzpTGwEJh5Qw79FaTcvEPEYsePNx+Z5RQDqxfrRZdtfTa649NH Ek7usiE4B9IXAW41FdBfUh5C3Bedl7PkTLt7QmkjKjilwU5YIERV5PkIrZ0CcUp4GC+f +Ifg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YInI2N0HehEWoHTu3/IQnutvIbD9Tvk9+TKtWH2cjo8=; b=KUNMuTcV4LcyA2eapYTfRFlDntsfBYGLrxiTm5Kw5WAvpk1ZqJn78S0JaqWBopXJ9I bgXbH03lbbBhEQPB9stjcERtgj+hlNBtRD/FTC5rCduHBTl6RMPS9Via4elNUsAOQw9n z0lcZswTJVoDvC0AM2JAkmwTsYLvuqNnkaDlrngCyXw9eCUDS9lm3eKNJO8nUvjBntVO Hxg8K5BL0rPkgOwYdlektsgTA+G3QP6JS2FPUQC+ZERYTTFscnL6hcT8wYd2joCHxJsk Ihp7iB9tFpVOxHSzfvOE1KUxO0IehMbCNQCp8PXcf/qo1vFe+5zeUvxTqaNajUsUD3gc LrlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=F6PEVMkz; 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 l185-v6si16949399pgl.270.2018.10.08.09.40.53; Mon, 08 Oct 2018 09:41:08 -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=F6PEVMkz; 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 S1726567AbeJHXwu (ORCPT + 99 others); Mon, 8 Oct 2018 19:52:50 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:52016 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJHXwu (ORCPT ); Mon, 8 Oct 2018 19:52:50 -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-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=YInI2N0HehEWoHTu3/IQnutvIbD9Tvk9+TKtWH2cjo8=; b=F6PEVMkzTGMB0HqM+ZaTJJQo5d c6rEft4z7WpORPMu3wp0nfkWe4/y4KTrfU/2318zfFDE+uXXdAkkcFDv5xqev60XUvSGhRi/ZDB+4 4vU1PoXI8Xk8xZxev9RN/mUzO8iZR2qgdFhwh0/S7JPVR629rD0JnlJiLgHPILXc9Kxbw/bcfTl84 MZgjYkswEjHh6IxkoBdauAtkNflhdlV4fHZ6Q9lyesDSrCsoFI/jx9+aABw30il31R9q+xDSzVITS nDGt+q0iBd5ng+PBK+7WixbRVhNu1UReijPdNGYO6Euqt/64sr1C+wdz47DGN+GWPzXrYp8vQdmjM xJGEql3g==; 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 1g9YZY-0001uj-8N; Mon, 08 Oct 2018 16:39:56 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3387B20294F78; Mon, 8 Oct 2018 18:39:53 +0200 (CEST) Date: Mon, 8 Oct 2018 18:39:53 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Steven Rostedt , linux-kernel@vger.kernel.org, Linus Torvalds , Ingo Molnar , Andrew Morton , Thomas Gleixner , Masami Hiramatsu , Mathieu Desnoyers , Matthew Helsley , "Rafael J . Wysocki" , David Woodhouse , Paolo Bonzini , Josh Poimboeuf , Jason Baron , Jiri Kosina , ard.biesheuvel@linaro.org, Andy Lutomirski Subject: Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function" Message-ID: <20181008163953.GD5663@hirez.programming.kicks-ass.net> References: <20181006015110.653946300@goodmis.org> <20181006015720.634688468@goodmis.org> <20181006121211.GA5663@hirez.programming.kicks-ass.net> <20181006093905.46276505@vmware.local.home> <20181008072134.GB5663@hirez.programming.kicks-ass.net> <20181008155757.GC5663@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Mon, Oct 08, 2018 at 09:29:56AM -0700, Andy Lutomirski wrote: > > > > On Oct 8, 2018, at 8:57 AM, Peter Zijlstra wrote: > > > > On Mon, Oct 08, 2018 at 01:33:14AM -0700, Andy Lutomirski wrote: > >>> Can't we hijack the relocation records for these functions before they > >>> get thrown out in the (final) link pass or something? > >> > >> I could be talking out my arse here, but I thought we could do this, > >> too, then changed my mind. The relocation records give us the > >> location of the call or jump operand, but they don’t give the address > >> of the beginning of the instruction. > > > > But that's like 1 byte before the operand, right? We could even double check > > this by reading back that byte and ensuring it is in fact 0xE8 (CALL). > > > > AFAICT there is only the _1_ CALL encoding, and that is the 5 byte: E8 , > > so if we have the PLT32 location, we also have the instruction location. Or am > > I missing something? > > There’s also JMP and Jcc, any of which can be used for rail calls, but > those are also one byte. I suppose GCC is unlikely to emit a prefixed > form of any of these. So maybe we really can assume they’re all one > byte. Oh, I had not considered tail calls.. > But there is a nasty potential special case: anything that takes the > function’s address. This includes jump tables, computed gotos, and > plain old function pointers. And I suspect that any of these could > have one of the rather large number of CALL/JMP/Jcc bytes before the > relocation by coincidence. We can have objtool verify the CALL/JMP/Jcc only condition. So if someone tries to take the address of a patchable function, it will error out. Heck, it could initially even error out on tail calls.