Repository navigation
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
Open
claudiusthebot wants to merge 1 commit into
claudiusthebot wants to merge 1 commit into
Conversation
… 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_LowPowerCoreStatsEventParserin 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 newreply_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>= 2and 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
/usr/sbin/bluetoothd(read-only root image, SystemVersion 24B156),otool -tVof 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, #0x3after position 0xd0) branches to the assert at bcm_vsc.c line 0x435, theblwhose return address 0x10033ef70 is the frame in the crash reports.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.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.