Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp38529pxk; Wed, 16 Sep 2020 18:14:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGE7BK3XyNeDPTQmY7nrTQkTGahxL8nfBJ3F8+yuavuDyk0qJSco6geJLUgi7YUiwPUGNd X-Received: by 2002:a05:6402:a46:: with SMTP id bt6mr30455215edb.269.1600305265325; Wed, 16 Sep 2020 18:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600305265; cv=none; d=google.com; s=arc-20160816; b=OXsbqeVkAcX1JDGHYnZm9BPYjnGPn2CFmPUCbjsQwavg0UjqyTCpAE7Wk5z1HjmeIB mvK887ZFoR8lBSD4lDW042TFD/xp9iTIl5P9EKoLQWAoNkzuvR2ZXCSFPxW25vJnAGJV YDJNU2j+VnLdz+G94nmixX51vL9RjUREHOQvy/XNKNRNOjtr8X4al4obzqOF5b9euSzM 0a3LF4QQco35lO+UeOy7SWtDMgB8K4CxmNbJUgOAhuC1+T53yKS+rzHTw2nmdARPIfU/ dgoGgdAOZCYx4K/g42hheKY3UiiiByG6ZuT099UaP0F89fdU9IK2T2xQLqFoZDymU/xv lpSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=BaS/8wHpCTp032TnD3WM31fywUEEKfGd39t+tYwzDsI=; b=qXQVrByRvJWJ0FSqZJI4tv0U0CF3gb00uBxW4ssdxyrc1Y14uss4LkznftYusP3Pp5 yc7M3VEEQLxJXcqJ9aIb8sPQpFjmUwdCaaEyRhHykKOTaRLa4sKa2+tHWrfaAbpeYdgO /MmXRaZAKklPD7714MbIaH4xGbBTsdct8qymRm7zcWLxkQiApbDpMBGUgdYfQMrPyaX9 C3tjvzHheVY8VcJJQ+E025IP1vVaYyQ3Q/e0uAy2NVwS1l+xKmrjrT3U+T8TA7oWzJ6S TyGJi6wnwPJeypBXqukORCGHRuMuSppyzogEhpcUm/Pxy6tCgSiycHa3VJUL2aytLdpb A/NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si12632212ejz.567.2020.09.16.18.13.57; Wed, 16 Sep 2020 18:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726117AbgIQBKX (ORCPT + 99 others); Wed, 16 Sep 2020 21:10:23 -0400 Received: from albireo.enyo.de ([37.24.231.21]:38836 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbgIQBKK (ORCPT ); Wed, 16 Sep 2020 21:10:10 -0400 X-Greylist: delayed 347 seconds by postgrey-1.27 at vger.kernel.org; Wed, 16 Sep 2020 21:10:08 EDT Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1kIiLL-0001Q0-41; Thu, 17 Sep 2020 01:04:11 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1kIiLK-0001qn-R0; Thu, 17 Sep 2020 03:04:10 +0200 From: Florian Weimer To: madvenka@linux.microsoft.com Cc: kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, oleg@redhat.com, x86@kernel.org, libffi-discuss@sourceware.org Subject: Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor References: <20200916150826.5990-1-madvenka@linux.microsoft.com> Date: Thu, 17 Sep 2020 03:04:10 +0200 In-Reply-To: <20200916150826.5990-1-madvenka@linux.microsoft.com> (madvenka's message of "Wed, 16 Sep 2020 10:08:22 -0500") Message-ID: <87v9gdz01h.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * 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 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. I think the previous patch submission has also resulted in several comments along those lines, so I'm not sure why you are reposting this. > libffi > ====== > > I have implemented my solution for libffi and provided the changes for > X86 and ARM, 32-bit and 64-bit. Here is the reference patch: > > http://linux.microsoft.com/~madvenka/libffi/libffi.v2.txt The URL does not appear to work, I get a 403 error. > If the trampfd patchset gets accepted, I will send the libffi changes > to the maintainers for a review. BTW, I have also successfully executed > the libffi self tests. I have not seen your libffi changes, but I expect that the complexity is about the same as a userspace-only solution. Cc:ing libffi upstream for awareness. The start of the thread is here: