0004.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. diff -rcNP og/Documentation/admin-guide/sysctl/kernel.rst new/Documentation/admin-guide/sysctl/kernel.rst
  2. *** og/Documentation/admin-guide/sysctl/kernel.rst 2022-01-23 17:06:11.000000000 +0200
  3. --- new/Documentation/admin-guide/sysctl/kernel.rst 2022-01-23 17:04:03.000000000 +0200
  4. ***************
  5. *** 743,750 ****
  6. perf_event_paranoid:
  7. ====================
  8. ! Controls use of the performance events system by unprivileged
  9. ! users (without CAP_SYS_ADMIN). The default value is 2.
  10. === ==================================================================
  11. -1 Allow use of (almost) all events by all users
  12. --- 743,750 ----
  13. perf_event_paranoid:
  14. ====================
  15. ! Controls use of the performance events system by
  16. ! users. The default value is 2.
  17. === ==================================================================
  18. -1 Allow use of (almost) all events by all users
  19. ***************
  20. *** 759,765 ****
  21. >=2 Disallow kernel profiling by users without CAP_SYS_ADMIN
  22. ! >=3 Disallow use of any event by users without CAP_SYS_ADMIN
  23. === ==================================================================
  24. --- 759,767 ----
  25. >=2 Disallow kernel profiling by users without CAP_SYS_ADMIN
  26. ! >=3 Disallow all unprivileged perf event use
  27. !
  28. ! >=69 Disallow all perf event use by everyone, including root
  29. === ==================================================================
  30. diff -rcNP og/include/linux/perf_event.h new/include/linux/perf_event.h
  31. *** og/include/linux/perf_event.h 2022-01-23 17:06:04.000000000 +0200
  32. --- new/include/linux/perf_event.h 2022-01-23 17:00:53.000000000 +0200
  33. ***************
  34. *** 1257,1262 ****
  35. --- 1257,1267 ----
  36. return sysctl_perf_event_paranoid > 2;
  37. }
  38. + static inline bool perf_paranoid_all(void)
  39. + {
  40. + return sysctl_perf_event_paranoid = 69;
  41. + }
  42. +
  43. static inline bool perf_paranoid_tracepoint_raw(void)
  44. {
  45. return sysctl_perf_event_paranoid > -1;
  46. diff -rcNP og/kernel/events/core.c new/kernel/events/core.c
  47. *** og/kernel/events/core.c 2022-01-23 17:06:05.000000000 +0200
  48. --- new/kernel/events/core.c 2022-01-23 17:00:53.000000000 +0200
  49. ***************
  50. *** 405,410 ****
  51. --- 405,411 ----
  52. * 1 - disallow cpu events for unpriv
  53. * 2 - disallow kernel profiling for unpriv
  54. * 3 - disallow all unpriv perf event use
  55. + * 69 - disallow all perf event use
  56. */
  57. #ifdef CONFIG_SECURITY_PERF_EVENTS_RESTRICT
  58. int sysctl_perf_event_paranoid __read_mostly = 3;
  59. ***************
  60. *** 10940,10945 ****
  61. --- 10941,10949 ----
  62. if (flags & ~PERF_FLAG_ALL)
  63. return -EINVAL;
  64. + if (perf_paranoid_all())
  65. + return -EACCES;
  66. +
  67. if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
  68. return -EACCES;