its_sysfs.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Copyright (c) 2025 Intel Corporation
  5. #
  6. # Test for Indirect Target Selection(ITS) mitigation sysfs status.
  7. import sys, os, re
  8. this_dir = os.path.dirname(os.path.realpath(__file__))
  9. sys.path.insert(0, this_dir + '/../../kselftest')
  10. import ksft
  11. from common import *
  12. bug = "indirect_target_selection"
  13. mitigation = get_sysfs(bug)
  14. ITS_MITIGATION_ALIGNED_THUNKS = "Mitigation: Aligned branch/return thunks"
  15. ITS_MITIGATION_RETPOLINE_STUFF = "Mitigation: Retpolines, Stuffing RSB"
  16. ITS_MITIGATION_VMEXIT_ONLY = "Mitigation: Vulnerable, KVM: Not affected"
  17. ITS_MITIGATION_VULNERABLE = "Vulnerable"
  18. def check_mitigation():
  19. if mitigation == ITS_MITIGATION_ALIGNED_THUNKS:
  20. if cmdline_has(f'{bug}=stuff') and sysfs_has("spectre_v2", "Retpolines"):
  21. bug_check_fail(bug, ITS_MITIGATION_ALIGNED_THUNKS, ITS_MITIGATION_RETPOLINE_STUFF)
  22. return
  23. if cmdline_has(f'{bug}=vmexit') and cpuinfo_has('its_native_only'):
  24. bug_check_fail(bug, ITS_MITIGATION_ALIGNED_THUNKS, ITS_MITIGATION_VMEXIT_ONLY)
  25. return
  26. bug_check_pass(bug, ITS_MITIGATION_ALIGNED_THUNKS)
  27. return
  28. if mitigation == ITS_MITIGATION_RETPOLINE_STUFF:
  29. if cmdline_has(f'{bug}=stuff') and sysfs_has("spectre_v2", "Retpolines"):
  30. bug_check_pass(bug, ITS_MITIGATION_RETPOLINE_STUFF)
  31. return
  32. if sysfs_has('retbleed', 'Stuffing'):
  33. bug_check_pass(bug, ITS_MITIGATION_RETPOLINE_STUFF)
  34. return
  35. bug_check_fail(bug, ITS_MITIGATION_RETPOLINE_STUFF, ITS_MITIGATION_ALIGNED_THUNKS)
  36. if mitigation == ITS_MITIGATION_VMEXIT_ONLY:
  37. if cmdline_has(f'{bug}=vmexit') and cpuinfo_has('its_native_only'):
  38. bug_check_pass(bug, ITS_MITIGATION_VMEXIT_ONLY)
  39. return
  40. bug_check_fail(bug, ITS_MITIGATION_VMEXIT_ONLY, ITS_MITIGATION_ALIGNED_THUNKS)
  41. if mitigation == ITS_MITIGATION_VULNERABLE:
  42. if sysfs_has("spectre_v2", "Vulnerable"):
  43. bug_check_pass(bug, ITS_MITIGATION_VULNERABLE)
  44. else:
  45. bug_check_fail(bug, "Mitigation", ITS_MITIGATION_VULNERABLE)
  46. bug_status_unknown(bug, mitigation)
  47. return
  48. ksft.print_header()
  49. ksft.set_plan(1)
  50. ksft.print_msg(f'{bug}: {mitigation} ...')
  51. if not basic_checks_sufficient(bug, mitigation):
  52. check_mitigation()
  53. ksft.finished()