audit.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AppArmor security module
  4. *
  5. * This file contains AppArmor auditing function definitions.
  6. *
  7. * Copyright (C) 1998-2008 Novell/SUSE
  8. * Copyright 2009-2010 Canonical Ltd.
  9. */
  10. #ifndef __AA_AUDIT_H
  11. #define __AA_AUDIT_H
  12. #include <linux/audit.h>
  13. #include <linux/fs.h>
  14. #include <linux/lsm_audit.h>
  15. #include <linux/sched.h>
  16. #include <linux/slab.h>
  17. #include "file.h"
  18. #include "label.h"
  19. extern const char *const audit_mode_names[];
  20. #define AUDIT_MAX_INDEX 5
  21. enum audit_mode {
  22. AUDIT_NORMAL, /* follow normal auditing of accesses */
  23. AUDIT_QUIET_DENIED, /* quiet all denied access messages */
  24. AUDIT_QUIET, /* quiet all messages */
  25. AUDIT_NOQUIET, /* do not quiet audit messages */
  26. AUDIT_ALL /* audit all accesses */
  27. };
  28. enum audit_type {
  29. AUDIT_APPARMOR_AUDIT,
  30. AUDIT_APPARMOR_ALLOWED,
  31. AUDIT_APPARMOR_DENIED,
  32. AUDIT_APPARMOR_HINT,
  33. AUDIT_APPARMOR_STATUS,
  34. AUDIT_APPARMOR_ERROR,
  35. AUDIT_APPARMOR_KILL,
  36. AUDIT_APPARMOR_AUTO
  37. };
  38. #define OP_NULL NULL
  39. #define OP_SYSCTL "sysctl"
  40. #define OP_CAPABLE "capable"
  41. #define OP_UNLINK "unlink"
  42. #define OP_MKDIR "mkdir"
  43. #define OP_RMDIR "rmdir"
  44. #define OP_MKNOD "mknod"
  45. #define OP_TRUNC "truncate"
  46. #define OP_LINK "link"
  47. #define OP_SYMLINK "symlink"
  48. #define OP_RENAME_SRC "rename_src"
  49. #define OP_RENAME_DEST "rename_dest"
  50. #define OP_CHMOD "chmod"
  51. #define OP_CHOWN "chown"
  52. #define OP_GETATTR "getattr"
  53. #define OP_OPEN "open"
  54. #define OP_FRECEIVE "file_receive"
  55. #define OP_FPERM "file_perm"
  56. #define OP_FLOCK "file_lock"
  57. #define OP_FMMAP "file_mmap"
  58. #define OP_FMPROT "file_mprotect"
  59. #define OP_INHERIT "file_inherit"
  60. #define OP_PIVOTROOT "pivotroot"
  61. #define OP_MOUNT "mount"
  62. #define OP_UMOUNT "umount"
  63. #define OP_CREATE "create"
  64. #define OP_POST_CREATE "post_create"
  65. #define OP_BIND "bind"
  66. #define OP_CONNECT "connect"
  67. #define OP_LISTEN "listen"
  68. #define OP_ACCEPT "accept"
  69. #define OP_SENDMSG "sendmsg"
  70. #define OP_RECVMSG "recvmsg"
  71. #define OP_GETSOCKNAME "getsockname"
  72. #define OP_GETPEERNAME "getpeername"
  73. #define OP_GETSOCKOPT "getsockopt"
  74. #define OP_SETSOCKOPT "setsockopt"
  75. #define OP_SHUTDOWN "socket_shutdown"
  76. #define OP_PTRACE "ptrace"
  77. #define OP_SIGNAL "signal"
  78. #define OP_EXEC "exec"
  79. #define OP_CHANGE_HAT "change_hat"
  80. #define OP_CHANGE_PROFILE "change_profile"
  81. #define OP_CHANGE_ONEXEC "change_onexec"
  82. #define OP_STACK "stack"
  83. #define OP_STACK_ONEXEC "stack_onexec"
  84. #define OP_SETPROCATTR "setprocattr"
  85. #define OP_SETRLIMIT "setrlimit"
  86. #define OP_PROF_REPL "profile_replace"
  87. #define OP_PROF_LOAD "profile_load"
  88. #define OP_PROF_RM "profile_remove"
  89. struct apparmor_audit_data {
  90. int error;
  91. int type;
  92. const char *op;
  93. struct aa_label *label;
  94. const char *name;
  95. const char *info;
  96. u32 request;
  97. u32 denied;
  98. union {
  99. /* these entries require a custom callback fn */
  100. struct {
  101. struct aa_label *peer;
  102. union {
  103. struct {
  104. const char *target;
  105. kuid_t ouid;
  106. } fs;
  107. struct {
  108. int rlim;
  109. unsigned long max;
  110. } rlim;
  111. struct {
  112. int signal;
  113. int unmappedsig;
  114. };
  115. struct {
  116. int type, protocol;
  117. struct sock *peer_sk;
  118. void *addr;
  119. int addrlen;
  120. } net;
  121. };
  122. };
  123. struct {
  124. struct aa_profile *profile;
  125. const char *ns;
  126. long pos;
  127. } iface;
  128. struct {
  129. const char *src_name;
  130. const char *type;
  131. const char *trans;
  132. const char *data;
  133. unsigned long flags;
  134. } mnt;
  135. };
  136. };
  137. /* macros for dealing with apparmor_audit_data structure */
  138. #define aad(SA) ((SA)->apparmor_audit_data)
  139. #define DEFINE_AUDIT_DATA(NAME, T, X) \
  140. /* TODO: cleanup audit init so we don't need _aad = {0,} */ \
  141. struct apparmor_audit_data NAME ## _aad = { .op = (X), }; \
  142. struct common_audit_data NAME = \
  143. { \
  144. .type = (T), \
  145. .u.tsk = NULL, \
  146. }; \
  147. NAME.apparmor_audit_data = &(NAME ## _aad)
  148. void aa_audit_msg(int type, struct common_audit_data *sa,
  149. void (*cb) (struct audit_buffer *, void *));
  150. int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
  151. void (*cb) (struct audit_buffer *, void *));
  152. #define aa_audit_error(ERROR, SA, CB) \
  153. ({ \
  154. aad((SA))->error = (ERROR); \
  155. aa_audit_msg(AUDIT_APPARMOR_ERROR, (SA), (CB)); \
  156. aad((SA))->error; \
  157. })
  158. static inline int complain_error(int error)
  159. {
  160. if (error == -EPERM || error == -EACCES)
  161. return 0;
  162. return error;
  163. }
  164. void aa_audit_rule_free(void *vrule);
  165. int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule);
  166. int aa_audit_rule_known(struct audit_krule *rule);
  167. int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule);
  168. #endif /* __AA_AUDIT_H */