-
Notifications
You must be signed in to change notification settings - Fork 8k
Bluetooth: Host: Add req/rsp l2cap validation #94080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: Host: Add req/rsp l2cap validation #94080
Conversation
f701d07
to
f2a963c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than my change request below.
f2a963c
to
e1b49ab
Compare
e1b49ab
to
f8e625f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds request/response validation to L2CAP channels by storing the opcode of pending requests and validating that responses match the expected request type. This prevents processing of unsolicited responses and improves protocol robustness.
- Expands the ident lookup function to compare received response types against stored request opcodes
- Adds
pending_req
field to store the opcode of outgoing requests in L2CAP channels - Updates all request sending functions to set the pending request opcode and all response handlers to validate opcodes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
subsys/bluetooth/host/l2cap.c | Updates lookup functions to validate request/response matching and sets pending_req field when sending requests |
include/zephyr/bluetooth/l2cap.h | Adds pending_req field to bt_l2cap_le_chan structure for storing request opcodes |
Comments suppressed due to low confidence (1)
sizeof(struct bt_l2cap_sig_hdr) + | ||
sizeof(struct bt_l2cap_disconn_req)), | ||
CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 0x100 for ANY_OPCODE lacks documentation explaining why this specific value was chosen and its significance in the context of L2CAP opcodes.
/* | |
* ANY_OPCODE is used as a sentinel value to represent a wildcard match for L2CAP opcodes. | |
* L2CAP opcodes are 1-byte values (0x00-0xFF); 0x100 is chosen as it is outside the valid range, | |
* ensuring it does not conflict with any real opcode. | |
*/ |
Copilot uses AI. Check for mistakes.
f8e625f
to
c291c14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must address the Copilot comment about le_disconn_rsp
.
c291c14
to
e4f95ee
Compare
L2CAP channels will now, along with the ident, store the opcode of the pending request. This commit expands the ident lookup function to also compare received response types to this opcode, and will ignore unsolicited responses. Setting of idents for channels are moved after verification of buffer allocation for the request to be sent. A TODO is added for improving this functionality at a later time. Signed-off-by: Håvard Reierstad <[email protected]>
e4f95ee
to
5bb73f7
Compare
|
L2CAP channels will now, along with the ident, store the opcode of the pending request. This commit expands the ident lookup function to also compare received response types to this opcode, and will ignore unsolicited responses.