341-v5.2-0002-brcmfmac-fix-NULL-pointer-derefence-during-USB-disco.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. From 5cdb0ef6144f47440850553579aa923c20a63f23 Mon Sep 17 00:00:00 2001
  2. From: Piotr Figiel <p.figiel@camlintechnologies.com>
  3. Date: Mon, 4 Mar 2019 15:42:52 +0000
  4. Subject: [PATCH] brcmfmac: fix NULL pointer derefence during USB disconnect
  5. In case USB disconnect happens at the moment transmitting workqueue is in
  6. progress the underlying interface may be gone causing a NULL pointer
  7. dereference. Add synchronization of the workqueue destruction with the
  8. detach implementation in core so that the transmitting workqueue is stopped
  9. during detach before the interfaces are removed.
  10. Fix following Oops:
  11. Unable to handle kernel NULL pointer dereference at virtual address 00000008
  12. pgd = 9e6a802d
  13. [00000008] *pgd=00000000
  14. Internal error: Oops: 5 [#1] PREEMPT SMP ARM
  15. Modules linked in: nf_log_ipv4 nf_log_common xt_LOG xt_limit iptable_mangle
  16. xt_connmark xt_tcpudp xt_conntrack nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4
  17. iptable_filter ip_tables x_tables usb_f_mass_storage usb_f_rndis u_ether
  18. usb_serial_simple usbserial cdc_acm brcmfmac brcmutil smsc95xx usbnet
  19. ci_hdrc_imx ci_hdrc ulpi usbmisc_imx 8250_exar 8250_pci 8250 8250_base
  20. libcomposite configfs udc_core
  21. CPU: 0 PID: 7 Comm: kworker/u8:0 Not tainted 4.19.23-00076-g03740aa-dirty #102
  22. Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
  23. Workqueue: brcmf_fws_wq brcmf_fws_dequeue_worker [brcmfmac]
  24. PC is at brcmf_txfinalize+0x34/0x90 [brcmfmac]
  25. LR is at brcmf_fws_dequeue_worker+0x218/0x33c [brcmfmac]
  26. pc : [<7f0dee64>] lr : [<7f0e4140>] psr: 60010093
  27. sp : ee8abef0 ip : 00000000 fp : edf38000
  28. r10: ffffffed r9 : edf38970 r8 : edf38004
  29. r7 : edf3e970 r6 : 00000000 r5 : ede69000 r4 : 00000000
  30. r3 : 00000a97 r2 : 00000000 r1 : 0000888e r0 : ede69000
  31. Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none
  32. Control: 10c5387d Table: 7d03c04a DAC: 00000051
  33. Process kworker/u8:0 (pid: 7, stack limit = 0x24ec3e04)
  34. Stack: (0xee8abef0 to 0xee8ac000)
  35. bee0: ede69000 00000000 ed56c3e0 7f0e4140
  36. bf00: 00000001 00000000 edf38004 edf3e99c ed56c3e0 80d03d00 edfea43a edf3e970
  37. bf20: ee809880 ee804200 ee971100 00000000 edf3e974 00000000 ee804200 80135a70
  38. bf40: 80d03d00 ee804218 ee809880 ee809894 ee804200 80d03d00 ee804218 ee8aa000
  39. bf60: 00000088 80135d5c 00000000 ee829f00 ee829dc0 00000000 ee809880 80135d30
  40. bf80: ee829f1c ee873eac 00000000 8013b1a0 ee829dc0 8013b07c 00000000 00000000
  41. bfa0: 00000000 00000000 00000000 801010e8 00000000 00000000 00000000 00000000
  42. bfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  43. bfe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
  44. [<7f0dee64>] (brcmf_txfinalize [brcmfmac]) from [<7f0e4140>] (brcmf_fws_dequeue_worker+0x218/0x33c [brcmfmac])
  45. [<7f0e4140>] (brcmf_fws_dequeue_worker [brcmfmac]) from [<80135a70>] (process_one_work+0x138/0x3f8)
  46. [<80135a70>] (process_one_work) from [<80135d5c>] (worker_thread+0x2c/0x554)
  47. [<80135d5c>] (worker_thread) from [<8013b1a0>] (kthread+0x124/0x154)
  48. [<8013b1a0>] (kthread) from [<801010e8>] (ret_from_fork+0x14/0x2c)
  49. Exception stack(0xee8abfb0 to 0xee8abff8)
  50. bfa0: 00000000 00000000 00000000 00000000
  51. bfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  52. bfe0: 00000000 00000000 00000000 00000000 00000013 00000000
  53. Code: e1530001 0a000007 e3560000 e1a00005 (05942008)
  54. ---[ end trace 079239dd31c86e90 ]---
  55. Signed-off-by: Piotr Figiel <p.figiel@camlintechnologies.com>
  56. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  57. ---
  58. .../wireless/broadcom/brcm80211/brcmfmac/bcdc.c | 11 +++++++++--
  59. .../wireless/broadcom/brcm80211/brcmfmac/bcdc.h | 6 ++++--
  60. .../wireless/broadcom/brcm80211/brcmfmac/core.c | 4 +++-
  61. .../broadcom/brcm80211/brcmfmac/fwsignal.c | 16 ++++++++++++----
  62. .../broadcom/brcm80211/brcmfmac/fwsignal.h | 3 ++-
  63. .../wireless/broadcom/brcm80211/brcmfmac/proto.c | 10 ++++++++--
  64. .../wireless/broadcom/brcm80211/brcmfmac/proto.h | 3 ++-
  65. 7 files changed, 40 insertions(+), 13 deletions(-)
  66. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c
  67. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c
  68. @@ -479,11 +479,18 @@ fail:
  69. return -ENOMEM;
  70. }
  71. -void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr)
  72. +void brcmf_proto_bcdc_detach_pre_delif(struct brcmf_pub *drvr)
  73. +{
  74. + struct brcmf_bcdc *bcdc = drvr->proto->pd;
  75. +
  76. + brcmf_fws_detach_pre_delif(bcdc->fws);
  77. +}
  78. +
  79. +void brcmf_proto_bcdc_detach_post_delif(struct brcmf_pub *drvr)
  80. {
  81. struct brcmf_bcdc *bcdc = drvr->proto->pd;
  82. drvr->proto->pd = NULL;
  83. - brcmf_fws_detach(bcdc->fws);
  84. + brcmf_fws_detach_post_delif(bcdc->fws);
  85. kfree(bcdc);
  86. }
  87. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.h
  88. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.h
  89. @@ -18,14 +18,16 @@
  90. #ifdef CPTCFG_BRCMFMAC_PROTO_BCDC
  91. int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr);
  92. -void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr);
  93. +void brcmf_proto_bcdc_detach_pre_delif(struct brcmf_pub *drvr);
  94. +void brcmf_proto_bcdc_detach_post_delif(struct brcmf_pub *drvr);
  95. void brcmf_proto_bcdc_txflowblock(struct device *dev, bool state);
  96. void brcmf_proto_bcdc_txcomplete(struct device *dev, struct sk_buff *txp,
  97. bool success);
  98. struct brcmf_fws_info *drvr_to_fws(struct brcmf_pub *drvr);
  99. #else
  100. static inline int brcmf_proto_bcdc_attach(struct brcmf_pub *drvr) { return 0; }
  101. -static inline void brcmf_proto_bcdc_detach(struct brcmf_pub *drvr) {}
  102. +static void brcmf_proto_bcdc_detach_pre_delif(struct brcmf_pub *drvr) {};
  103. +static inline void brcmf_proto_bcdc_detach_post_delif(struct brcmf_pub *drvr) {}
  104. #endif
  105. #endif /* BRCMFMAC_BCDC_H */
  106. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  107. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  108. @@ -1290,6 +1290,8 @@ void brcmf_detach(struct device *dev)
  109. brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN);
  110. + brcmf_proto_detach_pre_delif(drvr);
  111. +
  112. /* make sure primary interface removed last */
  113. for (i = BRCMF_MAX_IFS-1; i > -1; i--)
  114. brcmf_remove_interface(drvr->iflist[i], false);
  115. @@ -1299,7 +1301,7 @@ void brcmf_detach(struct device *dev)
  116. brcmf_bus_stop(drvr->bus_if);
  117. - brcmf_proto_detach(drvr);
  118. + brcmf_proto_detach_post_delif(drvr);
  119. brcmf_debug_detach(drvr);
  120. bus_if->drvr = NULL;
  121. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c
  122. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c
  123. @@ -2420,17 +2420,25 @@ struct brcmf_fws_info *brcmf_fws_attach(
  124. return fws;
  125. fail:
  126. - brcmf_fws_detach(fws);
  127. + brcmf_fws_detach_pre_delif(fws);
  128. + brcmf_fws_detach_post_delif(fws);
  129. return ERR_PTR(rc);
  130. }
  131. -void brcmf_fws_detach(struct brcmf_fws_info *fws)
  132. +void brcmf_fws_detach_pre_delif(struct brcmf_fws_info *fws)
  133. {
  134. if (!fws)
  135. return;
  136. -
  137. - if (fws->fws_wq)
  138. + if (fws->fws_wq) {
  139. destroy_workqueue(fws->fws_wq);
  140. + fws->fws_wq = NULL;
  141. + }
  142. +}
  143. +
  144. +void brcmf_fws_detach_post_delif(struct brcmf_fws_info *fws)
  145. +{
  146. + if (!fws)
  147. + return;
  148. /* cleanup */
  149. brcmf_fws_lock(fws);
  150. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.h
  151. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.h
  152. @@ -19,7 +19,8 @@
  153. #define FWSIGNAL_H_
  154. struct brcmf_fws_info *brcmf_fws_attach(struct brcmf_pub *drvr);
  155. -void brcmf_fws_detach(struct brcmf_fws_info *fws);
  156. +void brcmf_fws_detach_pre_delif(struct brcmf_fws_info *fws);
  157. +void brcmf_fws_detach_post_delif(struct brcmf_fws_info *fws);
  158. bool brcmf_fws_queue_skbs(struct brcmf_fws_info *fws);
  159. bool brcmf_fws_fc_active(struct brcmf_fws_info *fws);
  160. void brcmf_fws_hdrpull(struct brcmf_if *ifp, s16 siglen, struct sk_buff *skb);
  161. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.c
  162. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.c
  163. @@ -66,16 +66,22 @@ fail:
  164. return -ENOMEM;
  165. }
  166. -void brcmf_proto_detach(struct brcmf_pub *drvr)
  167. +void brcmf_proto_detach_post_delif(struct brcmf_pub *drvr)
  168. {
  169. brcmf_dbg(TRACE, "Enter\n");
  170. if (drvr->proto) {
  171. if (drvr->bus_if->proto_type == BRCMF_PROTO_BCDC)
  172. - brcmf_proto_bcdc_detach(drvr);
  173. + brcmf_proto_bcdc_detach_post_delif(drvr);
  174. else if (drvr->bus_if->proto_type == BRCMF_PROTO_MSGBUF)
  175. brcmf_proto_msgbuf_detach(drvr);
  176. kfree(drvr->proto);
  177. drvr->proto = NULL;
  178. }
  179. }
  180. +
  181. +void brcmf_proto_detach_pre_delif(struct brcmf_pub *drvr)
  182. +{
  183. + if (drvr->proto && drvr->bus_if->proto_type == BRCMF_PROTO_BCDC)
  184. + brcmf_proto_bcdc_detach_pre_delif(drvr);
  185. +}
  186. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h
  187. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h
  188. @@ -53,7 +53,8 @@ struct brcmf_proto {
  189. int brcmf_proto_attach(struct brcmf_pub *drvr);
  190. -void brcmf_proto_detach(struct brcmf_pub *drvr);
  191. +void brcmf_proto_detach_pre_delif(struct brcmf_pub *drvr);
  192. +void brcmf_proto_detach_post_delif(struct brcmf_pub *drvr);
  193. static inline int brcmf_proto_hdrpull(struct brcmf_pub *drvr, bool do_fws,
  194. struct sk_buff *skb,