Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp792970pxk; Wed, 23 Sep 2020 16:53:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYpAKOfyDW3z7Oom0eTd9HcGJt4jsVnUPskejaWLKP0fP31xb7mgQBg9GwC0bZhIUgFN2O X-Received: by 2002:aa7:cc8d:: with SMTP id p13mr1949455edt.136.1600905185350; Wed, 23 Sep 2020 16:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600905185; cv=none; d=google.com; s=arc-20160816; b=uK11nidV0ciFrlcoM8cf+OGRrpVxhXu92dbECiyjqQttO9a3WSfKVU8h9uZhKdqYmU otR5PEpz0QdpDURYUeyE9oWSvXaP0cHnH1w3TRcT050ihP3aMgosTsROMZVCcVUqFHMr VyvASiHIg35SYrbaKwKDgrt4BWjDCUfAvCUtjiaGwEwMuLWvTzR16GlRmxzUQd555CzJ 8RVJ5jOPVXele6PpyppdYcfVrqF3JcyPMk+xFFQDp5GmdSQXnWVsHuQnHK069HbiAGxu Xwwb2T7GQWW+9o7P8QJEYl30mi39AsQTNhf643yWHFx5pm1s3lDvSwfgE/1/p9imKvb9 z/7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-filter; bh=GqgBG7sD6S7qtNstlI1PIKQbA+siGqVV5q8dqxKHvGg=; b=KbHIU6j+2NmMkHkId6E2FY9wYwcd8Yye/tYVI9ww/qmtMYKKa+u9B5mjsJpxNKIfYu iALibKvHFLH3Xm6G1MnLaZA13LsnqkJa2AMCTK8TmI8dRAo179QwwHHAmZ0dfe1zX4cV Q3cM7xsK6meiSn3iZxFKi153z8U8FQLN0Hb+TGPDLTFAjx7XXqhnhx4Fie/U8w/l4E+w Ra/fCfQbzcXitK6JqYJSCEnH1eeb5csYzMzcevTMuszXEwa/PogqIkRCu+HK+pSZtmiv Df0MpLx5rJxz18pQVqSKnrrOZQBZIGGzkDbPYXOhi9SQiR9IFddbsVzlhxkvOUKm1ygv o2Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=RV5cXfK+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si920591ejb.541.2020.09.23.16.52.41; Wed, 23 Sep 2020 16:53:05 -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; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=RV5cXfK+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726703AbgIWXvq (ORCPT + 99 others); Wed, 23 Sep 2020 19:51:46 -0400 Received: from linux.microsoft.com ([13.77.154.182]:53490 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgIWXvp (ORCPT ); Wed, 23 Sep 2020 19:51:45 -0400 Received: from [192.168.254.38] (unknown [47.187.206.220]) by linux.microsoft.com (Postfix) with ESMTPSA id C6A2220B7179; Wed, 23 Sep 2020 16:51:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C6A2220B7179 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1600905104; bh=GqgBG7sD6S7qtNstlI1PIKQbA+siGqVV5q8dqxKHvGg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=RV5cXfK+8CDkots7pritItEd6mNvifrnS8eLmaxWpuRVt+XnVh2Tz1Us3fIONgAX4 fq5WeRAMXAUcIUU48OhIz2OVF7gsx9JiFKd8W+rta/V3LhcEf/ZVP030TgL2NDuwTs IeJj3m3tJ2yNhp553s/EKSx3XL0QR1MUcpO5F7WI= Subject: Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor To: Arvind Sankar Cc: Florian Weimer , 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, luto@kernel.org, David.Laight@ACULAB.COM, mark.rutland@arm.com, mic@digikod.net, pavel@ucw.cz References: <20200916150826.5990-1-madvenka@linux.microsoft.com> <87v9gdz01h.fsf@mid.deneb.enyo.de> <96ea02df-4154-5888-1669-f3beeed60b33@linux.microsoft.com> <20200923014616.GA1216401@rani.riverdale.lan> <20200923091125.GB1240819@rani.riverdale.lan> <20200923195147.GA1358246@rani.riverdale.lan> From: "Madhavan T. Venkataraman" Message-ID: <6409d394-9dd2-ae84-88fc-03218515d57d@linux.microsoft.com> Date: Wed, 23 Sep 2020 18:51:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200923195147.GA1358246@rani.riverdale.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/23/20 2:51 PM, Arvind Sankar wrote: > On Wed, Sep 23, 2020 at 02:17:30PM -0500, Madhavan T. Venkataraman wrote: >> >> >> On 9/23/20 4:11 AM, Arvind Sankar wrote: >>> For libffi, I think the proposed standard trampoline won't actually >>> work, because not all ABIs have two scratch registers available to use >>> as code_reg and data_reg. Eg i386 fastcall only has one, and register >>> has zero scratch registers. I believe 32-bit ARM only has one scratch >>> register as well. >> >> The trampoline is invoked as a function call in the libffi case. Any >> caller saved register can be used as code_reg, can it not? And the >> scratch register is needed only to jump to the code. After that, it >> can be reused for any other purpose. >> >> However, for ARM, you are quite correct. There is only one scratch >> register. This means that I have to provide two types of trampolines: >> >> - If an architecture has enough scratch registers, use the currently >> defined trampoline. >> >> - If the architecture has only one scratch register, but has PC-relative >> data references, then embed the code address at the bottom of the >> trampoline and access it using PC-relative addressing. >> >> Thanks for pointing this out. >> >> Madhavan > > libffi is trying to provide closures with non-standard ABIs as well: the > actual user function is standard ABI, but the closure can be called with > a different ABI. If the closure was created with FFI_REGISTER abi, there > are no registers available for the trampoline to use: EAX, EDX and ECX > contain the first three arguments of the function, and every other > register is callee-save. > > I provided a sample of the kind of trampoline that would be needed in > this case -- it's position-independent and doesn't clobber any registers > at all, and you get 255 trampolines per page. If I take another 16-byte > slot out of the page for the end trampoline that does the actual work, > I'm sure I could even come up with one that can just call a normal C > function, only the return might need special handling depending on the > return type. > > And again, do you actually have any example of an architecture that > cannot run position-independent code? PC-relative addressing is an > implementation detail: the fact that it's available for x86_64 but not > for i386 just makes position-independent code more cumbersome on i386, > but it doesn't make it impossible. For the tiny trampolines here, it > makes almost no difference. > Hi Arvind, I am preparing a response for all of your comments. I will send it out tomorrow. Sorry for the delay. Madhavan