bluetooth:Fix locking issues in the function l2cap_connect_cfm
Subsystems (2)
PATCH 1/1 bluetooth:Fix locking issues in the function l2cap_connect_cfm
This fixes a locking issue in the function l2cap_connect_cfm for not locking the mutex lock for channels on the l2cap_conn structure pointer conn before calling __l2cap_get_chan_by_dcid as all callers need to lock and unlock this mutex before calling this function due to issues with either concurrent users or race conditions arising if this mutex is not locked before these calls.
--- net/bluetooth/l2cap_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +4 -1
@@ -7285,9 +7285,11 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)struct l2cap_chan *chan, *next;/* Client fixed channels should override server ones */ +mutex_lock (&conn->chan_lock);if (__l2cap_get_chan_by_dcid (conn, pchan->scid)) goto next; - + +mutex_unlock (&conn->chan_lock);l2cap_chan_lock (pchan); chan = pchan->ops->new_connection (pchan);if (chan) {
@@ -7301,6 +7303,7 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)l2cap_chan_unlock (pchan); next: +mutex_unlock (&conn->chan_lock); next =l2cap_global_fixed_chan (pchan, hcon);l2cap_chan_put (pchan); pchan = next;
Signature · 1 line
2.1.4
Hi Nicholas,
Quoted 30 lines · Nicholas Krause
This fixes a locking issue in the function
l2cap_connect_cfmfor not locking the mutex lock for channels on thel2cap_connstructure pointer conn before calling__l2cap_get_chan_by_dcidas all callers need to lock and unlock this mutex before calling this function due to issues with either concurrent users or race conditions arising if this mutex is not locked before these calls.Signed-off-by Nicholas Krause <[email protected]>--- net/bluetooth/l2cap_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/bluetooth/l2cap_core.c +3
-1@@ -7285,9 +7285,11 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)struct l2cap_chan *chan, *next;/* Client fixed channels should override server ones */ +mutex_lock (&conn->chan_lock);if (__l2cap_get_chan_by_dcid (conn, pchan->scid)) goto next; - + +mutex_unlock (&conn->chan_lock);l2cap_chan_lock (pchan); chan = pchan->ops->new_connection (pchan);if (chan) {
net/bluetooth/l2cap_core.c static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status) · line 7309
Quoted 7 lines
net/bluetooth/l2cap_core.c +1
-0@@ -7301,6 +7303,7 @@ static void l2cap_connect_cfm(struct hci_conn *hcon, u8 status)l2cap_chan_unlock (pchan); next: +mutex_unlock (&conn->chan_lock); next =l2cap_global_fixed_chan (pchan, hcon);l2cap_chan_put (pchan); pchan = next;
This looks broken to me. If __l2cap_get_chan_by_dcid() returns NULL (i.e. the jump to 'next' is *not* taken then the code will end up calling mutex_unlock(&conn->chan_lock) twice. We can probably take the penalty of keeping the lock a bit longer, i.e. you should be able to drop your first unlock() call. In fact you *have* to keep the lock longer since __l2cap_chan_add() requires it.
Johan