audit.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor auditing function definitions.
  5. *
  6. * Copyright (C) 1998-2008 Novell/SUSE
  7. * Copyright 2009-2010 Canonical Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation, version 2 of the
  12. * License.
  13. */
  14. #ifndef __AA_AUDIT_H
  15. #define __AA_AUDIT_H
  16. #include <linux/audit.h>
  17. #include <linux/fs.h>
  18. #include <linux/lsm_audit.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include "file.h"
  22. struct aa_profile;
  23. extern const char *const audit_mode_names[];
  24. #define AUDIT_MAX_INDEX 5
  25. enum audit_mode {
  26. AUDIT_NORMAL, /* follow normal auditing of accesses */
  27. AUDIT_QUIET_DENIED, /* quiet all denied access messages */
  28. AUDIT_QUIET, /* quiet all messages */
  29. AUDIT_NOQUIET, /* do not quiet audit messages */
  30. AUDIT_ALL /* audit all accesses */
  31. };
  32. enum audit_type {
  33. AUDIT_APPARMOR_AUDIT,
  34. AUDIT_APPARMOR_ALLOWED,
  35. AUDIT_APPARMOR_DENIED,
  36. AUDIT_APPARMOR_HINT,
  37. AUDIT_APPARMOR_STATUS,
  38. AUDIT_APPARMOR_ERROR,
  39. AUDIT_APPARMOR_KILL,
  40. AUDIT_APPARMOR_AUTO
  41. };
  42. #define OP_NULL NULL
  43. #define OP_SYSCTL "sysctl"
  44. #define OP_CAPABLE "capable"
  45. #define OP_UNLINK "unlink"
  46. #define OP_MKDIR "mkdir"
  47. #define OP_RMDIR "rmdir"
  48. #define OP_MKNOD "mknod"
  49. #define OP_TRUNC "truncate"
  50. #define OP_LINK "link"
  51. #define OP_SYMLINK "symlink"
  52. #define OP_RENAME_SRC "rename_src"
  53. #define OP_RENAME_DEST "rename_dest"
  54. #define OP_CHMOD "chmod"
  55. #define OP_CHOWN "chown"
  56. #define OP_GETATTR "getattr"
  57. #define OP_OPEN "open"
  58. #define OP_FPERM "file_perm"
  59. #define OP_FLOCK "file_lock"
  60. #define OP_FMMAP "file_mmap"
  61. #define OP_FMPROT "file_mprotect"
  62. #define OP_CREATE "create"
  63. #define OP_POST_CREATE "post_create"
  64. #define OP_BIND "bind"
  65. #define OP_CONNECT "connect"
  66. #define OP_LISTEN "listen"
  67. #define OP_ACCEPT "accept"
  68. #define OP_SENDMSG "sendmsg"
  69. #define OP_RECVMSG "recvmsg"
  70. #define OP_GETSOCKNAME "getsockname"
  71. #define OP_GETPEERNAME "getpeername"
  72. #define OP_GETSOCKOPT "getsockopt"
  73. #define OP_SETSOCKOPT "setsockopt"
  74. #define OP_SHUTDOWN "socket_shutdown"
  75. #define OP_PTRACE "ptrace"
  76. #define OP_EXEC "exec"
  77. #define OP_CHANGE_HAT "change_hat"
  78. #define OP_CHANGE_PROFILE "change_profile"
  79. #define OP_CHANGE_ONEXEC "change_onexec"
  80. #define OP_SETPROCATTR "setprocattr"
  81. #define OP_SETRLIMIT "setrlimit"
  82. #define OP_PROF_REPL "profile_replace"
  83. #define OP_PROF_LOAD "profile_load"
  84. #define OP_PROF_RM "profile_remove"
  85. struct apparmor_audit_data {
  86. int error;
  87. const char *op;
  88. int type;
  89. void *profile;
  90. const char *name;
  91. const char *info;
  92. union {
  93. /* these entries require a custom callback fn */
  94. struct {
  95. struct aa_profile *peer;
  96. struct {
  97. const char *target;
  98. u32 request;
  99. u32 denied;
  100. kuid_t ouid;
  101. } fs;
  102. };
  103. struct {
  104. const char *name;
  105. long pos;
  106. const char *ns;
  107. } iface;
  108. struct {
  109. int rlim;
  110. unsigned long max;
  111. } rlim;
  112. };
  113. };
  114. /* macros for dealing with apparmor_audit_data structure */
  115. #define aad(SA) ((SA)->apparmor_audit_data)
  116. #define DEFINE_AUDIT_DATA(NAME, T, X) \
  117. /* TODO: cleanup audit init so we don't need _aad = {0,} */ \
  118. struct apparmor_audit_data NAME ## _aad = { .op = (X), }; \
  119. struct common_audit_data NAME = \
  120. { \
  121. .type = (T), \
  122. .u.tsk = NULL, \
  123. }; \
  124. NAME.apparmor_audit_data = &(NAME ## _aad)
  125. void aa_audit_msg(int type, struct common_audit_data *sa,
  126. void (*cb) (struct audit_buffer *, void *));
  127. int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
  128. void (*cb) (struct audit_buffer *, void *));
  129. #define aa_audit_error(ERROR, SA, CB) \
  130. ({ \
  131. aad((SA))->error = (ERROR); \
  132. aa_audit_msg(AUDIT_APPARMOR_ERROR, (SA), (CB)); \
  133. aad((SA))->error; \
  134. })
  135. static inline int complain_error(int error)
  136. {
  137. if (error == -EPERM || error == -EACCES)
  138. return 0;
  139. return error;
  140. }
  141. #endif /* __AA_AUDIT_H */