Skip to contentSkip to conversation

Bluetooth: btmtk: Fix null pointer when processing coredump

PATCH Superseded Chris Lu 4 participants 5 messages Jul 12, 2023 – Jul 13, 2023

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Chris Lu

author
#0 lore raw

PATCH v4 1/1 Bluetooth: btmtk: Fix null pointer when processing coredump

There may be a potential null pointer risk if offset value is less than 0 when doing memcmp in btmtk_process_coredump(). Check offset is valid before doing memcmp.

---
v2: fix typo
v3: fix bot checking error
v4: reduce variable 'offset' declaration in v3

---
 drivers/bluetooth/btmtk.c | 12 ++++++------
 drivers/bluetooth/btmtk.h |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmtk.c +6 -6
index 786f775196ae..9cc789272ab7 100644
@@ -395,12 +395,12 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 
 		/* Mediatek coredump data would be more than MTK_COREDUMP_NUM */
 		if (data->cd_info.cnt > MTK_COREDUMP_NUM &&
-		    skb->len > sizeof(MTK_COREDUMP_END) &&
-		    !memcmp((char *)&skb->data[skb->len - sizeof(MTK_COREDUMP_END)],
-			    MTK_COREDUMP_END, sizeof(MTK_COREDUMP_END) - 1)) {
-			bt_dev_info(hdev, "Mediatek coredump end");
-			hci_devcd_complete(hdev);
-		}
+		    skb->len > MTK_COREDUMP_END_LEN)
+			if (!memcmp((char *)&skb->data[skb->len - MTK_COREDUMP_END_LEN],
+			    MTK_COREDUMP_END, MTK_COREDUMP_END_LEN - 1)) {
+				bt_dev_info(hdev, "Mediatek coredump end");
+				hci_devcd_complete(hdev);
+			}
 
 		break;
 	}
drivers/bluetooth/btmtk.h +1 -0
index 68309dfe076a..56f5502baadf 100644
@@ -24,6 +24,7 @@
 
 #define MTK_COREDUMP_SIZE		(1024 * 1000)
 #define MTK_COREDUMP_END		"coredump end"
+#define MTK_COREDUMP_END_LEN		(sizeof(MTK_COREDUMP_END))
 #define MTK_COREDUMP_NUM		255
 
 enum {
Signature · 1 line
2.18.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=764864

---Test result---

Test Summary:

CheckPatch                    PASS      0.76 seconds
GitLint                       PASS      0.28 seconds
SubjectPrefix                 PASS      0.10 seconds
BuildKernel                   PASS      32.72 seconds
CheckAllWarning               PASS      35.67 seconds
CheckSparse                   PASS      40.50 seconds
CheckSmatch                   PASS      113.44 seconds
BuildKernel32                 PASS      31.76 seconds
TestRunnerSetup               PASS      477.48 seconds
TestRunner_l2cap-tester       PASS      22.23 seconds
TestRunner_iso-tester         PASS      39.87 seconds
TestRunner_bnep-tester        PASS      10.26 seconds
TestRunner_mgmt-tester        PASS      212.08 seconds
TestRunner_rfcomm-tester      PASS      15.16 seconds
TestRunner_sco-tester         PASS      15.95 seconds
TestRunner_ioctl-tester       PASS      17.20 seconds
TestRunner_mesh-tester        PASS      12.71 seconds
TestRunner_smp-tester         PASS      13.75 seconds
TestRunner_userchan-tester    PASS      10.54 seconds
IncrementalBuild              PASS      29.52 seconds

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Chris Lu

…

Quoted 3 lines

v4: reduce variable 'offset' declaration in v3

---
 drivers/bluetooth/btmtk.c | 12 ++++++------

…

I suggest to replace the marker by a line break.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.5-rc1#n711

Would it be helpful to adjust the wording “Fix null pointer” in the subject?

How do you think about to add the tag “Fixes”?

Regards,
Markus

#3 lore raw
In reply to Chris Lu

Hi Chris,

Quoted 8 lines · Chris Lu

There may be a potential null pointer risk if offset value is less than 0 when doing memcmp in btmtk_process_coredump(). Check offset is valid before doing memcmp.

You should probably include the Fixes tag of the patch that introduced the problem.

Quoted 47 lines

---
v2: fix typo
v3: fix bot checking error
v4: reduce variable 'offset' declaration in v3

---
 drivers/bluetooth/btmtk.c | 12 ++++++------
 drivers/bluetooth/btmtk.h |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmtk.c +6 -6
index 786f775196ae..9cc789272ab7 100644
@@ -395,12 +395,12 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 
                /* Mediatek coredump data would be more than MTK_COREDUMP_NUM */
                if (data->cd_info.cnt > MTK_COREDUMP_NUM &&
-                   skb->len > sizeof(MTK_COREDUMP_END) &&
-                   !memcmp((char *)&skb->data[skb->len - sizeof(MTK_COREDUMP_END)],
-                           MTK_COREDUMP_END, sizeof(MTK_COREDUMP_END) - 1)) {
-                       bt_dev_info(hdev, "Mediatek coredump end");
-                       hci_devcd_complete(hdev);
-               }
+                   skb->len > MTK_COREDUMP_END_LEN)
+                       if (!memcmp((char *)&skb->data[skb->len - MTK_COREDUMP_END_LEN],
+                           MTK_COREDUMP_END, MTK_COREDUMP_END_LEN - 1)) {
+                               bt_dev_info(hdev, "Mediatek coredump end");
+                               hci_devcd_complete(hdev);
+                       }
 
                break;
        }
drivers/bluetooth/btmtk.h +1 -1
index 68309dfe076a..56f5502baadf 100644
@@ -24,6 +24,7 @@
 
 #define MTK_COREDUMP_SIZE              (1024 * 1000)
 #define MTK_COREDUMP_END               "coredump end"
+#define MTK_COREDUMP_END_LEN           (sizeof(MTK_COREDUMP_END))
 #define MTK_COREDUMP_NUM               255
 
 enum {
--

2.18.0

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw
Quoted 12 lines · Luiz Augusto von Dentz

External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi Chris,

Quoted 5 lines · Chris Lu

There may be a potential null pointer risk if offset value is less than 0 when doing memcmp in btmtk_process_coredump(). Check offset is valid before doing memcmp.

Quoted 8 lines
Quoted 3 lines

You should probably include the Fixes tag of the patch that introduced
the problem.

Hi Luiz,

Thanks for reminding, I'll update Bug ad fixs info in commit message and send the v5 patch.

BRs,
Chris

Quoted 58 lines

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev

Quoted 14 lines

---
v2: fix typo
v3: fix bot checking error
v4: reduce variable 'offset' declaration in v3

---
 drivers/bluetooth/btmtk.c | 12 ++++++------
 drivers/bluetooth/btmtk.h |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/bluetooth/btmtk.c +0 -0
index 786f775196ae..9cc789272ab7 100644
@@ -395,12 +395,12 @@ int btmtk_process_coredump(struct hci_dev

*hdev, struct sk_buff *skb)

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev · line 395

Quoted 2 lines
drivers/bluetooth/btmtk.c +0 -0
                /* Mediatek coredump data would be more than

MTK_COREDUMP_NUM */

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)

Quoted 3 lines
drivers/bluetooth/btmtk.c +0 -2
                if (data->cd_info.cnt > MTK_COREDUMP_NUM &&
-                   skb->len > sizeof(MTK_COREDUMP_END) &&
-                   !memcmp((char *)&skb->data[skb->len -

sizeof(MTK_COREDUMP_END)],

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev · line 399

Quoted 1 line
drivers/bluetooth/btmtk.c +0 -1
-                           MTK_COREDUMP_END,

sizeof(MTK_COREDUMP_END) - 1)) {

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)

Quoted 5 lines
drivers/bluetooth/btmtk.c +2 -3
-                       bt_dev_info(hdev, "Mediatek coredump end");
-                       hci_devcd_complete(hdev);
-               }
+                   skb->len > MTK_COREDUMP_END_LEN)
+                       if (!memcmp((char *)&skb->data[skb->len -

MTK_COREDUMP_END_LEN],

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev · line 399

Quoted 1 line
drivers/bluetooth/btmtk.c +1 -0
+                           MTK_COREDUMP_END, MTK_COREDUMP_END_LEN

- 1)) {

drivers/bluetooth/btmtk.c int btmtk_process_coredump(struct hci_dev · line 400

Quoted 1 line
drivers/bluetooth/btmtk.c +1 -0
+                               bt_dev_info(hdev, "Mediatek

coredump end");

Quoted 20 lines
drivers/bluetooth/btmtk.c +2 -0
+                               hci_devcd_complete(hdev);
+                       }
 
                break;
        }
drivers/bluetooth/btmtk.h +1 -1
index 68309dfe076a..56f5502baadf 100644
@@ -24,6 +24,7 @@
 
 #define MTK_COREDUMP_SIZE              (1024 * 1000)
 #define MTK_COREDUMP_END               "coredump end"
+#define MTK_COREDUMP_END_LEN           (sizeof(MTK_COREDUMP_END))
 #define MTK_COREDUMP_NUM               255
 
 enum {
--

2.18.0

Signature · 1 line
Luiz Augusto von Dentz