Skip to content

Audit fixes: a use-after-free, job ids, resume after a commit error, memory bounds, blocked devices - #22

Merged
phantomptr merged 8 commits into
mainfrom
fix-audit-2026-11-26
Nov 26, 2026
Merged

phantomptr merged 8 commits into
mainfrom
fix-audit-2026-11-26

Conversation

@phantomptr

Copy link
Copy Markdown
Owner

Five fixes from an audit, each with a regression test that fails on the old code. Wire stays version 1; nothing a correct peer sends is refused.

  • A FileRoot during a new manifest waits for it (a use-after-free ASan reports on the old code).
  • A download JobOpen ends only a download of its own (a second device could free another job).
  • An upload that failed on an I/O error at the end can be resumed.
  • A peer can no longer grow memory through a JobMap, a FileRoot or credit (C and Rust senders, C receiver; spec §11.5 and §12.4 updated).
  • A blocked device stays blocked when it sends a token.

make check passes; the ava1-ctest suite was also run under ASan+UBSan with no reports. The version stays 1.0.12 for now (CHANGELOG "Unreleased").

🤖 Generated with Claude Code

https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT

adorabledev and others added 8 commits November 26, 2026 01:00
When a sender sent a new manifest in the same session, the job thread moved and
freed the large-file states without the job lock while it adopted it, and the
feeder could apply a FileRoot at the same time, into a state that had just been
freed. A FileRoot now waits until the job thread has taken up the new manifest
(and for any hold on the feeder), so it lands on the new manifest's file. The
freed slots are also cleared at once.

Test: a FileRoot sent while remap takes its time (a new test knob) lands on the
new file and the job finishes; before, ASan reported a heap-use-after-free and
without it the root was lost and the job stalled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
A JobOpen for a download freed whatever job had its id, so a peer could end
another device's upload, a copy, a send to another console or a download another
session was running. It now starts over only a download of that id, and only
when it is the same device's or no session drives it (as an upload moves to
another device). Anything else is refused: ERR_PROTOCOL for another kind of job,
ERR_UNKNOWN_JOB for another device's running download. The table also gets a
call that unlists exactly the job it is given.

Test: a second device's download open under a running upload's id is refused
and the upload finishes; another device's running download cannot be taken, the
same device's reconnect can, and a parked one can. Before, the first open
succeeded and freed the upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
A commit or the end of a job that failed on an I/O error (a rename into place,
a folder sync, a drive check) journals Done with ERR_IO. On the next JobOpen the
replayed Done was taken as the job's end: every file was reported done and the
same failure came back, every time, so the upload could never finish. A
replayed Done now ends the job only when its status is final (OK, ERR_EXISTS,
ERR_CROSS_DEVICE), the same rule a job still in memory follows; any other is
where the last run stopped, and the job resumes from its journal (reconcile
already finds a file whose rename went through). Journals written by older
versions resume the same way; what is written does not change.

Test: a large file's rename into place fails once (a new test fault point and
knob); the job ends ERR_IO, and a reopen of the same job commits it and ends
OK. Before, the reopen ended ERR_IO again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
What a peer sends is now bounded by the job's manifest or a fixed size before
any of it is stored:

- A sender (C and Rust) reads the receiver's JobMap against the manifest: each
  done file once and only ids the manifest has, and durable ranges inside a file
  of the manifest, no more of them than the file has groups. Before, the pages
  were stored as they came (a run of 4 G ids, or any number of pages of tiny
  disjoint ranges). A map or a Rust sender's Durable that names more ends the
  job with ERR_PROTOCOL; a receiver never builds one.
- The C receiver keeps a FileRoot, ManifestEnd or Resume waiting in a job's
  inbox at its own size (re-encoded, unknown extensions dropped as the decoder
  drops them), not as the 64 KiB frame it came in.
- The C sender uses at most 64 MiB of window, whatever it is granted: frames in
  flight stay in memory until their Received. A version 1 receiver grants 64 MiB.

Tests: a bounded map takes every map a receiver builds and refuses the rest
(Rust unit tests); a Rust sender given a map or Durable past the manifest ends
the job instead of hanging on 4 G ids; the C sender ends a download whose map
names a file past the manifest, bytes past a file, or more ranges than groups;
600 FileRoots with 60 KiB extensions wait for the map and the upload finishes
(before, the inbox overflowed and the job ended); credit past the cap is not
used. Each failed on the code before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
A ClientInfo with a token was taken for another console's ticket before the
token was checked, so it skipped the owner's device rules (the refused and
admit_new hooks). A blocked device still in the trust store could add any token
and get a full paired session. The ticket is now checked first: only a ticket
this console holds for that key skips the device rules; any other token is a
device like one without it.

Test: a paired device is let in with or without a token that is no ticket,
and once blocked it is refused both ways (the test server now has a refused
hook). Before, the blocked device with a token got a Welcome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
The version stays 1.0.12 until a release: ps5upload pins the crates.io ava1 to
the submodule's version. Also corrects a comment (a control frame is at most
64 KiB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
In a merge a file P is written through P.ava-part beside it. A manifest that
also named P.ava-part (in any letter case) had the two share one file: a merge
download of such a tree reported success with the files mixed. Both receivers
now refuse it with ERR_PATH, before the manifest is stored or journaled (the C
receiver in recv_events, the Rust LocalSink in a new Sink::check that the
receive loop runs before its journal; LocalSink's path checks run there too, so
a refused manifest leaves nothing on disk). A staged job writes each file under
its own name and still takes such a manifest. Wire version 1 unchanged.

Tests: a merge upload to the C receiver of x plus x.ava-part (and
X.AVA-Part) is refused with ERR_PATH and stores no manifest, while a staged one
is taken; a merge download of such a tree to the Rust receiver is refused and
writes no journal, manifest or file; part_name_clash unit tests. Before, the C
map was OK and the Rust download reported success.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtiJiJdHq1hekoZ6vizvVT
@phantomptr
phantomptr merged commit 3433a20 into main Nov 26, 2026
13 checks passed
@phantomptr
phantomptr deleted the fix-audit-2026-11-26 branch November 26, 2026 10:51
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