Skip to contentSkip to conversation

Bluetooth: Enforce zero-valued hash/rand192 for LE OOB

PATCH Superseded Johan Hedberg 2 participants 5 messages Jan 26, 2015 – Jan 27, 2015

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

PATCH 1/1 Bluetooth: Enforce zero-valued hash/rand192 for LE OOB

From: Johan Hedberg <[email protected]>

Until legacy SMP OOB pairing is implemented user space should be given a clear error when trying to use it. This patch adds a corresponding check to the Add Remote OOB Data handler function which returns "invalid parameters" if non-zero Rand192 or Hash192 parameters were given for an LE address.

---
 net/bluetooth/mgmt.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
net/bluetooth/mgmt.c +14 -0
index 25e40e82b9a2..cf257cc0e09d 100644
@@ -3673,6 +3673,20 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
 		u8 status;
 
 		if (bdaddr_type_is_le(cp->addr.type)) {
+			static const u8 z16[16] = { 0 };
+
+			/* Enforce zero-valued 192-bit parameters as
+			 * long as legacy SMP OOB isn't implemented.
+			 */
+			if (memcmp(cp->rand192, z16, 16) ||
+			    memcmp(cp->hash192, z16, 16)) {
+				err = cmd_complete(sk, hdev->id,
+						   MGMT_OP_ADD_REMOTE_OOB_DATA,
+						   MGMT_STATUS_INVALID_PARAMS,
+						   addr, sizeof(*addr));
+				goto unlock;
+			}
+
 			rand192 = NULL;
 			hash192 = NULL;
 		} else {
Signature · 1 line
2.1.0
maintainer
#1 lore raw

Hi Johan,

Quoted 16 lines

Until legacy SMP OOB pairing is implemented user space should be given a clear error when trying to use it. This patch adds a corresponding check to the Add Remote OOB Data handler function which returns "invalid parameters" if non-zero Rand192 or Hash192 parameters were given for an LE address.

---
net/bluetooth/mgmt.c | 14 ++++++++++++++

1 file changed, 14 insertions(+)
net/bluetooth/mgmt.c +0 -0
index 25e40e82b9a2..cf257cc0e09d 100644

net/bluetooth/mgmt.c static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, · line 3676

Quoted 4 lines
net/bluetooth/mgmt.c +1 -0
@@ -3673,6 +3673,20 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
 		u8 status;
 
 		if (bdaddr_type_is_le(cp->addr.type)) {
+			static const u8 z16[16] = { 0 };

aren't these suppose to be done as = { 0, }; to ensure that the whole array is zeroed?

Quoted 6 lines
net/bluetooth/mgmt.c +6 -0
+
+			/* Enforce zero-valued 192-bit parameters as
+			 * long as legacy SMP OOB isn't implemented.
+			 */
+			if (memcmp(cp->rand192, z16, 16) ||
+			    memcmp(cp->hash192, z16, 16)) {

net/bluetooth/mgmt.c static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, · line 3692

Quoted 10 lines
net/bluetooth/mgmt.c +7 -0
+				err = cmd_complete(sk, hdev->id,
+						   MGMT_OP_ADD_REMOTE_OOB_DATA,
+						   MGMT_STATUS_INVALID_PARAMS,
+						   addr, sizeof(*addr));
+				goto unlock;
+			}
+
 			rand192 = NULL;
 			hash192 = NULL;
 		} else {

Regards

Marcel

#2 lore raw

Hi Marcel,

Quoted 18 lines · Marcel Holtmann
Quoted 18 lines

Until legacy SMP OOB pairing is implemented user space should be given a clear error when trying to use it. This patch adds a corresponding check to the Add Remote OOB Data handler function which returns "invalid parameters" if non-zero Rand192 or Hash192 parameters were given for an LE address.

---
net/bluetooth/mgmt.c | 14 ++++++++++++++

1 file changed, 14 insertions(+)
net/bluetooth/mgmt.c +0 -0
index 25e40e82b9a2..cf257cc0e09d 100644
@@ -3673,6 +3673,20 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
 		u8 status;
 
Quoted 5 lines

net/bluetooth/mgmt.c static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, · line 3676

Quoted 2 lines
net/bluetooth/mgmt.c +1 -0
 		if (bdaddr_type_is_le(cp->addr.type)) {
+			static const u8 z16[16] = { 0 };

aren't these suppose to be done as = { 0, }; to ensure that the whole array is zeroed?

I think either way should work. Even if there was no initialization at all the C-standard guarantees that static variables are initialized to zero unless initialized explicitly (this includes aggregate types like arrays). We could however leave out the 'static' part with something like you suggested since it's essentially redundant as far as the initialization is concerned.

Johan

#3 lore raw

PATCH v2 1/1 Bluetooth: Enforce zero-valued hash/rand192 for LE OOB

In reply to Johan Hedberg

From: Johan Hedberg <[email protected]>

Until legacy SMP OOB pairing is implemented user space should be given a clear error when trying to use it. This patch adds a corresponding check to the Add Remote OOB Data handler function which returns "invalid parameters" if non-zero Rand192 or Hash192 parameters were given for an LE address.

---
v2: Use a define instead of a variable for the zero-valued key

 net/bluetooth/mgmt.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
net/bluetooth/mgmt.c +15 -0
index 25e40e82b9a2..8417ab387d1a 100644
@@ -131,6 +131,9 @@ static const u16 mgmt_events[] = {
 
 #define CACHE_TIMEOUT	msecs_to_jiffies(2 * 1000)
 
+#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \
+		 "\x00\x00\x00\x00\x00\x00\x00\x00"
+
 struct pending_cmd {
 	struct list_head list;
 	u16 opcode;
@@ -3673,6 +3676,18 @@ static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
 		u8 status;
 
 		if (bdaddr_type_is_le(cp->addr.type)) {
+			/* Enforce zero-valued 192-bit parameters as
+			 * long as legacy SMP OOB isn't implemented.
+			 */
+			if (memcmp(cp->rand192, ZERO_KEY, 16) ||
+			    memcmp(cp->hash192, ZERO_KEY, 16)) {
+				err = cmd_complete(sk, hdev->id,
+						   MGMT_OP_ADD_REMOTE_OOB_DATA,
+						   MGMT_STATUS_INVALID_PARAMS,
+						   addr, sizeof(*addr));
+				goto unlock;
+			}
+
 			rand192 = NULL;
 			hash192 = NULL;
 		} else {
Signature · 1 line
2.1.0
maintainer
#4 lore raw

Hi Johan,

Quoted 6 lines

Until legacy SMP OOB pairing is implemented user space should be given a clear error when trying to use it. This patch adds a corresponding check to the Add Remote OOB Data handler function which returns "invalid parameters" if non-zero Rand192 or Hash192 parameters were given for an LE address.

Quoted 6 lines

---
v2: Use a define instead of a variable for the zero-valued key

net/bluetooth/mgmt.c | 15 +++++++++++++++

1 file changed, 15 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel