319-v4.12-0043-brcmfmac-add-length-checks-in-scheduled-scan-result-.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 4835f37e3bafc138f8bfa3cbed2920dd56fed283 Mon Sep 17 00:00:00 2001
  2. From: Arend Van Spriel <arend.vanspriel@broadcom.com>
  3. Date: Thu, 6 Apr 2017 13:14:40 +0100
  4. Subject: [PATCH] brcmfmac: add length checks in scheduled scan result handler
  5. Assure the event data buffer is long enough to hold the array
  6. of netinfo items and that SSID length does not exceed the maximum
  7. of 32 characters as per 802.11 spec.
  8. Reviewed-by: Hante Meuleman <hante.meuleman@broadcom.com>
  9. Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
  10. Reviewed-by: Franky Lin <franky.lin@broadcom.com>
  11. Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
  12. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  13. ---
  14. .../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 13 +++++++++++--
  15. 1 file changed, 11 insertions(+), 2 deletions(-)
  16. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  17. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  18. @@ -3300,6 +3300,7 @@ brcmf_notify_sched_scan_results(struct b
  19. struct brcmf_pno_scanresults_le *pfn_result;
  20. u32 result_count;
  21. u32 status;
  22. + u32 datalen;
  23. brcmf_dbg(SCAN, "Enter\n");
  24. @@ -3326,6 +3327,14 @@ brcmf_notify_sched_scan_results(struct b
  25. brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
  26. goto out_err;
  27. }
  28. +
  29. + netinfo_start = brcmf_get_netinfo_array(pfn_result);
  30. + datalen = e->datalen - ((void *)netinfo_start - (void *)pfn_result);
  31. + if (datalen < result_count * sizeof(*netinfo)) {
  32. + brcmf_err("insufficient event data\n");
  33. + goto out_err;
  34. + }
  35. +
  36. request = brcmf_alloc_internal_escan_request(wiphy,
  37. result_count);
  38. if (!request) {
  39. @@ -3333,8 +3342,6 @@ brcmf_notify_sched_scan_results(struct b
  40. goto out_err;
  41. }
  42. - netinfo_start = brcmf_get_netinfo_array(pfn_result);
  43. -
  44. for (i = 0; i < result_count; i++) {
  45. netinfo = &netinfo_start[i];
  46. if (!netinfo) {
  47. @@ -3344,6 +3351,8 @@ brcmf_notify_sched_scan_results(struct b
  48. goto out_err;
  49. }
  50. + if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
  51. + netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
  52. brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n",
  53. netinfo->SSID, netinfo->channel);
  54. err = brcmf_internal_escan_add_info(request,