Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-27 Thread Madhavan T. Venkataraman
Before I implement the user land solution recommended by reviewers, I just want an opinion on where the code should reside. I am thinking glibc. The other choice would be a separate library, say, libtramp. What do you recommend? Madhavan

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-27 Thread Madhavan T. Venkataraman
On 9/26/20 10:55 AM, Arvind Sankar wrote: > On Fri, Sep 25, 2020 at 05:44:56PM -0500, Madhavan T. Venkataraman wrote: >> >> >> On 9/24/20 6:43 PM, Arvind Sankar wrote: >>> >>> The source PC will generally not be available if the compiler decided to >>> tail-call optimize the call to the

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-26 Thread Arvind Sankar
On Fri, Sep 25, 2020 at 05:44:56PM -0500, Madhavan T. Venkataraman wrote: > > > On 9/24/20 6:43 PM, Arvind Sankar wrote: > > > > The source PC will generally not be available if the compiler decided to > > tail-call optimize the call to the trampoline into a jump. > > > > This is still work

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-25 Thread Madhavan T. Venkataraman
On 9/24/20 6:43 PM, Arvind Sankar wrote: > On Thu, Sep 24, 2020 at 03:23:52PM -0500, Madhavan T. Venkataraman wrote: >> >> >>> 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). >> >>

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-25 Thread Madhavan T. Venkataraman
On 9/24/20 3:52 PM, Florian Weimer wrote: > * Madhavan T. Venkataraman: > >> Otherwise, using an ABI quirk or a calling convention side effect to >> load the PC into a GPR is, IMO, non-standard or non-compliant or >> non-approved or whatever you want to call it. I would be >> conservative and

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-25 Thread Mickaël Salaün
On 25/09/2020 00:05, Pavel Machek wrote: > Hi! > > I believe you should simply delete confusing "introduction" and > provide details of super-secure system where your patches would be > useful, instead. This RFC talks about converting dynamic code (which cannot be

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Arvind Sankar
On Thu, Sep 24, 2020 at 03:23:52PM -0500, Madhavan T. Venkataraman wrote: > > > > 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). > > Position Independent Code needs PC-relative

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Pavel Machek
Hi! > PC-relative data referencing > > > I agree that the current PC value can be loaded in a GPR using the trick > of call, pop on i386. > > Perhaps, on other architectures, we can do similar things. For instance, > in architectures that load the return address in

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Pavel Machek
Hi! > >>> I believe you should simply delete confusing "introduction" and > >>> provide details of super-secure system where your patches would be > >>> useful, instead. > >> > >> This RFC talks about converting dynamic code (which cannot be > >> authenticated) > >> to static code that can be

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Florian Weimer
* Madhavan T. Venkataraman: > Otherwise, using an ABI quirk or a calling convention side effect to > load the PC into a GPR is, IMO, non-standard or non-compliant or > non-approved or whatever you want to call it. I would be > conservative and not use it. Who knows what incompatibility there >

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Madhavan T. Venkataraman
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-24 Thread Mickaël Salaün
On 23/09/2020 22:51, Pavel Machek wrote: > Hi! > Scenario 2 -- We know what code we need in advance. User trampolines are a good example of this. It is possible to define such code statically with some help from the kernel. This RFC

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
On 9/23/20 9:39 AM, Florian Weimer wrote: > * Solar Designer: > >> While I share my opinion here, I don't mean that to block Madhavan's >> work. I'd rather defer to people more knowledgeable in current userland >> and ABI issues/limitations and plans on dealing with those, especially >> to

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
On 9/23/20 3:51 PM, Pavel Machek wrote: > Hi! > Scenario 2 -- We know what code we need in advance. User trampolines are a good example of this. It is possible to define such code statically with some help from the kernel. This RFC

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Pavel Machek
Hi! > >> Scenario 2 > >> -- > >> > >> We know what code we need in advance. User trampolines are a good example > >> of > >> this. It is possible to define such code statically with some help from the > >> kernel. > >> > >> This RFC addresses (2). (1) needs a general purpose trusted code

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Arvind Sankar
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
On 9/23/20 4:14 AM, Solar Designer wrote: >>> The W^X implementation today is not complete. There exist many user level >>> tricks that can be used to load and execute dynamic code. E.g., >>> >>> - Load the code into a file and map the file with R-X. >>> >>> - Load the code in an RW- page.

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
On 9/23/20 3:42 AM, Pavel Machek wrote: > Hi! > >> Solution proposed in this RFC >> = >> >> >From this RFC's perspective, there are two scenarios for dynamic code: >> >> Scenario 1 >> -- >> >> We know what code we need only at runtime. For instance, JIT code

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Arvind Sankar
On Wed, Sep 23, 2020 at 08:11:36PM +0200, Solar Designer wrote: > On Wed, Sep 23, 2020 at 04:39:31PM +0200, Florian Weimer wrote: > > * Solar Designer: > > > > > While I share my opinion here, I don't mean that to block Madhavan's > > > work. I'd rather defer to people more knowledgeable in

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread James Morris
On Wed, 23 Sep 2020, Pavel Machek wrote: > This is not first crazy patch from your company. Perhaps you should > have a person with strong Unix/Linux experience performing "straight > face test" on outgoing patches? Just for the record: the author of the code has 30+ years experience in SunOS,

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Madhavan T. Venkataraman
... >> The W^X implementation today is not complete. There exist many user level >> tricks that can be used to load and execute dynamic code. E.g., >> >> - Load the code into a file and map the file with R-X. >> >> - Load the code in an RW- page. Change the permissions to R--. Then, >> change

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Solar Designer
On Wed, Sep 23, 2020 at 08:00:07PM +0200, Solar Designer wrote: > A couple of other things Brad kindly pointed out: > > SELinux already has similar protections (execmem, execmod): > > http://lkml.iu.edu/hypermail/linux/kernel/0508.2/0194.html > https://danwalsh.livejournal.com/6117.html

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Solar Designer
On Wed, Sep 23, 2020 at 04:39:31PM +0200, Florian Weimer wrote: > * Solar Designer: > > > While I share my opinion here, I don't mean that to block Madhavan's > > work. I'd rather defer to people more knowledgeable in current userland > > and ABI issues/limitations and plans on dealing with

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Andy Lutomirski
On Wed, Sep 23, 2020 at 7:39 AM Florian Weimer wrote: > > * Solar Designer: > > > While I share my opinion here, I don't mean that to block Madhavan's > > work. I'd rather defer to people more knowledgeable in current userland > > and ABI issues/limitations and plans on dealing with those,

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Solar Designer
On Wed, Sep 23, 2020 at 05:18:35PM +0200, Pavel Machek wrote: > > It sure does make sense to combine ret2libc/ROP to mprotect() with one's > > own injected shellcode. Compared to doing everything from ROP, this is > > easier and more reliable across versions/builds if the desired > > payload > >

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Pavel Machek
Hi! > > > > The W^X implementation today is not complete. There exist many user > > > > level > > > > tricks that can be used to load and execute dynamic code. E.g., > > > > > > > > - Load the code into a file and map the file with R-X. > > > > > > > > - Load the code in an RW- page. Change

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Florian Weimer
* Solar Designer: > While I share my opinion here, I don't mean that to block Madhavan's > work. I'd rather defer to people more knowledgeable in current userland > and ABI issues/limitations and plans on dealing with those, especially > to Florian Weimer. I haven't seen Florian say anything

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Solar Designer
On Wed, Sep 23, 2020 at 11:14:56AM +0200, Solar Designer wrote: > On Wed, Sep 23, 2020 at 10:14:26AM +0200, Pavel Machek wrote: > > > Introduction > > > > > > > > > Dynamic code is used in many different user applications. Dynamic code is > > > often generated at runtime. Dynamic

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Solar Designer
On Wed, Sep 23, 2020 at 10:14:26AM +0200, Pavel Machek wrote: > > Introduction > > > > > > Dynamic code is used in many different user applications. Dynamic code is > > often generated at runtime. Dynamic code can also just be a pre-defined > > sequence of machine instructions in a

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Arvind Sankar
On Tue, Sep 22, 2020 at 09:46:16PM -0400, Arvind Sankar wrote: > 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 > > >> === > > >> > > >>

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Pavel Machek
Hi! > Solution proposed in this RFC > = > > >From this RFC's perspective, there are two scenarios for dynamic code: > > Scenario 1 > -- > > We know what code we need only at runtime. For instance, JIT code generated > for frequently executed Java methods.

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-23 Thread Pavel Machek
Hi! > Introduction > > > Dynamic code is used in many different user applications. Dynamic code is > often generated at runtime. Dynamic code can also just be a pre-defined > sequence of machine instructions in a data buffer. Examples of dynamic > code are trampolines, JIT code, DBT

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-22 Thread Arvind Sankar
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-22 Thread Madhavan T. Venkataraman
I just resent the trampfd v2 RFC. I forgot to CC the reviewers who provided comments before. So sorry. Madhavan On 9/22/20 4:53 PM, madve...@linux.microsoft.com wrote: > From: "Madhavan T. Venkataraman" > > Introduction > > > Dynamic code is used in many different user

[PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-22 Thread madvenka
From: "Madhavan T. Venkataraman" Introduction Dynamic code is used in many different user applications. Dynamic code is often generated at runtime. Dynamic code can also just be a pre-defined sequence of machine instructions in a data buffer. Examples of dynamic code are

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-17 Thread Madhavan T. Venkataraman
On 9/17/20 10:36 AM, Madhavan T. Venkataraman wrote: >>> 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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-17 Thread Florian Weimer
* Madhavan T. Venkataraman: > On 9/17/20 10:36 AM, Madhavan T. Venkataraman wrote: 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:

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-17 Thread Madhavan T. Venkataraman
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

Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-16 Thread Florian Weimer
* 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

[PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-16 Thread madvenka
From: "Madhavan T. Venkataraman" Introduction Dynamic code is used in many different user applications. Dynamic code is often generated at runtime. Dynamic code can also just be a pre-defined sequence of machine instructions in a data buffer. Examples of dynamic code are