Skip to content

determining operational cageid for syscalls. #896

@stupendoussuperpowers

Description

@stupendoussuperpowers

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.wasm issues open("/path", ...), it is intercepted by the chroot-grate which will change the path to /tmp/path.
  • This new path buffer (/tmp/path) now exists in the grate's memory, so we will now call make_threei_call(..., new_path, grateid,...).
  • The current way open_syscall in rawposix handles things, the operational_cageid is determined by the path_arg_cageid, so in this scenario it would call open on behalf of the chroot-grate, and not program.wasm, and an FD will be opened for the grate.
    // 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:

  1. 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.

  2. Change the semantics of how (selfcageid, targetcageid) work. Cons: This is a really complicated change.

  3. For make_threei_call replace the unused syscall_name parameter to represent the operational cageid instead, and change rawposix syscall signatures to add an added parameter called operational_cageid. We would also need to change the signature of pass_fptr_to_wt so that grates know which cage it received this call from.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions