343-v5.2-brcmfmac-fix-Oops-when-bringing-up-interface-during-.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From 24d413a31afaee9bbbf79226052c386b01780ce2 Mon Sep 17 00:00:00 2001
  2. From: Piotr Figiel <p.figiel@camlintechnologies.com>
  3. Date: Wed, 13 Mar 2019 09:52:01 +0000
  4. Subject: [PATCH] brcmfmac: fix Oops when bringing up interface during USB
  5. disconnect
  6. Fix a race which leads to an Oops with NULL pointer dereference. The
  7. dereference is in brcmf_config_dongle() when cfg_to_ndev() attempts to get
  8. net_device structure of interface with index 0 via if2bss mapping. This
  9. shouldn't fail because of check for bus being ready in brcmf_netdev_open(),
  10. but it's not synchronised with USB disconnect and there is a race: after
  11. the check the bus can be marked down and the mapping for interface 0 may be
  12. gone.
  13. Solve this by modifying disconnect handling so that the removal of mapping
  14. of ifidx to brcmf_if structure happens after netdev removal (which is
  15. synchronous with brcmf_netdev_open() thanks to rtln being locked in
  16. devinet_ioctl()). This assures brcmf_netdev_open() returns before the
  17. mapping is removed during disconnect.
  18. Unable to handle kernel NULL pointer dereference at virtual address 00000008
  19. pgd = bcae2612
  20. [00000008] *pgd=8be73831
  21. Internal error: Oops: 17 [#1] PREEMPT SMP ARM
  22. Modules linked in: brcmfmac brcmutil nf_log_ipv4 nf_log_common xt_LOG xt_limit
  23. iptable_mangle xt_connmark xt_tcpudp xt_conntrack nf_conntrack nf_defrag_ipv6
  24. nf_defrag_ipv4 iptable_filter ip_tables x_tables usb_f_mass_storage usb_f_rndis
  25. u_ether usb_serial_simple usbserial cdc_acm smsc95xx usbnet ci_hdrc_imx ci_hdrc
  26. usbmisc_imx ulpi 8250_exar 8250_pci 8250 8250_base libcomposite configfs
  27. udc_core [last unloaded: brcmutil]
  28. CPU: 2 PID: 24478 Comm: ifconfig Not tainted 4.19.23-00078-ga62866d-dirty #115
  29. Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
  30. PC is at brcmf_cfg80211_up+0x94/0x29c [brcmfmac]
  31. LR is at brcmf_cfg80211_up+0x8c/0x29c [brcmfmac]
  32. pc : [<7f26a91c>] lr : [<7f26a914>] psr: a0070013
  33. sp : eca99d28 ip : 00000000 fp : ee9c6c00
  34. r10: 00000036 r9 : 00000000 r8 : ece4002c
  35. r7 : edb5b800 r6 : 00000000 r5 : 80f08448 r4 : edb5b968
  36. r3 : ffffffff r2 : 00000000 r1 : 00000002 r0 : 00000000
  37. Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
  38. Control: 10c5387d Table: 7ca0c04a DAC: 00000051
  39. Process ifconfig (pid: 24478, stack limit = 0xd9e85a0e)
  40. Stack: (0xeca99d28 to 0xeca9a000)
  41. 9d20: 00000000 80f873b0 0000000d 80f08448 eca99d68 50d45f32
  42. 9d40: 7f27de94 ece40000 80f08448 80f08448 7f27de94 ece4002c 00000000 00000036
  43. 9d60: ee9c6c00 7f27262c 00001002 50d45f32 ece40000 00000000 80f08448 80772008
  44. 9d80: 00000001 00001043 00001002 ece40000 00000000 50d45f32 ece40000 00000001
  45. 9da0: 80f08448 00001043 00001002 807723d0 00000000 50d45f32 80f08448 eca99e58
  46. 9dc0: 80f87113 50d45f32 80f08448 ece40000 ece40138 00001002 80f08448 00000000
  47. 9de0: 00000000 80772434 edbd5380 eca99e58 edbd5380 80f08448 ee9c6c0c 80805f70
  48. 9e00: 00000000 ede08e00 00008914 ece40000 00000014 ee9c6c0c 600c0013 00001043
  49. 9e20: 0208a8c0 ffffffff 00000000 50d45f32 eca98000 80f08448 7ee9fc38 00008914
  50. 9e40: 80f68e40 00000051 eca98000 00000036 00000003 80808b9c 6e616c77 00000030
  51. 9e60: 00000000 00000000 00001043 0208a8c0 ffffffff 00000000 80f08448 00000000
  52. 9e80: 00000000 816d8b20 600c0013 00000001 ede09320 801763d4 00000000 50d45f32
  53. 9ea0: eca98000 80f08448 7ee9fc38 50d45f32 00008914 80f08448 7ee9fc38 80f68e40
  54. 9ec0: ed531540 8074721c 00000800 00000001 00000000 6e616c77 00000030 00000000
  55. 9ee0: 00000000 00001002 0208a8c0 ffffffff 00000000 50d45f32 80f08448 7ee9fc38
  56. 9f00: ed531560 ec8fc900 80285a6c 80285138 edb910c0 00000000 ecd91008 ede08e00
  57. 9f20: 80f08448 00000000 00000000 816d8b20 600c0013 00000001 ede09320 801763d4
  58. 9f40: 00000000 50d45f32 00021000 edb91118 edb910c0 80f08448 01b29000 edb91118
  59. 9f60: eca99f7c 50d45f32 00021000 ec8fc900 00000003 ec8fc900 00008914 7ee9fc38
  60. 9f80: eca98000 00000036 00000003 80285a6c 00086364 7ee9fe1c 000000c3 00000036
  61. 9fa0: 801011c4 80101000 00086364 7ee9fe1c 00000003 00008914 7ee9fc38 00086364
  62. 9fc0: 00086364 7ee9fe1c 000000c3 00000036 0008630c 7ee9fe1c 7ee9fc38 00000003
  63. 9fe0: 000a42b8 7ee9fbd4 00019914 76e09acc 600c0010 00000003 00000000 00000000
  64. [<7f26a91c>] (brcmf_cfg80211_up [brcmfmac]) from [<7f27262c>] (brcmf_netdev_open+0x74/0xe8 [brcmfmac])
  65. [<7f27262c>] (brcmf_netdev_open [brcmfmac]) from [<80772008>] (__dev_open+0xcc/0x150)
  66. [<80772008>] (__dev_open) from [<807723d0>] (__dev_change_flags+0x168/0x1b4)
  67. [<807723d0>] (__dev_change_flags) from [<80772434>] (dev_change_flags+0x18/0x48)
  68. [<80772434>] (dev_change_flags) from [<80805f70>] (devinet_ioctl+0x67c/0x79c)
  69. [<80805f70>] (devinet_ioctl) from [<80808b9c>] (inet_ioctl+0x210/0x3d4)
  70. [<80808b9c>] (inet_ioctl) from [<8074721c>] (sock_ioctl+0x350/0x524)
  71. [<8074721c>] (sock_ioctl) from [<80285138>] (do_vfs_ioctl+0xb0/0x9b0)
  72. [<80285138>] (do_vfs_ioctl) from [<80285a6c>] (ksys_ioctl+0x34/0x5c)
  73. [<80285a6c>] (ksys_ioctl) from [<80101000>] (ret_fast_syscall+0x0/0x28)
  74. Exception stack(0xeca99fa8 to 0xeca99ff0)
  75. 9fa0: 00086364 7ee9fe1c 00000003 00008914 7ee9fc38 00086364
  76. 9fc0: 00086364 7ee9fe1c 000000c3 00000036 0008630c 7ee9fe1c 7ee9fc38 00000003
  77. 9fe0: 000a42b8 7ee9fbd4 00019914 76e09acc
  78. Code: e5970328 eb002021 e1a02006 e3a01002 (e5909008)
  79. ---[ end trace 5cbac2333f3ac5df ]---
  80. Signed-off-by: Piotr Figiel <p.figiel@camlintechnologies.com>
  81. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  82. ---
  83. .../net/wireless/broadcom/brcm80211/brcmfmac/core.c | 10 +++++++---
  84. 1 file changed, 7 insertions(+), 3 deletions(-)
  85. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  86. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
  87. @@ -810,17 +810,17 @@ static void brcmf_del_if(struct brcmf_pu
  88. bool rtnl_locked)
  89. {
  90. struct brcmf_if *ifp;
  91. + int ifidx;
  92. ifp = drvr->iflist[bsscfgidx];
  93. - drvr->iflist[bsscfgidx] = NULL;
  94. if (!ifp) {
  95. bphy_err(drvr, "Null interface, bsscfgidx=%d\n", bsscfgidx);
  96. return;
  97. }
  98. brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx,
  99. ifp->ifidx);
  100. - if (drvr->if2bss[ifp->ifidx] == bsscfgidx)
  101. - drvr->if2bss[ifp->ifidx] = BRCMF_BSSIDX_INVALID;
  102. + ifidx = ifp->ifidx;
  103. +
  104. if (ifp->ndev) {
  105. if (bsscfgidx == 0) {
  106. if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
  107. @@ -848,6 +848,10 @@ static void brcmf_del_if(struct brcmf_pu
  108. brcmf_p2p_ifp_removed(ifp, rtnl_locked);
  109. kfree(ifp);
  110. }
  111. +
  112. + drvr->iflist[bsscfgidx] = NULL;
  113. + if (drvr->if2bss[ifidx] == bsscfgidx)
  114. + drvr->if2bss[ifidx] = BRCMF_BSSIDX_INVALID;
  115. }
  116. void brcmf_remove_interface(struct brcmf_if *ifp, bool rtnl_locked)