Skip to content

Commit df81d3b

Browse files
committed
Remove stale cgroup v2 dependency and references
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 67de24e commit df81d3b

File tree

11 files changed

+39
-226
lines changed

11 files changed

+39
-226
lines changed

src/sandlock/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
"""Sandlock: Lightweight process sandbox.
33
4-
Uses Landlock, seccomp, and cgroup v2 for process confinement
4+
Uses Landlock and seccomp for process confinement
55
without root or namespaces.
66
"""
77

@@ -21,7 +21,6 @@
2121
ConfinementError,
2222
LandlockUnavailableError,
2323
SeccompError,
24-
CgroupError,
2524
ChildError,
2625
MemoryProtectError,
2726
NotifError,

src/sandlock/_cgroup.py

Lines changed: 0 additions & 176 deletions
This file was deleted.

src/sandlock/_checkpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
socket. The child runs save_fn and sends raw bytes back.
1313
This covers state that ptrace can't see (open sockets, epoll, etc.).
1414
15-
Combined with BranchFS (O(1) filesystem snapshot) and cgroup freeze,
15+
Combined with BranchFS (O(1) filesystem snapshot) and SIGSTOP,
1616
this provides full checkpoint/restore without CRIU or root.
1717
1818
Control socket protocol (for app-level state only):

src/sandlock/_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Each child is confined via Landlock (filesystem + network), seccomp
55
(syscall blocklist + allowlist), and a seccomp user-notification
66
supervisor for resource limits, /proc virtualization, and network
7-
enforcement. No root or cgroups required.
7+
enforcement. No root required.
88
99
With the default ``policy.strict=True``, confinement failures (Landlock
1010
unavailable, seccomp installation failure) abort the child process.
@@ -129,11 +129,11 @@ class SandboxContext:
129129
"""Fork-based sandbox context.
130130
131131
Forks a child process and applies confinement (Landlock, seccomp,
132-
cgroup v2) according to the given Policy.
132+
seccomp) according to the given Policy.
133133
134134
The child confinement sequence:
135135
1. setpgid(0, 0) — new process group
136-
2. Add self to cgroup — resource limits apply immediately
136+
2. Apply resource limits — RLIMIT_CPU, seccomp notif
137137
3. chroot(path) if policy.chroot — optional path illusion
138138
4. confine(writable, readable) — Landlock (irreversible)
139139
5. install notif filter + send fd — seccomp user notification (optional)
@@ -325,7 +325,7 @@ def __enter__(self) -> "SandboxContext":
325325
# User namespace is only needed for privileged mode (UID 0 mapping)
326326
needs_userns = self._policy.privileged
327327
if needs_userns:
328-
from ._userns import unshare_user_cgroup, setup_userns_in_parent, userns_available # noqa: F811
328+
from ._userns import unshare_user, setup_userns_in_parent, userns_available # noqa: F811
329329

330330
# Sync pipes for user namespace setup:
331331
# child_to_parent: child signals "I've unshared"
@@ -374,12 +374,12 @@ def __enter__(self) -> "SandboxContext":
374374
try:
375375
os.setpgid(0, 0)
376376

377-
# 1. User namespace for cgroup delegation (if needed)
377+
# 1. User namespace for privileged mode (if needed)
378378
if needs_userns and userns_c2p_w >= 0:
379379
os.close(userns_c2p_r)
380380
os.close(userns_p2c_w)
381381
try:
382-
unshare_user_cgroup()
382+
unshare_user()
383383
os.write(userns_c2p_w, b"1") # Tell parent: unshared
384384
os.close(userns_c2p_w)
385385
os.read(userns_p2c_r, 1) # Wait: maps written

src/sandlock/_notif_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def decide(
9292
Args:
9393
path: Resolved absolute path from the intercepted syscall.
9494
sandbox_pids: Set of PIDs belonging to this sandbox (from
95-
cgroup). Only used when ``isolate_pids`` is True.
95+
the sandbox). Only used when ``isolate_pids`` is True.
9696
9797
Returns:
9898
(action, errno_code, virtual_content) tuple.

src/sandlock/_ptrace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
Requires:
1313
- The target process must be a direct child (or ptrace-attachable).
14-
- The process should be frozen (cgroup.freeze) before dumping to
14+
- The process should be stopped (SIGSTOP) before dumping to
1515
guarantee a consistent snapshot.
1616
"""
1717

@@ -239,7 +239,7 @@ def _list_threads(pid: int) -> list[int]:
239239
def dump_process_state(pid: int) -> ProcessState:
240240
"""Capture the full OS-level state of a frozen process.
241241
242-
The process must be stopped (cgroup.freeze or ptrace-stopped)
242+
The process must be stopped (SIGSTOP or ptrace-stopped)
243243
before calling this. Does NOT freeze/unfreeze — caller manages that.
244244
245245
Steps:

src/sandlock/_userns.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
"""User namespace helpers for unprivileged cgroup creation.
2+
"""User namespace helpers for privileged mode.
33
4-
When cgroup v2 delegation is not available (stock Ubuntu), sandlock
5-
uses CLONE_NEWUSER + CLONE_NEWCGROUP to create a new cgroup namespace.
6-
Inside the namespace the process has CAP_SYS_ADMIN and can create
7-
sub-cgroups with resource limits.
4+
Sandlock uses CLONE_NEWUSER to create a new user namespace for
5+
privileged mode (UID 0 mapping inside the sandbox).
86
9-
This module only creates user + cgroup namespaces — no PID, network,
10-
or mount namespaces are created.
7+
This module only creates user namespaces — no PID, network, or mount
8+
namespaces are created.
119
"""
1210

1311
from __future__ import annotations
@@ -19,7 +17,6 @@
1917
_libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True)
2018

2119
CLONE_NEWUSER = 0x10000000
22-
CLONE_NEWCGROUP = 0x02000000
2320

2421

2522
def setup_userns_in_parent(child_pid: int, privileged: bool = False) -> None:
@@ -42,20 +39,19 @@ def setup_userns_in_parent(child_pid: int, privileged: bool = False) -> None:
4239
_write_id_map(f"/proc/{child_pid}/gid_map", inner_gid, gid, 1)
4340

4441

45-
def unshare_user_cgroup() -> None:
46-
"""Create new user + cgroup namespaces via unshare(2).
42+
def unshare_user() -> None:
43+
"""Create a new user namespace via unshare(2).
4744
4845
After this call (and after the parent writes uid/gid maps),
49-
the process has CAP_SYS_ADMIN in the new user namespace and
50-
can create cgroup sub-trees freely.
46+
the process has CAP_SYS_ADMIN in the new user namespace.
5147
5248
Raises:
5349
OSError: If unshare fails (e.g. kernel.unprivileged_userns_clone=0).
5450
"""
55-
ret = _libc.unshare(ctypes.c_int(CLONE_NEWUSER | CLONE_NEWCGROUP))
51+
ret = _libc.unshare(ctypes.c_int(CLONE_NEWUSER))
5652
if ret < 0:
5753
err = ctypes.get_errno()
58-
raise OSError(err, f"unshare(NEWUSER|NEWCGROUP): {os.strerror(err)}")
54+
raise OSError(err, f"unshare(NEWUSER): {os.strerror(err)}")
5955

6056

6157
def userns_available() -> bool:

src/sandlock/cli.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@ def cmd_check(args: argparse.Namespace) -> int:
172172
except Exception as e:
173173
print(f" seccomp: error ({e})")
174174

175-
# cgroup v2
176-
try:
177-
from ._cgroup import _find_user_cgroup
178-
cg = _find_user_cgroup()
179-
print(f" cgroup v2: available ({cg})")
180-
except Exception as e:
181-
print(f" cgroup v2: not available ({e})")
182-
183175
print()
184176
return 0
185177

src/sandlock/exceptions.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class NotifError(SeccompError):
5050
pass
5151

5252

53-
class CgroupError(SandboxError):
54-
"""cgroup creation/configuration failed."""
55-
56-
pass
57-
5853

5954

6055
class ChildError(SandboxError):

src/sandlock/policy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Policy dataclasses for Sandlock sandbox configuration.
33
44
A Policy is frozen after creation — live updates go through
5-
BPF maps + cgroup writes, not Policy mutation.
5+
BPF maps + seccomp notif, not Policy mutation.
66
"""
77

88
from __future__ import annotations
@@ -140,7 +140,7 @@ class Policy:
140140
"""TCP ports the sandbox may connect to. Empty = unrestricted.
141141
Each entry is a port number or a ``"lo-hi"`` range string."""
142142

143-
# Resource limits (cgroup v2)
143+
# Resource limits
144144
max_memory: str | int | None = None
145145
"""Memory limit. String like '512M' or int bytes."""
146146

0 commit comments

Comments
 (0)