diff mbox series

Bluetooth: btmtk: Fix null pointer when processing coredump

Message ID 20230712033229.12339-1-chris.lu@mediatek.com (mailing list archive)
State Superseded
Headers show
Series Bluetooth: btmtk: Fix null pointer when processing coredump | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING: Co-developed-by: must be immediately followed by Signed-off-by: #85: Co-developed-by: Sean Wang <sean.wang@mediatek.com> --- total: 0 errors, 1 warnings, 30 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13309548.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint success Gitlint PASS
tedd_an/SubjectPrefix success Gitlint PASS
tedd_an/BuildKernel fail BuildKernel: FAIL: drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2
tedd_an/CheckAllWarning fail CheckAllWarning: FAIL: drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2
tedd_an/CheckSparse fail CheckSparse: FAIL: net/bluetooth/af_bluetooth.c:223:25: warning: context imbalance in 'bt_accept_enqueue' - different lock contexts for basic block drivers/bluetooth/hci_ag6xx.c:257:24: warning: restricted __le32 degrades to integer drivers/bluetooth/hci_mrvl.c:170:23: warning: restricted __le16 degrades to integer drivers/bluetooth/hci_mrvl.c:203:23: warning: restricted __le16 degrades to integer net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): ./include/net/bluetooth/hci.h:2658:47: warning: array of flexible structures ./include/net/bluetooth/hci.h:2744:43: warning: array of flexible structures drivers/bluetooth/btmtksdio.c:557:63: warning: Using plain integer as NULL pointer drivers/bluetooth/btmtksdio.c:579:55: warning: Using plain integer as NULL pointer drivers/bluetooth/btmtksdio.c:611:63: warning: Using plain integer as NULL pointer drivers/bluetooth/btmtksdio.c:624:63: warning: Using plain integer as NULL pointer drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... net/bluetooth/hci_codec.c: note: in included file: ./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures net/bluetooth/sco.c: note: in included file: ./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2
tedd_an/CheckSmatch fail CheckSparse: FAIL: net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h): ./include/net/bluetooth/hci.h:2658:47: warning: array of flexible structures ./include/net/bluetooth/hci.h:2744:43: warning: array of flexible structures drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... net/bluetooth/hci_codec.c: note: in included file: ./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures net/bluetooth/sco.c: note: in included file: ./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2
tedd_an/BuildKernel32 fail BuildKernel32: FAIL: drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2
tedd_an/TestRunnerSetup success TestRunnerSetup PASS
tedd_an/TestRunner_l2cap-tester success TestRunner PASS
tedd_an/TestRunner_iso-tester success TestRunner PASS
tedd_an/TestRunner_bnep-tester success TestRunner PASS
tedd_an/TestRunner_mgmt-tester success TestRunner PASS
tedd_an/TestRunner_rfcomm-tester success TestRunner PASS
tedd_an/TestRunner_sco-tester success TestRunner PASS
tedd_an/TestRunner_ioctl-tester success TestRunner PASS
tedd_an/TestRunner_mesh-tester success TestRunner PASS
tedd_an/TestRunner_smp-tester success TestRunner PASS
tedd_an/TestRunner_userchan-tester success TestRunner PASS
tedd_an/IncrementalBuild fail Bluetooth: btmtk: Fix null pointer when processing coredump drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’ 398 | if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0) | ^ make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1 make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:477: drivers] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2 make: *** [Makefile:234: __sub-make] Error 2

Commit Message

Chris Lu July 12, 2023, 3:32 a.m. UTC
There may be a potential null pointer risk if offset value is
less than 0 when doing memcmp in btmtk_process_coredump().
Checking offset is valid before doing memcmp.

Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Co-developed-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/bluetooth/btmtk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

bluez.test.bot@gmail.com July 12, 2023, 4:07 a.m. UTC | #1
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=764632

---Test result---

Test Summary:
CheckPatch                    FAIL      0.89 seconds
GitLint                       PASS      0.22 seconds
SubjectPrefix                 PASS      0.06 seconds
BuildKernel                   FAIL      34.11 seconds
CheckAllWarning               FAIL      37.03 seconds
CheckSparse                   FAIL      42.07 seconds
CheckSmatch                   FAIL      113.08 seconds
BuildKernel32                 FAIL      32.88 seconds
TestRunnerSetup               PASS      501.34 seconds
TestRunner_l2cap-tester       PASS      24.05 seconds
TestRunner_iso-tester         PASS      42.97 seconds
TestRunner_bnep-tester        PASS      10.86 seconds
TestRunner_mgmt-tester        PASS      220.20 seconds
TestRunner_rfcomm-tester      PASS      16.15 seconds
TestRunner_sco-tester         PASS      17.06 seconds
TestRunner_ioctl-tester       PASS      18.50 seconds
TestRunner_mesh-tester        PASS      13.52 seconds
TestRunner_smp-tester         PASS      14.45 seconds
TestRunner_userchan-tester    PASS      11.27 seconds
IncrementalBuild              FAIL      31.44 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
Bluetooth: btmtk: Fix null pointer when processing coredump
WARNING: Co-developed-by: must be immediately followed by Signed-off-by:
#85: 
Co-developed-by: Sean Wang <sean.wang@mediatek.com>
---

total: 0 errors, 1 warnings, 30 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13309548.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: BuildKernel - FAIL
Desc: Build Kernel for Bluetooth
Output:

drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2
##############################
Test: CheckAllWarning - FAIL
Desc: Run linux kernel with all warning enabled
Output:

drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2
##############################
Test: CheckSparse - FAIL
Desc: Run sparse tool with linux kernel
Output:

net/bluetooth/af_bluetooth.c:223:25: warning: context imbalance in 'bt_accept_enqueue' - different lock contexts for basic block
drivers/bluetooth/hci_ag6xx.c:257:24: warning: restricted __le32 degrades to integer
drivers/bluetooth/hci_mrvl.c:170:23: warning: restricted __le16 degrades to integer
drivers/bluetooth/hci_mrvl.c:203:23: warning: restricted __le16 degrades to integer
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
./include/net/bluetooth/hci.h:2658:47: warning: array of flexible structures
./include/net/bluetooth/hci.h:2744:43: warning: array of flexible structures
drivers/bluetooth/btmtksdio.c:557:63: warning: Using plain integer as NULL pointer
drivers/bluetooth/btmtksdio.c:579:55: warning: Using plain integer as NULL pointer
drivers/bluetooth/btmtksdio.c:611:63: warning: Using plain integer as NULL pointer
drivers/bluetooth/btmtksdio.c:624:63: warning: Using plain integer as NULL pointer
drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
net/bluetooth/hci_codec.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/sco.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
./include/net/bluetooth/hci.h:2658:47: warning: array of flexible structures
./include/net/bluetooth/hci.h:2744:43: warning: array of flexible structures
drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
net/bluetooth/hci_codec.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/sco.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2
##############################
Test: BuildKernel32 - FAIL
Desc: Build 32bit Kernel for Bluetooth
Output:

drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series
Output:
Bluetooth: btmtk: Fix null pointer when processing coredump

drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:398:20: error: ‘struct btmtk_coredump_info’ has no member named ‘dump_cnt’
  398 |   if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
      |                    ^
make[4]: *** [scripts/Makefile.build:243: drivers/bluetooth/btmtk.o] Error 1
make[3]: *** [scripts/Makefile.build:477: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:477: drivers] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/github/workspace/src/src/Makefile:2020: .] Error 2
make: *** [Makefile:234: __sub-make] Error 2


---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index 786f775196ae..9ae46b4c98b9 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -370,7 +370,7 @@  EXPORT_SYMBOL_GPL(btmtk_register_coredump);
 int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct btmediatek_data *data = hci_get_priv(hdev);
-	int err;
+	int err, offset;
 
 	if (!IS_ENABLED(CONFIG_DEV_COREDUMP))
 		return 0;
@@ -392,15 +392,15 @@  int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 		if (err < 0)
 			break;
 		data->cd_info.cnt++;
+		offset = skb->len - sizeof(MTK_COREDUMP_END);
 
 		/* 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);
-		}
+		if (data->cd_info.dump_cnt > MTK_COREDUMP_NUM && offset > 0)
+			if (!memcmp((char *)&skb->data[offset], MTK_COREDUMP_END,
+				    sizeof(MTK_COREDUMP_END) - 1)) {
+				bt_dev_info(hdev, "Mediatek coredump end");
+				hci_devcd_complete(hdev);
+			}
 
 		break;
 	}