Skip to contentSkip to conversation

bluetooth:Fix NULL pointer deference issue in the function load_irks

PATCH In review Nicholas Krause 2 participants 2 messages Aug 19, 2015 – Aug 24, 2015

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

PATCH 1/1 bluetooth:Fix NULL pointer deference issue in the function load_irks

This fixes a possible NULL pointer deference issue in the function load_irks if the call to the function hci_add_link fails and returns NULL by instead checking if this return value occurs before returning -ENOMEM to the function load_irks caller as the function hci_add_link only fails due to a memory allocation error therfore due to this we only need to return the error -ENOMEM directly to the function load_irks

---
 net/bluetooth/mgmt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +3 -2
index 92720f3..e286d63 100644
@@ -5602,8 +5602,9 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data,
 		else
 			addr_type = ADDR_LE_DEV_RANDOM;
 
-		hci_add_irk(hdev, &irk->addr.bdaddr, addr_type, irk->val,
-			    BDADDR_ANY);
+		if (!hci_add_irk(hdev, &irk->addr.bdaddr, addr_type, irk->val,
+				 BDADDR_ANY))
+			return -ENOMEM;
 	}
 
 	hci_dev_set_flag(hdev, HCI_RPA_RESOLVING);
Signature · 1 line
2.1.4
#1 lore raw

Hi Nicholas,

(dropping unneeded recipients from CC - in the future linux-bluetooth should be enough for patches like this)

Quoted 3 lines · Nicholas Krause

This fixes a possible NULL pointer deference issue in the function load_irks if the call to the function hci_add_link fails and returns NULL

I don't see what NULL dereference this is fixing. The load_irk() function doesn't do anything with the returned pointer from hci_add_irk().

Quoted 8 lines
 net/bluetooth/mgmt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +0 -0
index 92720f3..e286d63 100644

net/bluetooth/mgmt.c static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, · line 5607

Quoted 8 lines
net/bluetooth/mgmt.c +3 -2
@@ -5602,8 +5602,9 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data,
 		else
 			addr_type = ADDR_LE_DEV_RANDOM;
 
-		hci_add_irk(hdev, &irk->addr.bdaddr, addr_type, irk->val,
-			    BDADDR_ANY);
+		if (!hci_add_irk(hdev, &irk->addr.bdaddr, addr_type, irk->val,
+				 BDADDR_ANY))
+			return -ENOMEM;

This could result in a partial IRK list being stored in the kernel, i.e. you should at least make a call to hci_smp_irks_clear() before returning a failure.

Johan