Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill out more scheme builtins #4355

Merged
merged 16 commits into from
Oct 25, 2023
Merged

Fill out more scheme builtins #4355

merged 16 commits into from
Oct 25, 2023

Conversation

dolio
Copy link
Contributor

@dolio dolio commented Oct 24, 2023

This PR includes various builtin additions, mainly for scheme, the most significant of which are sandboxing related.

  • Value.dependencies and Code.dependencies will be included, as they are auto-generated from unison, and will appear when the share version is incremented
  • Code.isMissing has been implemented in scheme
  • A system mirroring the sandbox checks has been implemented in scheme. This keeps track of sensitive builtins for each defined function, and looks them up to check if a value's evaluation should be allowed
  • A couple new sandbox related builtins have been added:
    • sandboxLinks looks up the list of sensitive builtins associated with a termlink. This is used when statically generating code, to just look up the sandboxing information in the current runtime and add it to the file.
    • Value.validateSandboxed is a revised version of the sandboxing check. It allows checking the sandboxing status of a Value before it is loaded into an arbitrary unison value. This is a bit easier to check on the scheme side. It also has a different API, which can report all the builtins that caused the value to fail the sandbox check, rather than just a boolean.

Some tests are included, but I'm going to add a bit more, as I think there might be at least one corner case I missed on the scheme end.

dolio added 9 commits October 23, 2023 12:45
- `Value.validateSandboxed` checks an interchange value for sandboxing
  before it is decoded. It either returns a list of dependencies the
  runtime doesn't know about yet, or a list of disallowed builtins, both
  as lists of termlinks
- `sandboxLinks` returns the list of sandboxed builtins transitively
  referenced by the code associated to a given termlink
- Creates a map storing associations of termlinks with sensitive ops
- Procedures for dynamically expanding the map, and declaring
  associations statically
- Structural termlink equality and hashing has been added to the struct,
  because otherwise looking up associated links was failing.
- Declarations for all the sensitive builtins have been included
  statically in the sandbox implementation file
  * Generated code will use a direct declaration of all builtins
    transitively used, since we can look that up at code generation time
- Both sandbox validation functions have been provided, but the one for
  arbitrary values is incomplete.
- Sandboxing has been added to the jit test suite.
Lists vs. chunked lists, byte strings vs. typelinks, etc.
- Value.validateSandboxed wasn't being aliased there
- The sandbox check in the interpreter wasn't handling builtin
  dependencies correctly
Copy link
Member

@pchiusano pchiusano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left one very minor comment. I'd say merge whenever you're ready.

pure (denv, ustk, bstk, k)
exec !env !denv !_activeThreads !ustk !bstk !k _ (BPrim2 SDBX i j)
| sandboxed env =
die "attempted to use sandboxed operation: sandboxLinks"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the error message say "sandboxLinks" here or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is correct, but I'd put it in the wrong case there. It was meant for SDBL.

(sandbox-builtin "IO.array")
(sandbox-builtin "IO.arrayOf")
(sandbox-builtin "IO.bytearray")
(sandbox-builtin "IO.bytearrayOf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and double checked these to make sure they're consistent with what's in Builtin.hs.

dolio added 7 commits October 24, 2023 12:30
Contains a serialized, mutually recursive function that won't be
recognized as unsafe unless the sandboxing information is expanded
correctly.
It was failing to check the case where we already have all dependencies,
which was causing a crash when generating the module name, since we use
the termlinks to influence the name.
Was wrapping in value too many times, which makes things safe.
CACH wasn't actually adding to the sandbox, and the sandbox expansion
algorithm wasn't correctly handling mutually recursive functions.
Add some cases that actually fail if statically generated sandboxing
information isn't produced.
@dolio dolio merged commit d425300 into trunk Oct 25, 2023
6 checks passed
@dolio dolio deleted the topic/scheme-sandbox branch October 25, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants