1 /* audit.h -- Auditing support
3 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
23 #ifndef _LINUX_AUDIT_H_
24 #define _LINUX_AUDIT_H_
26 #include <linux/sched.h>
27 #include <linux/ptrace.h>
28 #include <linux/namei.h> /* LOOKUP_* */
29 #include <uapi/linux/audit.h>
31 #define AUDIT_INO_UNSET ((unsigned long)-1)
32 #define AUDIT_DEV_UNSET ((dev_t)-1)
34 struct audit_sig_info {
43 struct netlink_skb_parms;
57 u32 mask[AUDIT_BITMASK_SIZE];
58 u32 buflen; /* for data alloc on list rules */
60 char *filterkey; /* ties events to rules */
61 struct audit_field *fields;
62 struct audit_field *arch_f; /* quick access to arch field */
63 struct audit_field *inode_f; /* quick access to an inode field */
64 struct audit_watch *watch; /* associated watch */
65 struct audit_tree *tree; /* associated watched tree */
66 struct audit_fsnotify_mark *exe;
67 struct list_head rlist; /* entry in audit_{watch,tree}.rules list */
68 struct list_head list; /* for AUDIT_LIST* purposes only */
72 /* Flag to indicate legacy AUDIT_LOGINUID unset usage */
73 #define AUDIT_LOGINUID_LEGACY 0x1
89 extern int is_audit_feature_set(int which);
91 extern int __init audit_register_class(int class, unsigned *list);
92 extern int audit_classify_syscall(int abi, unsigned syscall);
93 extern int audit_classify_arch(int arch);
94 /* only for compat system calls */
95 extern unsigned compat_write_class[];
96 extern unsigned compat_read_class[];
97 extern unsigned compat_dir_class[];
98 extern unsigned compat_chattr_class[];
99 extern unsigned compat_signal_class[];
101 extern int audit_classify_compat_syscall(int abi, unsigned syscall);
103 /* audit_names->type values */
104 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
105 #define AUDIT_TYPE_NORMAL 1 /* a "normal" audit record */
106 #define AUDIT_TYPE_PARENT 2 /* a parent audit record */
107 #define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
108 #define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
110 /* maximized args number that audit_socketcall can process */
111 #define AUDITSC_ARGS 6
113 /* bit values for ->signal->audit_tty */
114 #define AUDIT_TTY_ENABLE BIT(0)
115 #define AUDIT_TTY_LOG_PASSWD BIT(1)
121 #define AUDIT_LOCKED 2
123 /* These are defined in audit.c */
125 extern __printf(4, 5)
126 void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
127 const char *fmt, ...);
129 extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
130 extern __printf(2, 3)
131 void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
132 extern void audit_log_end(struct audit_buffer *ab);
133 extern bool audit_string_contains_control(const char *string,
135 extern void audit_log_n_hex(struct audit_buffer *ab,
136 const unsigned char *buf,
138 extern void audit_log_n_string(struct audit_buffer *ab,
141 extern void audit_log_n_untrustedstring(struct audit_buffer *ab,
144 extern void audit_log_untrustedstring(struct audit_buffer *ab,
146 extern void audit_log_d_path(struct audit_buffer *ab,
148 const struct path *path);
149 extern void audit_log_key(struct audit_buffer *ab,
151 extern void audit_log_link_denied(const char *operation);
152 extern void audit_log_lost(const char *message);
154 extern int audit_log_task_context(struct audit_buffer *ab);
155 extern void audit_log_task_info(struct audit_buffer *ab);
157 extern int audit_update_lsm_rules(void);
159 /* Private API (for audit.c only) */
160 extern int audit_rule_change(int type, int seq, void *data, size_t datasz);
161 extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
163 extern int audit_set_loginuid(kuid_t loginuid);
165 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
167 return tsk->loginuid;
170 static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
172 return tsk->sessionid;
175 extern u32 audit_enabled;
176 #else /* CONFIG_AUDIT */
177 static inline __printf(4, 5)
178 void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
179 const char *fmt, ...)
181 static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
182 gfp_t gfp_mask, int type)
186 static inline __printf(2, 3)
187 void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
189 static inline void audit_log_end(struct audit_buffer *ab)
191 static inline void audit_log_n_hex(struct audit_buffer *ab,
192 const unsigned char *buf, size_t len)
194 static inline void audit_log_n_string(struct audit_buffer *ab,
195 const char *buf, size_t n)
197 static inline void audit_log_n_untrustedstring(struct audit_buffer *ab,
198 const char *string, size_t n)
200 static inline void audit_log_untrustedstring(struct audit_buffer *ab,
203 static inline void audit_log_d_path(struct audit_buffer *ab,
205 const struct path *path)
207 static inline void audit_log_key(struct audit_buffer *ab, char *key)
209 static inline void audit_log_link_denied(const char *string)
211 static inline int audit_log_task_context(struct audit_buffer *ab)
215 static inline void audit_log_task_info(struct audit_buffer *ab)
218 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
223 static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
225 return AUDIT_SID_UNSET;
228 #define audit_enabled AUDIT_OFF
229 #endif /* CONFIG_AUDIT */
231 #ifdef CONFIG_AUDIT_COMPAT_GENERIC
232 #define audit_is_compat(arch) (!((arch) & __AUDIT_ARCH_64BIT))
234 #define audit_is_compat(arch) false
237 #ifdef CONFIG_AUDITSYSCALL
238 #include <asm/syscall.h> /* for syscall_get_arch() */
240 /* These are defined in auditsc.c */
242 extern int audit_alloc(struct task_struct *task);
243 extern void __audit_free(struct task_struct *task);
244 extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
245 unsigned long a2, unsigned long a3);
246 extern void __audit_syscall_exit(int ret_success, long ret_value);
247 extern struct filename *__audit_reusename(const __user char *uptr);
248 extern void __audit_getname(struct filename *name);
250 #define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
251 #define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
252 #define AUDIT_INODE_NOEVAL 4 /* audit record incomplete */
253 extern void __audit_inode(struct filename *name, const struct dentry *dentry,
255 extern void __audit_file(const struct file *);
256 extern void __audit_inode_child(struct inode *parent,
257 const struct dentry *dentry,
258 const unsigned char type);
259 extern void audit_seccomp(unsigned long syscall, long signr, int code);
260 extern void audit_seccomp_actions_logged(const char *names,
261 const char *old_names, int res);
262 extern void __audit_ptrace(struct task_struct *t);
264 static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
266 task->audit_context = ctx;
269 static inline struct audit_context *audit_context(void)
271 return current->audit_context;
274 static inline bool audit_dummy_context(void)
276 void *p = audit_context();
277 return !p || *(int *)p;
279 static inline void audit_free(struct task_struct *task)
281 if (unlikely(task->audit_context))
284 static inline void audit_syscall_entry(int major, unsigned long a0,
285 unsigned long a1, unsigned long a2,
288 if (unlikely(audit_context()))
289 __audit_syscall_entry(major, a0, a1, a2, a3);
291 static inline void audit_syscall_exit(void *pt_regs)
293 if (unlikely(audit_context())) {
294 int success = is_syscall_success(pt_regs);
295 long return_code = regs_return_value(pt_regs);
297 __audit_syscall_exit(success, return_code);
300 static inline struct filename *audit_reusename(const __user char *name)
302 if (unlikely(!audit_dummy_context()))
303 return __audit_reusename(name);
306 static inline void audit_getname(struct filename *name)
308 if (unlikely(!audit_dummy_context()))
309 __audit_getname(name);
311 static inline void audit_inode(struct filename *name,
312 const struct dentry *dentry,
313 unsigned int flags) {
314 if (unlikely(!audit_dummy_context())) {
315 unsigned int aflags = 0;
317 if (flags & LOOKUP_PARENT)
318 aflags |= AUDIT_INODE_PARENT;
319 if (flags & LOOKUP_NO_EVAL)
320 aflags |= AUDIT_INODE_NOEVAL;
321 __audit_inode(name, dentry, aflags);
324 static inline void audit_file(struct file *file)
326 if (unlikely(!audit_dummy_context()))
329 static inline void audit_inode_parent_hidden(struct filename *name,
330 const struct dentry *dentry)
332 if (unlikely(!audit_dummy_context()))
333 __audit_inode(name, dentry,
334 AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
336 static inline void audit_inode_child(struct inode *parent,
337 const struct dentry *dentry,
338 const unsigned char type) {
339 if (unlikely(!audit_dummy_context()))
340 __audit_inode_child(parent, dentry, type);
342 void audit_core_dumps(long signr);
344 static inline void audit_ptrace(struct task_struct *t)
346 if (unlikely(!audit_dummy_context()))
350 /* Private API (for audit.c only) */
351 extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
352 extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
353 extern void __audit_bprm(struct linux_binprm *bprm);
354 extern int __audit_socketcall(int nargs, unsigned long *args);
355 extern int __audit_sockaddr(int len, void *addr);
356 extern void __audit_fd_pair(int fd1, int fd2);
357 extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
358 extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout);
359 extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
360 extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
361 extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
362 const struct cred *new,
363 const struct cred *old);
364 extern void __audit_log_capset(const struct cred *new, const struct cred *old);
365 extern void __audit_mmap_fd(int fd, int flags);
366 extern void __audit_log_kern_module(char *name);
367 extern void __audit_fanotify(unsigned int response);
369 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
371 if (unlikely(!audit_dummy_context()))
372 __audit_ipc_obj(ipcp);
374 static inline void audit_fd_pair(int fd1, int fd2)
376 if (unlikely(!audit_dummy_context()))
377 __audit_fd_pair(fd1, fd2);
379 static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode)
381 if (unlikely(!audit_dummy_context()))
382 __audit_ipc_set_perm(qbytes, uid, gid, mode);
384 static inline void audit_bprm(struct linux_binprm *bprm)
386 if (unlikely(!audit_dummy_context()))
389 static inline int audit_socketcall(int nargs, unsigned long *args)
391 if (unlikely(!audit_dummy_context()))
392 return __audit_socketcall(nargs, args);
396 static inline int audit_socketcall_compat(int nargs, u32 *args)
398 unsigned long a[AUDITSC_ARGS];
401 if (audit_dummy_context())
404 for (i = 0; i < nargs; i++)
405 a[i] = (unsigned long)args[i];
406 return __audit_socketcall(nargs, a);
409 static inline int audit_sockaddr(int len, void *addr)
411 if (unlikely(!audit_dummy_context()))
412 return __audit_sockaddr(len, addr);
415 static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
417 if (unlikely(!audit_dummy_context()))
418 __audit_mq_open(oflag, mode, attr);
420 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout)
422 if (unlikely(!audit_dummy_context()))
423 __audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
425 static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
427 if (unlikely(!audit_dummy_context()))
428 __audit_mq_notify(mqdes, notification);
430 static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
432 if (unlikely(!audit_dummy_context()))
433 __audit_mq_getsetattr(mqdes, mqstat);
436 static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
437 const struct cred *new,
438 const struct cred *old)
440 if (unlikely(!audit_dummy_context()))
441 return __audit_log_bprm_fcaps(bprm, new, old);
445 static inline void audit_log_capset(const struct cred *new,
446 const struct cred *old)
448 if (unlikely(!audit_dummy_context()))
449 __audit_log_capset(new, old);
452 static inline void audit_mmap_fd(int fd, int flags)
454 if (unlikely(!audit_dummy_context()))
455 __audit_mmap_fd(fd, flags);
458 static inline void audit_log_kern_module(char *name)
460 if (!audit_dummy_context())
461 __audit_log_kern_module(name);
464 static inline void audit_fanotify(unsigned int response)
466 if (!audit_dummy_context())
467 __audit_fanotify(response);
470 extern int audit_n_rules;
471 extern int audit_signals;
472 #else /* CONFIG_AUDITSYSCALL */
473 static inline int audit_alloc(struct task_struct *task)
477 static inline void audit_free(struct task_struct *task)
479 static inline void audit_syscall_entry(int major, unsigned long a0,
480 unsigned long a1, unsigned long a2,
483 static inline void audit_syscall_exit(void *pt_regs)
485 static inline bool audit_dummy_context(void)
489 static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
491 static inline struct audit_context *audit_context(void)
495 static inline struct filename *audit_reusename(const __user char *name)
499 static inline void audit_getname(struct filename *name)
501 static inline void __audit_inode(struct filename *name,
502 const struct dentry *dentry,
505 static inline void __audit_inode_child(struct inode *parent,
506 const struct dentry *dentry,
507 const unsigned char type)
509 static inline void audit_inode(struct filename *name,
510 const struct dentry *dentry,
513 static inline void audit_file(struct file *file)
516 static inline void audit_inode_parent_hidden(struct filename *name,
517 const struct dentry *dentry)
519 static inline void audit_inode_child(struct inode *parent,
520 const struct dentry *dentry,
521 const unsigned char type)
523 static inline void audit_core_dumps(long signr)
525 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
527 static inline void audit_seccomp_actions_logged(const char *names,
528 const char *old_names, int res)
530 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
532 static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
533 gid_t gid, umode_t mode)
535 static inline void audit_bprm(struct linux_binprm *bprm)
537 static inline int audit_socketcall(int nargs, unsigned long *args)
542 static inline int audit_socketcall_compat(int nargs, u32 *args)
547 static inline void audit_fd_pair(int fd1, int fd2)
549 static inline int audit_sockaddr(int len, void *addr)
553 static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
555 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
556 unsigned int msg_prio,
557 const struct timespec64 *abs_timeout)
559 static inline void audit_mq_notify(mqd_t mqdes,
560 const struct sigevent *notification)
562 static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
564 static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
565 const struct cred *new,
566 const struct cred *old)
570 static inline void audit_log_capset(const struct cred *new,
571 const struct cred *old)
573 static inline void audit_mmap_fd(int fd, int flags)
576 static inline void audit_log_kern_module(char *name)
580 static inline void audit_fanotify(unsigned int response)
583 static inline void audit_ptrace(struct task_struct *t)
585 #define audit_n_rules 0
586 #define audit_signals 0
587 #endif /* CONFIG_AUDITSYSCALL */
589 static inline bool audit_loginuid_set(struct task_struct *tsk)
591 return uid_valid(audit_get_loginuid(tsk));
594 static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
596 audit_log_n_string(ab, buf, strlen(buf));