Skip to content

aop, sio: reply-length heap overflow and stop completion (port from MakrSas/Inferno) - #59

Merged
dylanneve1 merged 2 commits into
masterfrom
port/aop-sio-fixes
Oct 22, 2026
Merged

dylanneve1 merged 2 commits into
masterfrom
port/aop-sio-fixes

Conversation

@dylanneve1

Copy link
Copy Markdown
Collaborator

Two fixes from MakrSas/Inferno (ios branch) by Makr, one commit each, with authorship kept. MakrSas found both while bringing up audio, but both affect every t8030 boot, so they are a PR of their own. The audio work (#24) needs the SIO fix for streams to stop cleanly.

aop: handlers get the reply length without the result word (181c83d)

An AOP endpoint reply is a 4-byte result word followed by out_len bytes. handle_command received actual_out_payload, which already points past the word, together with actual_out_len, which still counts it. A handler that filled the buffer it was told about wrote 4 bytes into the next heap block. MakrSas saw malloc later spin in the corrupted free list. Handlers now get out_len.

sio: a stop completes every transfer still queued (2a79c19)

apple_sio_dma_stop destroyed the queued buffers and sent a bare completion. XNU's AppleSmartIODMA::_stopDMA sleeps uninterruptibly until every command it handed out has come back, so a stop with buffers still queued never returned. With audio, that left mediaserverd in TH_UNINT until the watchdog killed it. Each queued buffer is now written back as completed (tag, bytes done, timestamps) before the stop's own completion. The forward declaration uses Pyre's AppleSIO type name.

Testing

Android cross build on emulator-5554, together with #24, against master d9118068e5:

  • Restore boot (restore_bench.py, iOS 14.0 restore, real SEP, -smp 4): 3/3 runs reached waiting_host with no panic (10.0–10.1 s). With audio=on, 3/3 also reached it (10.3–11.8 s).
  • patch-check: JSON identical to master's.
  • a13-test: 29/29 passed.

🤖 Generated with Claude Code

MakrSas and others added 2 commits October 22, 2026 20:10
…m MakrSas/Inferno)

An AOP endpoint reply holds the 4-byte result word followed by out_len bytes
of payload. handle_command was given actual_out_payload, which already points
past the result word, together with actual_out_len, which still counts the
word. A handler that filled the buffer it was told about wrote 4 bytes past
the end of the allocation, into the next heap block. MakrSas saw malloc later
spin in the damaged free list with the guest stopped. Handlers are now given
out_len.

Ported from MakrSas/Inferno commit 181c83d ("aop: stop writing past the
end of the reply buffer", branch ios) by Makr <ngrom33@gmail.com>, under
the same licence as the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Inferno)

A SIO DMA stop destroyed the buffers still queued on the channel and sent a
bare completion. XNU's AppleSmartIODMA::_stopDMA sleeps, uninterruptibly,
until the channel goes idle, and a channel goes idle only once every command
it handed out has come back. A stream normally ends with a buffer or two
still queued, so the stopping thread never woke. With audio, MakrSas saw this
leave mediaserverd in TH_WAIT|TH_UNINT after the first stop; the watchdog
then killed it and all sound was gone until reboot.

Every buffer still out is now written back as completed, with its tag, the
bytes done so far and its timestamps, ahead of the stop's own completion.

Ported from MakrSas/Inferno commit 2a79c19 ("sio: hand back every
transfer a stop leaves queued", branch ios) by Makr <ngrom33@gmail.com>,
under the same licence as the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dylanneve1
dylanneve1 merged commit e9bc83b into master Oct 22, 2026
5 checks passed
@dylanneve1
dylanneve1 deleted the port/aop-sio-fixes branch November 2, 2026 01:56
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