Device Lab - Repo Scan Findings
Runbook 09 - Repo scan findings: the most exploitable attack vector (bluetooth / Fluoride)
Purpose: this runbook records the actual source scan of the highest-value attack vector from runbook 08. Runbook 08 section 5 scored bluetooth as the widest-reach channel (20 high / 40 medium / 109 total CVE-report rows vs 4/7/41 for call_telephony) and named a specific repo to scan (packages/modules/Bluetooth, the Fluoride stack) plus a list of expected findings. This runbook answers that list against real source, per finding: what malicious input reaches the code, what the vulnerable code looks like, and how to prevent it.
Scan target and method:
| item | value |
|---|---|
| repo | AOSP packages/modules/Bluetooth (Fluoride), main stack under system/ |
| commit scanned | 745ee92b87ed62b5a8a1bac47d5df8cad623bf59 (2025-03-17, matches lab device era) |
| how | manual read + grep; no semgrep/codeql available in the lab environment |
| key files | system/stack/sdp/, system/stack/gatt/, system/stack/l2cap/, system/stack/smp/, system/stack/avct/, system/stack/avrc/, system/stack/fuzzers/ |
Bottom line up front: none of the findings below is a directly reachable, unguarded overflow in this tree. Every primitive with an unsigned-length arithmetic smell is today protected by a caller-side guard. The scan separated the actual state (residual robustness smells + one trust-model gap) from the pattern list runbook 08 expected, and the contrast is the lesson: the explicitly hardened parsers (section 4) are what "prevention looks like" in this codebase.
1. Findings at a glance
| id | location | pattern (from runbook 08) | directly exploitable in this tree? |
|---|---|---|---|
| F1 | system/stack/sdp/sdp_utils.cc:1415 | integer wrap in packet length math | no (callers guard the offset today) |
| F2 | system/stack/gatt/gatt_sr.cc:1051-1055 | integer wrap / under-trusted length | no (dispatch gates SIGN writes first) |
| F3 | system/stack/avct/avct_l2c.cc:108 | missing caller-address check on AVRCP connections | reachable but limited by hardened parse layer below |
Section 2 details each finding ("malicious input / vulnerable code / prevention"). Section 3 explains the trust model that keeps F1 and F2 unreachable today, so the reader sees exactly what a future removal-and-attacker-input change would look like. Section 4 is the good news: the peer-input parsers the runbook singled out are, for this 2025 snapshot, hardened correctly, and section 5 points at the in-tree fuzz harnesses that keep them that way.
2. Findings
F1. SDP partial-attribute builder trusts its offset (unsigned wrap read)
What it is. sdpu_build_partial_attrib_entry copies a slice of an SDP attribute for continuation responses. The attacker-controlled size is len (how many bytes remain in this continuation response packet); *offset is server-side state that advances across responses.
Malicious input. len is bounded by the SDP response assembly: the continuation request carries max_list_len (capped by the server before reuse) and the service data's p_attr comes from the device's own SDP database, not from the wire. So the peer's only direct knob is len and the response budget. For the wrap to corrupt, *offset would have to exceed attr_len, i.e. server state must go inconsistent.
Vulnerable code (sdp_utils.cc:1403-1422):
uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out, const tSDP_ATTRIBUTE* p_attr,
uint16_t len, uint16_t* offset) {
uint8_t* p_attr_buff = reinterpret_cast<uint8_t*>(osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN));
sdpu_build_attrib_entry(p_attr_buff, p_attr);
uint16_t attr_len = sdpu_get_attrib_entry_len(p_attr);
if (len > SDP_MAX_ATTR_LEN) { /* len is clamped: good */
log::error("len {} exceeds SDP_MAX_ATTR_LEN", len);
len = SDP_MAX_ATTR_LEN;
}
size_t len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset) : len; /* wrap here */
memcpy(p_out, &p_attr_buff[*offset], len_to_copy); /* read past buffer if *offset > attr_len */
...
}
attr_len and *offset are both uint16_t. If *offset > attr_len, then (because C promotes uint16_t operands to signed int before subtracting) attr_len - *offset computes a small negative number (e.g. 5 - 300 = -295), NOT a wrapped 65538. A negative is always < len, so the ternary picks the attr_len - *offset branch, and assigning it to size_t widens it to ~2^64. memcpy then reads 2^64 bytes starting at &p_attr_buff[*offset], i.e. it slams the read pointer 300 bytes past a SDP_MAX_ATTR_LEN (400) allocation and keeps going. Verified against a compile+ASan repro (section 6): the sanitizer reports negative-size-param / heap-buffer-overflow at exactly that memcpy. A remote in-range device can reach SDP pre-pairing over PSM 0x1, so this is the leak/disclosure shape to defend against first.
How it becomes a bug. Both current callers in sdp_server.cc (lines ~452-474 and ~734-757) check p_ccb->cont_info.attr_offset < attr_len before calling, so the guard lives in the caller, not in the helper that owns the arithmetic. Any future caller that forgets the check reintroduces the OOB read with peer-controllable len.
Prevention:
- move the invariant into the helper:
if (*offset >= attr_len) { error; return nullptr; }
before any attr_len - *offset arithmetic;
- make
attr_len - *offseta checked subtraction against the true allocation size,
not against attacker-projected lengths;
- keep the
len > SDP_MAX_ATTR_LENclamp (it exists and is correct) and add the
symmetric clamp for the source index *offset before the &p_attr_buff[*offset] load.
F2. GATT server sign-write handler subtracts a constant without a length check
What it is. gatts_process_write_req handles GATT_SIGN_CMD_WRITE (signed write "command with data signing", VALID over unencrypted transports because the SIG field authenticates). It subtracts the 12-byte GATT_AUTH_SIGN_LEN from the remaining packet length without first checking that the packet is that long.
Malicious input. A remote LE or BR/EDR peer sends a GATT_SIGN_CMD_WRITE PDU whose body is shorter than 12 bytes after the 2-byte handle. If such a PDU reached this switch, len -= GATT_AUTH_SIGN_LEN wraps uint16_t len to ~65500; the later if (len > GATT_MAX_ATTR_LEN) len = GATT_MAX_ATTR_LEN; clamp (line 1063) prevents the subsequent memcpy from over-reading, but sr_data.write_req.len would have carried a wrapped value and the permission check at line 1075 is called with a wrapped len (upcast to uint).
Vulnerable code (gatt_sr.cc:1051-1069):
case GATT_SIGN_CMD_WRITE:
if (op_code == GATT_SIGN_CMD_WRITE) {
log::verbose("Write CMD with data sigining");
len -= GATT_AUTH_SIGN_LEN; /* no if (len < GATT_AUTH_SIGN_LEN) guard */
}
FALLTHROUGH_INTENDED;
case GATT_CMD_WRITE:
case GATT_REQ_WRITE:
...
sr_data.write_req.len = len;
if (len != 0 && p != nullptr) {
memcpy(sr_data.write_req.value, p, len); /* length is clamped above; source len is not vetted before the -= */
}
How it becomes a bug. Today, GATT_SIGN_CMD_WRITE never reaches this switch directly: the dispatcher (gatt_main.cc:1081) routes that opcode through gatt_verify_signature, which rejects any buffer with p_buf->len < GATT_AUTH_SIGN_LEN + 4 (gatt_auth.cc:108) before the write handler runs. So the subtraction is safe only because of an out-of-line gate, not because the arithmetic itself is safe. Any future path that forwards a SIGN write without the signature gate (a new transport, a deduplicated handler) turns the trust bug real.
Prevention:
- guard in the same function that subtracts:
if (len < GATT_AUTH_SIGN_LEN) { send GATT_INVALID_PDU; return; }
immediately before len -= GATT_AUTH_SIGN_LEN;
- keep the
GATT_MAX_ATTR_LENclamp (good belt and suspenders), and validate the
source pointer p covers len before the memcpy (mirrors GATT_REQ_PREPARE_WRITE which does the p == nullptr and offset checks);
- teach
gatt_verify_signaturethe exact RFC minimum and reject below it (already does),
and make the write handler not rely on that gate for its own arithmetic.
F3. AVCTP accept path has no caller-address check (the runbook-08 "missing caller-address check on AVRCP" finding)
What it is. AVRCP runs over AVCTP (L2CAP PSM 0x17, browse PSM 0x1b). The stack registers these PSMs with security requirement AUTHENTICATE | ENCRYPT only (avct_api.cc:72), and the L2CAP connect-indication handler accepts the channel for any peer address that satisfies it. There is no check that the connecting peer BDA is a device this profile is supposed to serve (e.g. the bonded A2DP source device).
Malicious input. A Bluetooth device already in this phone's bonding table (or one that successfully passes an authenticated/encrypted link) opens PSM 0x17 and sends AVRCP target commands: pass-through key events (play/pause/volume/launch-app), register-notification, vendor commands. A victim who ever paired with a compromised "companion" device, or an attack device that inherits a link key, is exposed. This is the classic Bluetooth "related device / connected device" trust problem: encryption proves the peer knows the key, not that the peer is the profile partner.
Vulnerable code (avct_l2c.cc:108-133):
void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t /* psm */,
uint8_t /* id */) {
tL2CAP_CONN result = tL2CAP_CONN::L2CAP_CONN_OK;
tAVCT_LCB* p_lcb = avct_lcb_by_bd(bd_addr); /* accepts ANY bd_addr */
if (p_lcb == nullptr) {
p_lcb = avct_lcb_alloc(bd_addr);
...
}
...
}
with the PSM registered at avct_api.cc:75:
uint16_t sec = BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT; /* no address/relationship check */
L2CA_RegisterWithSecurity(BT_PSM_AVCTP, avct_l2c_appl, ..., sec);
Why impact is bounded today. The AVRCP parser layer below the accept path is length-checked (section 4 below), so F3 is a trust-model / profile-abuse gap, not a memory-corruption primitive in this snapshot. Persistent misbehavior from a non-partner bonded device is the realistic outcome, matching many historical AVRCP-key-press-abuse advisories. Because BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT is already required, the fix is about identity, not link encryption.
Prevention:
- at accept time, compare
bd_addragainst the profile partner set (the bonded device
that negotiated A2DP/AVRCP), and reject others with L2CAP_CONN_NO_RESOURCES (the same reject path the handler already has at line 159-167);
- require the caller-configured peer (explicit accept/deny) for AVCTP rather than only
link-level auth+encrypt;
- keep the hardened parser layer (section 4) as the second line in case the address
check is ever relaxed.
3. Why F1 and F2 are not exploitable in this tree (the trust model)
The pattern list assumed underflow bugs; the scan found the underflow arithmetic but both are choked at the point the peer's bytes meet the arithmetic:
- F1: the SDP server advance of
cont_info.attr_offsetnever exceeds the attribute
length because the two process_... handlers validate before calling sdpu_build_partial_attrib_entry, and attr_offset is computed from the local attribute table, not from the wire. The peer controls len and max_list_len, and both have server-side clamps.
- F2:
GATT_SIGN_CMD_WRITEcannot reachgatts_process_write_reqwith a short body
because the only dispatch path goes through gatt_verify_signature (length gate). Even if it did, the GATT_MAX_ATTR_LEN clamp stops the memcpy from over-reading.
The takeaway for the vector report: these rows are latent (robustness), not live (RCE) in the 2025 Fluoride snapshot. They are the correct things to monitor and harden, and are exactly where a historical unguarded variant turns into a Bluetooth-in-range CVE if a refactor drops a caller guard.
4. Verified-guarded parsers: what "prevention looks like" in this codebase
These are the peer-input parsers runbook 08 section 5 named, and this scan confirms each is correctly bounded in the 2025 snapshot. Copy these idioms when fixing F1/F2:
| parser | file:line | guard that makes it safe |
|---|---|---|
| SMP command length table | system/stack/smp/smp_utils.cc:1038-1110 | smp_cmd_size_per_spec[] exact-length table + per-opcode range validators; rcvd_cmd_len must equal spec size |
| GATT client multi-value notification | system/stack/gatt/gatt_cl.cc:648-691 | rejects value.len > len - 4 and value.len > GATT_MAX_ATTR_LEN before STREAM_TO_ARRAY |
| GATT client value reassembly | system/stack/gatt/gatt_cl.cc:770-806 | value.len = std::min((uint16_t)rem_len, value.len) and value.len > sizeof(value.value) check per element |
| SDP UUID sequence | system/stack/sdp/sdp_utils.cc:753+ | explicit bounds check before every STREAM read in sdpu_extract_uid_seq |
| SDP continuation offset | system/stack/sdp/sdp_server.cc:648-650 | peer cont_offset validated against stored p_ccb->cont_offset before reuse |
| L2CAP FCR SDU reassembly | system/stack/l2cap/l2c_fcr.cc:707-770 | sdu_length clamped to MTU, p_buf->len vs remaining-length check before memcpy |
| AVRCP pass-through payload | system/stack/avrc/avrc_api.cc:835-863 | requires p_pkt->len >= 5; pass_len reconciled to p_pkt->len - 5 before use |
The common idiom: validate length against the received buffer budget before any memcpy/STREAM_TO, and prefer exact-length tables over range checks when the spec length is fixed.
5. Fuzz surface answer (runbook 08 asked "fuzz targets present?")
Yes, in-tree and current:
system/stack/fuzzers/
avrc_fuzzer.cc bnep_fuzzer.cc gatt_fuzzer.cc
l2cap_fuzzer.cc rfcomm_fuzzer.cc sdp_fuzzer.cc
smp_fuzzer.cc README.md
One LLVM-libFuzzer target per protocol service. The guarded parsers in section 4 and the latent smells in section 2 are the next corpus/schedule target: SDP partial-attr and the GATT sign-write path are not currently in the fuzz harness input set, so adding continuation-response and short-sign-write corpus entries is the cheap way to keep F1/F2 from regressing into live bugs.
6. Scoring impact on the vector row
For runbook 01/08 use: bluetooth keeps its rank as the widest-reach channel (radio on ~all fleet, BR/EDR in range pre-pairing) but with a caveat the CVE count alone does not show: in the scanned 2025 stack the classic in-range memory bugs are caller-guarded, so the practical exploit spread for this device class is dominated by (a) patch-gated OS rows from the ASB/NVD data in runbook 07-08, and (b) the F3-class trust-model abuse that requires a prior bond. The latent F1/F2 arithmetic is the retention risk across updates, and is the specific spot a future CVE on this vector should first be checked against.
7. Reading the findings and building/running the repro
Section 2 quotes the functions from the device source. Two clean, self-contained reproductions of the vulnerable arithmetic ship next to this runbook (f1_partial_attr.cc and f2_sign_len.cc). Build and run them on any Linux box with g++; no Android build is needed, which matters because a full Fluoride compile is an AOSP-scale build (~an hour+ of Soong, enormous disk).
7.1 Read F1 line by line
uint8_t* sdpu_build_partial_attrib_entry(uint8_t* p_out, const tSDP_ATTRIBUTE* p_attr,
uint16_t len, uint16_t* offset)
p_out- where the SDP response bytes are being assembled.p_attr- one attribute object from the device's own SDP database (safe data).len- how many bytes THIS response still has room for (the peer-tunable budget
derived from max_list_len). This is the number that leaks attacker influence into the function.
*offset- a cursor INTO the attribute, advanced across continuation responses. This
is server state; the bug is that nothing in this function proves it is sane.
Body of the function, in order:
malloc(SDP_MAX_ATTR_LEN)(400 bytes) and serialize the attribute into it.attr_len = sdpu_get_attrib_entry_len(p_attr)- the real serialized size (1 type
byte + attribute bytes), e.g. 5 for our repro attribute.
if (len > SDP_MAX_ATTR_LEN) len = SDP_MAX_ATTR_LEN;- the ONE clamp present. It
bounds the amount written, but not *offset, which is the actual attacker-relevant input here.
- The bug line:
size_t len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset) : len;
Intended behavior: "copy whichever is smaller - the bytes left of the attribute, or the response budget." If *offset is a sane value <= attr_len this is exactly right. If *offset > attr_len (e.g. 300 vs 5), then, because C promotes both operands to signed int, the subtraction yields -295, a NEGATIVE number. A negative is always < len, so the ternary picks it, and assigning a negative int to size_t widens it to ~2^64.
memcpy(p_out, &p_attr_buff[*offset], len_to_copy);- the write length is now
astronomically large, and the source pointer is already positioned 300 bytes past a 400-byte heap buffer. The memcpy reads heap far out of bounds. Under ASan this fires immediately as negative-size-param.
Why the malicious input matters: SDP is connectionless and answered to any in-range device BEFORE pairing (PSM 0x1). If a future code path feeds a bad *offset in, an unauthenticated radio attacker gets a heap over-read of whatever sits past that heap buffer, echoed back in the SDP response.
7.2 Read F2 line by line
static void gatts_process_write_req(... uint8_t op_code, uint16_t len, uint8_t* p_data, ...)
len- byte count of the write PDU remaining after opcode + 2-byte handle were
consumed upstream. The GATT write PDU is: opcode(1) + handle(2) + value[0..512] + signature(12) for signed writes.
p_data- pointer into the received L2CAP buffer at the first value byte.op_code- e.g.GATT_SIGN_CMD_WRITE(0x52) for a signed write.
The signed-write branch:
case GATT_SIGN_CMD_WRITE:
if (op_code == GATT_SIGN_CMD_WRITE) {
len -= GATT_AUTH_SIGN_LEN; /* 12 */
}
The handler assumes len already covers the 12-byte signature. If a signed write body is 6 bytes (our repro) instead of a valid minimum (payload >= 14 after the handle for a signal-free body plus 12 sig bytes), 6 - 12 wraps a uint16_t to 65530. Then the shared tail:
if (len > GATT_MAX_ATTR_LEN) len = GATT_MAX_ATTR_LEN; /* clamp to 512 */
sr_data.write_req.len = len;
if (len != 0 && p != nullptr) {
memcpy(sr_data.write_req.value, p, len); /* reads 512 bytes that were not sent */
}
The clamp stops the DESTINATION (a fixed 512-byte value[]) from overflowing, but the SOURCE read now extends 512 bytes from p_data even though the peer only sent 6 value bytes. In a normal-size L2CAP receive buffer that lands inside the buffer's slack, so on-device this is a logical over-read plus a bogus write_req.len (512) being handed to the attribute permission check and to the app's write callback - the value is validated and acted on at a length the peer never supplied. A future call site that skips the proxy gate in gatt_verify_signature is all it takes to expose this.
7.3 Build and run the repro
With g++ and AddressSanitizer (nothing else required):
cd <runbook dir>
g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer -o f1 f1_partial_attr.cc
g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer -o f2 f2_sign_len.cc
./f1 # ASan aborts at the memcpy with "negative-size-param"
./f2 # ASan aborts at the memcpy with "heap-buffer-overflow" READ of size 512
Observed output (2025-era g++ 12 / ASan):
./f1
ERROR: AddressSanitizer: negative-size-param: (size=-295)
#0 ... in __interceptor_memcpy ...
#1 ... in sdpu_build_partial_attrib_entry f1_partial_attr.cc:43
#2 ... in main f1_partial_attr.cc:68
0x61... is located 300 bytes inside of 400-byte region [0x..,0x..)
./f2
ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60...
READ of size 512 at 0x60... thread T0
#0 ... in __interceptor_memcpy ...
#1 ... in gatts_process_write_req_subset f2_sign_len.cc:40
0x60... is located 0 bytes to the right of 8-byte region [0x..,0x..)
That is the proof-of-bug in ~10 seconds, with no AOSP build tree.
7.4 What a real exploit would additionally need
The repro triggers the arithmetic; a working device exploit of F1/F2 would additionally need one of:
- a code change or variant of the stack that calls
sdpu_build_partial_attrib_entry
(or the sign-write handler) without the caller-side guards from sections 3; then the repro's behavior is the exploit's behavior;
- the in-tree fuzz harnesses (
system/stack/fuzzers/sdp_fuzzer.cc,
gatt_fuzzer.cc) extended with continuation-response / short-sign-write corpus entries, built with libFuzzer against the Soong-built module, so a regression that drops a guard is caught as a sanitizer finding under fuzzing before shipment;
- a real over-the-air path against a phone, which this lab does not do (scope) and
which needs a BT radio (e.g. a second rooted Android phone or USB BT adapter running a host-side SM l2cap test tool) - in-scope exercise, out-of-scope weaponization.
8. Actually exploiting it: a running example
First, watch the whole thing move instead of reading about it. Thirty seconds, no tools needed:
- F2 (the 6-byte write that reads 512): web animation (plays on its own, step
through with Back/Next): /lab/exploit-animation.html - terminal: bash exploit_show.sh
- F1 (the 5-byte attribute that reads the heap): web animation:
/lab/exploit-f1-animation.html - terminal: bash exploit_f1_show.sh
exploit_f2_leak.cc shows the F2 bug used for real, instead of just triggering it. It does not use AddressSanitizer, on purpose. ASan is the lab tool that catches the bug first (section 7.3); this file shows what happens on a device with nobody watching. It models the phone's receive buffer: the attacker controls only the first 6 bytes of value, and a mock secret lives a few bytes later in the same buffer pool (the real-world equivalent on-device is other packets, sessions, or keys).
Build and run:
g++ -O0 -g -o exploit_f2_leak exploit_f2_leak.cc && ./exploit_f2_leak
Actual output:
attacker sent: 6 bytes of value
phone accepted: 512 bytes of value (thinks the write is 512 bytes long)
bytes the attacker*intended* to write (first 6):
aa bb cc dd ee ff
bytes the phone copied past the packet (6..511)
- first 12 of the leaked region:
00 00 00 00 00 00 44 45 56 49 43 45
- as text, shows device memory the attacker was never sent:
"DEVICE_SESSION_TOKEN:AKIA1234567890..........."
result: unauthenticated local radio attacker performs a heap over-read of 506 bytes and
recovers device memory (here: a session token) via one undersized signed write.
What the output proves:
- The attacker sends 6 value bytes.
6 - 12wrapsuint16_tto ~65530, the clamp turns that into 512.- The phone copies 512 bytes starting at the packet, so bytes 7..512 are device
memory that was never sent - and the "secret" planted in the buffer pool leaks out (visible as plain text in the response path).
Two honest caveats, restated:
- This is the exploit's behavior on a stack where the bug is reachable. Today the
real device dispatcher gates signed writes through gatt_verify_signature, so this exact leak is not yet reachable on the 2025 build. The demo proves what the arithmetic does the moment a future caller drops (or forgets) that gate.
- An actual over-the-air delivery needs a radio and a compliant target, both
out-of-scope for this lab. The code and the leak are reproduced; the last mile is a hardware exercise, not a code exercise.
9. How hackers turn a bug into a custom exploit (plain language)
This is the general recipe, not a step unique to Bluetooth. The same chain applies to any service that parses attacker bytes.
Step 1: find the spot where attacker input reaches a number that is trusted. Look for length math: "packet has N bytes, so copy N bytes". In F2 the trusted number is len; the handler subtracts 12 from it without proving there are 12 more bytes. The attacker controls len (how many value bytes the write claims), so the attacker controls the subtraction result.
Step 2: prove the bug is real with a checker. A sanitizer (ASan) puts invisible fences between memory chunks. When the buggy memcpy crosses a fence, ASan stops the program and prints exactly which line overflowed and by how much. That is why section 7.3 runs with ASan first: it turns a silent crash into a readable stack trace.
Step 3: decide what the bug is worth. Two outcomes matter, in rising order of danger:
- over-read: the copy reads PAST the received data into other memory. Payoff: the
attacker sees data they were not sent. F1 and F2 are both over-reads.
- over-write: the copy writes past its target. Payoff: the attacker can overwrite a
function pointer or an object and make the phone run chosen code. This lab found no reachable over-write in 2025 Fluoride; it is the outcome to fear most.
Step 4: shape memory so "past the data" is interesting. An over-read only leaks something if the memory right after the packet is worth having. Attackers arrange this by sizing and ordering allocations (here: the mock secret sits 12 bytes after the packet in the same buffer pool). On a real device they look for where sessions, keys, or other packets land, and time the send so their target allocation sits in the leak window.
Step 5: build the payload, run it against the checker, then run it against the real thing. The payload is the exact byte sequence that makes the trusted number wrong (here: a 6-byte signed write). Test under ASan until the trace is clean and the crash is exactly the intended line, then remove ASan and run the same bytes against a copy of the real stack (the repro binary) to observe the leak without interference.
Step 6: take it over the wire. The in-range radio packets replace the function call. The attacker builds the same PDU an app would send, but with the crafted 6-byte length. Proof-of-exploit on the lab-bench binary is what this repo shows; moving to air is a hardware exercise kept out of scope.
Purpose of this runbook: make steps 1-5 reproducible with g++ and two small files, so a future stack change that drops a guard is caught as a leak test, not learned about from a CVE.
Glossary (words used above, defined):
| word | meaning |
|---|---|
| sanitizer / ASan | a tool that adds invisible fences around memory blocks and stops the program if anything reads or writes across one; it converts a silent bug into a readable crash report |
| over-read | a copy command reads more bytes than the received data contains, so it pulls in neighboring memory; leaks data |
| over-write | a copy command writes more bytes than the target can hold, so it overwrites neighboring memory; can let the attacker run chosen code |
| payload | the exact attacker bytes that make the bug fire |
| packet / PDU | a unit of data a device sends over the radio; has a body length field the receiver trusts |
| buffer pool | a shared area of memory where the stack reuses receive buffers; other data (other packets, secrets) sits nearby |
| trusted number | a length or offset read from attacker input that the code uses without checking it matches reality |
| gate / caller guard | a check one function performs BEFORE calling another, e.g. "reject if fewer than 16 bytes"; F1/F2 depend on these today |
| reachable | an attacker can actually get their bytes to the buggy line on the real device |
| stack (as in "caller") | the set of functions running at once; the "call stack" records who is calling whom |
10. How to test that the exploit works
One command proves it, and proves the fix too. test_exploit_f2_leak.cc is a self-test that runs three checks:
- the buggy handler really leaks the secret (attack works),
- the same 6-byte write against the patched handler leaks nothing (the fix works),
- the leaked bytes sit past position 6, i.e. this is an over-read, not a normal
copy (it lets the attacker see memory they were never sent).
Build and run:
g++ -O0 -g -o test_exploit_f2_leak test_exploit_f2_leak.cc && ./test_exploit_f2_leak
Actual output:
PASS exploit: 6-byte write is accepted as 512 bytes
PASS exploit: attacker bytes survive at 0..5
PASS exploit: secret leaks out of device memory (over-read)
PASS fix: patched handler rejects the undersized write
PASS fix: same write against patched handler leaks nothing
PASS over-read 'imports' 506 bytes the peer never sent
ALL CHECKS PASS - exploit proven, fix verified
Exit code 0 means "the exploit works and the fix stops it". Any FAIL line means a check broke - the most likely cause is a future stack change that alters the handler arithmetic, which is exactly what this test exists to catch.
How to read the result, simply:
- PASS on check 1-3 = attacker input really pulls out memory it was never sent
(that is what "exploited" means for this bug class).
- PASS on check 4-5 = the one-line guard (reject writes shorter than 12 bytes) is
the correct fix; the same exploit input is now harmless.
- The patched handler in the test is the fix from section 2 (F2 prevention),
written exactly as the runbook recommends, so the test doubles as a regression guard for the stack: run it after any change near gatt_sr.cc and it tells you whether the protection still holds.
Honest scope note (same as sections 3 and 8): passing tests prove the bug and the fix on the lab bench, not that the 2025 device is exploitable today. The real dispatcher still gates signed writes through gatt_verify_signature. The test is the tripwire for when that gate changes; it is not a claim of a live device compromise.