linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btmtk: Fix null pointer when processing coredump
@ 2023-07-12  3:32 Chris Lu
  2023-07-12  4:07 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Lu @ 2023-07-12  3:32 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
  Cc: Sean Wang, Aaron Hou, Steve Lee, linux-bluetooth, linux-kernel,
	linux-mediatek, Chris Lu

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(-)

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;
 	}
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: Bluetooth: btmtk: Fix null pointer when processing coredump
  2023-07-12  3:32 [PATCH] Bluetooth: btmtk: Fix null pointer when processing coredump Chris Lu
@ 2023-07-12  4:07 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2023-07-12  4:07 UTC (permalink / raw)
  To: linux-bluetooth, chris.lu

[-- Attachment #1: Type: text/plain, Size: 8437 bytes --]

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-12  4:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-12  3:32 [PATCH] Bluetooth: btmtk: Fix null pointer when processing coredump Chris Lu
2023-07-12  4:07 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).