audit.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. #include "label.h"
  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_FRECEIVE "file_receive"
  59. #define OP_FPERM "file_perm"
  60. #define OP_FLOCK "file_lock"
  61. #define OP_FMMAP "file_mmap"
  62. #define OP_FMPROT "file_mprotect"
  63. #define OP_INHERIT "file_inherit"
  64. #define OP_PIVOTROOT "pivotroot"
  65. #define OP_MOUNT "mount"
  66. #define OP_UMOUNT "umount"
  67. #define OP_CREATE "create"
  68. #define OP_POST_CREATE "post_create"
  69. #define OP_BIND "bind"
  70. #define OP_CONNECT "connect"
  71. #define OP_LISTEN "listen"
  72. #define OP_ACCEPT "accept"
  73. #define OP_SENDMSG "sendmsg"
  74. #define OP_RECVMSG "recvmsg"
  75. #define OP_GETSOCKNAME "getsockname"
  76. #define OP_GETPEERNAME "getpeername"
  77. #define OP_GETSOCKOPT "getsockopt"
  78. #define OP_SETSOCKOPT "setsockopt"
  79. #define OP_SHUTDOWN "socket_shutdown"
  80. #define OP_PTRACE "ptrace"
  81. #define OP_SIGNAL "signal"
  82. #define OP_EXEC "exec"
  83. #define OP_CHANGE_HAT "change_hat"
  84. #define OP_CHANGE_PROFILE "change_profile"
  85. #define OP_CHANGE_ONEXEC "change_onexec"
  86. #define OP_STACK "stack"
  87. #define OP_STACK_ONEXEC "stack_onexec"
  88. #define OP_SETPROCATTR "setprocattr"
  89. #define OP_SETRLIMIT "setrlimit"
  90. #define OP_PROF_REPL "profile_replace"
  91. #define OP_PROF_LOAD "profile_load"
  92. #define OP_PROF_RM "profile_remove"
  93. struct apparmor_audit_data {
  94. int error;
  95. int type;
  96. const char *op;
  97. struct aa_label *label;
  98. const char *name;
  99. const char *info;
  100. u32 request;
  101. u32 denied;
  102. union {
  103. /* these entries require a custom callback fn */
  104. struct {
  105. struct aa_label *peer;
  106. union {
  107. struct {
  108. const char *target;
  109. kuid_t ouid;
  110. } fs;
  111. struct {
  112. int rlim;
  113. unsigned long max;
  114. } rlim;
  115. int signal;
  116. };
  117. };
  118. struct {
  119. struct aa_profile *profile;
  120. const char *ns;
  121. long pos;
  122. } iface;
  123. struct {
  124. const char *src_name;
  125. const char *type;
  126. const char *trans;
  127. const char *data;
  128. unsigned long flags;
  129. } mnt;
  130. };
  131. };
  132. /* macros for dealing with apparmor_audit_data structure */
  133. #define aad(SA) ((SA)->apparmor_audit_data)
  134. #define DEFINE_AUDIT_DATA(NAME, T, X) \
  135. /* TODO: cleanup audit init so we don't need _aad = {0,} */ \
  136. struct apparmor_audit_data NAME ## _aad = { .op = (X), }; \
  137. struct common_audit_data NAME = \
  138. { \
  139. .type = (T), \
  140. .u.tsk = NULL, \
  141. }; \
  142. NAME.apparmor_audit_data = &(NAME ## _aad)
  143. void aa_audit_msg(int type, struct common_audit_data *sa,
  144. void (*cb) (struct audit_buffer *, void *));
  145. int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
  146. void (*cb) (struct audit_buffer *, void *));
  147. #define aa_audit_error(ERROR, SA, CB) \
  148. ({ \
  149. aad((SA))->error = (ERROR); \
  150. aa_audit_msg(AUDIT_APPARMOR_ERROR, (SA), (CB)); \
  151. aad((SA))->error; \
  152. })
  153. static inline int complain_error(int error)
  154. {
  155. if (error == -EPERM || error == -EACCES)
  156. return 0;
  157. return error;
  158. }
  159. #endif /* __AA_AUDIT_H */