ksyms_common.c 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ksyms_common.c: A split of kernel/kallsyms.c
  4. * Contains a few generic function definations independent of config KALLSYMS.
  5. */
  6. #include <linux/kallsyms.h>
  7. #include <linux/security.h>
  8. static inline int kallsyms_for_perf(void)
  9. {
  10. #ifdef CONFIG_PERF_EVENTS
  11. extern int sysctl_perf_event_paranoid;
  12. if (sysctl_perf_event_paranoid <= 1)
  13. return 1;
  14. #endif
  15. return 0;
  16. }
  17. /*
  18. * We show kallsyms information even to normal users if we've enabled
  19. * kernel profiling and are explicitly not paranoid (so kptr_restrict
  20. * is clear, and sysctl_perf_event_paranoid isn't set).
  21. *
  22. * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to
  23. * block even that).
  24. */
  25. bool kallsyms_show_value(const struct cred *cred)
  26. {
  27. switch (kptr_restrict) {
  28. case 0:
  29. if (kallsyms_for_perf())
  30. return true;
  31. fallthrough;
  32. case 1:
  33. if (security_capable(cred, &init_user_ns, CAP_SYSLOG,
  34. CAP_OPT_NOAUDIT) == 0)
  35. return true;
  36. fallthrough;
  37. default:
  38. return false;
  39. }
  40. }