Skip to contentSkip to conversation

Bluetooth: Fix potential NULL dereference in SMP channel setup

PATCH Applied Marcel Holtmann 2 participants 2 messages Mar 17, 2015 – Mar 18, 2015

Subsystems (2)
lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: Fix potential NULL dereference in SMP channel setup

When the allocation of the L2CAP channel for the BR/EDR security manager fails, then the smp variable might be NULL. In that case do not try to free the non-existing crypto contexts

---
 net/bluetooth/smp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/bluetooth/smp.c +5 -3
index 6a5afb972358..1ec3f66b5a74 100644
@@ -3124,9 +3124,11 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)
 create_chan:
 	chan = l2cap_chan_create();
 	if (!chan) {
-		crypto_free_blkcipher(smp->tfm_aes);
-		crypto_free_hash(smp->tfm_cmac);
-		kzfree(smp);
+		if (smp) {
+			crypto_free_blkcipher(smp->tfm_aes);
+			crypto_free_hash(smp->tfm_cmac);
+			kzfree(smp);
+		}
 		return ERR_PTR(-ENOMEM);
 	}
 
Signature · 1 line
2.1.0
#1 lore raw

Hi Marcel,

Quoted 9 lines · Marcel Holtmann

When the allocation of the L2CAP channel for the BR/EDR security manager fails, then the smp variable might be NULL. In that case do not try to free the non-existing crypto contexts

---
 net/bluetooth/smp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Applied to bluetooth-next. Thanks.

Johan