Skip to content
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: conn: check for disconnected earlier when sending #68748

Merged

Conversation

jori-nordic
Copy link
Collaborator

Verify the connection is active before popping the buffer from the TX
queue.

The current behavior enables a race condition between create_frag and
the connection being torn down, as buf can be popped from the TX queue
but not destroyed by bt_conn_process_tx.

In that case, buf will be leaked.

Original analysis and fix proposal by @watsug.

Verify the connection is active before popping the buffer from the TX
queue.

The current behavior enables a race condition between `create_frag` and
the connection being torn down, as `buf` can be popped from the TX queue
but not destroyed by `bt_conn_process_tx`.

In that case, `buf` will be leaked.

Original analysis and fix proposal by @watsug.

Signed-off-by: Jonathan Rico <[email protected]>
Reported-by: Adam Augustyn<[email protected]>
It is unclear from a cursory glance at the code what the caller of
`send_buf(buf)` should do with `buf` based on the returned error codes.

Document when ownership is and isn't transferred to `send_buf()`.

Signed-off-by: Jonathan Rico <[email protected]>
@jori-nordic
Copy link
Collaborator Author

@watsug Could you check that this PR fixes #63217?

@jori-nordic jori-nordic added the bug The issue is a bug, or the PR is fixing a bug label Feb 8, 2024
@jori-nordic jori-nordic added this to the v3.6.0 milestone Feb 9, 2024
Comment on lines +734 to +736
* - -EIO: buffer failed to send due to HCI error. `buf` ownership returned to
* caller BUT `buf` is popped from the TX queue. The caller shall destroy
* `buf` and its TX context.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the caller shall destroy on this error, couldn't this function do that?

Copy link
Collaborator Author

@jori-nordic jori-nordic Feb 9, 2024

Choose a reason for hiding this comment

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

ownership is a bit messy regarding those 3 functions.
I am currently rewriting the whole TX flow so I'd rather quick-fix this particular issue and reserve the in-depth review for the refactor if that's alright.

@MaureenHelm MaureenHelm merged commit a066921 into zephyrproject-rtos:main Feb 9, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants