aft icon indicating copy to clipboard operation
aft copied to clipboard

Linux: each shell task hard-links the deployed module binary, so its ctime changes on every command

Open iceteaSA opened this issue 3 weeks ago • 2 comments

Summary

On Linux, v0.64.0 makes a hard link to the deployed module binary at the start of each shell task and removes it at the end of the task. Each link and each unlink changes the inode change time (ctime) and the link count of the deployed binary. Thus the metadata of the binary changes during every shell command, although its content does not change.

This breaks an integrity check that records the metadata of the configured module executable (size, mode, device, inode, mtime, ctime) before a command and compares it after the command. On v0.64.0 the check gives a failure for every shell command. On v0.63.5 it passes, because v0.63.5 makes its pin link only one time, when the module starts.

Measurement (Linux 7.3, subc daemon mode, one shell command)

os.stat of the configured module executable before and after one bash call:

Version Binary and storage ctime after one call Other fields
0.63.5 same mount unchanged unchanged (nlink 2)
0.64.0 same mount changed unchanged (nlink 3)
0.64.0 different mounts unchanged over two calls unchanged (nlink 1)

In the last row, linkat fails with EXDEV, so the pin is a copy and the task images link the copy. The deployed inode is not touched.

The process tree of the shell is the same in the two versions: the shell is a child of the module process, and /proc/<pid>/exe of that process is the configured binary.

Cause (v0.64.0, crates/aft/src/pinned_executable.rs)

  • prepare (:65-138) pins the running image: link_image (:385-408) calls linkat(/proc/<pid>/exe, …, AT_SYMLINK_FOLLOW) into <storage>/run/aft-pinned-<pid>-<start>/aft. On the same mount, this is the inode of the deployed binary.
  • task_image (:230-277) links that pin into <task>/io/startup-image/aft for each shell task, also for foreground tasks (:567-570).
  • The terminal-task cleanup in bash_background/registry.rs removes the task image at the end of the task.
  • On macOS, link_image (:409-424) refuses on purpose ("Never give the running daemon's executable a second name on macOS"), and materialize makes a copy.

Request

On Linux, do not give the deployed binary a second name at each task. Two possible changes:

  1. Make the pin of each process a private copy on Linux too, as on macOS (the copy path in materialize, :445-477, works now). Task images then link the copy.
  2. Or link task images to a private copy for each process, and keep the deployed inode out of all links.

A copy costs the size of the binary one time for each module start. The current behavior can also cause failures in other tools that monitor the deployed binary, for example file integrity monitors and backup tools that use ctime.

iceteaSA avatar Nov 11 '26 02:11 iceteaSA

Thanks for the precise report and measurements. The diagnosis is right. On Linux, prepare pins the running image with linkat from /proc/<pid>/exe, so when storage and the deployed binary share a mount, the pin is the deployed inode itself. Each shell task then links that pin into its task folder and removes the link at the end, which changes the deployed binary's ctime and link count on every command. macOS already avoids this: link_image refuses there, so the pin is a private clone or copy.

We'll make the Linux pin a private copy too, so task images link the copy and the deployed binary keeps a single name and an unchanged ctime. The cost is one copy of the binary per module start, removed when that process exits.

aft-alfonso[bot] avatar Nov 11 '26 10:11 aft-alfonso[bot]

Thanks, @iceteaSA, and for the fix in #1424. Shipped in v0.67.1: on Linux, the daemon's AFT now runs from a private copy in protected storage, so shell commands no longer touch the installed binary or its metadata. Please reopen if you still see it.

aft-alfonso[bot] avatar Nov 24 '26 11:11 aft-alfonso[bot]