【蓝牙】CVE-2018-9357 BNEP_Write越界写导致RCE
/*******************************************************************************
*
* Function BNEP_Write
*
* Description This function sends data over a BNEP connection
*
* Parameters: handle - handle of the connection to write
* p_dest_addr - BD_ADDR/Ethernet addr of the destination
* p_data - pointer to data start
* protocol - protocol type of the packet
* p_src_addr - (optional) BD_ADDR/ethernet address of the
* source
* (should be NULL if it is local BD Addr)
* fw_ext_present - forwarded extensions present
*
* Returns: BNEP_WRONG_HANDLE - if passed handle is not valid
* BNEP_MTU_EXCEDED - If the data length is greater than
* the MTU
* BNEP_IGNORE_CMD - If the packet is filtered out
* BNEP_Q_SIZE_EXCEEDED - If the Tx Q is full
* BNEP_NO_RESOURCES - If not able to allocate a buffer
* BNEP_SUCCESS - If written successfully
*
******************************************************************************/
tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
uint8_t* p_data, uint16_t len, uint16_t protocol,
const RawAddress* p_src_addr, bool fw_ext_present) {
tBNEP_CONN* p_bcb;
uint8_t* p;
// MTU检查
/* Check MTU size. Consider the possibility of having extension headers */
if (len > BNEP_MTU_SIZE) {
BNEP_TRACE_ERROR("BNEP_Write() length %d exceeded MTU %d", len, BNEP_MTU_SIZE);
return (BNEP_MTU_EXCEDED);
}
// handle检查
if ((!handle) || (handle > BNEP_MAX_CONNECTIONS)) return (BNEP_WRONG_HANDLE);
p_bcb = &(bnep_cb.bcb[handle - 1]); // 获取p_pcb
/* Check if the packet should be filtered out */
if (bnep_is_packet_allowed(p_bcb, p_dest_addr, protocol, fw_ext_present, p_data) != BNEP_SUCCESS) {
/*
** If packet is filtered and ext headers are present
** drop the data and forward the ext headers
*/
if (fw_ext_present) {
uint8_t ext, length;
uint16_t org_len, new_len;
/* parse the extension headers and findout the new packet len */
org_len = len; // org_len表示Buffer原本长度
new_len = 0; // new_len表示新的Buffer长度
p = p_data; // p表示Buffer原始起始地址
do {
ext = *p_data++; // 获取第一个字节作为ext
length = *p_data++; // 获取第二个字节作为length
p_data += length; // 移动p_data指向下一个扩展起始地址
new_len += (length + 2); // new_length加上ext,length两字节,再加上length长度的数据
if (new_len > org_len) return BNEP_IGNORE_CMD; // new_len不能超过原始Buffer整体长度org_len
} while (ext & 0x80);
if (protocol != BNEP_802_1_P_PROTOCOL)
protocol = 0;
else {
// new_len加上4
new_len += 4;
p_data[2] = 0;
p_data[3] = 0;
}
len = new_len; // len为最终的新Buffer长度
p_data = p; // p_data重新指向Buffer起始
} else
return BNEP_IGNORE_CMD;
}
...
}
Value
BNEP Packet Type

Value
Parameter Description
Value
Parameter Description
Previous【蓝牙】CVE-2017-13258 CVE-2017-13260 CVE-2017-13261 CVE-2017-13262信息泄露Next【蓝牙】CVE-2018-9358 信息泄露
Last updated