Skip to content

bt_vsc: answer 0xFE3B (LP-core statistics) with the 212 bytes iOS 27.2.1's bluetoothd reads - #399

Open
claudiusthebot wants to merge 1 commit into
mainfrom
fix/bt-fe3b-reply-212
Open

claudiusthebot wants to merge 1 commit into
mainfrom
fix/bt-fe3b-reply-212

Conversation

@claudiusthebot

@claudiusthebot claudiusthebot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Built, not phone-tested.

What was wrong

On iOS 27.2.1 (24B156), on boots where Bluetooth comes up, bluetoothd aborts again and again (15-17 times in 15 minutes on phone 2, 19 November; 4 times in 4 minutes on the pre-restore roots) on one assert, ByteStream_NumReadBytesAvail(*pBs) >= 4, in its parser for the reply to Broadcom vendor command 0xFE3B (LE Meta Get LP-Core Statistics, _BCM_LowPowerCoreStatsEventParser in bcm_vsc.c). About two minutes after the first crash imagent starts spinning at 150-490 % CPU (correlation 7 of 7 boots), the main CPU hog on the full-services root.

The BCM4361 does not know 0xFE3B; the bt_vsc table (drivers/bluetooth/bcm4361/hakios.bt_vsc.h) answers it with status 00 and 208 zero bytes, sized from 24A446's parser (48 x 32-bit + 8 x 16-bit). 24B156's parser reads 212 bytes: 43 x 32, 4 x 16, 2 x 32, 4 x 16, 4 x 32 bits = 49 x 32 + 8 x 16. Its last check (stream position 208, needs 4 more bytes) fails on a 208-byte reply, and bluetoothd aborts.

What changed

  • hakios.bt_vsc.h: the 0xFE3B entry answers status 00 and 212 zero bytes; its comment says what each iOS build reads and why 212.
  • tools/bt_vsc_test.c: the 0xFE3B reply test expects 212 bytes (event length 216); a new reply_lengths() checks every ANSWER entry against what each known bluetoothd build reads after the status (0xFDDA: 4; 0xFE3B: 208 for 24A446, 212 for 24B156). It fails on the old 208 table (checked).

Why 212 and not more

Neither parser checks that the reply ends after what it reads (24B156: the function's only assert strings are the 49 >= 4, 8 >= 2 and one RWFlag check; after the last read it calls the completion callback). So 212 satisfies 24B156 exactly and 24A446's "at least 208"; bytes past 212 would be read by no parser, so the table's maximum (240) would add nothing. 4 + 212 = 216 fits an HCI event (255) and the filter's output buffer (BT_VSC_OUT_MAX 260).

How it was verified

  • 24B156 /usr/sbin/bluetoothd (read-only root image, SystemVersion 24B156), otool -tV of the parser at 0x10033dfbc: the stream position advances 0x4 ... 0xac, 0xae ... 0xb4, 0xb8, 0xbc, 0xbe ... 0xc4, 0xc8 ... 0xd4 (49 x 4 + 8 x 2 = 212); the last check (cmp w10, #0x3 after position 0xd0) branches to the assert at bcm_vsc.c line 0x435, the bl whose return address 0x10033ef70 is the frame in the crash reports.
  • 24A446's 208 is from the table's original comment (the 24A446 binary was not at hand); not re-checked.
  • sh tools/bt-vsc-test.sh (ASan/UBSan): 87 checks, 0 failed; bcm-bt-parsers-test.sh, bcm-hci-test.sh, provenance-check.py, arch-check.py --report, ios27/builds/builds-test.py, drivers-check.py, boot-args.py --check, docs-check.py, build-lock-test.sh: pass.
  • Kernel built (ios-27 STARLTE DEVELOPMENT, the same recipe and xnu27 fork tree c2f63b275 as the L6 kernel): rc=0; the 0xFE3B rule in the built kernel has zeros = 212 at the offset where L6's kernel has 208. Boot images made with the L6 recipe (the recipe reproduces L6 8610de84 byte for byte from L6's kernel).

Not run on a phone: whether bluetoothd now gets past this parser, whether the next vendor command then trips something else, and whether imagent stops spinning, are open. A phone test plan is with the build.

… iOS 27.2.1's bluetoothd reads

The table answered Broadcom vendor command 0xFE3B with status 00 and 208 zero
bytes, sized from iOS 27.0.1's (24A446) parser: 48 x 32-bit and 8 x 16-bit
counters. iOS 27.2.1's (24B156) _BCM_LowPowerCoreStatsEventParser (bcm_vsc.c)
reads 49 x 32-bit and 8 x 16-bit (212 bytes), its last
"ByteStream_NumReadBytesAvail(*pBs) >= 4" at byte 208. With 208 bytes that
check fails and bluetoothd aborts, 15-17 times in 15 minutes on boots where
Bluetooth comes up; imagent then spins (150-490 % CPU).

Neither parser checks that the reply ends after what it reads, so 212 bytes
satisfy both. tools/bt_vsc_test.c: the 0xFE3B reply is 212 bytes, and a new
check of each answered reply against what each known bluetoothd build reads
(fails on the old 208 table).
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.

1 participant