forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/drivers/net/wireless/ath/ath9k/htc_hst.c
....@@ -30,6 +30,7 @@
3030 hdr->endpoint_id = epid;
3131 hdr->flags = flags;
3232 hdr->payload_len = cpu_to_be16(len);
33
+ memset(hdr->control, 0, sizeof(hdr->control));
3334
3435 status = target->hif->send(target->hif_dev, endpoint->ul_pipeid, skb);
3536
....@@ -173,7 +174,6 @@
173174 time_left = wait_for_completion_timeout(&target->cmd_wait, HZ);
174175 if (!time_left) {
175176 dev_err(target->dev, "HTC credit config timeout\n");
176
- kfree_skb(skb);
177177 return -ETIMEDOUT;
178178 }
179179
....@@ -209,7 +209,6 @@
209209 time_left = wait_for_completion_timeout(&target->cmd_wait, HZ);
210210 if (!time_left) {
211211 dev_err(target->dev, "HTC start timeout\n");
212
- kfree_skb(skb);
213212 return -ETIMEDOUT;
214213 }
215214
....@@ -274,6 +273,10 @@
274273 conn_msg->dl_pipeid = endpoint->dl_pipeid;
275274 conn_msg->ul_pipeid = endpoint->ul_pipeid;
276275
276
+ /* To prevent infoleak */
277
+ conn_msg->svc_meta_len = 0;
278
+ conn_msg->pad = 0;
279
+
277280 ret = htc_issue_send(target, skb, skb->len, 0, ENDPOINT0);
278281 if (ret)
279282 goto err;
....@@ -282,7 +285,6 @@
282285 if (!time_left) {
283286 dev_err(target->dev, "Service connection timeout for: %d\n",
284287 service_connreq->service_id);
285
- kfree_skb(skb);
286288 return -ETIMEDOUT;
287289 }
288290
....@@ -362,33 +364,27 @@
362364 }
363365
364366 static void ath9k_htc_fw_panic_report(struct htc_target *htc_handle,
365
- struct sk_buff *skb)
367
+ struct sk_buff *skb, u32 len)
366368 {
367369 uint32_t *pattern = (uint32_t *)skb->data;
368370
369
- switch (*pattern) {
370
- case 0x33221199:
371
- {
371
+ if (*pattern == 0x33221199 && len >= sizeof(struct htc_panic_bad_vaddr)) {
372372 struct htc_panic_bad_vaddr *htc_panic;
373373 htc_panic = (struct htc_panic_bad_vaddr *) skb->data;
374374 dev_err(htc_handle->dev, "ath: firmware panic! "
375375 "exccause: 0x%08x; pc: 0x%08x; badvaddr: 0x%08x.\n",
376376 htc_panic->exccause, htc_panic->pc,
377377 htc_panic->badvaddr);
378
- break;
379
- }
380
- case 0x33221299:
381
- {
378
+ return;
379
+ }
380
+ if (*pattern == 0x33221299) {
382381 struct htc_panic_bad_epid *htc_panic;
383382 htc_panic = (struct htc_panic_bad_epid *) skb->data;
384383 dev_err(htc_handle->dev, "ath: firmware panic! "
385384 "bad epid: 0x%08x\n", htc_panic->epid);
386
- break;
387
- }
388
- default:
389
- dev_err(htc_handle->dev, "ath: unknown panic pattern!\n");
390
- break;
385
+ return;
391386 }
387
+ dev_err(htc_handle->dev, "ath: unknown panic pattern!\n");
392388 }
393389
394390 /*
....@@ -409,16 +405,26 @@
409405 if (!htc_handle || !skb)
410406 return;
411407
408
+ /* A valid message requires len >= 8.
409
+ *
410
+ * sizeof(struct htc_frame_hdr) == 8
411
+ * sizeof(struct htc_ready_msg) == 8
412
+ * sizeof(struct htc_panic_bad_vaddr) == 16
413
+ * sizeof(struct htc_panic_bad_epid) == 8
414
+ */
415
+ if (unlikely(len < sizeof(struct htc_frame_hdr)))
416
+ goto invalid;
412417 htc_hdr = (struct htc_frame_hdr *) skb->data;
413418 epid = htc_hdr->endpoint_id;
414419
415420 if (epid == 0x99) {
416
- ath9k_htc_fw_panic_report(htc_handle, skb);
421
+ ath9k_htc_fw_panic_report(htc_handle, skb, len);
417422 kfree_skb(skb);
418423 return;
419424 }
420425
421426 if (epid < 0 || epid >= ENDPOINT_MAX) {
427
+invalid:
422428 if (pipe_id != USB_REG_IN_PIPE)
423429 dev_kfree_skb_any(skb);
424430 else
....@@ -430,21 +436,30 @@
430436
431437 /* Handle trailer */
432438 if (htc_hdr->flags & HTC_FLAGS_RECV_TRAILER) {
433
- if (be32_to_cpu(*(__be32 *) skb->data) == 0x00C60000)
439
+ if (be32_to_cpu(*(__be32 *) skb->data) == 0x00C60000) {
434440 /* Move past the Watchdog pattern */
435441 htc_hdr = (struct htc_frame_hdr *)(skb->data + 4);
442
+ len -= 4;
443
+ }
436444 }
437445
438446 /* Get the message ID */
447
+ if (unlikely(len < sizeof(struct htc_frame_hdr) + sizeof(__be16)))
448
+ goto invalid;
439449 msg_id = (__be16 *) ((void *) htc_hdr +
440450 sizeof(struct htc_frame_hdr));
441451
442452 /* Now process HTC messages */
443453 switch (be16_to_cpu(*msg_id)) {
444454 case HTC_MSG_READY_ID:
455
+ if (unlikely(len < sizeof(struct htc_ready_msg)))
456
+ goto invalid;
445457 htc_process_target_rdy(htc_handle, htc_hdr);
446458 break;
447459 case HTC_MSG_CONNECT_SERVICE_RESPONSE_ID:
460
+ if (unlikely(len < sizeof(struct htc_frame_hdr) +
461
+ sizeof(struct htc_conn_svc_rspmsg)))
462
+ goto invalid;
448463 htc_process_conn_rsp(htc_handle, htc_hdr);
449464 break;
450465 default: