-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Moving the discussion from the grates repo to here.
Currently, when a syscall execution hits rawposix, the way it determines the original calling cage changes based on individual syscalls, and the process of extracting this can lead to breakages in the semantic understanding of what the make_threei_call arguments represent. In most cases, this operational cageid is extracted from an arbitrary (argX, argXcageid) tuple.
Walking through this setup:
- We run
chroot-grate.wasm --chroot-dir /tmp program.wasm - When
program.wasmissuesopen("/path", ...), it is intercepted by thechroot-gratewhich will change the path to/tmp/path. - This new path buffer (
/tmp/path) now exists in the grate's memory, so we will now callmake_threei_call(..., new_path, grateid,...). - The current way
open_syscallin rawposix handles things, theoperational_cageidis determined by thepath_arg_cageid, so in this scenario it would callopenon behalf of the chroot-grate, and notprogram.wasm, and an FD will be opened for the grate.
lind-wasm/src/rawposix/src/fs_calls.rs
Lines 100 to 107 in 678448c
// Due to 3i syscall interposition, `cageid` refers to the // current execution context (possibly a forwarding grate), not // necessarily the original caller. // // For syscalls like `open`, the operation must be performed on the // the originating cage. Therefore, we derive the semantic operation // cage from the argument metadata (`path_cageid`). let operation_cageid = path_cageid;
In the implementation that exists right now, the only safe way to modify open's path buffer is to overwrite the existing argument, and this will only be safe in cases where the new_path length is equal to or less than the original path.
We have the following possible fixes for this:
-
Use unused args to represent the operational cageid: For e.g.
(arg6, arg6cage)when unused. Cons: This is a little hacky, and might lead to problems for syscalls that utilize all 6 arguments. It also breaks the contract of where(argX, argXcage)are only supposed to be used for address translations without any hidden meaning. -
Change the semantics of how
(selfcageid, targetcageid)work. Cons: This is a really complicated change. -
For
make_threei_callreplace the unusedsyscall_nameparameter to represent the operational cageid instead, and change rawposix syscall signatures to add an added parameter calledoperational_cageid. We would also need to change the signature ofpass_fptr_to_wtso that grates know which cage it received this call from.