Skip to content

fix(golang): wipe guest buffers on failed placement and close stashgen's engine - #1550

Draft
cipherstash-agent wants to merge 1 commit into
mainfrom
claude/project-thread-ql9v09
Draft

cipherstash-agent wants to merge 1 commit into
mainfrom
claude/project-thread-ql9v09

Conversation

@cipherstash-agent

Copy link
Copy Markdown
Contributor

Requested by CipherStash · project thread

Summary

Fixes CIP-5160 (G1, G2). A failed hand-off to the guest no longer leaves a token or ZeroKMS response in guest memory, and stashgen releases its engine.

Changes

  • place (encrypt) and placeAuth (auth) were duplicates. They are replaced by one guest.Place in internal/guest.
  • On any failure after se_alloc, Place zeroes the bytes it wrote and clears the pointer slot, so a half-written out-slot pair cannot leave a dangling pointer.
  • It does not call se_dealloc. The guest ABI docs allow a host import to re-enter only through se_alloc, so the issue's suggested fix would violate them. The zeroed buffer is freed by the guest registry at shutdown.
  • stashgen's run now closes the engine it was given when it implements io.Closer, on every return path.

Verification

  • go build, go vet and go test pass for internal/guest, auth, encrypt, cmd/stashgen, and stashgen.
  • New tests fail without the fix and pass with it: buffer wiped and pointer slot cleared when either out-slot write fails, empty value placed, engine closed on success and on refusal.

Related

  • Linear CIP-5160.
  • No changeset: the Go module is released by hand, not through Changesets. No skill is affected.

Review notes

/code-review medium raised the se_dealloc re-entry, a stale pointer slot, and wrapper/test placement. These were fixed. It also suggested the caller should own the engine's lifetime; I kept run closing it and documented that on run.


Generated by Claude Code

…n's engine

place and placeAuth left the data in a registered guest buffer when an
out-slot write failed after se_alloc. They now share guest.Place, which
zeroes the bytes and clears the pointer slot on any failure. stashgen's run
now closes the engine it was given.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Jmn7qSiWtt22aUYDwvgVL
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

@cipherstash-agent cipherstash-agent self-assigned this Nov 6, 2026
@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c832493

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

No deployments
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.

2 participants