diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc index 1c6d43000e305a07b2d67c458b8f5515448b21d7..bc47f808351c96587de7b55b7972c6df4d8dad13 100644 --- a/system/stack/btm/btm_sec.cc +++ b/system/stack/btm/btm_sec.cc @@ -230,6 +230,25 @@ static bool btm_dev_16_digit_authenticated(tBTM_SEC_DEV_REC* p_dev_rec) { return (false); } +/******************************************************************************* + * + * Function access_secure_service_from_temp_bond + * + * Description a utility function to test whether an access to + * secure service from temp bonding is happening + * + * Returns true if the aforementioned condition holds, + * false otherwise + * + ******************************************************************************/ +static bool access_secure_service_from_temp_bond(const tBTM_SEC_DEV_REC* p_dev_rec, + bool locally_initiated, + uint16_t security_req) { + return !locally_initiated && (security_req & BTM_SEC_IN_AUTHENTICATE) && + p_dev_rec->is_device_authenticated() && + p_dev_rec->is_bond_type_temporary(); +} + /******************************************************************************* * * Function BTM_SecRegister @@ -1636,9 +1655,14 @@ tBTM_STATUS btm_sec_l2cap_access_req_by_requirement( } if (rc == BTM_SUCCESS) { + if (access_secure_service_from_temp_bond(p_dev_rec, is_originator, security_required)) { + LOG_ERROR("Trying to access a secure service from a temp bonding, rejecting"); + rc = BTM_FAILED_ON_SECURITY; + } + if (p_callback) - (*p_callback)(&bd_addr, transport, (void*)p_ref_data, BTM_SUCCESS); - return (BTM_SUCCESS); + (*p_callback)(&bd_addr, transport, (void*)p_ref_data, rc); + return (rc); } } @@ -4520,6 +4544,13 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { return (BTM_FAILED_ON_SECURITY); } + if (access_secure_service_from_temp_bond(p_dev_rec, + p_dev_rec->IsLocallyInitiated(), + p_dev_rec->security_required)) { + LOG_ERROR("Trying to access a secure service from a temp bonding, rejecting"); + return (BTM_FAILED_ON_SECURITY); + } + /* All required security procedures already established */ p_dev_rec->security_required &= ~(BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_AUTHENTICATE |