Bind by open descriptor: plan
Holger's H40-LIST 77. The coordinator accepted this plan on 2026-11-16 (walk plus proof, fail closed; the choices of section 8) and ordered the additions marked A1 to A4. An independent audit of the plan followed (AUDIT-BIND-FD-2026-11-16.md, eight findings); the coordinator's decisions on it are marked D-F1 to D-R4 below and listed in section 9. The build goes in the order of section 5.
- Tag before the work:
e-lane-before-bind-fd-20261116= main0ea2fa0737567427c24f056de3b435834963d24c. Everyfile:linebelow is at that tag. The landing ofe-lane/service-end-eventmoves lines incrates/heimdall-container/src/service.rs; the function names stay. - Branch:
e-lane/bind-fd. Written 2026-11-16. - Heimdall is a defensive sandbox. This change closes a gap between a caller's check of a directory and Heimdall's mount of it.
1. What a caller gets
A service's read binds, its socket directory and a function service's data directory can be given as an open descriptor instead of a path. Heimdall then gives the service the object the descriptor names, whatever stands at its old path by then, or it refuses the start. It never gives the service something else. A service that uses only paths behaves, serialises and is configured exactly as today.
The guarantee, in the words docs/API.md gets (A4): a bind by descriptor gives the service the object the descriptor names, or a refused start. A racing rename can make a start fail; it can never give the service another directory. A directory removed after the open cannot be bound. The same holds for a regular file given as a read bind.
The escape guard (A1): a descriptor of a host directory inside the service would be a way out (openat(fd, "..")). So no bind descriptor is ever open in the service's program or in the function, and no program that the shim, the intermediate process or the init executes inherits one. Section 3.5 says where each one is closed.
2. What the kernel and libcontainer allow (measured)
Measured 2026-11-16 in a KVM guest on the dwarf host (kernel 7.0.0-43-generic), as root, with and without a new user namespace, with plain system calls. "The descriptor" was opened with O_PATH before the new mount namespace existed, as a runner's descriptor always is.
| # | What was tried inside the new mount namespace | Result |
| M1 | mount(MS_BIND) from /proc/self/fd/<n> |
EINVAL |
| M2 | open_tree(<n>, "", OPEN_TREE_CLONE), and open_tree("/proc/self/fd/<n>", OPEN_TREE_CLONE) |
EINVAL |
| M3 | What libcontainer 0.7.0 does with the source /proc/self/fd/<n>: canonicalize, then open_tree on that path. The directory had been renamed away and another directory, or a symlink, put at its old path |
mounts the ORIGINAL (the kernel reports the descriptor's current path) |
| M4 | M3 in a process that is not dumpable, as libcontainer's init is | as M3 |
| M5 | M3, with another directory swapped in between the two walks | mounts the IMPOSTOR |
| M6 | M3, after the directory was removed and a directory named <name> (deleted) was made |
mounts the IMPOSTOR |
| M7 | fstat of the descriptor against stat of the mounted place |
equal in M3 and M4, different in M5 and M6 |
| M8 | No path at all: a process does fchdir(<n>), then unshare of a user and mount namespace. Its working directory is carried into the new namespace; open_tree(".") there, and move_mount of that tree in another namespace |
works for a directory; a regular file cannot be a working directory (ENOTDIR) |
| M9 | A directory that was removed after the descriptor was opened | cannot be mounted in either way (M3: ENOENT; M8: move_mount gives ENOENT) |
| M10 | A regular file: another file renamed OVER its path after the open (plain VFS, measured on the dwarf kernel without a namespace) | the original has no name any more: st_nlink 0, the kernel reports <path> (deleted); it is M9 for a file. Renamed AWAY first and another file put at the old path: st_nlink 1, the kernel reports the new path |
Why M1 and M2 fail: the kernel copies a mount only from a mount of the caller's own mount namespace. A descriptor opened on the host still points into the host's namespace, also when the mounting process holds it.
libcontainer 0.7.0 (=0.7.0 in crates/heimdall-container/Cargo.toml:61), src/rootfs/mount.rs:591-652: for a bind it calls canonicalize(source) (:594), then src.is_dir() (:599), then open_tree(AT_FDCWD, <that path>, OPEN_TREE_CLONE | AT_EMPTY_PATH | AT_RECURSIVE), mount_setattr and move_mount. That is three walks of a path string, and none is checked against anything.
What this means for the decision "/proc/self/fd/<n> as the OCI source where it is proven that the mounting process holds <n>". The mounting process does hold <n> (section 3.4). But the source is still a walk of the name the kernel reports for the descriptor at that moment, and M5 and M6 show the walk can be made to end elsewhere. So this source is safe only together with a proof (M7) that Heimdall makes itself, in the same process, before any code of the service runs. This plan adds that proof. It is the one place where the plan cannot follow "Heimdall never walks a path for it again" to the letter: Heimdall's own code never walks one, libcontainer walks the kernel's current name for the descriptor, and Heimdall proves the result or refuses. The way without any walk is in section 7.
Limits of walk plus proof (audit F5 and F6; decisions D-F5 and D-F6).
- The same directory through another mount. When the directory's filesystem is reachable through a second mount in the runner's mount namespace (the device mounted twice, a bind made for a backup), a host process that controls a parent of the descriptor's current name can turn a path component into a symlink into that second mount. The walk then ends in the same directory, reached through the other mount. Device, inode and type are equal and the proof passes. The service gets the directory the descriptor names; what it can differ in is what lies BELOW it (other mounts under it) and the second mount's flags. This is a stated limit of walk plus proof, and
docs/API.mdsays it in plain words. The proof also compares owner and mode (D-F5): a second mount with another id mapping is caught when the two owners differ inside the service's user namespace (two owners that both lie outside its range look the same). Measured in step 3 (section 5, M-F5): 34 of 40 raced starts went through the second mount with the proof passed, and an id-mapped second mount was refused every time it was reached. - Where device and inode are an identity. The proof is claimed only on filesystems where the pair is unique among live inodes (D-F6): ext2/3/4, xfs, btrfs, and tmpfs whose mount shows
inode64. Any other type (overlayfs, FUSE, a network filesystem, tmpfs with 32-bit numbers) is refused before the start (section 3.2). - After the start, and below the top directory (audit F3, F4): mounts made on the host later, and mounts below a bound directory, concern path binds as much as descriptor binds. They were measured in step 3 (the numbers are at the end of section 5) and reported before any code; they are not part of this change.
3. Design
3.1 The type (heimdall-core)
/// Where a bind comes from on the host.
#[derive(Clone, Debug)]
pub enum BindSource {
Path(PathBuf),
/// An `O_PATH` descriptor (`O_DIRECTORY` too for a socket or data directory).
#[cfg(unix)]
Fd(Arc<OwnedFd>),
}
- It replaces
host: PathBufinBindRo(crates/heimdall-core/src/service.rs:104-107),SocketDir(:117-120) andDataDir(crates/heimdall-core/src/function.rs:117-120). The field keeps its name. From<PathBuf>,From<&Path>,From<OwnedFd>. I addFrom<&str>andFrom<String>, so thathost: "/run/x".into()keeps compiling (this repo has such call sites indocs/API.md:487-489, 601-602,crates/heimdall-container/src/service.rs:1559-1563, 1605and the tests listed in section 4).- The
Fdvariant is#[cfg(unix)]:OwnedFdexists only there, and heimdall-core is otherwise portable code (its one othercfg(unix)is inoutputs.rs). CORRECTED 2026-11-16: this line said the guests build heimdall-core for wasm32. They do not: it is their host-side dev-dependency only, and the crate as it is does not build forwasm32-unknown-unknown(getrandom 0.2 without itsjsfeature). Checked instead: in a throwaway copy, with--features getrandom/js, the crate with this type checks forwasm32-unknown-unknown, so the code without the variant compiles. - The enum is
#[non_exhaustive](added in the build): with a variant that exists on unix only, a caller'smatchwould otherwise be complete on one target and not on another. Cloneclones theArc.PartialEqandEqare written by hand:PathwithPathby path,FdwithFdonly byArc::ptr_eq, neverPathwithFd.ServiceandFunctionServicekeep their derives.Serializeby hand: aPathgoes throughPathBuf's own impl, so today's JSON stays byte-identical; anFdfails withserde::ser::Error::custom(BIND_FD_NOT_SERIALISABLE).Deserializereads a path and givesPath.Display: aPathprints as today (the refusal texts of path binds stay as they are), anFdprintsdescriptor <n>.as_path() -> Option<&Path>; on unixas_fd() -> Option<BorrowedFd<'_>>.- Two public constants:
BIND_FD_NOT_SERIALISABLEandBIND_FD_REFUSED(section 3.6). Service::descriptor_binds()andFunctionService::descriptor_binds()(how many binds are descriptors), for a runner that must refuse them.
3.2 The runner's own work on a descriptor (heimdall-container, no path)
All of it in the supervisor thread, before the config is written, through new functions in the private sys module (crates/heimdall-container/src/sys.rs, the crate's only unsafe code):
| Today, by path | For an Fd |
socket_dir.host and data_dir.host must be absolute (service.rs:280-285, :373-382) |
does not apply |
| nothing: a path is not a descriptor | F_GETFD has FD_CLOEXEC (D-F2). A descriptor without it may already be open in the caller's other children, and the caller must know: refused |
a read bind must exist (service.rs:704-711, :978-985) |
fstat: a directory or a regular file; F_GETFL has O_PATH |
| nothing | the filesystem (D-F6): fstatfs gives ext2/3/4 (0xEF53), xfs or btrfs; or tmpfs whose mount shows inode64 (the descriptor's mount id from statx, looked up in /proc/self/mountinfo; no walk of the bind's path). Any other type is refused, with the type's name |
the data directory must be a directory (service.rs:986-994) |
fstat: a directory |
the socket directory is created when missing (service.rs:418-420) |
does not apply; fstat: a directory |
mode 0750, old sockets removed, anything else refuses (service.rs:423-436) |
one reopen openat(fd, ".", O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC), then fchmod, fdopendir/readdir, fstatat(.., AT_SYMLINK_NOFOLLOW), unlinkat on it |
the id shift lchown(socket_dir.host, ..) (service.rs:796-805, :1010-1018) |
fchown on the same reopened descriptor (the standard library's call, no unsafe code; the plan first said fchownat with AT_EMPTY_PATH on the O_PATH descriptor, which gives the same result with one more unsafe call) |
A descriptor that fails a check is RunError::InvalidJob whose reason starts with BIND_FD_REFUSED (not close-on-exec, not O_PATH, a file where a directory is needed). A filesystem on which the proof cannot be claimed is RunError::Unsupported, the text starting with the constant and naming the type.
The filesystem answer is the kernel's, and plain CI runs where a test directory is on overlayfs (/tmp of a toolchain container). So the runner asks it through the same seam as the duplicate (section 3.3): the hand-over tests give an accepting fake, the real check has its own tests (the decision as a table of types and mount lines; the real calls on the directory the test happens to have, held to that table), and the kernel tests use real directories (section 5).
An object that has no name any more (fstat gives st_nlink 0: a removed directory, a file that another was renamed over; M9, M10) is refused here, before anything is made, with RunError::Setup starting with BIND_FD_REFUSED. A removal that races the start after this check makes libcontainer's mount fail or the proof fail; the start is refused either way, and in the first of the two the text is libcontainer's.
3.3 Keeping the descriptor and handing it to each start
- Kept for the service's whole life.
start_unit(service.rs:1340) moves theServiceorFunctionServiceinto the supervisor thread;supervise(:1212) owns it as itsUnit(:453) until the service is over, restarts included. TheArc<OwnedFd>lives in it. Nothing new is needed to keep it. - A duplicate per start.
launch_in(:691) andlaunch_function_in(:960) duplicate each descriptor withF_DUPFD_CLOEXEC(floor 3; a number that is one of heimdall-seccomp's reservations, every number offds::ALL,crates/heimdall-seccomp/src/launch/fds.rs:18-20, the numbers themselves at:5-13, is duplicated again: D-R1) and record its(st_dev, st_ino). The numberngoes into the shim's request, NOT into the config (section 3.4, D-F1). - Across the shim's
execve.spawn_shim_cmd(crates/heimdall-container/src/lib.rs:603-640) gets the numbers to keep. The child side of the spawn (between fork and exec,CommandExt::pre_exec, wrapped insys) clears close-on-exec on exactly those numbers. The duplicates stay close-on-exec in the runner, so no other child of the runner's process ever inherits them. The runner drops its duplicates when the spawn returns. The closure is added ONLY when there are numbers to keep (D-F8): the standard library starts a command without one byposix_spawnand one with one byforkandexec, so a job or a path-only service keeps today's way of starting its shim. What holds the rule is the code: the oneif !keep.is_empty()inspawn_shim_cmd, with a comment that says why. A test holds only the half before it, that a start without descriptor binds has an empty keep list (a_start_without_descriptor_binds_has_nothing_to_keep,tests/bind_fd.rs). No test looks at the command itself: whether the standard library started a shim byposix_spawnor byforkandexecis not observed anywhere, so a change that added the closure for every start would pass every test. - In the shim.
ShimService(crates/heimdall-container/src/shim.rs:74) getsbinds: Vec<ShimBind { fd, dev, ino, dest }>, left out of the JSON when empty. First thing inrun(shim.rs:830): eachfdmust be open, mustfstatto the recorded(dev, ino), and gets close-on-exec back. A miss is the shim's error before a container exists. Then the shim writes each checked number into the bundle'sconfig.json(section 3.4, D-F1), and only then makes the container. - Seam for the tests. The duplicate and the filesystem answer are made through an object the runner holds (a trait, set in the style of
with_child_claim), so a test can make the duplicate fail and can answer for a filesystem the test host does not have. - The shim's environment (D-F1b, a commit of its own, also for every job). libcontainer leaves the numbers
3 .. 3 + LISTEN_FDS - 1out of its close-on-exec sweep whenLISTEN_FDSis in the environment (libcontainerprocess/init/process.rs:288-334), and the runner hands its whole environment to the shim (lib.rs:612-621). The runner removesLISTEN_PID,LISTEN_FDSandLISTEN_FDNAMESfrom the shim's environment. Measured in the guest first (does a descriptor in that range reach an image service's program today with a staleLISTEN_FDS); that measurement is its RED.
3.4 Who mounts, on each start path
Heimdall's own code mounts nothing today (there is no mount call in crates/), and nothing after this change. Every mount of a service is made by libcontainer from config.json.
| Start path | The config | The process that mounts | How the descriptor is open there |
Image service: HeimdallRunner::launch_in (service.rs:691); the binds at :789-792 through bind() (:440) |
written by the supervisor thread at :816-820. A Path bind's source is the path, as today. An Fd bind's source is a placeholder that no process can resolve, /proc/self/fd/heimdall-bind-<i> (a name in /proc/self/fd that is not a number never exists; <i> counts the start's descriptor binds). The shim replaces it by /proc/self/fd/<n> in the bundle's config.json, after its check on arrival and before it makes the container (D-F1) |
libcontainer's container init (container_init_process, libcontainer 0.7.0 src/process/init/process.rs:42; prepare_rootfs at :87), PID 1 of the service's PID namespace |
The init is a clone of libcontainer's intermediate process, which is a clone of the shim heimdall-container-shim (started by spawn_shim_cmd). No execve lies between the shim's start and the mounts, and libcontainer closes nothing before them: its one sweep (close_range, process.rs:334) comes after pivot_root and only sets close-on-exec; the executor is called from the same process at :482. So <n> in the init is the duplicate the runner made for this start |
Function service: launch_function_in (service.rs:960); the binds in spec::function (crates/heimdall-container/src/spec.rs:109, :145-149, through bind_mount, :93) |
written at service.rs:1020-1024, with the same placeholders; the starter replaces them as the shim does |
the same process | the same; here the shim is the caller's starter program, run from the runner's sealed memfd (service.rs:1061-1070, starter_image.rs:154) |
Jobs (JobRunner) |
not touched: a job has none of the three types |
Why the placeholder (D-F1, audit F1). The shim is a separate program and a starter is the caller's; nothing pins either to the runner's build. An older one ignores service.binds (the request has no version and unknown fields are not refused, shim.rs:65-86), and with a resolvable source it would mount without a proof and START THE PROGRAM: its start line comes only after the program's execve (shim.rs:1104-1125), and the runner checks the report after that (service.rs:897-953). With the placeholder an older shim leaves the source as it is, libcontainer's canonicalize fails (libcontainer rootfs/mount.rs:594), no container is made and nothing of the service runs. binds_proven (section 3.5) stays as the second check. A number that is "probably not open" in an older shim was considered and is not a proof; a name that is not a number is.
3.5 The proof
In HeimdallExecutor::exec (shim.rs:639), as its first step: before the learning uid (:650), before the function's view (:666) and before Landlock (:677). That is in the same init process that made the mounts, after pivot_root, before the service's program or function. In this order (D-R2):
fstatof every bind descriptor;- every bind descriptor closed with
sys::close_fd, whatever step 1 gave (after this,/proc/self/fd/<n>is no second route to the object); statof everydest.
For each bind the two must give the same (st_dev, st_ino), the same file type (a directory, or a regular file for a read bind of a file), the same mode, and the same owner, uid and gid (D-F5). On a miss the executor reports BIND_FD_REFUSED: <dest>: ... on the report pipe and returns an error; the program or function never starts.
What the init is by then (audit, under F6). libcontainer has already given the init the service's uid and gid, dropped every capability and installed the fixed seccomp profile (libcontainer process/init/process.rs:273-413; the executor is called at :482). So:
- Every system call of the proof must be in the fixed profile. They are
fstat,stat,newfstatatandstatx(which of them a C library uses forfstatandstatdiffers) andclose. All five are in the allow list the profile starts from (crates/heimdall-plain/src/default_profile.rs:44close,:88fstat,:211newfstatat,:337stat,:342statx), and none is in the lists thatcrates/heimdall-container/src/profile.rstakes out of it (REMOVED,KILL). A test holds this for the config of an image service and of a function service. No rule is added by hand. stat(dest)needs search rights for the service's user on the directories abovedest. A miss there is a refusal like any other miss of the proof. The host id test (A3) runs with a user other than root and covers it.
Where each holder of a bind descriptor lets go of it (A1).
| Holder | Image service | Function service |
| the runner (supervisor thread), on the host | the duplicates of one start are dropped when spawn_shim_cmd returns; the caller's descriptor lives in the Unit until the service is over |
the same |
| the shim, on the host, outside the container | first act of run (shim.rs:830, before the graph preparation, the broker probe or any other fork or exec): close-on-exec back on every bind descriptor. Its own copies are closed right after build() returned (shim.rs:977): the init has its own by then |
the same |
a program the shim or libcontainer's main process executes (the id-map helpers newuidmap, newgidmap) |
an execve: close-on-exec closes them |
the same |
| libcontainer's intermediate process | a clone that executes nothing and ends once the init exists | the same |
| the init, up to and through the mounts | open: libcontainer resolves /proc/self/fd/<n> there |
the same |
| a hook the init would execute | Heimdall configures none; it would be an execve: close-on-exec closes them |
the same |
the init, in HeimdallExecutor::exec (shim.rs:639) |
1. the proof; 2. sys::close_fd(n) for every bind; 3. everything else (Landlock at :677, the broker filter, the profile); 4. execve of the program, where close-on-exec is the second barrier (libcontainer's close_range, process.rs:334, set it on every descriptor from 3 up) |
1. the proof; 2. sys::close_fd(n) for every bind; 3. starter::enter_view (:666); 4. call_function (:464): sys::close_fds_except(REPORT_FD) at :499 closes every descriptor from 3 up but the report. There is no execve here, so close-on-exec does nothing: step 2 is the close, the sweep of step 4 is the second barrier; 5. the profile, the report written and closed, then the call (starter::call) |
So the program's first instruction, and the function's, run with no bind descriptor open, on the first start and on every restart (each start is a new shim, a new init and the same order).
Why this is enough: a mount's root cannot change once it is attached, the init is the only process in that mount namespace, and the held descriptor pins the inode, so its number cannot be given to another object.
InsideReport (shim.rs:122) gets binds_proven: u32, left out of the JSON when zero. start_and_confirm (service.rs:871, the check at :935) requires it to equal the service's number of descriptor binds, or it stops the start. This is the second check. The first is the placeholder of section 3.4: a shim or a starter that does not know the feature cannot make the container at all, so with it nothing of the service runs; binds_proven alone would only stop the service after its program had started.
3.6 Refusals
RunError (crates/heimdall-core/src/runner.rs:36) is not non_exhaustive: a new variant would break every match in Holger. The plan adds none. Every refusal of this feature uses an existing variant, and its text starts with the public constant BIND_FD_REFUSED ("bind by descriptor refused"), followed by which bind and why. A caller matches the variant and starts_with(BIND_FD_REFUSED).
| Case | Variant |
the caller's descriptor is wrong (not close-on-exec, not O_PATH, not a directory where one is needed) |
InvalidJob |
a runner that has no way to keep or pass a descriptor (descriptor_binds() is its check), or a filesystem on which the proof cannot be claimed |
Unsupported |
| the object has no name any more, the duplicate cannot be made, the shim did not get the descriptor, the shim did not prove the binds, or the mounted place is not the descriptor's | Setup |
No case falls back to a path.
The constant comes first in every refusal Heimdall decides itself (D-F7). That is the descriptor check, the duplicate, the hand-over, the arrival in the shim and the proof. Today's code puts its own words in front of what the shim and the executor say: "inside the job, before execve: ..." (lib.rs:685-718, inside_features) and "the service never started: ..." (service.rs:210-215, never_started). The runner builds those reasons with the constant first when what arrives tells of a bind refusal. A refused RESTART is returned to nobody: it becomes the text of the service's status (service.rs:1221-1241, ServiceStatus::Stopped.error and the backoff's), which today is the error's display text ("setup: ..."); for a bind refusal the status text is the reason itself, so it starts with the constant too.
A mount that libcontainer itself cannot make is NOT such a refusal: a walk that ends in ENOENT or EACCES, a directory removed in the moment between the runner's check and the mount, a parent the service's user cannot search. It stays a plain Setup "the service never started" with libcontainer's words and without the constant. docs/API.md says so.
3.7 A path bind is unchanged
The JSON of a Service or FunctionService with only Path binds, the shim's request and the written config.json stay byte-identical. Three tests pin them (section 5, written first, on today's types).
4. All affected code
| File | Lines at the tag | Change |
crates/heimdall-core/src/service.rs |
:36 imports; :82-87 field docs; :102-107 BindRo; :109-120 SocketDir |
BindSource, its impls, the two constants, Service::descriptor_binds; host: BindSource |
crates/heimdall-core/src/function.rs |
:18 module doc; :28 imports; :112-120 DataDir; :143-147 field docs |
host: BindSource; FunctionService::descriptor_binds |
crates/heimdall-core/src/lib.rs |
:40, :43 |
nothing to write: both modules are exported whole |
crates/heimdall-container/src/service.rs |
never_started :210-215; check_service :247, :280-285; check_function_service :337, :373-382; prepare_socket_dir :405-437; bind :440-447; launch_in :691: :704-711, :720, :789-792, :796-805, :844-851, :853; start_and_confirm :871: :881, :897-953; launch_function_in :960: :978-995, :1009, :1010-1018, :1048-1059, :1072; supervise :1212, the refused restart at :1221-1241; unit tests :1558-1563, :1605 |
sections 3.2 to 3.6; the constant first in "never started" and in the status text of a refused restart (D-F7) |
crates/heimdall-container/src/spec.rs |
bind_mount :93-100; function :109-155, the binds at :145-149 |
the source of an Fd bind; function takes the start's numbers |
crates/heimdall-container/src/lib.rs |
spawn_shim :582, spawn_shim_with :592, spawn_shim_cmd :603-640 (the command at :612-621); the runner's seams (beside with_child_claim, :498); inside_features :685-718 |
the numbers kept across execve, only when there are any (D-F8); LISTEN_* removed from the shim's environment (D-F1b); the seam for the duplicate and the filesystem answer; the constant first in the inside error (D-F7) |
crates/heimdall-container/src/shim.rs |
ShimService :74-86; InsideReport :122-145; HeimdallExecutor :349-367; exec :639-650; run :830, the executor made at :941-952, the container made at :977-985 |
binds, binds_proven, the check on arrival, the placeholder replaced in the bundle's config.json (D-F1), the proof |
crates/heimdall-seccomp/src/launch/fds.rs |
the numbers :5-13, ALL :18-20 |
read, not changed: the numbers a duplicate must not take (D-R1) |
crates/heimdall-plain/src/default_profile.rs, crates/heimdall-container/src/profile.rs |
:44, :88, :211, :337, :342; REMOVED, KILL |
read, not changed: the proof's calls are allowed (a test) |
crates/heimdall-container/src/sys.rs |
new functions beside dup_cloexec_to (:95) and close_fd (:268) |
duplicate with a floor, keep across exec, identity by fstat, the O_PATH and close-on-exec checks, the filesystem type (fstatfs) and the mount id (statx), the socket directory by descriptor, the owner by descriptor |
crates/heimdall-container/src/bindfd.rs |
new (step 2) | the runner's work on a descriptor in a module of its own: the seam BindFds (the duplicate, the filesystem), check, proof_holds_on, prepare_socket_dir, BindPlan (each bind's source in the config) and StartBinds (one start's duplicates and request), and the texts refused, relay, refusal_text. sys.rs holds only the raw calls |
crates/heimdall-cli/src/profile.rs |
:355-372 (the --function view options) |
read, not changed: they are paths inside the view |
docs/API.md |
:468-530 (services, the example at :478-489, the socket directory at :525); :582-630 (function services, the example at :592-602, the table rows at :615-617) |
the type, the refusals, the escape guard, and the guarantee in the words of section 1 (A4) |
CHANGELOG.md |
:14 [Unreleased] |
Added and Changed lines under Unreleased; the field type of three public structs changes, which breaks callers that pass a PathBuf without .into() |
| Tests that build the three types | crates/heimdall-core/tests/function_service.rs:24-29; crates/heimdall-container/tests/function_service.rs:29-41, 73; tests/service_fake_shim.rs:121-123; tests/service_kernel.rs:110-115; tests/function_kernel.rs:57-69 (ranges corrected, D-R4) |
compile with .into(); nothing else |
| Test fixtures | crates/heimdall-container/tests/fixtures/svc_daemon.rs:114-120 (a line that lists a directory); the function fixture of tests/function_kernel.rs (a word that lists and writes) |
new lines for the kernel tests |
Not touched: jobs, heimdall-plain, heimdall-broker, the wasm runner, the CLI's behaviour, libcontainer.
5. Tests, RED first, in build order
Each step is its own commits on e-lane/bind-fd, the RED commit pushed before the fix, each run in a container. Kernel tests run in a KVM guest through scripts/container-tests.sh, one build directory per tree.
Step 0, pins (green on today's code, written before anything changes). crates/heimdall-core/tests/bind_source.rs: the JSON of a Service and of a FunctionService with path binds equals a literal string. tests/service_fake_shim.rs: the request a fake shim receives and the config.json in its bundle, for a service with path binds, equal stored files. tests/spec.rs: spec::function for path binds equals a stored file.
Step 1, the type (core, plain CI). RED in bind_source.rs: a path source equals by path; a clone of a descriptor source equals it and shares the descriptor; two sources made from two descriptors of the same directory are not equal; a path never equals a descriptor; a descriptor source refuses to serialise and the error is BIND_FD_NOT_SERIALISABLE; a service with one refuses as a whole; deserialising gives Path; the From impls; Display. The three pins stay green.
Step 2, the runner's work and the hand-over (container, plain CI, fakes). RED unit tests in sys.rs and service.rs: the socket directory by descriptor (sockets removed, mode 0750, a file that is not a socket refuses, and all of it still lands in the original directory after it was renamed away and another put at its path); a descriptor without O_PATH refuses; a file where a directory is needed refuses; check_service and check_function_service take a descriptor where they demanded an absolute path. RED in tests/service_fake_shim.rs (the fake shim is a shell script; it prints stat -L -c %d:%i /proc/self/fd/<n> for the numbers in its request): a_descriptor_bind_reaches_the_shim_as_the_same_inode_under_the_number_in_its_request; the_descriptor_is_handed_again_at_every_restart_and_the_runner_leaks_none (the count of the runner's open descriptors is the same after three restarts); the_service_keeps_its_descriptor_after_the_caller_dropped_its_own; a_start_whose_descriptor_cannot_be_duplicated_is_refused_and_leaves_nothing_behind (the seam fails); a_shim_that_does_not_prove_its_binds_is_refused_and_leaves_nothing_behind (a start line without binds_proven); no_other_child_of_the_runner_inherits_the_descriptor. The request and config pins stay green.
As built (step 2). The unit tests are in tests/bind_fd.rs and, alone in its process, tests/bind_fd_numbers.rs; the fake-shim tests are the ones named above and those of the decisions below. The RED commit holds the tests and the names they need with every answer "not built yet": 38 tests failed, each on its own assertion. Four things are not as the lines of this plan say, or are not said in them:
- The words of the shim or of the executor lead with the constant only when they START with it (
relay), not when they contain it somewhere. A path of the caller's with those words in it changes no text. take_bindswith no bind does not read the config. A request withoutbindsis what a shim that does not know the feature sees; the placeholder must then stop the container runtime, and the D-F1 kernel test of step 3 plays exactly that with the current shim. A test holds this.- The runner refuses a start line whose
binds_provenis not the number it handed over, also when it is MORE, and also when a path-only service's shim claims any. - Until step 3 the real shim refuses a request with
bindsbefore it makes anything (text with the constant). The runner side is complete, the mount and the proof are not, so the branch fails closed between the two steps.
Added by the decisions, all RED first:
- D-F1, the runner's side: the config a fake shim finds has the placeholder as the source of every descriptor bind (a name under
/proc/self/fd/that is not a number), and the request carries the numbers. Unit tests of the shim's rewrite: each placeholder becomes/proc/self/fd/<n>of its checked descriptor; a placeholder left over, or a bind without its placeholder, is the shim's error and no config is written. - D-F2: a descriptor without close-on-exec is refused (
InvalidJob, the constant first);no_other_child_of_the_runner_inherits_the_descriptorhands in one opened without the flag and sees the refusal, and with a proper one sees that another child of the runner does not hold it. - D-F6: the decision as a table (ext, xfs, btrfs accepted; tmpfs by its mount line, with and without
inode64, and refused when its mount is not in the table; overlayfs, FUSE, NFS refused with the type's name); the real calls on the test's own directory held to that table; a start on a refused filesystem isUnsupportedwith the constant and leaves nothing behind. - D-F7: for each place, a test that the text STARTS with the constant: the descriptor check, a failed duplicate, a shim that ends with a bind refusal before its start line ("never started"), an inside error that tells of one, and the status text of a refused restart (
ServiceStatus's error after a first start that worked and a second that is refused). - D-F8: a start without descriptor binds adds no closure to the spawn (a test on the function that builds the command's keep list, and a comment at the spawn).
- D-R1: a duplicate never has a number of
fds::ALL(the seam's real implementation, with the lower numbers taken, in a process of its own).
Step 3, the mount and the proof (kernel tests, RED first; then the unit tests of the proof). In tests/service_kernel.rs, each opens the descriptor first:
a_read_bind_by_descriptor_shows_the_original_directory_after_another_was_put_at_its_path: rename the directory away, make another directory with other content at the old path, start; the daemon lists the bind; it must be the original's content.…_after_a_symlink_was_put_at_its_path: the same with a symlink to another directory at the old path.a_socket_directory_by_descriptor_gets_the_socket_in_the_original_directory: the same swap; the test reaches the daemon through/proc/self/fd/<fd>/<socket>, and the impostor directory stays empty.a_restart_binds_the_original_directory_again: the swap happens after the first start; the daemon is told to die; the restarted daemon still lists the original.a_mount_that_is_not_the_descriptors_directory_refuses_the_start: M6 made into a test (the directory removed after the open, a directory named<name> (deleted)with other content made). The start must fail withSetupstarting withBIND_FD_REFUSED, and nothing is left behind. Without the proof this test serves the impostor; that is its RED. Intests/function_kernel.rs:a_data_directory_by_descriptor_is_the_original_after_another_was_put_at_its_path(the function writes a file; it appears in the original, not in the impostor) and the same for a read bind. Plain CI: the proof function alone, with two directories and with two files (same: passes; different, or a file against a directory: the error starts with the constant), and a fake shim whose inside report carries that error: the runner returns the typed refusal. An object withst_nlink0 is refused before the start (a removed directory; a file another was renamed over).
Added by the decisions:
- D-F1, the kernel test with the real shim (RED first): a shim that gets a request WITHOUT
bindswhile the config has the placeholder (the current shim behind a wrapper that drops the field, which is what an older shim does) ends as "the service never started", and there is no trace of the program: no socket in the socket directory, no file of the daemon's, no cgroup, no bundle. - D-F5: the proof function refuses when only the mode, the uid or the gid differ (plain CI).
- D-F6: the kernel tests need directories on a filesystem the runner accepts. In the test container
/tmpis overlayfs. The tests use a directory under the build directory (CARGO_TARGET_TMPDIR: in the guest that is the guest's own disk, ext4, mounted into the test container), one test uses/dev/shm(tmpfs withinode64), and one asks for a bind on/tmpand must be refused with the type's name. - D-F1b, its own commits, measured first: with
LISTEN_FDS=1in the runner's environment, does a descriptor the runner holds at number 3 reach an image service's program (the daemon lists its descriptors)? Then the fix, and the same test must find none. Plain CI: a fake shim's environment has none of the three variables.
Measurements in the guest, reported to the coordinator BEFORE any code for them. They concern every bind, path binds too, and are not part of this change unless the coordinator says so.
- M-F3: after a service started, a mount made on the host on the bound directory, and one made below it: does the service see them (libcontainer makes
/rslave,rootfs/rootfs.rs:41-52)? Then withlinux.rootfsPropagation: "private"in the config: does the service still start, and are the events gone? - M-F4: a filesystem mounted below a read bind's directory on the host before the start: is it writable inside the service (the flags are set on the top mount only,
rootfs/mount.rs:671-688)? - M-F5: the same filesystem mounted twice with different content below the directory, and a symlink swap into the second mount: does the proof pass, as the audit suspects?
The escape guard (A1), kernel tests on both start paths. The test daemon gets a line, and the test function a word, that reports every descriptor it holds as number=dev:ino (the daemon through /proc/self/fd; the function, which has no /proc, by fstat of every number up to its RLIMIT_NOFILE).
tests/service_kernel.rs:a_daemon_holds_no_bind_descriptor_at_its_first_start_or_after_a_restart: a service with a read bind and a socket directory by descriptor; no descriptor the daemon holds has thedev:inoof either directory (compared with the test's ownfstat, not by count); the daemon is told to die, and the restarted daemon is asked again.tests/function_kernel.rs:a_function_holds_no_bind_descriptor_at_its_first_start_or_after_a_restart: the same for a read bind, the data directory and the socket directory.- In
a_mount_that_is_not_the_descriptors_directory_refuses_the_start(above) and its function twin: nothing of the service ran. The socket directory holds no socket, the function's data directory holds no file, and the start's cgroup and bundle are gone. - Plain CI: after the shim's check on arrival every bind descriptor has close-on-exec (a unit test in a process of its own); a fake shim that executes a child reports that the child holds none.
A regular file by descriptor (A2). tests/service_kernel.rs, the descriptor opened with O_PATH on a file with known content:
a_file_bind_by_descriptor_reads_the_original_after_another_file_was_put_at_its_path: the original is renamed away, then another file is renamed onto the old path; the daemon reads the bind: the ORIGINAL content. The proof compares the file'sdev:inoand its type.a_file_bind_whose_file_was_renamed_over_is_refused: another file is renamed OVER the original. The original then has no name (M10), so it cannot be bound; the start is refused with the typed error and the other file's content is never served.
Host ids (A3). tests/service_kernel.rs: with_host_ids_a_socket_directory_by_descriptor_is_owned_by_the_shifted_user_and_serves: a runner made with with_host_ids (as tests/container.rs:1539), a service with a user other than root and the socket directory by descriptor. After the start, fstat of the test's descriptor shows the shifted uid and gid (the owner change by descriptor), the daemon answers on its socket through /proc/self/fd/<fd>/<socket>, and after the swap of section 5 the socket is in the original directory. The guest can give a host id range: the two with_host_ids tests of tests/container.rs (:1529, :1565) passed there on 2026-11-16. The unit test of the owner change by descriptor stays beside it (it needs root, so it is a kernel test too; plain CI checks the call is made with the shifted ids through the seam).
The gate for the whole change: fmt, Clippy for core and for the container crate (plain, youki, youki,graph-follower), the tests of both crates in the same three shapes, the CLI's profile_function tests, and the whole scripts/container-tests.sh in the guest.
As built (step 3). The proof is commit c39bf74; the tests of it are 9088978; D-F1b is 4748741 and d78f6fd.
- The proof's kernel calls are behind a seam,
bindfd::ProofCalls(fstat,close,stat), withKernelProofas the real one. The order of D-R2 and every miss are tested with a played kernel intests/bind_fd.rs; the real calls are tested there on real directories and files.bindfd::PROOF_CALLSnames the system calls, and one test holds the fixed profile of an image service (with and without a generated profile on top) and of a function service to that list. - The refusal by the proof is made certain with the seam of step 2 (
with_bind_fds): the test'sduplicatefirst does what a racing process on the host does (it removes the directory and makes a directory named<name> (deleted)), then asks the kernel. That moment is after the runner's check and before the shim exists. libcontainer then mounts the other directory (M6) and the proof refuses. The same seam serves the function service, where no wrapper can stand in front of the starter (its bytes are pinned). - Without the second directory the same moment gives a start that libcontainer cannot make:
Setup, "the service never started: ...", without the constant (D-F7). A test pins it. - The socket directory tests reach the daemon through the path the original was renamed to, not through
/proc/self/fd/<fd>. - Filesystems in the kernel tests (D-F6): no test depends on where it runs. The kernel test files read the filesystem of a directory themselves (
fstatfs, and the mount's options for a tmpfs).on_disk(a directory underCARGO_TARGET_TMPDIR) fails the test with one line when a bind by descriptor is refused there. Two tests bind from the temp directory and from/dev/shmand hold the runner to the rule of whatever filesystem that is: the service starts, or the start is refused by the filesystem's name; each prints which. In the container ofscripts/container-tests.shthe temp directory is overlayfs (refused) and/dev/shma tmpfs withinode64(taken). - D-F1 held from its first run, because step 2 already writes the placeholder. What it guards against was measured in the guest (not committed): the same wrapper, which also wrote
/proc/self/fd/5into the config in place of the placeholder, as the design before the audit would have. The runner stopped that start ("the shim proved 0 of 1 binds: the start is stopped"), but the daemon's socket was in the socket directory: the program had run. With the placeholder nothing of the service runs. - D-F1b as measured: a stale
LISTEN_FDSalone hands a program nothing, because everything the shim holds from 3 up is close-on-exec. A runner that was started by socket activation holds number 3 inheritable and hasLISTEN_FDS=1: its service's program was started with that descriptor as its number 3. The kernel test plays exactly that (the test binary started again with a file at 3), and the runner now starts its shims without the three variables. heimdall-function-selftesthas three more words for the tests:read <file>,id <path>andfds(every number below 65536, byfstat: a function has no/proc).
Measured in step 3 (guest e-lane-kvm2, kernel 7.0.0-43-generic, libcontainer 0.7.0, the real runner and shim, 2026-11-16). None of it has code in this change.
- M-F3, mounts made on the host AFTER the start (path binds; it is the same for a descriptor). The answer depends on the mount that holds the bound directory. On a SHARED mount (what every mount of a systemd host is) the service sees both: a tmpfs mounted below the directory appears inside with its content (
/etc/svc/sub rw,relatime), and a tmpfs mounted on the directory appears inside too and hides the bound content (/etc/svc rw,relatime, on top of the read bind). Both arrive without the bind'sro,nosuid,nodevandnoexec. On a PRIVATE mount (the test container's own root) nothing arrives, which is why no existing kernel test sees this. Withlinux.rootfsPropagation: "private"in the config the service starts and serves, and neither mount arrives. - M-F4, a tmpfs mounted below a read bind's directory BEFORE the start: inside, the bind is
ro,nosuid,nodev,noexecand the filesystem below it isrw,relatime. A write to the bind itself givesEROFS. A write to the filesystem below givesEACCES: the mount would allow it and Landlock alone refuses it. - M-F5, the same filesystem mounted twice (audit F5). A tmpfs holds the directory, a second tmpfs is mounted below it, and the first filesystem is bound a second time elsewhere, without the mount below. A thread exchanges a parent directory with a symlink into the second mount in a loop, as an owner of that parent can without any privilege (3.4 million exchanges during 40 starts). 34 of 40 starts went through the second mount: the proof passed (same device, inode, mode and owner), the service got the descriptor's directory, and below it the second mount's content in place of the first's. 6 of 40 went through the first mount. No start failed. With the second mount id-mapped (
mount --map-users), 36 of 40 starts were refused by the proof ("its owner or group differs there") and 4 went through the first mount; none gave the service the id-mapped view. The coordinator's word: no code; it stays the stated limit of section 2, anddocs/API.mdsays it.
After the merge of main (2ddfe6e8: the end of a service, a function's SIGPIPE rule; 2026-11-16). Main and this change meet in two places, and each has a kernel test with a real container.
- The end descriptor of a service is an eventfd of the runner, made close-on-exec. A start with binds by descriptor hands the shim descriptors on purpose, but only the bind duplicates: the keep-list clears close-on-exec on those numbers alone, in the forked child. The test (
the_end_descriptor_of_a_service_with_binds_by_descriptor_stays_the_runners_and_tells_the_end): at the first start and after a restart the end descriptor is close-on-exec and silent, the daemon is started with the three standard descriptors only and holds neither a bind's object nor the end event, and the stop makes the descriptor readable with the exit inended(). Seen failing with the eventfd made without close-on-exec (guest copy only). - A function is called after the proof closed the bind descriptors and after its view set its signals,
SIGPIPEignored. The test (a_function_with_binds_by_descriptor_holds_none_of_them_and_runs_with_sigpipe_ignored): the function holds no bind's object, readsSIGPIPEback as ignored, getsEPIPEfrom a pipe nobody reads, and the same process serves on.heimdall-function-selftesthas two more words for it:sigpipe(the action read back) andclosed-pipe(the errno of the write). Seen failing withSIGPIPEput at its default in a function's signals (guest copy only). - Measured in that failing run: with
SIGPIPEat its default the function service was NOT killed by the write; it gotEPIPEall the same. A function service is the init of its PID namespace, and the kernel does not end such a process by a signal at its default action. So in a service the rule shows in the action the function reads back, not in the write. The write kills a function that is not a namespace's init: seen in a plain child process, which is where main's two unit tests of the rule run it. The two CLI modes that enter the same view (heimdall profile probe-exec --function,enforce --function) were not measured.
6. Kernel
Nothing here needs a kernel newer than the repo already needs for a service (Landlock, 5.13, crates/heimdall-container/src/kernel.rs:286). What the plan uses: O_PATH (2.6.39), F_DUPFD_CLOEXEC (2.6.24), /proc/self/fd, openat, fstat, fstatfs on an O_PATH descriptor (3.12), statx with the mount id (5.8), /proc/self/mountinfo. The mount itself is libcontainer's and does not change (open_tree and move_mount 5.2, mount_setattr 5.12; it has no fallback for older kernels today either). Everything in section 2 was measured on 7.0.0-43 only. The repo's other gate kernel, 6.8, was not measured: the kernel tests of step 3 should run there once before a release.
A directory that was removed after its descriptor was opened cannot be bound (M9). The start is refused.
7. The way without any walk (left out)
M8 shows it exists. It would take:
- in the shim, one short-lived helper process per descriptor:
fchdir(fd),unshareof a user and mount namespace of its own,open_tree(".", OPEN_TREE_CLONE | AT_RECURSIVE), the mount flags bymount_setattr, and the tree's descriptor sent back over a socket; - Heimdall code inside the container's mount namespace, with the right to mount there, that attaches each tree with
move_mount. Measured as root: a process that joins the parked init's user and mount namespace can do it. A runner that is not root cannot join them: the init is not dumpable (the same wallshim.rs:695-705describes for the broker). So that code would be an OCIcreateContainerhook: the shim's own program, and every starter program, run once more inside the container beforepivot_root; - a placeholder mount per bind, so that libcontainer still makes the mount point safely.
It works for directories only (M8). It would give three things the plan does not: no walk at all; a racing rename could not make a start fail; and a bind below a directory that the service's user namespace cannot search (which matters with with_host_ids). It costs several hundred lines of namespace code in sys.rs and shim.rs, two more kinds of short-lived process per start, and a new mode in every starter. Sections 3.1 to 3.3, 3.5, 3.6 and their tests would stay as they are; only section 3.4 changes. It is not in this plan. It is a second change on the coordinator's word.
8. Choices taken in this plan (all six accepted by the coordinator, 2026-11-16)
Version: this branch changes no version number. It lands on main after the gate lane's bump; if 0.6.0 is not published before it lands, it is part of 0.6.0. The CHANGELOG lines go under Unreleased.
- The mount is libcontainer's walk of the descriptor's current name plus Heimdall's proof, not the way without a walk (sections 2 and 7).
- No new
RunErrorvariant; a constant prefix on existing variants (section 3.6). From<&str>andFrom<String>beside the three orderedFromimpls (section 3.1).- The
Fdvariant exists on unix only (section 3.1). - A descriptor that is not
O_PATHis refused, though a plain read-only directory descriptor would work. - The field type of three public structs changes: callers that pass a
PathBufneed.into(). The version numbers of heimdall-core (0.5.1) and heimdall-container (0.5.6) are not changed by this branch.
9. Decisions after the audit (2026-11-16)
The audit (AUDIT-BIND-FD-2026-11-16.md beside the lane's report) found no way past the proof with a current shim on ext4, xfs or btrfs, and eight findings. The coordinator's decisions, and where each is in this plan:
| Decision | What | Step | Where |
| D-F1 | An older shim must fail BEFORE a container exists: a placeholder source that no process can resolve, replaced only by a shim that knows the feature | 2 and 3 | 3.3, 3.4, 3.5, section 5 |
| D-F1b | LISTEN_PID, LISTEN_FDS, LISTEN_FDNAMES removed from the shim's environment; measured first; its own commits |
with step 3 (it needs the guest) | 3.3, section 5 |
| D-F2 | A descriptor that is not close-on-exec is refused | 2 | 3.2, section 5 |
| D-F5 | The proof also compares owner and mode; the second mount of the same directory is a stated limit | 3 | section 2, 3.5 |
| D-F6 | The proof is claimed only on ext2/3/4, xfs, btrfs and tmpfs with inode64; any other type is refused |
2 | section 2, 3.2, section 5 |
| D-F7 | The constant first in every refusal Heimdall decides, also in "never started", the inside error and a refused restart's status text; libcontainer's own mount failure stays without it | 2 and 3 | 3.6, section 4 |
| D-F8 | The pre_exec closure only when there are numbers to keep |
2 | 3.3 |
| D-R1 | No duplicate on a number of fds::ALL; the cited lines corrected |
2 | 3.3, section 4 |
| D-R2 | The proof's order: fstat of all, close all, stat of all |
3 | 3.5 |
| D-R4 | The line ranges of the test rows corrected | plan | section 4 |
| (3.5) | The proof runs as the service's user, without capabilities, under the fixed profile: its calls named and held by a test | 3 | 3.5 |
| M-F3, M-F4, M-F5 | Measured in the guest and reported before any code | 3 | section 5 |
Not changed: section 7 (the way without a walk) stays out; the audit's remarks R3 and R5 need no change.