From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC431C4363D for ; Wed, 23 Sep 2020 01:47:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61B862371F for ; Wed, 23 Sep 2020 01:47:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lE6gNdEu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uhilotA2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61B862371F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=alum.mit.edu Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wW202E9Jtj7f8Q5Wnu8pS6Qth/e/BALaq7K1RfSDR4Y=; b=lE6gNdEuk+bhPKkIxiRoQSEcG kLl4fB9/MNqNGBl3muVTwH2VRKW+F6oSdxeQNXUpBHukrnTMUMIDT9USXhfE7cKkQraducu5KjH8b b8JRTVnr70c+UgBpRagCqa6/HxXOScnxmw6xaL7pshgNf7/l+Y82/H6NieAmfgkru9Xqibtak9b2c bMVlVdIE0t0MnZ5cx/xaExxbWcXZIoqxndYnKiHvIDtZJymA3Y4BUzArK6SwUTQ8V9sqztC9ZtCt9 wD6UQ9z3HCeg+lMO+jXY4pDVY+BpAJxwWXMMGzip4wkI3cJYO4s0daZ2uIe+wVxTHkhfqNigswK68 4XuZnSNwg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKtrT-0008Jy-Jr; Wed, 23 Sep 2020 01:46:23 +0000 Received: from mail-qv1-xf44.google.com ([2607:f8b0:4864:20::f44]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKtrR-0008Id-A2 for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 01:46:22 +0000 Received: by mail-qv1-xf44.google.com with SMTP id di5so10577259qvb.13 for ; Tue, 22 Sep 2020 18:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ssYhrlHCw7Ub9xPyJrNfDQfuZKnG7yNmanf9qk5D/30=; b=uhilotA2RIu/i3TSt6riD62hHewNX0HCYmMAm6Yecx7s6wLqAfVdwPC94TV27TBtq4 +0q0YajK8JyGTHcprchBDFv2ayV59vk0oXGyJlBiFXIqPW4j7qGv0v4IRsopqpngRSr1 Sy4HfLiaqVt6AkHeytLRBjGlCNtInHzH2aFM4TGr3Pn3QrgB/tRSBLBkE+o0ihGxfUiX dhbC8CXns3F1amdB7aenJ/Cxc4yWDSvifq4ZHXkuT03S+tFjT5yxE/eAMet3CHs3A7Hk OXdUPZQvllLZfjnidcNs42c0LsQ0538v8PzsgpNJMClW1XGO0YSC62irz5h/fviXUgUI YbEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ssYhrlHCw7Ub9xPyJrNfDQfuZKnG7yNmanf9qk5D/30=; b=GEcocxfv5cIYgHeBDy6zpjsXklU1hNTA+zbrzAoWUyCN3rSfdqkSmWe26yJVOPtywy BOmag5cGkcgrEA0KHRDJtcDyFj9mYtsuULbMWsERmPLgXVu4aa4hVheN52CgetPgHcCW REobMGqN54L1C7GoP5eW2C5b2veBIMLF6ATdTtABkDjnpKZu5F1AH1yAoTt/EfZPYx5g 5DRnVFzcuB8u4ns7EdNNkvNyc01QJOzWmhZozRDWjwH08JXg2Lq6rwmGvRB7QTvt0epl 9ISZF3PjXxXM9S9NUiYo4Ti4qrXiVZHrurAJfQMlBSWbnDluD480ZFUoyQ23wUVyO86a +hfg== X-Gm-Message-State: AOAM5320fja91aJIjoayhmSuHWaq7vjAKlST0uNDvI49jrfD4VubiQS8 q88CHggpPAG/H5s19sKNLpA= X-Google-Smtp-Source: ABdhPJx+f5G7LH8pGHaNrTcMRrb4zK95unM48fxm9EqaXus2Z/Ijl+3SuFhTwPqbe2UA1MqvfJS/1Q== X-Received: by 2002:a0c:cdc4:: with SMTP id a4mr9110819qvn.31.1600825579406; Tue, 22 Sep 2020 18:46:19 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id g4sm13248370qth.30.2020.09.22.18.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 18:46:18 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Tue, 22 Sep 2020 21:46:16 -0400 To: "Madhavan T. Venkataraman" Subject: Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor Message-ID: <20200923014616.GA1216401@rani.riverdale.lan> References: <20200916150826.5990-1-madvenka@linux.microsoft.com> <87v9gdz01h.fsf@mid.deneb.enyo.de> <96ea02df-4154-5888-1669-f3beeed60b33@linux.microsoft.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <96ea02df-4154-5888-1669-f3beeed60b33@linux.microsoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200922_214621_362072_3A698690 X-CRM114-Status: GOOD ( 32.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, pavel@ucw.cz, kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, oleg@redhat.com, mic@digikod.net, linux-security-module@vger.kernel.org, Florian Weimer , luto@kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, David.Laight@ACULAB.COM, libffi-discuss@sourceware.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 17, 2020 at 10:36:02AM -0500, Madhavan T. Venkataraman wrote: > > > On 9/16/20 8:04 PM, Florian Weimer wrote: > > * madvenka: > > > >> Examples of trampolines > >> ======================= > >> > >> libffi (A Portable Foreign Function Interface Library): > >> > >> libffi allows a user to define functions with an arbitrary list of > >> arguments and return value through a feature called "Closures". > >> Closures use trampolines to jump to ABI handlers that handle calling > >> conventions and call a target function. libffi is used by a lot > >> of different applications. To name a few: > >> > >> - Python > >> - Java > >> - Javascript > >> - Ruby FFI > >> - Lisp > >> - Objective C > > > > libffi does not actually need this. It currently collocates > > trampolines and the data they need on the same page, but that's > > actually unecessary. It's possible to avoid doing this just by > > changing libffi, without any kernel changes. > > > > I think this has already been done for the iOS port. > > > > The trampoline table that has been implemented for the iOS port (MACH) > is based on PC-relative data referencing. That is, the code and data > are placed in adjacent pages so that the code can access the data using > an address relative to the current PC. > > This is an ISA feature that is not supported on all architectures. > > Now, if it is a performance feature, we can include some architectures > and exclude others. But this is a security feature. IMO, we cannot > exclude any architecture even if it is a legacy one as long as Linux > is running on the architecture. So, we need a solution that does > not assume any specific ISA feature. Which ISA does not support PIC objects? You mentioned i386 below, but i386 does support them, it just needs to copy the PC into a GPR first (see below). > > >> The code for trampoline X in the trampoline table is: > >> > >> load &code_table[X], code_reg > >> load (code_reg), code_reg > >> load &data_table[X], data_reg > >> load (data_reg), data_reg > >> jump code_reg > >> > >> The addresses &code_table[X] and &data_table[X] are baked into the > >> trampoline code. So, PC-relative data references are not needed. The user > >> can modify code_table[X] and data_table[X] dynamically. > > > > You can put this code into the libffi shared object and map it from > > there, just like the rest of the libffi code. To get more > > trampolines, you can map the page containing the trampolines multiple > > times, each instance preceded by a separate data page with the control > > information. > > > > If you put the code in the libffi shared object, how do you pass data to > the code at runtime? If the code we are talking about is a function, then > there is an ABI defined way to pass data to the function. But if the > code we are talking about is some arbitrary code such as a trampoline, > there is no ABI defined way to pass data to it except in a couple of > platforms such as HP PA-RISC that have support for function descriptors > in the ABI itself. > > As mentioned before, if the ISA supports PC-relative data references > (e.g., X86 64-bit platforms support RIP-relative data references) > then we can pass data to that code by placing the code and data in > adjacent pages. So, you can implement the trampoline table for X64. > i386 does not support it. > i386 just needs a tiny bit of code to copy the PC into a GPR first, i.e. the trampoline would be: call 1f 1: pop %data_reg movl (code_table + X - 1b)(%data_reg), %code_reg movl (data_table + X - 1b)(%data_reg), %data_reg jmp *(%code_reg) I do not understand the point about passing data at runtime. This trampoline is to achieve exactly that, no? Thanks. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel