Skip to content

Commit 3695251

Browse files
committed
Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp}
jira VULN-154997 cve-pre CVE-2023-53297 commit-author Luiz Augusto von Dentz <luiz.von.dentz@intel.com> commit a2a9339 Similar to commit d0be834 ("Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put"), just use l2cap_chan_hold_unless_zero to prevent referencing a channel that is about to be destroyed. Cc: stable@kernel.org Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Min Li <lm0963hack@gmail.com> (cherry picked from commit a2a9339) Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com>
1 parent 2c8e534 commit 3695251

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

net/bluetooth/l2cap_core.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,33 +4631,27 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
46314631

46324632
BT_DBG("scid 0x%4.4x dcid 0x%4.4x", scid, dcid);
46334633

4634-
mutex_lock(&conn->chan_lock);
4635-
4636-
chan = __l2cap_get_chan_by_scid(conn, dcid);
4634+
chan = l2cap_get_chan_by_scid(conn, dcid);
46374635
if (!chan) {
4638-
mutex_unlock(&conn->chan_lock);
46394636
cmd_reject_invalid_cid(conn, cmd->ident, dcid, scid);
46404637
return 0;
46414638
}
46424639

4643-
l2cap_chan_hold(chan);
4644-
l2cap_chan_lock(chan);
4645-
46464640
rsp.dcid = cpu_to_le16(chan->scid);
46474641
rsp.scid = cpu_to_le16(chan->dcid);
46484642
l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
46494643

46504644
chan->ops->set_shutdown(chan);
46514645

4646+
mutex_lock(&conn->chan_lock);
46524647
l2cap_chan_del(chan, ECONNRESET);
4648+
mutex_unlock(&conn->chan_lock);
46534649

46544650
chan->ops->close(chan);
46554651

46564652
l2cap_chan_unlock(chan);
46574653
l2cap_chan_put(chan);
46584654

4659-
mutex_unlock(&conn->chan_lock);
4660-
46614655
return 0;
46624656
}
46634657

@@ -4677,33 +4671,27 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
46774671

46784672
BT_DBG("dcid 0x%4.4x scid 0x%4.4x", dcid, scid);
46794673

4680-
mutex_lock(&conn->chan_lock);
4681-
4682-
chan = __l2cap_get_chan_by_scid(conn, scid);
4674+
chan = l2cap_get_chan_by_scid(conn, scid);
46834675
if (!chan) {
46844676
mutex_unlock(&conn->chan_lock);
46854677
return 0;
46864678
}
46874679

4688-
l2cap_chan_hold(chan);
4689-
l2cap_chan_lock(chan);
4690-
46914680
if (chan->state != BT_DISCONN) {
46924681
l2cap_chan_unlock(chan);
46934682
l2cap_chan_put(chan);
4694-
mutex_unlock(&conn->chan_lock);
46954683
return 0;
46964684
}
46974685

4686+
mutex_lock(&conn->chan_lock);
46984687
l2cap_chan_del(chan, 0);
4688+
mutex_unlock(&conn->chan_lock);
46994689

47004690
chan->ops->close(chan);
47014691

47024692
l2cap_chan_unlock(chan);
47034693
l2cap_chan_put(chan);
47044694

4705-
mutex_unlock(&conn->chan_lock);
4706-
47074695
return 0;
47084696
}
47094697

0 commit comments

Comments
 (0)