Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
 <CY4PR1401MB1942930DCB5EC5CC62EC3F57E60E0@CY4PR1401MB1942.namprd14.prod.outlook.com>
Date: Sat, 3 Oct 2020 09:43:02 +0000
From: Jay K <jayk123@...mail.com>
To: Florian Weimer <fw@...eb.enyo.de>, "Madhavan T. Venkataraman"
	<madvenka@...ux.microsoft.com>
CC: "mark.rutland@....com" <mark.rutland@....com>,
	"linux-security-module@...r.kernel.org"
	<linux-security-module@...r.kernel.org>, "pavel@....cz" <pavel@....cz>,
	"kernel-hardening@...ts.openwall.com" <kernel-hardening@...ts.openwall.com>,
	"linux-api@...r.kernel.org" <linux-api@...r.kernel.org>, "x86@...nel.org"
	<x86@...nel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "oleg@...hat.com" <oleg@...hat.com>,
	"mic@...ikod.net" <mic@...ikod.net>, Arvind Sankar <nivedita@...m.mit.edu>,
	"David.Laight@...LAB.COM" <David.Laight@...LAB.COM>, "luto@...nel.org"
	<luto@...nel.org>, "linux-fsdevel@...r.kernel.org"
	<linux-fsdevel@...r.kernel.org>, "linux-integrity@...r.kernel.org"
	<linux-integrity@...r.kernel.org>, "libffi-discuss@...rceware.org"
	<libffi-discuss@...rceware.org>, "linux-arm-kernel@...ts.infradead.org"
	<linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

 > And this is not just for libffi that we can somehow do this within libffi. 
 > I would like to provide something so that the maintainers of other 
 > dynamic code can use it to convert their dynamic code to static code 
 > when their dynamic code is a lot more complex that the libffi trampoline. 


Having worked on stuff "like" this -- removing "arbitrary" codegen
from a system and replacing with "templatized" codegen,
because the runtime banned runtime codegen,
and despite being a lover of shared source and shared libraries,
I'm afraid to say, this is not an area very amenable
to sharing.

Specifically I've done this twice.


Providing examples is good and people will copy/paste.

The problem can be sort of split up into parts:

 - The management of a pool of thunks.

 - The thunks.

Where I mostly give up is:

 - Generalizing the thunks, such as to share them.

the management of the pool is kinda sorta generalizable, but the thunks,
again, it is difficult/impossible to share.

I do think, there is *some* opportunity here.

Stuff like, for some function f(x,y), produce
a new function f2(y,x) that swaps params and calls f
or a new function f3(x), that sets y to a constant and calls f.

Like my favorite Scheme-ish:

Given a static binary function:
  function add(x, y) (+ x y)

Provide for dynamically creating specialized unary functions:

 function make-add(x):
   return function addx(y) (+ x y)

And then generalized to arbitrary rearrangement and hardcoding of parameters.

I believe this is libffi, and might be able to replace some people's codegens.

It sounds a bit contrived, but I know this actually resembles real world cases.

Consider some library that accepts function pointers but fails to accept
an additional void* to pass on to them. qsort/bsearch are the classic broken-ish
cases. Wrapping Windows WNDPROCs in C++ are another -- you want a "thunk" to take
the Win32-defined parameters, and add a this pointer as well. So you create
a new function and when you create the function you give it the this pointer
to hardcode within it. i.e. atlthunk.

 > The kernel based solution gives you the opportunity to make additional
 > security checks at the time a trampoline is invoked. A purely user level
 > solution cannot do that. E.g., I would like to prevent even the minimal
 > trampoline from being used in BOP/ROP chains.

Like what? At some point, it is just normal static code.
Once libffi is fixed, so that the iOS solution is available on all platforms,
it is all just normal code. There are no checks to apply differently to libffi
and its output than any other code, right?
 
 > 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?

What functionality does the user land solution provide?

I suggest, other than lobbying the libffi developers to do their part,
and perhaps giving in and doing it yourself, identity some other dynamic but non-arbitrary
code generations that you wish to fix and work through fixing it.
See what patterns emerge.

 - Jay

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.