Skip to content

Commit cadafab

Browse files
committed
Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp}
jira VULN-155000 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: Jonathan Maple <jmaple@ciq.com>
1 parent bebef07 commit cadafab

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
@@ -4597,33 +4597,27 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
45974597

45984598
BT_DBG("scid 0x%4.4x dcid 0x%4.4x", scid, dcid);
45994599

4600-
mutex_lock(&conn->chan_lock);
4601-
4602-
chan = __l2cap_get_chan_by_scid(conn, dcid);
4600+
chan = l2cap_get_chan_by_scid(conn, dcid);
46034601
if (!chan) {
4604-
mutex_unlock(&conn->chan_lock);
46054602
cmd_reject_invalid_cid(conn, cmd->ident, dcid, scid);
46064603
return 0;
46074604
}
46084605

4609-
l2cap_chan_hold(chan);
4610-
l2cap_chan_lock(chan);
4611-
46124606
rsp.dcid = cpu_to_le16(chan->scid);
46134607
rsp.scid = cpu_to_le16(chan->dcid);
46144608
l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
46154609

46164610
chan->ops->set_shutdown(chan);
46174611

4612+
mutex_lock(&conn->chan_lock);
46184613
l2cap_chan_del(chan, ECONNRESET);
4614+
mutex_unlock(&conn->chan_lock);
46194615

46204616
chan->ops->close(chan);
46214617

46224618
l2cap_chan_unlock(chan);
46234619
l2cap_chan_put(chan);
46244620

4625-
mutex_unlock(&conn->chan_lock);
4626-
46274621
return 0;
46284622
}
46294623

@@ -4643,33 +4637,27 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
46434637

46444638
BT_DBG("dcid 0x%4.4x scid 0x%4.4x", dcid, scid);
46454639

4646-
mutex_lock(&conn->chan_lock);
4647-
4648-
chan = __l2cap_get_chan_by_scid(conn, scid);
4640+
chan = l2cap_get_chan_by_scid(conn, scid);
46494641
if (!chan) {
46504642
mutex_unlock(&conn->chan_lock);
46514643
return 0;
46524644
}
46534645

4654-
l2cap_chan_hold(chan);
4655-
l2cap_chan_lock(chan);
4656-
46574646
if (chan->state != BT_DISCONN) {
46584647
l2cap_chan_unlock(chan);
46594648
l2cap_chan_put(chan);
4660-
mutex_unlock(&conn->chan_lock);
46614649
return 0;
46624650
}
46634651

4652+
mutex_lock(&conn->chan_lock);
46644653
l2cap_chan_del(chan, 0);
4654+
mutex_unlock(&conn->chan_lock);
46654655

46664656
chan->ops->close(chan);
46674657

46684658
l2cap_chan_unlock(chan);
46694659
l2cap_chan_put(chan);
46704660

4671-
mutex_unlock(&conn->chan_lock);
4672-
46734661
return 0;
46744662
}
46754663

0 commit comments

Comments
 (0)