Devices and hooks: preserve the actual trust boundary
Separate device-node visibility from device authorization and scope OCI hook execution to the correct namespace, phase, and privilege context.
On this page
The question for today
What you’ll understand
- Distinguish a visible device path from authorization to use its driver interface.
- Explain cgroup v2 device BPF and the separate read/write/mknod permissions.
- Locate OCI v1.3.0 hooks in their documented namespace and lifecycle context.
An accelerator workload may need device nodes, driver interfaces, mounts, and setup hooks. Granting a broad privileged mode until it starts can hide which of those mechanisms was actually missing. A device file is a reference into a kernel driver, while a runtime hook can execute with authority outside the application's final environment. This lesson uses Linux 6.12 cgroup v2 device control and OCI Runtime Specification v1.3.0 hook names. Vendor drivers and concrete runtimes add requirements that must be recorded explicitly rather than assumed from the presence of a path under /dev.
Visibility, ownership, and device permission are distinct
A character or block device node identifies a device type and major/minor pair. Supplying the node, whether by creation or an appropriate bind mount, makes a name available but does not alone establish that the process may open or use it. Ordinary ownership and mode checks, relevant LSM rules, device policy, and driver-specific checks still participate. A readable directory listing is not an access test. A permission denied response likewise does not uniquely identify which layer rejected the operation.
Linux cgroup v2 device control uses attached cgroup BPF programs rather than the cgroup v1 devices.allow/devices.deny file interface. Decisions distinguish creation with mknod from read and write access to an existing device and inspect type and major/minor identity. A task able to create a node is not thereby guaranteed access through that node. Conversely, a previously supplied descriptor and a driver API may involve different operation boundaries than a new pathname open. Audit the actual setup and use path rather than assuming one flag governs all cases.
Hooks execute in specifically documented contexts
OCI v1.3.0 distinguishes createRuntime, createContainer, startContainer, poststart, and poststop hooks, while prestart is deprecated. The phase and namespace are part of the hook contract. For example, createRuntime executes in the runtime namespace, while createContainer executes in the container namespace even though its executable path is resolved in the runtime namespace. The specification explicitly leaves some setup details underspecified at those creation phases, so a hook must not assume every cgroup and LSM operation is already complete.
A hook binary, its arguments, environment, and input state cross a trust boundary. Host-side hooks must be managed as trusted runtime code, not loaded from an arbitrary writable image path because a name looks convenient. Use the runtime's documented ordering and failure handling, bounded execution, and validated inputs. A hook that returns success can still have left an incorrect device or mount configuration, so verify the resulting state. Keep vendor-specific setup narrowly scoped instead of granting the final workload all of the hook's temporary privileges.
Specify a small operational permission matrix
List each required device identity and operation, then test the application with its intended UID, groups, capability sets, seccomp profile, cgroup, and LSM label. Read/write permission is not a complete description of every ioctl's security meaning, and raw pointer inspection limitations still apply to seccomp filters. Record compatible driver/runtime versions and distinguish container setup failures from application initialization failures. Removing an unnecessary broad permission should leave a targeted test explaining which required operation remains supported.
The probability lab illustrates only sampled compatibility coverage. Reset, explicitly set p=0.20 and n=5, interpret success as encountering an omitted required device path, predict the zero-success bar, then Play or Step. For a separate comparison Reset and explicitly set p=0.20 and n=10. Independence and the detection probability are stipulated, not measured. The model does not represent major/minor IDs, device BPF, driver ioctls, hooks, namespaces, or host privilege. An operation matrix and actual runtime observations supply that evidence.
Work it through
Budget one phase without merging its trust contexts
Assume three trusted createRuntime hooks run serially in their documented runtime-namespace phase and take 25, 40, and 15 milliseconds. A startup budget reserves 150 milliseconds for this phase plus remaining setup. Separately, a device matrix permits read and write on two specified device identities.
The hook elapsed sum is 25+40+15=80 milliseconds under the stated serial assumption, excluding runtime overhead and scheduling variability.
The modeled remaining budget is 150−80=70 milliseconds. This arithmetic does not imply the later startContainer hook has already run or that container-side cgroup and LSM setup was complete at every earlier hook.
Two distinct device identities times two listed access types gives four allowed identity-operation pairs in the abstract matrix. That count does not authorize mknod, arbitrary extra devices, or every possible driver ioctl.
Phase latency and permission scope can be made explicit without pretending all hooks execute inside the final application boundary or that a visible node grants unrestricted driver access.
The living notebook
Explore the model
Interactive lab · probability
Sampled device paths do not define authorization
Use independent toy comparisons with Reset → explicitly set both p and n → predict → Play or Step at (0.20,5), then Reset and (0.20,10). Success means hypothetical detection of an omitted path. This model has no device identities, access flags, driver operations, OCI hook phases, or namespaces.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forTest sampling can expose compatibility gaps; the explicit device-operation matrix and trusted hook context determine the intended access boundary.
Pause & reason
Check your understanding
Your turn
Try it yourself
A proposed matrix permits read on three device identities and write on only one of those three. How many distinct identity-operation pairs are listed? Does that matrix prove a host-side hook is safe to load from a workload-writable directory?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count each device/access pair once, then treat hook code provenance as a separate authority question.
Compare with the solution
There are three read pairs plus one write pair, four distinct identity-operation pairs. The matrix does not establish a host-side hook's trustworthiness or constrain what that privileged hook can do. Its executable and configuration should be controlled by the trusted runtime administration path, with the exact phase, namespace, inputs, and failure handling verified. Workload-writable code is not made trustworthy merely because the final application device matrix is narrow. Driver-specific requirements and extra operations still need explicit testing.
Keep the idea
Take it with you
- A device path is a reference, while authorization and driver semantics are separate.
- Cgroup v2 device checks use BPF and distinguish read, write, and creation.
- OCI hook phase, executable resolution, namespace, and temporary authority must be reviewed together.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.