Skip to contentSkip to conversation

Bluetooth: Check minimum length of SMP packets

PATCH Applied Marcel Holtmann 2 participants 2 messages Oct 3, 2013

Subsystems (2)
lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: Check minimum length of SMP packets

When SMP packets are received, make sure they contain at least 1 byte header for the opcode. If not, drop the packet and disconnect the link.

---
 net/bluetooth/smp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
net/bluetooth/smp.c +7 -2
index 6e049497..884b208 100644
@@ -848,8 +848,7 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
 int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
 {
 	struct hci_conn *hcon = conn->hcon;
-	__u8 code = skb->data[0];
-	__u8 reason;
+	__u8 code, reason;
 	int err = 0;
 
 	if (hcon->type != LE_LINK) {
@@ -857,12 +856,18 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
 		return -ENOTSUPP;
 	}
 
+	if (skb->len < 1) {
+		kfree_skb(skb);
+		return -EILSEQ;
+	}
+
 	if (!test_bit(HCI_LE_ENABLED, &conn->hcon->hdev->dev_flags)) {
 		err = -ENOTSUPP;
 		reason = SMP_PAIRING_NOTSUPP;
 		goto done;
 	}
 
+	code = skb->data[0];
 	skb_pull(skb, sizeof(code));
 
 	/*
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Marcel,

Quoted 7 lines · Marcel Holtmann

When SMP packets are received, make sure they contain at least 1 byte header for the opcode. If not, drop the packet and disconnect the link.

---
 net/bluetooth/smp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Applied to bluetooth-next. Thanks.

Johan