Bluetooth: Fix l2cap_chan leak in SMP
Subsystems (2)
PATCH 1/1 Bluetooth: Fix l2cap_chan leak in SMP
From: Johan Hedberg <[email protected]>
The L2CAP core expects channel implementations to manage the reference returned by the new_connection callback. With sockets this is already handled with each channel being tied to the corresponding socket. With SMP however there's no context to tie the pointer to in the smp_new_conn_cb function. The function can also not just drop the reference since it's the only one at that point.
For fixed channels (like SMP) the code path inside the L2CAP core from new_connection() to ready() is short and straight-forwards. The crucial difference is that in ready() the implementation has access to the l2cap_conn that SMP needs associate its l2cap_chan. Instead of taking a new reference in smp_ready_cb() we can simply assume to already own the reference created in smp_new_conn_cb(), i.e. there is no need to call l2cap_chan_hold().
--- net/bluetooth/smp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/bluetooth/smp.c +6 -1
@@ -3027,8 +3027,13 @@ static void smp_ready_cb(struct l2cap_chan *chan)BT_DBG ("chan %p" , chan); +/* No need to call l2cap_chan_hold() here since we already own +* the reference taken in smp_new_conn_cb(). This is just the +* first time that we tie it to a specific pointer. The code in +* l2cap_core.c ensures that there's no risk this function wont +* get called if smp_new_conn_cb was previously called. +*/ conn->smp = chan; -l2cap_chan_hold (chan);if (hcon->type ==ACL_LINK &&test_bit (HCI_CONN_ENCRYPT , &hcon->flags))bredr_pairing (chan);
Signature · 1 line
2.5.0
Marcel Holtmann
maintainerHi Johan,
Quoted 15 lines
The L2CAP core expects channel implementations to manage the reference returned by the
new_connectioncallback. With sockets this is already handled with each channel being tied to the corresponding socket. With SMP however there's no context to tie the pointer to in thesmp_new_conn_cbfunction. The function can also not just drop the reference since it's the only one at that point.For fixed channels (like SMP) the code path inside the L2CAP core from
new_connection()toready()is short and straight-forwards. The crucial difference is that inready()the implementation has access to thel2cap_connthat SMP needs associate itsl2cap_chan. Instead of taking a new reference insmp_ready_cb()we can simply assume to already own the reference created insmp_new_conn_cb(), i.e. there is no need to calll2cap_chan_hold().
Quoted 5 lines
Signed-off-by Johan Hedberg <[email protected]>Cc [email protected] # 3.19+---
net/bluetooth/smp.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)
patch has been applied to bluetooth-stable tree.
Regards
Marcel