Skip to content

Conversation

cvinayak
Copy link
Contributor

Fix missing validation of Connection Update Ind PDU. Ignore invalid connection update parameters and let the connection either procedure timeout or supervision timeout if the central switched to using invalid connection parameters.

@cvinayak
Copy link
Contributor Author

cvinayak commented May 11, 2024

@thoh-ot @erbr-ot @wopu-ot @kruithofa is this behavior to let procedure/supervision timeout an acceptable outcome?
Will have to add/update unit tests accordingly.

@cvinayak cvinayak force-pushed the github_conn_update_ind_param_check branch from 4992255 to f7f65af Compare May 12, 2024 03:36
@erbr-ot
Copy link
Contributor

erbr-ot commented May 13, 2024

I tend to think we should be more pro-active in case of invalid params and disconnect with BT_HCI_ERR_INVALID_LL_PARAM. This could make recovery from a central mistake faster.

@thoh-ot
Copy link
Contributor

thoh-ot commented May 14, 2024

Take at look at how invalid LL_PHY_UPDATE_IND are handled in

static void lp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt,
void *param)
{
switch (evt) {
case LP_PU_EVT_PHY_UPDATE_IND:
LL_ASSERT(conn->lll.role == BT_HCI_ROLE_PERIPHERAL);
llcp_rr_set_incompat(conn, INCOMPAT_RESERVED);
llcp_pdu_decode_phy_update_ind(ctx, (struct pdu_data *)param);
const uint8_t end_procedure = pu_check_update_ind(conn, ctx);
/* Mark RX node to NOT release */
llcp_rx_node_retain(ctx);
if (!end_procedure) {
if (ctx->data.pu.p_to_c_phy) {
/* If periph to central phy changes apply tx timing restriction */
pu_set_timing_restrict(conn, ctx->data.pu.p_to_c_phy);
}
/* Since at least one phy will change,
* stop the procedure response timeout
*/
llcp_lr_prt_stop(conn);
ctx->state = LP_PU_STATE_WAIT_INSTANT;
} else {
llcp_rr_set_incompat(conn, INCOMPAT_NO_COLLISION);
if (ctx->data.pu.error != BT_HCI_ERR_SUCCESS) {
/* Mark the connection for termination */
conn->llcp_terminate.reason_final = ctx->data.pu.error;
}
ctx->data.pu.ntf_pu = ctx->data.pu.host_initiated;
lp_pu_complete(conn, ctx, evt, param);
}

@cvinayak cvinayak force-pushed the github_conn_update_ind_param_check branch from f7f65af to 8e762f6 Compare May 31, 2024 04:28
Fix missing validation of Connection Update Ind PDU. Ignore
invalid connection update parameters and force a silent
local connection termination.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
@cvinayak cvinayak force-pushed the github_conn_update_ind_param_check branch from 8e762f6 to e91b3e3 Compare May 31, 2024 08:00
@cvinayak cvinayak marked this pull request as ready for review May 31, 2024 08:39
@zephyrbot zephyrbot requested review from carlescufi and mtpr-ot May 31, 2024 08:39
Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, with some minor suggestions for improved readability

Comment on lines +206 to +212
return (interval_max >= CONN_INTERVAL_MIN(conn)) &&
(interval_max <= CONN_UPDATE_CONN_INTV_4SEC) &&
(latency <= CONN_UPDATE_LATENCY_MAX) &&
(timeout >= CONN_UPDATE_TIMEOUT_100MS) &&
(timeout <= CONN_UPDATE_TIMEOUT_32SEC) &&
((timeout * 4U) > /* *4U re. conn events is equivalent to *2U re. ms */
((latency + 1U) * interval_max));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to make this more readable by using the IN_RANGE macro

}
#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */

static bool cu_check_conn_ind_parameters(struct ll_conn *conn, struct proc_ctx *ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to rename check to valid or something.

If a check function returns true, is it really obvious that it's valid?

IMO check works better with int than bool

@carlescufi carlescufi merged commit 4b6d3f1 into zephyrproject-rtos:main May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants