Skip to contentSkip to conversation

Bluetooth: Fix clearing SMP keys if pairing fails

PATCH In review [email protected] 2 participants 2 messages Feb 28, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Fix clearing SMP keys if pairing fails

From: Johan Hedberg <[email protected]>

If SMP fails we should not leave any keys (LTKs or IRKs) hanging around the internal lists. This patch adds the necessary code to smp_chan_destroy to remove any keys we may have in case of pairing failure.

---
 net/bluetooth/smp.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
net/bluetooth/smp.c +18 -0
index 6ace0b48dc6a..710f4e171bf1 100644
@@ -589,6 +589,24 @@ void smp_chan_destroy(struct l2cap_conn *conn)
 	complete = test_bit(SMP_FLAG_COMPLETE, &smp->smp_flags);
 	mgmt_smp_complete(conn->hcon, complete);
 
+	/* If pairing failed clean up any keys we might have */
+	if (!complete) {
+		if (smp->ltk) {
+			list_del(&smp->ltk->list);
+			kfree(smp->ltk);
+		}
+
+		if (smp->slave_ltk) {
+			list_del(&smp->slave_ltk->list);
+			kfree(smp->slave_ltk);
+		}
+
+		if (smp->remote_irk) {
+			list_del(&smp->remote_irk->list);
+			kfree(smp->remote_irk);
+		}
+	}
+
 	kfree(smp);
 	conn->smp_chan = NULL;
 	conn->hcon->smp_conn = NULL;
Signature · 1 line
1.8.5.3
maintainer
#1 lore raw

Hi Johan,

Quoted 9 lines

If SMP fails we should not leave any keys (LTKs or IRKs) hanging around the internal lists. This patch adds the necessary code to smp_chan_destroy to remove any keys we may have in case of pairing failure.

---
net/bluetooth/smp.c | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel