sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

two problems when run in a baremetal or a devcontainer

Open nnWhisperer opened this issue 4 months ago • 3 comments

Hello, I'm using ubuntu 24.04, on both server and the docker devcontainer. The problem occurs in both the baremetal server and the docker container.

Sandlock partially works. Below are my findings for a 7.0.0-28-generic kernel: The command used to start an interactive shell here in this experiment is: sandlock run -i -r /usr -r /lib -r /lib64 -r /bin -r /etc -w /tmp -- /bin/sh

  1. while it is working, sandlock list from an alternative terminal says No running sandboxes.. In the shell, it is possible to do ls /tmp and it prints correctly, and ls . gives permission errors, expectedly as the current location wasn't shared.

When running python:

from sandlock import Sandbox, confine

sandbox = Sandbox(
    fs_writable=["/tmp/sandbox"],
    fs_readable=["/usr", "/lib", "/etc"],
    max_memory="256M",
    max_processes=10,
    clean_env=True,
)

# Run a command (with optional timeout in seconds)
result = sandbox.run(["python3", "-c", "print('hello')"], timeout=30)
  1. stops at the instant result line is sent to python repl, saying [1]+ Stopped python.

The 2nd failure step must be doing an effect like sending a ctrl+z to the python process and freezing it. When I say fg, python process continues:

$ fg
python
>>> result
Result(success=False, exit_code=-1, error='sandlock_create failed', reason=None, signal=-1)
>>> sandbox
Sandbox(fs_writable=['/tmp/sandbox'], fs_readable=['/usr', '/lib', '/etc'], fs_denied=[], extra_deny_syscalls=[], extra_allow_syscalls=[], net_allow=[], net_deny=[], no_coredump=False, net_allow_bind=[], net_deny_bind=[], http_allow=[], http_deny=[], http_ports=[], http_ca=None, http_key=None, http_inject_ca=[], http_ca_out=None, max_memory='256M', max_processes=10, max_open_files=None, max_cpu=None, cpu_cores=None, num_cpus=None, port_remap=False, random_seed=None, time_start=None, no_randomize_memory=False, no_huge_pages=False, deterministic_dirs=False, gpu_devices=None, chroot=None, fs_mount={}, clean_env=True, env={}, uid=None, gid=None, notif_policy=None, workdir=None, cwd=None, fs_storage=None, max_disk=None, on_exit=<BranchAction.COMMIT: 'commit'>, on_error=<BranchAction.ABORT: 'abort'>, allow_degraded=[], disable=[])

I hope this debug log helps

nnWhisperer avatar Jul 25 '26 13:07 nnWhisperer

@congwang-mk let me know if you need more debug info(but you need to refer me to a document that shows how to get that extra debug logs for sandlock. Thanks

nnWhisperer avatar Jul 26 '26 19:07 nnWhisperer

Thanks for the report, @nnWhisperer

The first issue is somehow expected, because when I introduced sandlock list for network port remapping initially, I didn't go beyond networking. It is a bug anyway, as it should go beyond just port mapping. See also https://github.com/multikernel/sandlock/issues/68 and PR #153

The second issue is a bug related to tcsetpgrp, I will fix it now.

congwang-mk avatar Jul 26 '26 19:07 congwang-mk

@nnWhisperer I verified on the latest main branch, both are fixed now.

congwang-mk avatar Jul 29 '26 22:07 congwang-mk