-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hey @Manishearth, I have some thoughts on how to make the serialization and deserialization of closures more secure. I'm sure it's not a realistic problem for the current users/uses of mitosis
, but it is currently vulnerable to arbitrary code execution due to the way closures are deserialized. A hypothetical example: a binary using mitosis
with its SUID bit set and owned by root can be used for privilege escalation by non-root users1.
I've been tackling a related problem – how to send closures between processes over the network – and have taken a similar but slightly different approach2. I have an idea for how to achieve soundness, and I'd be keen to hear your thoughts.
I see you are casting non-capturing closures to function pointers, made relative to a known base. I took this approach at first, but I could not see an attractive route to making this sound so I switched to using something that rustc
has more control over: trait objects.
Essentially my idea for soundness is an addition to Rust that enables programs to get all vtables for a particular trait. I have a working PR for that here rust-lang/rust#66113. Given that addition, on serialization of a closure upcast to a trait object you serialize the concrete type_id then the data3. On deserialization you look up the type_id to find the vtable, and if found then call the vtable method to deserialize the data. (See the PR for more details.) This is4 a way to achieve secure & sound deserialization of trait objects. There is some more research including prior art in a languishing RFC I've worked on here.
I'd love my projects and mitosis
to be able to deserialize closures securely so I'm keen to hear if you have any thoughts as to how best to go about achieving this.
- by creating an IPC channel, running the
mitosis
-using binary withMITOSIS_CONTENT_PROCESS_ID
set to the channel token, and then sending along the channel the arbitrary address to execute. - if you're interested here are the various related crates I've published:
serde_closure
– macros that wrap closures to make them (including captured variables) safely serializable and deserializable.serde_traitobject
– supertraits that enable the serialization and deserialization of trait objects. It is currently, likemitosis
, not sound or secure – though it does some validation to rule out non-malicious errors (see here) before dereferencing the received pointer.constellation
– uses the above to spawn closures across a cluster (standalone or kubernetes).
- the closure (including its captured variables) can made serializable and deserializable via for example
serde_closure
. - once Collisions in type_id rust-lang/rust#10389 is fixed.