Bluetooth: Prevents buffer overflow on l2cap_ertm_reassembly_sdu()
The checks should be done before the the memcpy to avoid buffer
overflow.
Reported-by: João Paulo Rechi Vita <jprvita@profusion.mobi>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index fe663e9..9ef01c3 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -3470,12 +3470,12 @@
if (!pi->sdu)
goto disconnect;
- memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len);
-
pi->partial_sdu_len += skb->len;
if (pi->partial_sdu_len > pi->sdu_len)
goto drop;
+ memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len);
+
break;
case L2CAP_SDU_END:
@@ -3486,8 +3486,6 @@
goto disconnect;
if (!(pi->conn_state & L2CAP_CONN_SAR_RETRY)) {
- memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len);
-
pi->partial_sdu_len += skb->len;
if (pi->partial_sdu_len > pi->imtu)
@@ -3495,6 +3493,8 @@
if (pi->partial_sdu_len != pi->sdu_len)
goto drop;
+
+ memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len);
}
_skb = skb_clone(pi->sdu, GFP_ATOMIC);