PageRenderTime 67ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/old-html/kernel-comments/01-files/audit.h

https://gitlab.com/manufacturaind/reading-kernel
C Header | 347 lines | 66 code | 5 blank | 276 comment | 7 complexity | 7ae11200ee6e7a326ac53d9510acc6b5 MD5 | raw file
  1. audit -- definition of audit_context structure and supporting types
  2. Copyright 2003-2004 Red Hat, Inc.
  3. Copyright 2005 Hewlett-Packard Development Company, L.P.
  4. Copyright 2005 IBM Corporation
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /*
  17. #include <linux/fs.h>
  18. #include <linux/audit.h>
  19. #include <linux/skbuff.h>
  20. #include <uapi/linux/mqueue.h>
  21. */ AUDIT_NAMES is the number of slots we reserve in the audit_context
  22. for saving names from getname(). If we get more names we will allocate
  23. a name dynamically and also add those to the list anchored by names_list. /*
  24. #define AUDIT_NAMES 5
  25. */ At task start time, the audit_state is set in the audit_context using
  26. a per-task filter. At syscall entry, the audit_state is augmented by
  27. the syscall filter. /*
  28. enum audit_state {
  29. AUDIT_DISABLED, */ Do not create per-task audit_context.
  30. No syscall-specific audit records can
  31. be generated. /*
  32. AUDIT_BUILD_CONTEXT, */ Create the per-task audit_context,
  33. and fill it in at syscall
  34. entry time. This makes a full
  35. syscall record available if some
  36. other part of the kernel decides it
  37. should be recorded. /*
  38. AUDIT_RECORD_CONTEXT */ Create the per-task audit_context,
  39. always fill it in at syscall entry
  40. time, and always write out the audit
  41. record at syscall exit time. /*
  42. };
  43. */ Rule lists /*
  44. struct audit_watch;
  45. struct audit_fsnotify_mark;
  46. struct audit_tree;
  47. struct audit_chunk;
  48. struct audit_entry {
  49. struct list_head list;
  50. struct rcu_head rcu;
  51. struct audit_krule rule;
  52. };
  53. struct audit_cap_data {
  54. kernel_cap_t permitted;
  55. kernel_cap_t inheritable;
  56. union {
  57. unsigned int fE; */ effective bit of file cap /*
  58. kernel_cap_t effective; */ effective set of process /*
  59. };
  60. };
  61. */ When fs/namei.c:getname() is called, we store the pointer in name and bump
  62. the refcnt in the associated filename struct.
  63. Further, in fs/namei.c:path_lookup() we store the inode and device.
  64. /*
  65. struct audit_names {
  66. struct list_head list; */ audit_context->names_list /*
  67. struct filename *name;
  68. int name_len; */ number of chars to log /*
  69. bool hidden; */ don't log this record /*
  70. unsigned long ino;
  71. dev_t dev;
  72. umode_t mode;
  73. kuid_t uid;
  74. kgid_t gid;
  75. dev_t rdev;
  76. u32 osid;
  77. struct audit_cap_data fcap;
  78. unsigned int fcap_ver;
  79. unsigned char type; */ record type /*
  80. */
  81. This was an allocated audit_names and not from the array of
  82. names allocated in the task audit context. Thus this name
  83. should be freed on syscall exit.
  84. /*
  85. bool should_free;
  86. };
  87. struct audit_proctitle {
  88. int len; */ length of the cmdline field. /*
  89. char *value; */ the cmdline field /*
  90. };
  91. */ The per-task audit context. /*
  92. struct audit_context {
  93. int dummy; */ must be the first element /*
  94. int in_syscall; */ 1 if task is in a syscall /*
  95. enum audit_state state, current_state;
  96. unsigned int serial; / serial number for record /*
  97. int major; / syscall number /*
  98. struct timespec ctime; / time of syscall entry /*
  99. unsigned long argv[4]; / syscall arguments /*
  100. long return_code;*/ syscall return code /*
  101. u64 prio;
  102. int return_valid;/ return code is valid /*
  103. */
  104. The names_list is the list of all audit_names collected during this
  105. syscall. The first AUDIT_NAMES entries in the names_list will
  106. actually be from the preallocated_names array for performance
  107. reasons. Except during allocation they should never be referenced
  108. through the preallocated_names array and should only be found/used
  109. by running the names_list.
  110. /*
  111. struct audit_names preallocated_names[AUDIT_NAMES];
  112. int name_count;/ total records in names_list /*
  113. struct list_head names_list; */ struct audit_names->list anchor /*
  114. char filterkey; */ key for rule that triggered record /*
  115. struct path pwd;
  116. struct audit_aux_dataaux;
  117. struct audit_aux_dataaux_pids;
  118. struct sockaddr_storagesockaddr;
  119. size_t sockaddr_len;
  120. */ Save things to print about task_struct /*
  121. pid_t pid, ppid;
  122. kuid_t uid, euid, suid, fsuid;
  123. kgid_t gid, egid, sgid, fsgid;
  124. unsigned long personality;
  125. int arch;
  126. pid_t target_pid;
  127. kuid_t target_auid;
  128. kuid_t target_uid;
  129. unsigned int target_sessionid;
  130. u32 target_sid;
  131. char target_comm[TASK_COMM_LEN];
  132. struct audit_tree_refstrees,first_trees;
  133. struct list_head killed_trees;
  134. int tree_count;
  135. int type;
  136. union {
  137. struct {
  138. int nargs;
  139. long args[6];
  140. } socketcall;
  141. struct {
  142. kuid_t uid;
  143. kgid_t gid;
  144. umode_t mode;
  145. u32 osid;
  146. int has_perm;
  147. uid_t perm_uid;
  148. gid_t perm_gid;
  149. umode_t perm_mode;
  150. unsigned long qbytes;
  151. } ipc;
  152. struct {
  153. mqd_t mqdes;
  154. struct mq_attr mqstat;
  155. } mq_getsetattr;
  156. struct {
  157. mqd_t mqdes;
  158. int sigev_signo;
  159. } mq_notify;
  160. struct {
  161. mqd_t mqdes;
  162. size_t msg_len;
  163. unsigned int msg_prio;
  164. struct timespec abs_timeout;
  165. } mq_sendrecv;
  166. struct {
  167. int oflag;
  168. umode_t mode;
  169. struct mq_attr attr;
  170. } mq_open;
  171. struct {
  172. pid_t pid;
  173. struct audit_cap_data cap;
  174. } capset;
  175. struct {
  176. int fd;
  177. int flags;
  178. } mmap;
  179. struct {
  180. int argc;
  181. } execve;
  182. };
  183. int fds[2];
  184. struct audit_proctitle proctitle;
  185. };
  186. extern u32 audit_ever_enabled;
  187. extern void audit_copy_inode(struct audit_namesname,
  188. const struct dentrydentry,
  189. struct inodeinode);
  190. extern void audit_log_cap(struct audit_bufferab, charprefix,
  191. kernel_cap_tcap);
  192. extern void audit_log_name(struct audit_contextcontext,
  193. struct audit_namesn, struct pathpath,
  194. int record_num, intcall_panic);
  195. extern int audit_pid;
  196. #define AUDIT_INODE_BUCKETS 32
  197. extern struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];
  198. static inline int audit_hash_ino(u32 ino)
  199. {
  200. return (ino & (AUDIT_INODE_BUCKETS-1));
  201. }
  202. */ Indicates that audit should log the full pathname. /*
  203. #define AUDIT_NAME_FULL -1
  204. extern int audit_match_class(int class, unsigned syscall);
  205. extern int audit_comparator(const u32 left, const u32 op, const u32 right);
  206. extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right);
  207. extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right);
  208. extern int parent_len(const charpath);
  209. extern int audit_compare_dname_path(const chardname, const charpath, int plen);
  210. extern struct sk_buffaudit_make_reply(__u32 portid, int seq, int type,
  211. int done, int multi,
  212. const voidpayload, int size);
  213. extern void audit_panic(const charmessage);
  214. struct audit_netlink_list {
  215. __u32 portid;
  216. struct netnet;
  217. struct sk_buff_head q;
  218. };
  219. int audit_send_list(void);
  220. struct audit_net {
  221. struct socknlsk;
  222. };
  223. extern int selinux_audit_rule_update(void);
  224. extern struct mutex audit_filter_mutex;
  225. extern int audit_del_rule(struct audit_entry);
  226. extern void audit_free_rule_rcu(struct rcu_head);
  227. extern struct list_head audit_filter_list[];
  228. extern struct audit_entryaudit_dupe_rule(struct audit_kruleold);
  229. extern void audit_log_d_path_exe(struct audit_bufferab,
  230. struct mm_structmm);
  231. */ audit watch functions /*
  232. #ifdef CONFIG_AUDIT_WATCH
  233. extern void audit_put_watch(struct audit_watchwatch);
  234. extern void audit_get_watch(struct audit_watchwatch);
  235. extern int audit_to_watch(struct audit_krulekrule, charpath, int len, u32 op);
  236. extern int audit_add_watch(struct audit_krulekrule, struct list_head*list);
  237. extern void audit_remove_watch_rule(struct audit_krulekrule);
  238. extern charaudit_watch_path(struct audit_watchwatch);
  239. extern int audit_watch_compare(struct audit_watchwatch, unsigned long ino, dev_t dev);
  240. extern struct audit_fsnotify_markaudit_alloc_mark(struct audit_krulekrule, charpathname, int len);
  241. extern charaudit_mark_path(struct audit_fsnotify_markmark);
  242. extern void audit_remove_mark(struct audit_fsnotify_markaudit_mark);
  243. extern void audit_remove_mark_rule(struct audit_krulekrule);
  244. extern int audit_mark_compare(struct audit_fsnotify_markmark, unsigned long ino, dev_t dev);
  245. extern int audit_dupe_exe(struct audit_krulenew, struct audit_kruleold);
  246. extern int audit_exe_compare(struct task_structtsk, struct audit_fsnotify_markmark);
  247. #else
  248. #define audit_put_watch(w) {}
  249. #define audit_get_watch(w) {}
  250. #define audit_to_watch(k, p, l, o) (-EINVAL)
  251. #define audit_add_watch(k, l) (-EINVAL)
  252. #define audit_remove_watch_rule(k) BUG()
  253. #define audit_watch_path(w) ""
  254. #define audit_watch_compare(w, i, d) 0
  255. #define audit_alloc_mark(k, p, l) (ERR_PTR(-EINVAL))
  256. #define audit_mark_path(m) ""
  257. #define audit_remove_mark(m)
  258. #define audit_remove_mark_rule(k)
  259. #define audit_mark_compare(m, i, d) 0
  260. #define audit_exe_compare(t, m) (-EINVAL)
  261. #define audit_dupe_exe(n, o) (-EINVAL)
  262. #endif */ CONFIG_AUDIT_WATCH /*
  263. #ifdef CONFIG_AUDIT_TREE
  264. extern struct audit_chunkaudit_tree_lookup(const struct inode);
  265. extern void audit_put_chunk(struct audit_chunk);
  266. extern bool audit_tree_match(struct audit_chunk, struct audit_tree);
  267. extern int audit_make_tree(struct audit_krule, char, u32);
  268. extern int audit_add_tree_rule(struct audit_krule);
  269. extern int audit_remove_tree_rule(struct audit_krule);
  270. extern void audit_trim_trees(void);
  271. extern int audit_tag_tree(charold, charnew);
  272. extern const charaudit_tree_path(struct audit_tree);
  273. extern void audit_put_tree(struct audit_tree);
  274. extern void audit_kill_trees(struct list_head);
  275. #else
  276. #define audit_remove_tree_rule(rule) BUG()
  277. #define audit_add_tree_rule(rule) -EINVAL
  278. #define audit_make_tree(rule, str, op) -EINVAL
  279. #define audit_trim_trees() (void)0
  280. #define audit_put_tree(tree) (void)0
  281. #define audit_tag_tree(old, new) -EINVAL
  282. #define audit_tree_path(rule) "" */ never called /*
  283. #define audit_kill_trees(list) BUG()
  284. #endif
  285. extern charaudit_unpack_string(void*, size_t, size_t);
  286. extern pid_t audit_sig_pid;
  287. extern kuid_t audit_sig_uid;
  288. extern u32 audit_sig_sid;
  289. #ifdef CONFIG_AUDITSYSCALL
  290. extern int __audit_signal_info(int sig, struct task_structt);
  291. static inline int audit_signal_info(int sig, struct task_structt)
  292. {
  293. if (unlikely((audit_pid && t->tgid == audit_pid) ||
  294. (audit_signals && !audit_dummy_context())))
  295. return __audit_signal_info(sig, t);
  296. return 0;
  297. }
  298. extern void audit_filter_inodes(struct task_struct, struct audit_context);
  299. extern struct list_headaudit_killed_trees(void);
  300. #else
  301. #define audit_signal_info(s,t) AUDIT_DISABLED
  302. #define audit_filter_inodes(t,c) AUDIT_DISABLED
  303. #endif
  304. extern struct mutex audit_cmd_mutex;
  305. */