OSDN Git Service

mm/vmalloc.c: fix align value calculation error
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / audit.h
1 /* audit.h -- Auditing support
2  *
3  * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
4  * All Rights Reserved.
5  *
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.
10  *
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.
15  *
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
19  *
20  * Written by Rickard E. (Rik) Faith <faith@redhat.com>
21  *
22  */
23 #ifndef _LINUX_AUDIT_H_
24 #define _LINUX_AUDIT_H_
25
26 #include <linux/sched.h>
27 #include <linux/ptrace.h>
28 #include <uapi/linux/audit.h>
29 #include <linux/tty.h>
30
31 #define AUDIT_INO_UNSET ((unsigned long)-1)
32 #define AUDIT_DEV_UNSET ((dev_t)-1)
33
34 struct audit_sig_info {
35         uid_t           uid;
36         pid_t           pid;
37         char            ctx[0];
38 };
39
40 struct audit_buffer;
41 struct audit_context;
42 struct inode;
43 struct netlink_skb_parms;
44 struct path;
45 struct linux_binprm;
46 struct mq_attr;
47 struct mqstat;
48 struct audit_watch;
49 struct audit_tree;
50 struct sk_buff;
51
52 struct audit_krule {
53         u32                     pflags;
54         u32                     flags;
55         u32                     listnr;
56         u32                     action;
57         u32                     mask[AUDIT_BITMASK_SIZE];
58         u32                     buflen; /* for data alloc on list rules */
59         u32                     field_count;
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 */
69         u64                     prio;
70 };
71
72 /* Flag to indicate legacy AUDIT_LOGINUID unset usage */
73 #define AUDIT_LOGINUID_LEGACY           0x1
74
75 struct audit_field {
76         u32                             type;
77         union {
78                 u32                     val;
79                 kuid_t                  uid;
80                 kgid_t                  gid;
81                 struct {
82                         char            *lsm_str;
83                         void            *lsm_rule;
84                 };
85         };
86         u32                             op;
87 };
88
89 extern int is_audit_feature_set(int which);
90
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[];
100
101 extern int audit_classify_compat_syscall(int abi, unsigned syscall);
102
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 */
109
110 /* maximized args number that audit_socketcall can process */
111 #define AUDITSC_ARGS            6
112
113 struct filename;
114
115 extern void audit_log_session_info(struct audit_buffer *ab);
116
117 #ifdef CONFIG_AUDIT_COMPAT_GENERIC
118 #define audit_is_compat(arch)  (!((arch) & __AUDIT_ARCH_64BIT))
119 #else
120 #define audit_is_compat(arch)  false
121 #endif
122
123 #ifdef CONFIG_AUDITSYSCALL
124 #include <asm/syscall.h> /* for syscall_get_arch() */
125
126 /* These are defined in auditsc.c */
127                                 /* Public API */
128 extern int  audit_alloc(struct task_struct *task);
129 extern void __audit_free(struct task_struct *task);
130 extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
131                                   unsigned long a2, unsigned long a3);
132 extern void __audit_syscall_exit(int ret_success, long ret_value);
133 extern struct filename *__audit_reusename(const __user char *uptr);
134 extern void __audit_getname(struct filename *name);
135
136 #define AUDIT_INODE_PARENT      1       /* dentry represents the parent */
137 #define AUDIT_INODE_HIDDEN      2       /* audit record should be hidden */
138 extern void __audit_inode(struct filename *name, const struct dentry *dentry,
139                                 unsigned int flags);
140 extern void __audit_file(const struct file *);
141 extern void __audit_inode_child(const struct inode *parent,
142                                 const struct dentry *dentry,
143                                 const unsigned char type);
144 extern void __audit_seccomp(unsigned long syscall, long signr, int code);
145 extern void __audit_ptrace(struct task_struct *t);
146
147 static inline bool audit_dummy_context(void)
148 {
149         void *p = current->audit_context;
150         return !p || *(int *)p;
151 }
152 static inline void audit_free(struct task_struct *task)
153 {
154         if (unlikely(task->audit_context))
155                 __audit_free(task);
156 }
157 static inline void audit_syscall_entry(int major, unsigned long a0,
158                                        unsigned long a1, unsigned long a2,
159                                        unsigned long a3)
160 {
161         if (unlikely(current->audit_context))
162                 __audit_syscall_entry(major, a0, a1, a2, a3);
163 }
164 static inline void audit_syscall_exit(void *pt_regs)
165 {
166         if (unlikely(current->audit_context)) {
167                 int success = is_syscall_success(pt_regs);
168                 long return_code = regs_return_value(pt_regs);
169
170                 __audit_syscall_exit(success, return_code);
171         }
172 }
173 static inline struct filename *audit_reusename(const __user char *name)
174 {
175         if (unlikely(!audit_dummy_context()))
176                 return __audit_reusename(name);
177         return NULL;
178 }
179 static inline void audit_getname(struct filename *name)
180 {
181         if (unlikely(!audit_dummy_context()))
182                 __audit_getname(name);
183 }
184 static inline void audit_inode(struct filename *name,
185                                 const struct dentry *dentry,
186                                 unsigned int parent) {
187         if (unlikely(!audit_dummy_context())) {
188                 unsigned int flags = 0;
189                 if (parent)
190                         flags |= AUDIT_INODE_PARENT;
191                 __audit_inode(name, dentry, flags);
192         }
193 }
194 static inline void audit_file(struct file *file)
195 {
196         if (unlikely(!audit_dummy_context()))
197                 __audit_file(file);
198 }
199 static inline void audit_inode_parent_hidden(struct filename *name,
200                                                 const struct dentry *dentry)
201 {
202         if (unlikely(!audit_dummy_context()))
203                 __audit_inode(name, dentry,
204                                 AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
205 }
206 static inline void audit_inode_child(const struct inode *parent,
207                                      const struct dentry *dentry,
208                                      const unsigned char type) {
209         if (unlikely(!audit_dummy_context()))
210                 __audit_inode_child(parent, dentry, type);
211 }
212 void audit_core_dumps(long signr);
213
214 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
215 {
216         /* Force a record to be reported if a signal was delivered. */
217         if (signr || unlikely(!audit_dummy_context()))
218                 __audit_seccomp(syscall, signr, code);
219 }
220
221 static inline void audit_ptrace(struct task_struct *t)
222 {
223         if (unlikely(!audit_dummy_context()))
224                 __audit_ptrace(t);
225 }
226
227                                 /* Private API (for audit.c only) */
228 extern unsigned int audit_serial(void);
229 extern int auditsc_get_stamp(struct audit_context *ctx,
230                               struct timespec *t, unsigned int *serial);
231 extern int audit_set_loginuid(kuid_t loginuid);
232
233 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
234 {
235         return tsk->loginuid;
236 }
237
238 static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
239 {
240         return tsk->sessionid;
241 }
242
243 static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
244 {
245         struct tty_struct *tty = NULL;
246         unsigned long flags;
247
248         spin_lock_irqsave(&tsk->sighand->siglock, flags);
249         if (tsk->signal)
250                 tty = tty_kref_get(tsk->signal->tty);
251         spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
252         return tty;
253 }
254
255 static inline void audit_put_tty(struct tty_struct *tty)
256 {
257         tty_kref_put(tty);
258 }
259
260 extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
261 extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
262 extern void __audit_bprm(struct linux_binprm *bprm);
263 extern int __audit_socketcall(int nargs, unsigned long *args);
264 extern int __audit_sockaddr(int len, void *addr);
265 extern void __audit_fd_pair(int fd1, int fd2);
266 extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
267 extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout);
268 extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
269 extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
270 extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
271                                   const struct cred *new,
272                                   const struct cred *old);
273 extern void __audit_log_capset(const struct cred *new, const struct cred *old);
274 extern void __audit_mmap_fd(int fd, int flags);
275
276 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
277 {
278         if (unlikely(!audit_dummy_context()))
279                 __audit_ipc_obj(ipcp);
280 }
281 static inline void audit_fd_pair(int fd1, int fd2)
282 {
283         if (unlikely(!audit_dummy_context()))
284                 __audit_fd_pair(fd1, fd2);
285 }
286 static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode)
287 {
288         if (unlikely(!audit_dummy_context()))
289                 __audit_ipc_set_perm(qbytes, uid, gid, mode);
290 }
291 static inline void audit_bprm(struct linux_binprm *bprm)
292 {
293         if (unlikely(!audit_dummy_context()))
294                 __audit_bprm(bprm);
295 }
296 static inline int audit_socketcall(int nargs, unsigned long *args)
297 {
298         if (unlikely(!audit_dummy_context()))
299                 return __audit_socketcall(nargs, args);
300         return 0;
301 }
302
303 static inline int audit_socketcall_compat(int nargs, u32 *args)
304 {
305         unsigned long a[AUDITSC_ARGS];
306         int i;
307
308         if (audit_dummy_context())
309                 return 0;
310
311         for (i = 0; i < nargs; i++)
312                 a[i] = (unsigned long)args[i];
313         return __audit_socketcall(nargs, a);
314 }
315
316 static inline int audit_sockaddr(int len, void *addr)
317 {
318         if (unlikely(!audit_dummy_context()))
319                 return __audit_sockaddr(len, addr);
320         return 0;
321 }
322 static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
323 {
324         if (unlikely(!audit_dummy_context()))
325                 __audit_mq_open(oflag, mode, attr);
326 }
327 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout)
328 {
329         if (unlikely(!audit_dummy_context()))
330                 __audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
331 }
332 static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
333 {
334         if (unlikely(!audit_dummy_context()))
335                 __audit_mq_notify(mqdes, notification);
336 }
337 static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
338 {
339         if (unlikely(!audit_dummy_context()))
340                 __audit_mq_getsetattr(mqdes, mqstat);
341 }
342
343 static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
344                                        const struct cred *new,
345                                        const struct cred *old)
346 {
347         if (unlikely(!audit_dummy_context()))
348                 return __audit_log_bprm_fcaps(bprm, new, old);
349         return 0;
350 }
351
352 static inline void audit_log_capset(const struct cred *new,
353                                    const struct cred *old)
354 {
355         if (unlikely(!audit_dummy_context()))
356                 __audit_log_capset(new, old);
357 }
358
359 static inline void audit_mmap_fd(int fd, int flags)
360 {
361         if (unlikely(!audit_dummy_context()))
362                 __audit_mmap_fd(fd, flags);
363 }
364
365 extern int audit_n_rules;
366 extern int audit_signals;
367 #else /* CONFIG_AUDITSYSCALL */
368 static inline int audit_alloc(struct task_struct *task)
369 {
370         return 0;
371 }
372 static inline void audit_free(struct task_struct *task)
373 { }
374 static inline void audit_syscall_entry(int major, unsigned long a0,
375                                        unsigned long a1, unsigned long a2,
376                                        unsigned long a3)
377 { }
378 static inline void audit_syscall_exit(void *pt_regs)
379 { }
380 static inline bool audit_dummy_context(void)
381 {
382         return true;
383 }
384 static inline struct filename *audit_reusename(const __user char *name)
385 {
386         return NULL;
387 }
388 static inline void audit_getname(struct filename *name)
389 { }
390 static inline void __audit_inode(struct filename *name,
391                                         const struct dentry *dentry,
392                                         unsigned int flags)
393 { }
394 static inline void __audit_inode_child(const struct inode *parent,
395                                         const struct dentry *dentry,
396                                         const unsigned char type)
397 { }
398 static inline void audit_inode(struct filename *name,
399                                 const struct dentry *dentry,
400                                 unsigned int parent)
401 { }
402 static inline void audit_file(struct file *file)
403 {
404 }
405 static inline void audit_inode_parent_hidden(struct filename *name,
406                                 const struct dentry *dentry)
407 { }
408 static inline void audit_inode_child(const struct inode *parent,
409                                      const struct dentry *dentry,
410                                      const unsigned char type)
411 { }
412 static inline void audit_core_dumps(long signr)
413 { }
414 static inline void __audit_seccomp(unsigned long syscall, long signr, int code)
415 { }
416 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
417 { }
418 static inline int auditsc_get_stamp(struct audit_context *ctx,
419                               struct timespec *t, unsigned int *serial)
420 {
421         return 0;
422 }
423 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
424 {
425         return INVALID_UID;
426 }
427 static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
428 {
429         return -1;
430 }
431 static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
432 {
433         return NULL;
434 }
435 static inline void audit_put_tty(struct tty_struct *tty)
436 { }
437 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
438 { }
439 static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
440                                         gid_t gid, umode_t mode)
441 { }
442 static inline void audit_bprm(struct linux_binprm *bprm)
443 { }
444 static inline int audit_socketcall(int nargs, unsigned long *args)
445 {
446         return 0;
447 }
448
449 static inline int audit_socketcall_compat(int nargs, u32 *args)
450 {
451         return 0;
452 }
453
454 static inline void audit_fd_pair(int fd1, int fd2)
455 { }
456 static inline int audit_sockaddr(int len, void *addr)
457 {
458         return 0;
459 }
460 static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
461 { }
462 static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
463                                      unsigned int msg_prio,
464                                      const struct timespec *abs_timeout)
465 { }
466 static inline void audit_mq_notify(mqd_t mqdes,
467                                    const struct sigevent *notification)
468 { }
469 static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
470 { }
471 static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
472                                        const struct cred *new,
473                                        const struct cred *old)
474 {
475         return 0;
476 }
477 static inline void audit_log_capset(const struct cred *new,
478                                     const struct cred *old)
479 { }
480 static inline void audit_mmap_fd(int fd, int flags)
481 { }
482 static inline void audit_ptrace(struct task_struct *t)
483 { }
484 #define audit_n_rules 0
485 #define audit_signals 0
486 #endif /* CONFIG_AUDITSYSCALL */
487
488 static inline bool audit_loginuid_set(struct task_struct *tsk)
489 {
490         return uid_valid(audit_get_loginuid(tsk));
491 }
492
493 #ifdef CONFIG_AUDIT
494 /* These are defined in audit.c */
495                                 /* Public API */
496 extern __printf(4, 5)
497 void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
498                const char *fmt, ...);
499
500 extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
501 extern __printf(2, 3)
502 void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
503 extern void                 audit_log_end(struct audit_buffer *ab);
504 extern bool                 audit_string_contains_control(const char *string,
505                                                           size_t len);
506 extern void                 audit_log_n_hex(struct audit_buffer *ab,
507                                           const unsigned char *buf,
508                                           size_t len);
509 extern void                 audit_log_n_string(struct audit_buffer *ab,
510                                                const char *buf,
511                                                size_t n);
512 extern void                 audit_log_n_untrustedstring(struct audit_buffer *ab,
513                                                         const char *string,
514                                                         size_t n);
515 extern void                 audit_log_untrustedstring(struct audit_buffer *ab,
516                                                       const char *string);
517 extern void                 audit_log_d_path(struct audit_buffer *ab,
518                                              const char *prefix,
519                                              const struct path *path);
520 extern void                 audit_log_key(struct audit_buffer *ab,
521                                           char *key);
522 extern void                 audit_log_link_denied(const char *operation,
523                                                   struct path *link);
524 extern void                 audit_log_lost(const char *message);
525 #ifdef CONFIG_SECURITY
526 extern void                 audit_log_secctx(struct audit_buffer *ab, u32 secid);
527 #else
528 static inline void          audit_log_secctx(struct audit_buffer *ab, u32 secid)
529 { }
530 #endif
531
532 extern int audit_log_task_context(struct audit_buffer *ab);
533 extern void audit_log_task_info(struct audit_buffer *ab,
534                                 struct task_struct *tsk);
535
536 extern int                  audit_update_lsm_rules(void);
537
538                                 /* Private API (for audit.c only) */
539 extern int audit_filter_user(int type);
540 extern int audit_filter_type(int type);
541 extern int audit_rule_change(int type, __u32 portid, int seq,
542                                 void *data, size_t datasz);
543 extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
544
545 extern u32 audit_enabled;
546 #else /* CONFIG_AUDIT */
547 static inline __printf(4, 5)
548 void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
549                const char *fmt, ...)
550 { }
551 static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
552                                                    gfp_t gfp_mask, int type)
553 {
554         return NULL;
555 }
556 static inline __printf(2, 3)
557 void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
558 { }
559 static inline void audit_log_end(struct audit_buffer *ab)
560 { }
561 static inline void audit_log_n_hex(struct audit_buffer *ab,
562                                    const unsigned char *buf, size_t len)
563 { }
564 static inline void audit_log_n_string(struct audit_buffer *ab,
565                                       const char *buf, size_t n)
566 { }
567 static inline void  audit_log_n_untrustedstring(struct audit_buffer *ab,
568                                                 const char *string, size_t n)
569 { }
570 static inline void audit_log_untrustedstring(struct audit_buffer *ab,
571                                              const char *string)
572 { }
573 static inline void audit_log_d_path(struct audit_buffer *ab,
574                                     const char *prefix,
575                                     const struct path *path)
576 { }
577 static inline void audit_log_key(struct audit_buffer *ab, char *key)
578 { }
579 static inline void audit_log_link_denied(const char *string,
580                                          const struct path *link)
581 { }
582 static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid)
583 { }
584 static inline int audit_log_task_context(struct audit_buffer *ab)
585 {
586         return 0;
587 }
588 static inline void audit_log_task_info(struct audit_buffer *ab,
589                                        struct task_struct *tsk)
590 { }
591 static inline int audit_update_lsm_rules(void)
592 {
593         return 0;
594 }
595 #define audit_enabled 0
596 #endif /* CONFIG_AUDIT */
597 static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
598 {
599         audit_log_n_string(ab, buf, strlen(buf));
600 }
601
602 #endif