Skip to content

Commit a2a9339

Browse files
committed
Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp}
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>
1 parent d2e4f1b commit a2a9339

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

net/bluetooth/l2cap_core.c

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

46534653
BT_DBG("scid 0x%4.4x dcid 0x%4.4x", scid, dcid);
46544654

4655-
mutex_lock(&conn->chan_lock);
4656-
4657-
chan = __l2cap_get_chan_by_scid(conn, dcid);
4655+
chan = l2cap_get_chan_by_scid(conn, dcid);
46584656
if (!chan) {
4659-
mutex_unlock(&conn->chan_lock);
46604657
cmd_reject_invalid_cid(conn, cmd->ident, dcid, scid);
46614658
return 0;
46624659
}
46634660

4664-
l2cap_chan_hold(chan);
4665-
l2cap_chan_lock(chan);
4666-
46674661
rsp.dcid = cpu_to_le16(chan->scid);
46684662
rsp.scid = cpu_to_le16(chan->dcid);
46694663
l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
46704664

46714665
chan->ops->set_shutdown(chan);
46724666

4667+
mutex_lock(&conn->chan_lock);
46734668
l2cap_chan_del(chan, ECONNRESET);
4669+
mutex_unlock(&conn->chan_lock);
46744670

46754671
chan->ops->close(chan);
46764672

46774673
l2cap_chan_unlock(chan);
46784674
l2cap_chan_put(chan);
46794675

4680-
mutex_unlock(&conn->chan_lock);
4681-
46824676
return 0;
46834677
}
46844678

@@ -4698,33 +4692,27 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
46984692

46994693
BT_DBG("dcid 0x%4.4x scid 0x%4.4x", dcid, scid);
47004694

4701-
mutex_lock(&conn->chan_lock);
4702-
4703-
chan = __l2cap_get_chan_by_scid(conn, scid);
4695+
chan = l2cap_get_chan_by_scid(conn, scid);
47044696
if (!chan) {
47054697
mutex_unlock(&conn->chan_lock);
47064698
return 0;
47074699
}
47084700

4709-
l2cap_chan_hold(chan);
4710-
l2cap_chan_lock(chan);
4711-
47124701
if (chan->state != BT_DISCONN) {
47134702
l2cap_chan_unlock(chan);
47144703
l2cap_chan_put(chan);
4715-
mutex_unlock(&conn->chan_lock);
47164704
return 0;
47174705
}
47184706

4707+
mutex_lock(&conn->chan_lock);
47194708
l2cap_chan_del(chan, 0);
4709+
mutex_unlock(&conn->chan_lock);
47204710

47214711
chan->ops->close(chan);
47224712

47234713
l2cap_chan_unlock(chan);
47244714
l2cap_chan_put(chan);
47254715

4726-
mutex_unlock(&conn->chan_lock);
4727-
47284716
return 0;
47294717
}
47304718

0 commit comments

Comments
 (0)