audit.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/init.h>
  3. #include <linux/types.h>
  4. #include <linux/audit.h>
  5. #include <asm/unistd.h>
  6. static unsigned dir_class[] = {
  7. #include <asm-generic/audit_dir_write.h>
  8. ~0U
  9. };
  10. static unsigned read_class[] = {
  11. #include <asm-generic/audit_read.h>
  12. ~0U
  13. };
  14. static unsigned write_class[] = {
  15. #include <asm-generic/audit_write.h>
  16. ~0U
  17. };
  18. static unsigned chattr_class[] = {
  19. #include <asm-generic/audit_change_attr.h>
  20. ~0U
  21. };
  22. static unsigned signal_class[] = {
  23. #include <asm-generic/audit_signal.h>
  24. ~0U
  25. };
  26. int audit_classify_arch(int arch)
  27. {
  28. if (audit_is_compat(arch))
  29. return 1;
  30. else
  31. return 0;
  32. }
  33. int audit_classify_syscall(int abi, unsigned syscall)
  34. {
  35. if (audit_is_compat(abi))
  36. return audit_classify_compat_syscall(abi, syscall);
  37. switch(syscall) {
  38. #ifdef __NR_open
  39. case __NR_open:
  40. return AUDITSC_OPEN;
  41. #endif
  42. #ifdef __NR_openat
  43. case __NR_openat:
  44. return AUDITSC_OPENAT;
  45. #endif
  46. #ifdef __NR_socketcall
  47. case __NR_socketcall:
  48. return AUDITSC_SOCKETCALL;
  49. #endif
  50. #ifdef __NR_execveat
  51. case __NR_execveat:
  52. #endif
  53. case __NR_execve:
  54. return AUDITSC_EXECVE;
  55. #ifdef __NR_openat2
  56. case __NR_openat2:
  57. return AUDITSC_OPENAT2;
  58. #endif
  59. default:
  60. return AUDITSC_NATIVE;
  61. }
  62. }
  63. static int __init audit_classes_init(void)
  64. {
  65. #ifdef CONFIG_AUDIT_COMPAT_GENERIC
  66. audit_register_class(AUDIT_CLASS_WRITE_32, compat_write_class);
  67. audit_register_class(AUDIT_CLASS_READ_32, compat_read_class);
  68. audit_register_class(AUDIT_CLASS_DIR_WRITE_32, compat_dir_class);
  69. audit_register_class(AUDIT_CLASS_CHATTR_32, compat_chattr_class);
  70. audit_register_class(AUDIT_CLASS_SIGNAL_32, compat_signal_class);
  71. #endif
  72. audit_register_class(AUDIT_CLASS_WRITE, write_class);
  73. audit_register_class(AUDIT_CLASS_READ, read_class);
  74. audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class);
  75. audit_register_class(AUDIT_CLASS_CHATTR, chattr_class);
  76. audit_register_class(AUDIT_CLASS_SIGNAL, signal_class);
  77. return 0;
  78. }
  79. __initcall(audit_classes_init);