Android security tags, read closely by Lightrion

CVE-2024-0039 AI-generated analysis

platform/packages/modules/Bluetooth, GATT/ATT stack (system/stack/gatt/att_protocol.cc)

AI-generated: written from the bulletin and the fixing diffs by claude-fable-5-1, then checked against the code by claude-opus-5-5 (6 corrections). Verify against the commit before relying on it.

Adds running size accounting (size_now) with a CHECK_SIZE guard before every write in attp_build_value_cmd, so the ATT PDU builder frees the buffer and returns nullptr instead of writing past the payload_size-sized allocation. It also widens and validates the Read By Type pair-length field.

Root cause

attp_build_value_cmd allocates sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET. It then writes, in order: the opcode; a 1-byte pair length (GATT_RSP_READ_BY_TYPE only); a 2-byte handle (all opcodes except GATT_RSP_READ_BLOB/GATT_RSP_READ); a 2-byte offset (prepare write req/rsp only); and finally the value. It never checks that payload_size is large enough for the fixed header bytes. The only check was 'if (payload_size - p_buf->len < len) len = payload_size - p_buf->len'. When payload_size is smaller than the bytes already emitted, this subtraction is negative and the comparison is true. The negative result is assigned to the uint16_t len, which gives a large length for ARRAY_TO_STREAM and a heap overflow. The pair_len field was also a uint8_t computed as len + 2, so it was silently truncated.

How the fix works

Completeness

Behavior changes

Per major

Unknowns

Back to March 2024 · Findings