Skip to contentSkip to conversation

Bluetooth: btintel: Fix bdaddress comparison with garbage value

PATCH Superseded Kiran K 4 participants 8 messages Oct 5, 2021 – Oct 13, 2021 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kiran K

author
#0 lore raw

PATCH 1/1 Bluetooth: btintel: Fix bdaddress comparison with garbage value

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader mode.

---
 drivers/bluetooth/btintel.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/bluetooth/btintel.c +11 -8
index 9359bff47296..d1703cc99705 100644
@@ -2081,14 +2081,16 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
 	if (ver->img_type == 0x03) {
 		btintel_clear_flag(hdev, INTEL_BOOTLOADER);
 		btintel_check_bdaddr(hdev);
-	}
-
-	/* If the OTP has no valid Bluetooth device address, then there will
-	 * also be no valid address for the operational firmware.
-	 */
-	if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-		bt_dev_info(hdev, "No device address configured");
-		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+	} else {
+		/*
+		 * Check for valid bd address in boot loader mode. Device
+		 * will be marked as unconfigured if empty bd address is
+		 * found.
+		 */
+		if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+			bt_dev_info(hdev, "No device address configured");
+			set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+		}
 	}
 
 	btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct hci_dev *hdev)
 		goto exit_error;
 	}
 
+	memset(&ver_tlv, 0, sizeof(ver_tlv));
 	/* For TLV type device, parse the tlv data */
 	err = btintel_parse_version_tlv(hdev, &ver_tlv, skb);
 	if (err) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kiran K

Intel Read Verision(TLV) data is parsed into a local structure variable
and it contains a field for bd address. Bd address is returned only in
bootloader mode and hence bd address in TLV structure needs to be validated
only if controller is present in boot loader mode.

Quoted 50 lines
---
 drivers/bluetooth/btintel.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/bluetooth/btintel.c +0 -3
index 9359bff47296..d1703cc99705 100644
@@ -2081,14 +2081,16 @@ static int
 btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
 	if (ver->img_type == 0x03) {
 		btintel_clear_flag(hdev, INTEL_BOOTLOADER);
 		btintel_check_bdaddr(hdev);
-	}
-
-	/* If the OTP has no valid Bluetooth device address, then there

will

drivers/bluetooth/btintel.c +3 -5
-	 * also be no valid address for the operational firmware.
-	 */
-	if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-		bt_dev_info(hdev, "No device address configured");
-		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+	} else {
+		/*
+		 * Check for valid bd address in boot loader mode.

Device

drivers/bluetooth/btintel.c +1 -0
+		 * will be marked as unconfigured if empty bd address

is

drivers/bluetooth/btintel.c +4 -0
+		 * found.
+		 */
+		if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+			bt_dev_info(hdev, "No device address

configured");

drivers/bluetooth/btintel.c +1 -0
+			set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev-
Quoted 1 line

quirks);

drivers/bluetooth/btintel.c +2 -0
+		}
 	}
 
 	btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct
 hci_dev *hdev)
 		goto exit_error;
 	}
 
+	memset(&ver_tlv, 0, sizeof(ver_tlv));
 	/* For TLV type device, parse the tlv data */
 	err = btintel_parse_version_tlv(hdev, &ver_tlv, skb);

if (err) {

maintainer
#2 lore raw
In reply to Kiran K

Hi Kiran,

Quoted 40 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader mode.

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
drivers/bluetooth/btintel.c +10 -8
index 9359bff47296..d1703cc99705 100644
@@ -2081,14 +2081,16 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
 	if (ver->img_type == 0x03) {
 		btintel_clear_flag(hdev, INTEL_BOOTLOADER);
 		btintel_check_bdaddr(hdev);
-	}
-
-	/* If the OTP has no valid Bluetooth device address, then there will
-	 * also be no valid address for the operational firmware.
-	 */
-	if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-		bt_dev_info(hdev, "No device address configured");
-		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+	} else {
+		/*
+		 * Check for valid bd address in boot loader mode. Device
+		 * will be marked as unconfigured if empty bd address is
+		 * found.
+		 */
+		if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+			bt_dev_info(hdev, "No device address configured");
+			set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+		}
 	}
 
 	btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct hci_dev *hdev) · line 2471

Quoted 4 lines
drivers/bluetooth/btintel.c +1 -0
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct hci_dev *hdev)
 		goto exit_error;
 	}
 
+	memset(&ver_tlv, 0, sizeof(ver_tlv));

this change is not described in the commit message. Why is that now out of a sudden needed?

Regards

Marcel

#3 lore raw

Hi Marcel,

Quoted 41 lines · Marcel Holtmann

Hi Kiran,

Quoted 38 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader mode.

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
drivers/bluetooth/btintel.c +10 -8
index 9359bff47296..d1703cc99705 100644
@@ -2081,14 +2081,16 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
      if (ver->img_type == 0x03) {
              btintel_clear_flag(hdev, INTEL_BOOTLOADER);
              btintel_check_bdaddr(hdev);
-     }
-
-     /* If the OTP has no valid Bluetooth device address, then there will
-      * also be no valid address for the operational firmware.
-      */
-     if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-             bt_dev_info(hdev, "No device address configured");
-             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+     } else {
+             /*
+              * Check for valid bd address in boot loader mode. Device
+              * will be marked as unconfigured if empty bd address is
+              * found.
+              */
+             if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+                     bt_dev_info(hdev, "No device address configured");
+                     set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+             }
      }
 
Quoted 8 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct hci_dev *hdev) · line 2471

Quoted 6 lines
drivers/bluetooth/btintel.c +1 -0
      btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct hci_dev *hdev)
              goto exit_error;
      }
 
+     memset(&ver_tlv, 0, sizeof(ver_tlv));

this change is not described in the commit message. Why is that now out of a sudden needed?

I guess this is just to make sure the ver_tlv is initialized so its otp_bd_addr be set to all zeros (BDADDR_ANY) otherwise the code above doesn't work as it attempts to compare to BDADDR_ANY.

Quoted 4 lines

Regards

Marcel

Signature · 1 line
Luiz Augusto von Dentz
author
#4 lore raw

Hi Marcel, Luiz,

Quoted 65 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Wednesday, October 6, 2021 11:19 PM
To: Marcel Holtmann <[email protected]>
Cc: K, Kiran <[email protected]>; linux-bluetooth <linux- [email protected]>; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; An, Tedd <[email protected]>
Subject: Re: [PATCH v1] Bluetooth: btintel: Fix bdaddress comparison with garbage value

Hi Marcel,

Quoted 7 lines · Marcel Holtmann

Hi Kiran,

Quoted 4 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader

mode.

Quoted 6 lines
Quoted 6 lines

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
Quoted 6 lines

drivers/bluetooth/btintel.c static int

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/bluetooth/btintel.c index 9359bff47296..d1703cc99705 100644

drivers/bluetooth/btintel.c +0 -0
@@ -2081,14 +2081,16 @@ static int

btintel_prepare_fw_download_tlv(struct hci_dev *hdev,

Quoted 23 lines
Quoted 23 lines
drivers/bluetooth/btintel.c +10 -8
      if (ver->img_type == 0x03) {
              btintel_clear_flag(hdev, INTEL_BOOTLOADER);
              btintel_check_bdaddr(hdev);
-     }
-
-     /* If the OTP has no valid Bluetooth device address, then there will
-      * also be no valid address for the operational firmware.
-      */
-     if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-             bt_dev_info(hdev, "No device address configured");
-             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+     } else {
+             /*
+              * Check for valid bd address in boot loader mode. Device
+              * will be marked as unconfigured if empty bd address is
+              * found.
+              */
+             if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+                     bt_dev_info(hdev, "No device address configured");
+                     set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+             }
      }
 
Quoted 2 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct

Quoted 2 lines
drivers/bluetooth/btintel.c +0 -0
      btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct

hci_dev *hdev)

Quoted 3 lines
Quoted 3 lines
drivers/bluetooth/btintel.c +0 -0
              goto exit_error;
      }
 
Quoted 8 lines
Quoted 3 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct hci_dev *hdev) · line 2471

Quoted 1 line
drivers/bluetooth/btintel.c +1 -0
+     memset(&ver_tlv, 0, sizeof(ver_tlv));

this change is not described in the commit message. Why is that now out of

a sudden needed?

I guess this is just to make sure the ver_tlv is initialized so its otp_bd_addr be set to all zeros (BDADDR_ANY) otherwise the code above doesn't work as it attempts to compare to BDADDR_ANY.

Yes. If not memset, then garbage value is compared against BDADDR_ANY.

Quoted 9 lines
Quoted 5 lines

Regards

Marcel

--
Luiz Augusto von Dentz

author
#5 lore raw

Hi Marcel,

Friendly reminder.

Quoted 84 lines

-----Original Message-----
From: K, Kiran
Sent: Thursday, October 7, 2021 11:36 AM
To: Luiz Augusto von Dentz <[email protected]>; Marcel Holtmann <[email protected]>
Cc: linux-bluetooth <[email protected]>; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; An, Tedd <[email protected]>
Subject: RE: [PATCH v1] Bluetooth: btintel: Fix bdaddress comparison with garbage value

Hi Marcel, Luiz,

Quoted 11 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Wednesday, October 6, 2021 11:19 PM
To: Marcel Holtmann <[email protected]>
Cc: K, Kiran <[email protected]>; linux-bluetooth <linux- [email protected]>; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; An, Tedd <[email protected]>
Subject: Re: [PATCH v1] Bluetooth: btintel: Fix bdaddress comparison with garbage value

Quoted 3 lines

Hi Marcel,

On Wed, Oct 6, 2021 at 1:52 AM Marcel Holtmann

<[email protected]>

Quoted 56 lines
Quoted 8 lines · wrote:

Hi Kiran,

Quoted 5 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader

mode.

Quoted 6 lines
Quoted 6 lines

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
Quoted 6 lines

drivers/bluetooth/btintel.c static int

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/bluetooth/btintel.c index 9359bff47296..d1703cc99705 100644

drivers/bluetooth/btintel.c +0 -0
@@ -2081,14 +2081,16 @@ static int

btintel_prepare_fw_download_tlv(struct hci_dev *hdev,

Quoted 23 lines
Quoted 23 lines
drivers/bluetooth/btintel.c +10 -8
      if (ver->img_type == 0x03) {
              btintel_clear_flag(hdev, INTEL_BOOTLOADER);
              btintel_check_bdaddr(hdev);
-     }
-
-     /* If the OTP has no valid Bluetooth device address, then there will
-      * also be no valid address for the operational firmware.
-      */
-     if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-             bt_dev_info(hdev, "No device address configured");
-             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+     } else {
+             /*
+              * Check for valid bd address in boot loader mode. Device
+              * will be marked as unconfigured if empty bd address is
+              * found.
+              */
+             if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+                     bt_dev_info(hdev, "No device address configured");
+                     set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+             }
      }
 
Quoted 2 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct

Quoted 2 lines
drivers/bluetooth/btintel.c +0 -0
      btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct

hci_dev *hdev)

Quoted 7 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct hci_dev *hdev) · line 2471

Quoted 4 lines
drivers/bluetooth/btintel.c +1 -0
              goto exit_error;
      }
 
+     memset(&ver_tlv, 0, sizeof(ver_tlv));

this change is not described in the commit message. Why is that now out of

Quoted 16 lines
Quoted 5 lines

a sudden needed?

I guess this is just to make sure the ver_tlv is initialized so its otp_bd_addr be set to all zeros (BDADDR_ANY) otherwise the code above doesn't work as it attempts to compare to BDADDR_ANY.

Yes. If not memset, then garbage value is compared against BDADDR_ANY.

Quoted 9 lines
Quoted 5 lines

Regards

Marcel

--
Luiz Augusto von Dentz

Thanks,
Kiran

maintainer
#6 lore raw
In reply to K, Kiran

Hi Kiran,

Quoted 49 lines
Quoted 49 lines
Quoted 4 lines
Quoted 4 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader

mode.

Quoted 6 lines
Quoted 6 lines

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
Quoted 6 lines

drivers/bluetooth/btintel.c static int

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/bluetooth/btintel.c index 9359bff47296..d1703cc99705 100644

drivers/bluetooth/btintel.c +0 -0
@@ -2081,14 +2081,16 @@ static int

btintel_prepare_fw_download_tlv(struct hci_dev *hdev,

Quoted 23 lines
Quoted 23 lines
drivers/bluetooth/btintel.c +10 -8
     if (ver->img_type == 0x03) {
             btintel_clear_flag(hdev, INTEL_BOOTLOADER);
             btintel_check_bdaddr(hdev);
-     }
-
-     /* If the OTP has no valid Bluetooth device address, then there will
-      * also be no valid address for the operational firmware.
-      */
-     if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-             bt_dev_info(hdev, "No device address configured");
-             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+     } else {
+             /*
+              * Check for valid bd address in boot loader mode. Device
+              * will be marked as unconfigured if empty bd address is
+              * found.
+              */
+             if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+                     bt_dev_info(hdev, "No device address configured");
+                     set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+             }
     }
 
Quoted 2 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct

Quoted 2 lines
drivers/bluetooth/btintel.c +0 -0
     btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct

hci_dev *hdev)

Quoted 5 lines
Quoted 4 lines
drivers/bluetooth/btintel.c +1 -0
             goto exit_error;
     }
 
+     memset(&ver_tlv, 0, sizeof(ver_tlv));
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

this change is not described in the commit message. Why is that now out of

a sudden needed?

I guess this is just to make sure the ver_tlv is initialized so its otp_bd_addr be set to all zeros (BDADDR_ANY) otherwise the code above doesn't work as it attempts to compare to BDADDR_ANY.

Yes. If not memset, then garbage value is compared against BDADDR_ANY.

since that is not obviously clear, the takeaway from my review should have been that you either describe this properly in the commit message or you add a comment.

Regards

Marcel

author
#7 lore raw

Hi Marcel,

Quoted 71 lines

-----Original Message-----
From: Marcel Holtmann <[email protected]>
Sent: Tuesday, October 12, 2021 9:27 PM
To: K, Kiran <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>; linux-bluetooth <linux- [email protected]>; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; An, Tedd <[email protected]>
Subject: Re: [PATCH v1] Bluetooth: btintel: Fix bdaddress comparison with garbage value

Hi Kiran,

Quoted 58 lines
Quoted 57 lines
Quoted 5 lines
Quoted 5 lines

Intel Read Verision(TLV) data is parsed into a local structure variable and it contains a field for bd address. Bd address is returned only in bootloader mode and hence bd address in TLV structure needs to be validated only if controller is present in boot loader

mode.

Quoted 6 lines
Quoted 6 lines

---
drivers/bluetooth/btintel.c | 19 +++++++++++--------

1 file changed, 11 insertions(+), 8 deletions(-)
Quoted 6 lines

drivers/bluetooth/btintel.c static int

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/bluetooth/btintel.c index 9359bff47296..d1703cc99705 100644

drivers/bluetooth/btintel.c +0 -0
@@ -2081,14 +2081,16 @@ static int

btintel_prepare_fw_download_tlv(struct hci_dev *hdev,

Quoted 23 lines
Quoted 23 lines
drivers/bluetooth/btintel.c +10 -8
     if (ver->img_type == 0x03) {
             btintel_clear_flag(hdev, INTEL_BOOTLOADER);
             btintel_check_bdaddr(hdev);
-     }
-
-     /* If the OTP has no valid Bluetooth device address, then there will
-      * also be no valid address for the operational firmware.
-      */
-     if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
-             bt_dev_info(hdev, "No device address configured");
-             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+     } else {
+             /*
+              * Check for valid bd address in boot loader mode. Device
+              * will be marked as unconfigured if empty bd address is
+              * found.
+              */
+             if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
+                     bt_dev_info(hdev, "No device address configured");
+                     set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+             }
     }
 
Quoted 2 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct

Quoted 2 lines
drivers/bluetooth/btintel.c +0 -0
     btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
@@ -2466,6 +2468,7 @@ static int btintel_setup_combined(struct

hci_dev *hdev)

Quoted 7 lines

drivers/bluetooth/btintel.c static int btintel_setup_combined(struct hci_dev *hdev) · line 2471

Quoted 4 lines
drivers/bluetooth/btintel.c +1 -0
             goto exit_error;
     }
 
+     memset(&ver_tlv, 0, sizeof(ver_tlv));

this change is not described in the commit message. Why is that now out of

a sudden needed?

I guess this is just to make sure the ver_tlv is initialized so its otp_bd_addr be set to all zeros (BDADDR_ANY) otherwise the code above doesn't work as it attempts to compare to BDADDR_ANY.

Quoted 5 lines
Quoted 1 line

Yes. If not memset, then garbage value is compared against BDADDR_ANY.

since that is not obviously clear, the takeaway from my review should have been that you either describe this properly in the commit message or you add a comment.

I will add a comment and send an updated patch. Thanks.

Quoted 4 lines

Regards

Marcel