Skip to content

Commit

Permalink
Bluetooth: Check packet FCS earlier
Browse files Browse the repository at this point in the history
This way, if FCS is enabled and the packet is corrupted, we just drop it
without read it len, which could be corrupted.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Gustavo F. Padovan authored and Marcel Holtmann committed Jul 21, 2010
1 parent 45d65c4 commit 2600008
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4166,25 +4166,25 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
skb_pull(skb, 2);
len = skb->len;

/*
* We can just drop the corrupted I-frame here.
* Receiver will miss it and start proper recovery
* procedures and ask retransmission.
*/
if (l2cap_check_fcs(pi, skb))
goto drop;

if (__is_sar_start(control) && __is_iframe(control))
len -= 2;

if (pi->fcs == L2CAP_FCS_CRC16)
len -= 2;

/*
* We can just drop the corrupted I-frame here.
* Receiver will miss it and start proper recovery
* procedures and ask retransmission.
*/
if (len > pi->mps) {
l2cap_send_disconn_req(pi->conn, sk);
goto drop;
}

if (l2cap_check_fcs(pi, skb))
goto drop;

req_seq = __get_reqseq(control);
req_seq_offset = (req_seq - pi->expected_ack_seq) % 64;
if (req_seq_offset < 0)
Expand Down Expand Up @@ -4224,6 +4224,9 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
skb_pull(skb, 2);
len = skb->len;

if (l2cap_check_fcs(pi, skb))
goto drop;

if (__is_sar_start(control))
len -= 2;

Expand All @@ -4233,9 +4236,6 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
if (len > pi->mps || len < 0 || __is_sframe(control))
goto drop;

if (l2cap_check_fcs(pi, skb))
goto drop;

tx_seq = __get_txseq(control);

if (pi->expected_tx_seq == tx_seq)
Expand Down

0 comments on commit 2600008

Please sign in to comment.