Skip to content

fix(fspy): use memfd for Linux shared memory#523

Merged
wan9chi merged 10 commits into
mainfrom
linux-memfd-shm
Jul 11, 2026
Merged

fix(fspy): use memfd for Linux shared memory#523
wan9chi merged 10 commits into
mainfrom
linux-memfd-shm

Conversation

@wan9chi

@wan9chi wan9chi commented Jul 9, 2026

Copy link
Copy Markdown
Member

Motivation

Stop Linux file-access tracking from consuming the container's /dev/shm quota and crashing with SIGBUS.

Changes

  • Replaces POSIX shared memory with a sealed memfd.
  • Uses an abstract Unix socket broker to send the descriptor to each opener.
  • Runs the broker asynchronously and keeps the preload client synchronous.
  • Stops new opens when the owner is dropped while keeping existing mappings valid.
  • Sets close-on-exec and derives the mapping length from the sealed descriptor.
  • Covers concurrent and invalid opens.
  • Updates the constrained-/dev/shm fixture to succeed.

Fixes #353

wan9chi commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 308b887e8b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fspy_shm/src/linux/broker.rs Outdated
Comment thread crates/fspy_shm/src/lib.rs Outdated
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from aaaf01b to a64e9b8 Compare July 9, 2026 07:57
@wan9chi wan9chi force-pushed the linux-memfd-shm branch from 308b887 to 379cedd Compare July 9, 2026 07:57
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from a64e9b8 to ae72983 Compare July 9, 2026 14:16
@wan9chi wan9chi force-pushed the linux-memfd-shm branch from 379cedd to 67534d3 Compare July 9, 2026 14:16
@wan9chi wan9chi marked this pull request as draft July 10, 2026 01:16
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from ae72983 to ac080f6 Compare July 10, 2026 06:02
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from ac080f6 to ca12e8b Compare July 10, 2026 06:57
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from ca12e8b to 4119fee Compare July 10, 2026 07:04
@wan9chi wan9chi force-pushed the linux-memfd-shm branch 2 times, most recently from 3f7527b to a6a417e Compare July 10, 2026 07:14
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from 4119fee to d949311 Compare July 10, 2026 07:14
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch from 8dac1e8 to 3433486 Compare July 10, 2026 23:32
@wan9chi wan9chi marked this pull request as ready for review July 10, 2026 23:33
@wan9chi wan9chi force-pushed the constrained-dev-shm-e2e branch 2 times, most recently from 0f5cacc to cf3315b Compare July 10, 2026 23:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a55127096e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fspy_shm/src/linux/broker.rs
@wan9chi wan9chi changed the base branch from constrained-dev-shm-e2e to graphite-base/523 July 10, 2026 23:40
@wan9chi wan9chi force-pushed the graphite-base/523 branch from cf3315b to 9e72876 Compare July 10, 2026 23:40
@graphite-app graphite-app Bot changed the base branch from graphite-base/523 to main July 10, 2026 23:41
@wan9chi wan9chi marked this pull request as draft July 10, 2026 23:43
wan9chi and others added 10 commits July 11, 2026 08:36
Replace the Linux /dev/shm-backed adapter with a sealed memfd mapping. Each client connection receives the descriptor immediately from a broker task on the ambient Tokio runtime. Dropping the owner cancels the broker, while already-open mappings remain valid.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
@wan9chi wan9chi marked this pull request as ready for review July 11, 2026 00:44
@wan9chi wan9chi merged commit 14807a2 into main Jul 11, 2026
16 checks passed

wan9chi commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

Merge activity

@wan9chi wan9chi deleted the linux-memfd-shm branch July 11, 2026 00:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc96f186e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +99 to +100
let address = SocketAddrUnix::new_abstract_name(id.as_bytes())?;
connect(&socket, &address)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid namespace-scoped broker addresses

When a traced task execs a descendant after entering another network namespace (for example through unshare -n or a sandbox helper), Linux abstract AF_UNIX names are looked up in that new namespace, so this connect cannot reach the broker that was bound in the parent namespace. The preload constructor treats ChannelConf::sender() failures as ipc_sender: None and then drops all accesses from that process, which can leave cache inputs incomplete for those sandboxed subtrees; use a namespace-independent handoff such as an inherited broker fd or an accessible filesystem socket instead.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vitest worker SIGBUS on /dev/shm-constrained hosts with task cache enabled

1 participant