From 585da25b57e21697286f6e594dd26c144f8ce8d3 Mon Sep 17 00:00:00 2001 From: Claudius Date: Fri, 20 Nov 2026 17:20:49 +0000 Subject: [PATCH] bt_vsc: answer 0xFE3B (LP-core statistics) with 212 bytes, the length 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). --- drivers/bluetooth/bcm4361/hakios.bt_vsc.h | 14 +++++--- tools/bt_vsc_test.c | 41 +++++++++++++++++++++-- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/bluetooth/bcm4361/hakios.bt_vsc.h b/drivers/bluetooth/bcm4361/hakios.bt_vsc.h index 3c75d6a5a..5362d904c 100644 --- a/drivers/bluetooth/bcm4361/hakios.bt_vsc.h +++ b/drivers/bluetooth/bcm4361/hakios.bt_vsc.h @@ -145,12 +145,16 @@ static const struct bt_vsc_rule bt_vsc_table[] = { "HDR Control off: done (this chip has no HDR, so it is off); HDR on stays refused" }, /* * 0xFE3B, LE Meta Get LP-Core Statistics (one byte; phone 1 sent 01): the counters of Apple's low-power scan core. - * bluetoothd's parser reads them as 32- and 16-bit words, 48 and 8 of them at most (208 bytes), each asserting that - * it is there; it was the last command refused before each restart on phone 1 (17 November). This chip has no LP - * core, so every counter of it is zero: status 00 and 208 zero bytes. (BT_NO_SCAN_CORE=1 on the root should stop - * bluetoothd asking.) + * bluetoothd's parser (_BCM_LowPowerCoreStatsEventParser, bcm_vsc.c) reads them in order as 32- and 16-bit words, + * each asserting that it is there ("ByteStream_NumReadBytesAvail(*pBs) >= 4" or ">= 2") and none checking that the + * reply ends after them: iOS 27.0.1 (24A446) reads 48 and 8 of them (208 bytes); iOS 27.2.1 (24B156) reads 49 and 8 + * (43 x 32, 4 x 16, 2 x 32, 4 x 16, 4 x 32 bits: 212 bytes; its last check is at byte 208). 208 bytes made 24B156's + * bluetoothd abort on that last check and restart, 15-17 times in 15 minutes (phone 2, 19 November). The reply is the + * 212 bytes 24B156 reads, which is also "at least 208" for 24A446; more would only be bytes no parser reads. It was + * the last command refused before each restart on phone 1 (17 November). This chip has no LP core, so every counter + * of it is zero: status 00 and 212 zero bytes. (BT_NO_SCAN_CORE=1 on the root should stop bluetoothd asking.) */ - { 0xFE3B, BT_VSC_ANY, BT_VSC_ANY, 0x00, 0, { 0 }, 208, 0, NULL, + { 0xFE3B, BT_VSC_ANY, BT_VSC_ANY, 0x00, 0, { 0 }, 212, 0, NULL, "LP-core statistics: all zero (this chip has no LP core)" }, /* bluetoothd restarts when this one is refused (phone 1, 17 November): above */ { 0xFE37, BT_VSC_ANY, BT_VSC_ANY, 0, 0, { 0 }, 0, 0x200B, bt_vsc_x_scan_params, diff --git a/tools/bt_vsc_test.c b/tools/bt_vsc_test.c index 65257133f..a90fdafaa 100644 --- a/tools/bt_vsc_test.c +++ b/tools/bt_vsc_test.c @@ -117,6 +117,42 @@ table_itself(void) } } +/* + * What bluetoothd's parser reads after the status of each answered reply, per iOS build (from the binaries' structure: + * every read asserts that its bytes are there; none checks that the reply ends after them). An ANSWER entry must give + * at least this many bytes for every build listed, or that build's bluetoothd aborts. + */ +static const struct { + uint16_t opcode; + const char *build; + unsigned need; +} parser_reads[] = { + { 0xFDDA, "24A446", 4 }, + { 0xFE3B, "24A446", 208 }, /* 48 x 32 + 8 x 16 bits */ + { 0xFE3B, "24B156", 212 }, /* 49 x 32 + 8 x 16 bits */ +}; + +static void +reply_lengths(void) +{ + for (size_t k = 0; k < sizeof(parser_reads) / sizeof(parser_reads[0]); k++) { + bool found = false; + + for (size_t i = 0; i < sizeof(bt_vsc_table) / sizeof(bt_vsc_table[0]); i++) { + const struct bt_vsc_rule *r = &bt_vsc_table[i]; + + if (r->opcode != parser_reads[k].opcode || r->to != 0) { + continue; + } + found = true; + CHECK((unsigned)r->ret_len + r->zeros >= parser_reads[k].need, + "%04x: %u bytes after the status, %s's bluetoothd reads %u", r->opcode, r->ret_len + r->zeros, + parser_reads[k].build, parser_reads[k].need); + } + CHECK(found, "%04x (%s) has no ANSWER entry", parser_reads[k].opcode, parser_reads[k].build); + } +} + static void answers(void) { @@ -166,7 +202,7 @@ answers(void) CHECK(n == sizeof(other_rej) && memcmp(out, other_rej, n) == 0, "a vendor command not in the table: as it is"); { - /* 0xFE3B: 208 zero bytes after the status */ + /* 0xFE3B: 212 zero bytes after the status (24B156's parser reads 212, 24A446's 208) */ static const uint8_t fe3b_cmd[] = { 0x01, 0x3b, 0xfe, 0x01, 0x01 }; static const uint8_t fe3b_rej[] = { 0x04, 0x0e, 0x04, 0x01, 0x3b, 0xfe, 0x01 }; bool zero = true; @@ -176,7 +212,7 @@ answers(void) for (size_t i = 7; i < n; i++) { zero &= out[i] == 0; } - CHECK(n == 7 + 208 && out[2] == 212 && out[6] == 0 && zero, "0xFE3B: status 00 and 208 zero bytes (%zu)", n); + CHECK(n == 7 + 212 && out[2] == 216 && out[6] == 0 && zero, "0xFE3B: status 00 and 212 zero bytes (%zu)", n); } /* commands split anywhere, replies a byte at a time: the same */ @@ -396,6 +432,7 @@ int main(void) { table_itself(); + reply_lengths(); answers(); translations(); untouched();