-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Bluetooth: conn: check for disconnected earlier when sending #68748
Conversation
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]>
* - -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. |
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.
If the caller shall destroy on this error, couldn't this function do that?
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.
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.
Verify the connection is active before popping the buffer from the TX
queue.
The current behavior enables a race condition between
create_frag
andthe connection being torn down, as
buf
can be popped from the TX queuebut not destroyed by
bt_conn_process_tx
.In that case,
buf
will be leaked.Original analysis and fix proposal by @watsug.