The module probe
A module of commands that tests the sandbox of an isolated call. A call to a module that is not trusted runs the module as its own process, and its arguments travel as records. Each export does what a module must not be able to do to its caller: read any address, take all the processor time, use a handle that it did not receive. The console calls it with isolate("probe"). Do not load it directly: then it runs with the memory and the handles of the console.
What it is for. It shows the limits of a sandbox from the inside. A reader calls the exports one by one and sees that each harm stays in the sandboxed process: the console goes on, and the next call gets a new process with new data.
Example, in the console:
isolate("probe") probe: 8 commands in a sandboxed process
count() + count() * 10 21
stop_machine(1) 2: the sandbox holds no handle
peek(0) error: the process probe stopped: a fault, page fault
count() 1: a new process
spin() Escape stops the call
probe module with no entry
- Hash
c6c297aa502c76042ba3363ed692acc45490bcbeb6b39d9d60bbd1c99e721d4a- Size
36864 bytes- Exports
8- Imports
0- Imported by
0- License
- MIT
A module of commands that tests the sandbox of an isolated call
| Fact | Value |
|---|---|
| Kind | Modules with no entry |
| Source | src/modules/tests/probe |
| Boot image | yes: in the boot image, 36864 bytes in this build |
| Build settings | none: the defaults of the source |
| Imports | none |
| Imported by | none |
Neighbours
It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.
Exports
| Export | What it does |
|---|---|
peek(address: Integer) -> Integer | reads 8 bytes at an address |
count() -> Integer | gives the number of calls of count |
spin() -> Integer | never returns |
stop_machine(handle: Integer) -> Integer | asks the kernel to stop the machine with a handle |
checksum(text: Text) -> Integer | adds the bytes of a text |
shout(text: Text) -> Text | gives a text in capital letters |
lie(count: Integer) -> Text | writes no text, and gives a false count of bytes |
log_long(count: Integer) -> Integer | writes one text of count bytes on the log (at most 2000): digits, then the words "the end of the long text" |
peek
peek(address: ) ->
peek reads 8 bytes at an address. In a call host, the address space has only the module, the call ring and the call region.
An address outside these stops the sandboxed process on a page fault; the console reports it, and its own memory is not reachable. After load("probe") the same call reads the memory of the console.
count
count() ->
count gives the number of calls of count. The data of a module is private to the process that runs it.
It starts at 1 in each new sandboxed process: a fault in an earlier call resets it.
spin
spin() ->
spin never returns.
The console runs the line in its second thread, keeps the keys of the next line, and stops the call when the input presses Escape: "error: Escape stopped the call of spin". The sandbox has its own budget of processor time, so other processes go on.
stop_machine
stop_machine(handle: ) ->
stop_machine asks the kernel to stop the machine with a handle. The result is the status of the kernel operation.
In a sandbox the handle names nothing: the result is 2, "no handle", for each value. The machine never stops through this export unless the caller loaded the module directly and passes the number of a handle of the machine that it holds.
checksum
checksum(text: ) ->
checksum adds the bytes of a text. The bytes are in the call region.
shout
shout(text: ) ->
shout gives a text in capital letters. In a call host, the buffer of the result is in the call region: the caller reads the text there.
lie
lie(count: ) ->
lie writes no text, and gives a false count of bytes. The caller must not read more than its buffer.
lie(100000) gives "error: the result of lie has 100000 bytes: it does not fit"; length(lie(3)) gives 3: the console reads the bytes that the call region holds, never more.
log_long
log_long(count: ) ->
log_long writes one text of count bytes on the log (at most 2000): digits, then the words "the end of the long text". The log keeps a text whole: a text longer than its part of 512 bytes goes in several lines, never cut in silence. The result is the count of bytes of the text.
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
