Bluetooth: Fix potential double-frees of L2CAP skbs
Subsystems (2)
PATCH 1/1 Bluetooth: Fix potential double-frees of L2CAP skbs
From: Johan Hedberg <[email protected]>
The l2cap_recv_frame function is expected to take ownership and eventually free the skb passed to it. We need to ensure that the conn->rx_skb pointer is no longer reachable when calling l2cap_recv_frame so that no other function, such as l2cap_conn_del, may think that it can free conn->rx_skb.
An actual situation when this can happen is when smp_sig_channel (called from l2cap_recv_frame) fails and l2cap_conn_del gets called as a consequence. The l2cap_conn_del function would then try to free conn->rx_skb, but as the same skb was just passed to smp_sig_channel and freed we get a double-free.
--- net/bluetooth/l2cap_core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +6 -2
@@ -6798,9 +6798,13 @@ int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) conn->rx_len -= skb->len;if (!conn->rx_len) { -/* Complete frame received */ -l2cap_recv_frame (conn, conn->rx_skb); +/* Complete frame received. l2cap_recv_frame +* takes ownership of the skb so set the global +* rx_skb pointer to NULL first. +*/ +struct sk_buff *rx_skb = conn->rx_skb; conn->rx_skb =NULL ; +l2cap_recv_frame (conn, rx_skb); }break ; }
Signature · 1 line
1.8.3.1
Marcel Holtmann
maintainerHi Johan,
Quoted 12 lines
The
l2cap_recv_framefunction is expected to take ownership and eventually free the skb passed to it. We need to ensure that theconn->rx_skbpointer is no longer reachable when callingl2cap_recv_frameso that no other function, such asl2cap_conn_del, may think that it can freeconn->rx_skb.An actual situation when this can happen is when
smp_sig_channel(called froml2cap_recv_frame) fails andl2cap_conn_delgets called as a consequence. Thel2cap_conn_delfunction would then try to freeconn->rx_skb, but as the same skb was just passed tosmp_sig_channeland freed we get a double-free.
Quoted 4 lines
Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/l2cap_core.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel