test_kernel.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Test a few kernel bugs
  2. # Copyright (c) 2016, Intel Deutschland GmbH
  3. #
  4. # Author: Johannes Berg <johannes.berg@intel.com>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import hostapd
  9. import binascii
  10. def _test_kernel_bss_leak(dev, apdev, deauth):
  11. ssid = "test-bss-leak"
  12. passphrase = 'qwertyuiop'
  13. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  14. hapd = hostapd.add_ap(apdev[0], params)
  15. hapd.set("ext_mgmt_frame_handling", "1")
  16. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  17. while True:
  18. pkt = hapd.mgmt_rx()
  19. if not pkt:
  20. raise Exception("MGMT RX wait timed out for auth frame")
  21. if pkt['fc'] & 0xc:
  22. continue
  23. if pkt['subtype'] == 0: # assoc request
  24. if deauth:
  25. # return a deauth immediately
  26. hapd.mgmt_tx({
  27. 'fc': 0xc0,
  28. 'sa': pkt['da'],
  29. 'da': pkt['sa'],
  30. 'bssid': pkt['bssid'],
  31. 'payload': '\x01\x00',
  32. })
  33. break
  34. else:
  35. hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % (
  36. binascii.hexlify(pkt['frame']), ))
  37. hapd.set("ext_mgmt_frame_handling", "0")
  38. hapd.request("STOP_AP")
  39. dev[0].request("REMOVE_NETWORK all")
  40. dev[0].wait_disconnected()
  41. dev[0].flush_scan_cache(freq=5180)
  42. res = dev[0].request("SCAN_RESULTS")
  43. if len(res.splitlines()) > 1:
  44. raise Exception("BSS entry should no longer be around")
  45. def test_kernel_bss_leak_deauth(dev, apdev):
  46. """cfg80211/mac80211 BSS leak on deauthentication"""
  47. return _test_kernel_bss_leak(dev, apdev, deauth=True)
  48. def test_kernel_bss_leak_timeout(dev, apdev):
  49. """cfg80211/mac80211 BSS leak on timeout"""
  50. return _test_kernel_bss_leak(dev, apdev, deauth=False)