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 <uapi/linux/audit.h>
29 #include <linux/tty.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)
119 extern void audit_log_session_info(struct audit_buffer
*ab
);
122 /* These are defined in audit.c */
124 extern __printf(4, 5)
125 void audit_log(struct audit_context
*ctx
, gfp_t gfp_mask
, int type
,
126 const char *fmt
, ...);
128 extern struct audit_buffer
*audit_log_start(struct audit_context
*ctx
, gfp_t gfp_mask
, int type
);
129 extern __printf(2, 3)
130 void audit_log_format(struct audit_buffer
*ab
, const char *fmt
, ...);
131 extern void audit_log_end(struct audit_buffer
*ab
);
132 extern bool audit_string_contains_control(const char *string
,
134 extern void audit_log_n_hex(struct audit_buffer
*ab
,
135 const unsigned char *buf
,
137 extern void audit_log_n_string(struct audit_buffer
*ab
,
140 extern void audit_log_n_untrustedstring(struct audit_buffer
*ab
,
143 extern void audit_log_untrustedstring(struct audit_buffer
*ab
,
145 extern void audit_log_d_path(struct audit_buffer
*ab
,
147 const struct path
*path
);
148 extern void audit_log_key(struct audit_buffer
*ab
,
150 extern void audit_log_link_denied(const char *operation
,
152 extern void audit_log_lost(const char *message
);
153 #ifdef CONFIG_SECURITY
154 extern void audit_log_secctx(struct audit_buffer
*ab
, u32 secid
);
156 static inline void audit_log_secctx(struct audit_buffer
*ab
, u32 secid
)
160 extern int audit_log_task_context(struct audit_buffer
*ab
);
161 extern void audit_log_task_info(struct audit_buffer
*ab
,
162 struct task_struct
*tsk
);
164 extern int audit_update_lsm_rules(void);
166 /* Private API (for audit.c only) */
167 extern int audit_filter_user(int type
);
168 extern int audit_filter_type(int type
);
169 extern int audit_rule_change(int type
, __u32 portid
, int seq
,
170 void *data
, size_t datasz
);
171 extern int audit_list_rules_send(struct sk_buff
*request_skb
, int seq
);
173 extern u32 audit_enabled
;
174 #else /* CONFIG_AUDIT */
175 static inline __printf(4, 5)
176 void audit_log(struct audit_context
*ctx
, gfp_t gfp_mask
, int type
,
177 const char *fmt
, ...)
179 static inline struct audit_buffer
*audit_log_start(struct audit_context
*ctx
,
180 gfp_t gfp_mask
, int type
)
184 static inline __printf(2, 3)
185 void audit_log_format(struct audit_buffer
*ab
, const char *fmt
, ...)
187 static inline void audit_log_end(struct audit_buffer
*ab
)
189 static inline void audit_log_n_hex(struct audit_buffer
*ab
,
190 const unsigned char *buf
, size_t len
)
192 static inline void audit_log_n_string(struct audit_buffer
*ab
,
193 const char *buf
, size_t n
)
195 static inline void audit_log_n_untrustedstring(struct audit_buffer
*ab
,
196 const char *string
, size_t n
)
198 static inline void audit_log_untrustedstring(struct audit_buffer
*ab
,
201 static inline void audit_log_d_path(struct audit_buffer
*ab
,
203 const struct path
*path
)
205 static inline void audit_log_key(struct audit_buffer
*ab
, char *key
)
207 static inline void audit_log_link_denied(const char *string
,
208 const struct path
*link
)
210 static inline void audit_log_secctx(struct audit_buffer
*ab
, u32 secid
)
212 static inline int audit_log_task_context(struct audit_buffer
*ab
)
216 static inline void audit_log_task_info(struct audit_buffer
*ab
,
217 struct task_struct
*tsk
)
219 #define audit_enabled 0
220 #endif /* CONFIG_AUDIT */
222 #ifdef CONFIG_AUDIT_COMPAT_GENERIC
223 #define audit_is_compat(arch) (!((arch) & __AUDIT_ARCH_64BIT))
225 #define audit_is_compat(arch) false
228 #ifdef CONFIG_AUDITSYSCALL
229 #include <asm/syscall.h> /* for syscall_get_arch() */
231 /* These are defined in auditsc.c */
233 extern int audit_alloc(struct task_struct
*task
);
234 extern void __audit_free(struct task_struct
*task
);
235 extern void __audit_syscall_entry(int major
, unsigned long a0
, unsigned long a1
,
236 unsigned long a2
, unsigned long a3
);
237 extern void __audit_syscall_exit(int ret_success
, long ret_value
);
238 extern struct filename
*__audit_reusename(const __user
char *uptr
);
239 extern void __audit_getname(struct filename
*name
);
241 #define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
242 #define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
243 extern void __audit_inode(struct filename
*name
, const struct dentry
*dentry
,
245 extern void __audit_file(const struct file
*);
246 extern void __audit_inode_child(struct inode
*parent
,
247 const struct dentry
*dentry
,
248 const unsigned char type
);
249 extern void __audit_seccomp(unsigned long syscall
, long signr
, int code
);
250 extern void __audit_ptrace(struct task_struct
*t
);
252 static inline bool audit_dummy_context(void)
254 void *p
= current
->audit_context
;
255 return !p
|| *(int *)p
;
257 static inline void audit_free(struct task_struct
*task
)
259 if (unlikely(task
->audit_context
))
262 static inline void audit_syscall_entry(int major
, unsigned long a0
,
263 unsigned long a1
, unsigned long a2
,
266 if (unlikely(current
->audit_context
))
267 __audit_syscall_entry(major
, a0
, a1
, a2
, a3
);
269 static inline void audit_syscall_exit(void *pt_regs
)
271 if (unlikely(current
->audit_context
)) {
272 int success
= is_syscall_success(pt_regs
);
273 long return_code
= regs_return_value(pt_regs
);
275 __audit_syscall_exit(success
, return_code
);
278 static inline struct filename
*audit_reusename(const __user
char *name
)
280 if (unlikely(!audit_dummy_context()))
281 return __audit_reusename(name
);
284 static inline void audit_getname(struct filename
*name
)
286 if (unlikely(!audit_dummy_context()))
287 __audit_getname(name
);
289 static inline void audit_inode(struct filename
*name
,
290 const struct dentry
*dentry
,
291 unsigned int parent
) {
292 if (unlikely(!audit_dummy_context())) {
293 unsigned int flags
= 0;
295 flags
|= AUDIT_INODE_PARENT
;
296 __audit_inode(name
, dentry
, flags
);
299 static inline void audit_file(struct file
*file
)
301 if (unlikely(!audit_dummy_context()))
304 static inline void audit_inode_parent_hidden(struct filename
*name
,
305 const struct dentry
*dentry
)
307 if (unlikely(!audit_dummy_context()))
308 __audit_inode(name
, dentry
,
309 AUDIT_INODE_PARENT
| AUDIT_INODE_HIDDEN
);
311 static inline void audit_inode_child(struct inode
*parent
,
312 const struct dentry
*dentry
,
313 const unsigned char type
) {
314 if (unlikely(!audit_dummy_context()))
315 __audit_inode_child(parent
, dentry
, type
);
317 void audit_core_dumps(long signr
);
319 static inline void audit_seccomp(unsigned long syscall
, long signr
, int code
)
324 /* Force a record to be reported if a signal was delivered. */
325 if (signr
|| unlikely(!audit_dummy_context()))
326 __audit_seccomp(syscall
, signr
, code
);
329 static inline void audit_ptrace(struct task_struct
*t
)
331 if (unlikely(!audit_dummy_context()))
335 /* Private API (for audit.c only) */
336 extern unsigned int audit_serial(void);
337 extern int auditsc_get_stamp(struct audit_context
*ctx
,
338 struct timespec
*t
, unsigned int *serial
);
339 extern int audit_set_loginuid(kuid_t loginuid
);
341 static inline kuid_t
audit_get_loginuid(struct task_struct
*tsk
)
343 return tsk
->loginuid
;
346 static inline unsigned int audit_get_sessionid(struct task_struct
*tsk
)
348 return tsk
->sessionid
;
351 static inline struct tty_struct
*audit_get_tty(struct task_struct
*tsk
)
353 struct tty_struct
*tty
= NULL
;
356 spin_lock_irqsave(&tsk
->sighand
->siglock
, flags
);
358 tty
= tty_kref_get(tsk
->signal
->tty
);
359 spin_unlock_irqrestore(&tsk
->sighand
->siglock
, flags
);
363 static inline void audit_put_tty(struct tty_struct
*tty
)
368 extern void __audit_ipc_obj(struct kern_ipc_perm
*ipcp
);
369 extern void __audit_ipc_set_perm(unsigned long qbytes
, uid_t uid
, gid_t gid
, umode_t mode
);
370 extern void __audit_bprm(struct linux_binprm
*bprm
);
371 extern int __audit_socketcall(int nargs
, unsigned long *args
);
372 extern int __audit_sockaddr(int len
, void *addr
);
373 extern void __audit_fd_pair(int fd1
, int fd2
);
374 extern void __audit_mq_open(int oflag
, umode_t mode
, struct mq_attr
*attr
);
375 extern void __audit_mq_sendrecv(mqd_t mqdes
, size_t msg_len
, unsigned int msg_prio
, const struct timespec
*abs_timeout
);
376 extern void __audit_mq_notify(mqd_t mqdes
, const struct sigevent
*notification
);
377 extern void __audit_mq_getsetattr(mqd_t mqdes
, struct mq_attr
*mqstat
);
378 extern int __audit_log_bprm_fcaps(struct linux_binprm
*bprm
,
379 const struct cred
*new,
380 const struct cred
*old
);
381 extern void __audit_log_capset(const struct cred
*new, const struct cred
*old
);
382 extern void __audit_mmap_fd(int fd
, int flags
);
384 static inline void audit_ipc_obj(struct kern_ipc_perm
*ipcp
)
386 if (unlikely(!audit_dummy_context()))
387 __audit_ipc_obj(ipcp
);
389 static inline void audit_fd_pair(int fd1
, int fd2
)
391 if (unlikely(!audit_dummy_context()))
392 __audit_fd_pair(fd1
, fd2
);
394 static inline void audit_ipc_set_perm(unsigned long qbytes
, uid_t uid
, gid_t gid
, umode_t mode
)
396 if (unlikely(!audit_dummy_context()))
397 __audit_ipc_set_perm(qbytes
, uid
, gid
, mode
);
399 static inline void audit_bprm(struct linux_binprm
*bprm
)
401 if (unlikely(!audit_dummy_context()))
404 static inline int audit_socketcall(int nargs
, unsigned long *args
)
406 if (unlikely(!audit_dummy_context()))
407 return __audit_socketcall(nargs
, args
);
410 static inline int audit_sockaddr(int len
, void *addr
)
412 if (unlikely(!audit_dummy_context()))
413 return __audit_sockaddr(len
, addr
);
416 static inline void audit_mq_open(int oflag
, umode_t mode
, struct mq_attr
*attr
)
418 if (unlikely(!audit_dummy_context()))
419 __audit_mq_open(oflag
, mode
, attr
);
421 static inline void audit_mq_sendrecv(mqd_t mqdes
, size_t msg_len
, unsigned int msg_prio
, const struct timespec
*abs_timeout
)
423 if (unlikely(!audit_dummy_context()))
424 __audit_mq_sendrecv(mqdes
, msg_len
, msg_prio
, abs_timeout
);
426 static inline void audit_mq_notify(mqd_t mqdes
, const struct sigevent
*notification
)
428 if (unlikely(!audit_dummy_context()))
429 __audit_mq_notify(mqdes
, notification
);
431 static inline void audit_mq_getsetattr(mqd_t mqdes
, struct mq_attr
*mqstat
)
433 if (unlikely(!audit_dummy_context()))
434 __audit_mq_getsetattr(mqdes
, mqstat
);
437 static inline int audit_log_bprm_fcaps(struct linux_binprm
*bprm
,
438 const struct cred
*new,
439 const struct cred
*old
)
441 if (unlikely(!audit_dummy_context()))
442 return __audit_log_bprm_fcaps(bprm
, new, old
);
446 static inline void audit_log_capset(const struct cred
*new,
447 const struct cred
*old
)
449 if (unlikely(!audit_dummy_context()))
450 __audit_log_capset(new, old
);
453 static inline void audit_mmap_fd(int fd
, int flags
)
455 if (unlikely(!audit_dummy_context()))
456 __audit_mmap_fd(fd
, flags
);
459 extern int audit_n_rules
;
460 extern int audit_signals
;
461 #else /* CONFIG_AUDITSYSCALL */
462 static inline int audit_alloc(struct task_struct
*task
)
466 static inline void audit_free(struct task_struct
*task
)
468 static inline void audit_syscall_entry(int major
, unsigned long a0
,
469 unsigned long a1
, unsigned long a2
,
472 static inline void audit_syscall_exit(void *pt_regs
)
474 static inline bool audit_dummy_context(void)
478 static inline struct filename
*audit_reusename(const __user
char *name
)
482 static inline void audit_getname(struct filename
*name
)
484 static inline void __audit_inode(struct filename
*name
,
485 const struct dentry
*dentry
,
488 static inline void __audit_inode_child(struct inode
*parent
,
489 const struct dentry
*dentry
,
490 const unsigned char type
)
492 static inline void audit_inode(struct filename
*name
,
493 const struct dentry
*dentry
,
496 static inline void audit_file(struct file
*file
)
499 static inline void audit_inode_parent_hidden(struct filename
*name
,
500 const struct dentry
*dentry
)
502 static inline void audit_inode_child(struct inode
*parent
,
503 const struct dentry
*dentry
,
504 const unsigned char type
)
506 static inline void audit_core_dumps(long signr
)
508 static inline void __audit_seccomp(unsigned long syscall
, long signr
, int code
)
510 static inline void audit_seccomp(unsigned long syscall
, long signr
, int code
)
512 static inline int auditsc_get_stamp(struct audit_context
*ctx
,
513 struct timespec
*t
, unsigned int *serial
)
517 static inline kuid_t
audit_get_loginuid(struct task_struct
*tsk
)
521 static inline unsigned int audit_get_sessionid(struct task_struct
*tsk
)
525 static inline struct tty_struct
*audit_get_tty(struct task_struct
*tsk
)
529 static inline void audit_put_tty(struct tty_struct
*tty
)
531 static inline void audit_ipc_obj(struct kern_ipc_perm
*ipcp
)
533 static inline void audit_ipc_set_perm(unsigned long qbytes
, uid_t uid
,
534 gid_t gid
, umode_t mode
)
536 static inline void audit_bprm(struct linux_binprm
*bprm
)
538 static inline int audit_socketcall(int nargs
, unsigned long *args
)
542 static inline void audit_fd_pair(int fd1
, int fd2
)
544 static inline int audit_sockaddr(int len
, void *addr
)
548 static inline void audit_mq_open(int oflag
, umode_t mode
, struct mq_attr
*attr
)
550 static inline void audit_mq_sendrecv(mqd_t mqdes
, size_t msg_len
,
551 unsigned int msg_prio
,
552 const struct timespec
*abs_timeout
)
554 static inline void audit_mq_notify(mqd_t mqdes
,
555 const struct sigevent
*notification
)
557 static inline void audit_mq_getsetattr(mqd_t mqdes
, struct mq_attr
*mqstat
)
559 static inline int audit_log_bprm_fcaps(struct linux_binprm
*bprm
,
560 const struct cred
*new,
561 const struct cred
*old
)
565 static inline void audit_log_capset(const struct cred
*new,
566 const struct cred
*old
)
568 static inline void audit_mmap_fd(int fd
, int flags
)
570 static inline void audit_ptrace(struct task_struct
*t
)
572 #define audit_n_rules 0
573 #define audit_signals 0
574 #endif /* CONFIG_AUDITSYSCALL */
576 static inline bool audit_loginuid_set(struct task_struct
*tsk
)
578 return uid_valid(audit_get_loginuid(tsk
));
581 static inline void audit_log_string(struct audit_buffer
*ab
, const char *buf
)
583 audit_log_n_string(ab
, buf
, strlen(buf
));
This page took 0.046195 seconds and 6 git commands to generate.