b206795c09f7034214c2b20177d05c9c09bcf798
[safe/jmp/linux-2.6] / include / linux / security.h
1 /*
2  * Linux Security plug
3  *
4  * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5  * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
6  * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7  * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
8  * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
9  *
10  *      This program is free software; you can redistribute it and/or modify
11  *      it under the terms of the GNU General Public License as published by
12  *      the Free Software Foundation; either version 2 of the License, or
13  *      (at your option) any later version.
14  *
15  *      Due to this file being licensed under the GPL there is controversy over
16  *      whether this permits you to write a module that #includes this file
17  *      without placing your module under the GPL.  Please consult a lawyer for
18  *      advice before doing this.
19  *
20  */
21
22 #ifndef __LINUX_SECURITY_H
23 #define __LINUX_SECURITY_H
24
25 #include <linux/fs.h>
26 #include <linux/binfmts.h>
27 #include <linux/signal.h>
28 #include <linux/resource.h>
29 #include <linux/sem.h>
30 #include <linux/shm.h>
31 #include <linux/mm.h> /* PAGE_ALIGN */
32 #include <linux/msg.h>
33 #include <linux/sched.h>
34 #include <linux/key.h>
35 #include <linux/xfrm.h>
36 #include <linux/gfp.h>
37 #include <net/flow.h>
38
39 /* Maximum number of letters for an LSM name string */
40 #define SECURITY_NAME_MAX       10
41
42 /* If capable should audit the security request */
43 #define SECURITY_CAP_NOAUDIT 0
44 #define SECURITY_CAP_AUDIT 1
45
46 struct ctl_table;
47 struct audit_krule;
48
49 /*
50  * These functions are in security/capability.c and are used
51  * as the default capabilities functions
52  */
53 extern int cap_capable(struct task_struct *tsk, const struct cred *cred,
54                        int cap, int audit);
55 extern int cap_settime(struct timespec *ts, struct timezone *tz);
56 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
57 extern int cap_ptrace_traceme(struct task_struct *parent);
58 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
59 extern int cap_capset(struct cred *new, const struct cred *old,
60                       const kernel_cap_t *effective,
61                       const kernel_cap_t *inheritable,
62                       const kernel_cap_t *permitted);
63 extern int cap_bprm_set_creds(struct linux_binprm *bprm);
64 extern int cap_bprm_secureexec(struct linux_binprm *bprm);
65 extern int cap_inode_setxattr(struct dentry *dentry, const char *name,
66                               const void *value, size_t size, int flags);
67 extern int cap_inode_removexattr(struct dentry *dentry, const char *name);
68 extern int cap_inode_need_killpriv(struct dentry *dentry);
69 extern int cap_inode_killpriv(struct dentry *dentry);
70 extern int cap_file_mmap(struct file *file, unsigned long reqprot,
71                          unsigned long prot, unsigned long flags,
72                          unsigned long addr, unsigned long addr_only);
73 extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags);
74 extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
75                           unsigned long arg4, unsigned long arg5);
76 extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
77 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
78 extern int cap_task_setnice(struct task_struct *p, int nice);
79 extern int cap_syslog(int type, bool from_file);
80 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
81
82 struct msghdr;
83 struct sk_buff;
84 struct sock;
85 struct sockaddr;
86 struct socket;
87 struct flowi;
88 struct dst_entry;
89 struct xfrm_selector;
90 struct xfrm_policy;
91 struct xfrm_state;
92 struct xfrm_user_sec_ctx;
93 struct seq_file;
94
95 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
96 extern int cap_netlink_recv(struct sk_buff *skb, int cap);
97
98 void reset_security_ops(void);
99
100 #ifdef CONFIG_MMU
101 extern unsigned long mmap_min_addr;
102 extern unsigned long dac_mmap_min_addr;
103 #else
104 #define dac_mmap_min_addr       0UL
105 #endif
106
107 /*
108  * Values used in the task_security_ops calls
109  */
110 /* setuid or setgid, id0 == uid or gid */
111 #define LSM_SETID_ID    1
112
113 /* setreuid or setregid, id0 == real, id1 == eff */
114 #define LSM_SETID_RE    2
115
116 /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
117 #define LSM_SETID_RES   4
118
119 /* setfsuid or setfsgid, id0 == fsuid or fsgid */
120 #define LSM_SETID_FS    8
121
122 /* forward declares to avoid warnings */
123 struct sched_param;
124 struct request_sock;
125
126 /* bprm->unsafe reasons */
127 #define LSM_UNSAFE_SHARE        1
128 #define LSM_UNSAFE_PTRACE       2
129 #define LSM_UNSAFE_PTRACE_CAP   4
130
131 #ifdef CONFIG_MMU
132 /*
133  * If a hint addr is less than mmap_min_addr change hint to be as
134  * low as possible but still greater than mmap_min_addr
135  */
136 static inline unsigned long round_hint_to_min(unsigned long hint)
137 {
138         hint &= PAGE_MASK;
139         if (((void *)hint != NULL) &&
140             (hint < mmap_min_addr))
141                 return PAGE_ALIGN(mmap_min_addr);
142         return hint;
143 }
144 extern int mmap_min_addr_handler(struct ctl_table *table, int write,
145                                  void __user *buffer, size_t *lenp, loff_t *ppos);
146 #endif
147
148 #ifdef CONFIG_SECURITY
149
150 struct security_mnt_opts {
151         char **mnt_opts;
152         int *mnt_opts_flags;
153         int num_mnt_opts;
154 };
155
156 static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
157 {
158         opts->mnt_opts = NULL;
159         opts->mnt_opts_flags = NULL;
160         opts->num_mnt_opts = 0;
161 }
162
163 static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
164 {
165         int i;
166         if (opts->mnt_opts)
167                 for (i = 0; i < opts->num_mnt_opts; i++)
168                         kfree(opts->mnt_opts[i]);
169         kfree(opts->mnt_opts);
170         opts->mnt_opts = NULL;
171         kfree(opts->mnt_opts_flags);
172         opts->mnt_opts_flags = NULL;
173         opts->num_mnt_opts = 0;
174 }
175
176 /**
177  * struct security_operations - main security structure
178  *
179  * Security module identifier.
180  *
181  * @name:
182  *      A string that acts as a unique identifeir for the LSM with max number
183  *      of characters = SECURITY_NAME_MAX.
184  *
185  * Security hooks for program execution operations.
186  *
187  * @bprm_set_creds:
188  *      Save security information in the bprm->security field, typically based
189  *      on information about the bprm->file, for later use by the apply_creds
190  *      hook.  This hook may also optionally check permissions (e.g. for
191  *      transitions between security domains).
192  *      This hook may be called multiple times during a single execve, e.g. for
193  *      interpreters.  The hook can tell whether it has already been called by
194  *      checking to see if @bprm->security is non-NULL.  If so, then the hook
195  *      may decide either to retain the security information saved earlier or
196  *      to replace it.
197  *      @bprm contains the linux_binprm structure.
198  *      Return 0 if the hook is successful and permission is granted.
199  * @bprm_check_security:
200  *      This hook mediates the point when a search for a binary handler will
201  *      begin.  It allows a check the @bprm->security value which is set in the
202  *      preceding set_creds call.  The primary difference from set_creds is
203  *      that the argv list and envp list are reliably available in @bprm.  This
204  *      hook may be called multiple times during a single execve; and in each
205  *      pass set_creds is called first.
206  *      @bprm contains the linux_binprm structure.
207  *      Return 0 if the hook is successful and permission is granted.
208  * @bprm_committing_creds:
209  *      Prepare to install the new security attributes of a process being
210  *      transformed by an execve operation, based on the old credentials
211  *      pointed to by @current->cred and the information set in @bprm->cred by
212  *      the bprm_set_creds hook.  @bprm points to the linux_binprm structure.
213  *      This hook is a good place to perform state changes on the process such
214  *      as closing open file descriptors to which access will no longer be
215  *      granted when the attributes are changed.  This is called immediately
216  *      before commit_creds().
217  * @bprm_committed_creds:
218  *      Tidy up after the installation of the new security attributes of a
219  *      process being transformed by an execve operation.  The new credentials
220  *      have, by this point, been set to @current->cred.  @bprm points to the
221  *      linux_binprm structure.  This hook is a good place to perform state
222  *      changes on the process such as clearing out non-inheritable signal
223  *      state.  This is called immediately after commit_creds().
224  * @bprm_secureexec:
225  *      Return a boolean value (0 or 1) indicating whether a "secure exec"
226  *      is required.  The flag is passed in the auxiliary table
227  *      on the initial stack to the ELF interpreter to indicate whether libc
228  *      should enable secure mode.
229  *      @bprm contains the linux_binprm structure.
230  *
231  * Security hooks for filesystem operations.
232  *
233  * @sb_alloc_security:
234  *      Allocate and attach a security structure to the sb->s_security field.
235  *      The s_security field is initialized to NULL when the structure is
236  *      allocated.
237  *      @sb contains the super_block structure to be modified.
238  *      Return 0 if operation was successful.
239  * @sb_free_security:
240  *      Deallocate and clear the sb->s_security field.
241  *      @sb contains the super_block structure to be modified.
242  * @sb_statfs:
243  *      Check permission before obtaining filesystem statistics for the @mnt
244  *      mountpoint.
245  *      @dentry is a handle on the superblock for the filesystem.
246  *      Return 0 if permission is granted.
247  * @sb_mount:
248  *      Check permission before an object specified by @dev_name is mounted on
249  *      the mount point named by @nd.  For an ordinary mount, @dev_name
250  *      identifies a device if the file system type requires a device.  For a
251  *      remount (@flags & MS_REMOUNT), @dev_name is irrelevant.  For a
252  *      loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
253  *      pathname of the object being mounted.
254  *      @dev_name contains the name for object being mounted.
255  *      @path contains the path for mount point object.
256  *      @type contains the filesystem type.
257  *      @flags contains the mount flags.
258  *      @data contains the filesystem-specific data.
259  *      Return 0 if permission is granted.
260  * @sb_copy_data:
261  *      Allow mount option data to be copied prior to parsing by the filesystem,
262  *      so that the security module can extract security-specific mount
263  *      options cleanly (a filesystem may modify the data e.g. with strsep()).
264  *      This also allows the original mount data to be stripped of security-
265  *      specific options to avoid having to make filesystems aware of them.
266  *      @type the type of filesystem being mounted.
267  *      @orig the original mount data copied from userspace.
268  *      @copy copied data which will be passed to the security module.
269  *      Returns 0 if the copy was successful.
270  * @sb_umount:
271  *      Check permission before the @mnt file system is unmounted.
272  *      @mnt contains the mounted file system.
273  *      @flags contains the unmount flags, e.g. MNT_FORCE.
274  *      Return 0 if permission is granted.
275  * @sb_post_remount:
276  *      Update the security module's state when a filesystem is remounted.
277  *      This hook is only called if the remount was successful.
278  *      @mnt contains the mounted file system.
279  *      @flags contains the new filesystem flags.
280  *      @data contains the filesystem-specific data.
281  * @sb_post_addmount:
282  *      Update the security module's state when a filesystem is mounted.
283  *      This hook is called any time a mount is successfully grafetd to
284  *      the tree.
285  *      @mnt contains the mounted filesystem.
286  *      @mountpoint contains the path for the mount point.
287  * @sb_pivotroot:
288  *      Check permission before pivoting the root filesystem.
289  *      @old_path contains the path for the new location of the current root (put_old).
290  *      @new_path contains the path for the new root (new_root).
291  *      Return 0 if permission is granted.
292  * @sb_post_pivotroot:
293  *      Update module state after a successful pivot.
294  *      @old_path contains the path for the old root.
295  *      @new_path contains the path for the new root.
296  * @sb_set_mnt_opts:
297  *      Set the security relevant mount options used for a superblock
298  *      @sb the superblock to set security mount options for
299  *      @opts binary data structure containing all lsm mount data
300  * @sb_clone_mnt_opts:
301  *      Copy all security options from a given superblock to another
302  *      @oldsb old superblock which contain information to clone
303  *      @newsb new superblock which needs filled in
304  * @sb_parse_opts_str:
305  *      Parse a string of security data filling in the opts structure
306  *      @options string containing all mount options known by the LSM
307  *      @opts binary data structure usable by the LSM
308  *
309  * Security hooks for inode operations.
310  *
311  * @inode_alloc_security:
312  *      Allocate and attach a security structure to @inode->i_security.  The
313  *      i_security field is initialized to NULL when the inode structure is
314  *      allocated.
315  *      @inode contains the inode structure.
316  *      Return 0 if operation was successful.
317  * @inode_free_security:
318  *      @inode contains the inode structure.
319  *      Deallocate the inode security structure and set @inode->i_security to
320  *      NULL.
321  * @inode_init_security:
322  *      Obtain the security attribute name suffix and value to set on a newly
323  *      created inode and set up the incore security field for the new inode.
324  *      This hook is called by the fs code as part of the inode creation
325  *      transaction and provides for atomic labeling of the inode, unlike
326  *      the post_create/mkdir/... hooks called by the VFS.  The hook function
327  *      is expected to allocate the name and value via kmalloc, with the caller
328  *      being responsible for calling kfree after using them.
329  *      If the security module does not use security attributes or does
330  *      not wish to put a security attribute on this particular inode,
331  *      then it should return -EOPNOTSUPP to skip this processing.
332  *      @inode contains the inode structure of the newly created inode.
333  *      @dir contains the inode structure of the parent directory.
334  *      @name will be set to the allocated name suffix (e.g. selinux).
335  *      @value will be set to the allocated attribute value.
336  *      @len will be set to the length of the value.
337  *      Returns 0 if @name and @value have been successfully set,
338  *              -EOPNOTSUPP if no security attribute is needed, or
339  *              -ENOMEM on memory allocation failure.
340  * @inode_create:
341  *      Check permission to create a regular file.
342  *      @dir contains inode structure of the parent of the new file.
343  *      @dentry contains the dentry structure for the file to be created.
344  *      @mode contains the file mode of the file to be created.
345  *      Return 0 if permission is granted.
346  * @inode_link:
347  *      Check permission before creating a new hard link to a file.
348  *      @old_dentry contains the dentry structure for an existing link to the file.
349  *      @dir contains the inode structure of the parent directory of the new link.
350  *      @new_dentry contains the dentry structure for the new link.
351  *      Return 0 if permission is granted.
352  * @path_link:
353  *      Check permission before creating a new hard link to a file.
354  *      @old_dentry contains the dentry structure for an existing link
355  *      to the file.
356  *      @new_dir contains the path structure of the parent directory of
357  *      the new link.
358  *      @new_dentry contains the dentry structure for the new link.
359  *      Return 0 if permission is granted.
360  * @inode_unlink:
361  *      Check the permission to remove a hard link to a file.
362  *      @dir contains the inode structure of parent directory of the file.
363  *      @dentry contains the dentry structure for file to be unlinked.
364  *      Return 0 if permission is granted.
365  * @path_unlink:
366  *      Check the permission to remove a hard link to a file.
367  *      @dir contains the path structure of parent directory of the file.
368  *      @dentry contains the dentry structure for file to be unlinked.
369  *      Return 0 if permission is granted.
370  * @inode_symlink:
371  *      Check the permission to create a symbolic link to a file.
372  *      @dir contains the inode structure of parent directory of the symbolic link.
373  *      @dentry contains the dentry structure of the symbolic link.
374  *      @old_name contains the pathname of file.
375  *      Return 0 if permission is granted.
376  * @path_symlink:
377  *      Check the permission to create a symbolic link to a file.
378  *      @dir contains the path structure of parent directory of
379  *      the symbolic link.
380  *      @dentry contains the dentry structure of the symbolic link.
381  *      @old_name contains the pathname of file.
382  *      Return 0 if permission is granted.
383  * @inode_mkdir:
384  *      Check permissions to create a new directory in the existing directory
385  *      associated with inode strcture @dir.
386  *      @dir containst the inode structure of parent of the directory to be created.
387  *      @dentry contains the dentry structure of new directory.
388  *      @mode contains the mode of new directory.
389  *      Return 0 if permission is granted.
390  * @path_mkdir:
391  *      Check permissions to create a new directory in the existing directory
392  *      associated with path strcture @path.
393  *      @dir containst the path structure of parent of the directory
394  *      to be created.
395  *      @dentry contains the dentry structure of new directory.
396  *      @mode contains the mode of new directory.
397  *      Return 0 if permission is granted.
398  * @inode_rmdir:
399  *      Check the permission to remove a directory.
400  *      @dir contains the inode structure of parent of the directory to be removed.
401  *      @dentry contains the dentry structure of directory to be removed.
402  *      Return 0 if permission is granted.
403  * @path_rmdir:
404  *      Check the permission to remove a directory.
405  *      @dir contains the path structure of parent of the directory to be
406  *      removed.
407  *      @dentry contains the dentry structure of directory to be removed.
408  *      Return 0 if permission is granted.
409  * @inode_mknod:
410  *      Check permissions when creating a special file (or a socket or a fifo
411  *      file created via the mknod system call).  Note that if mknod operation
412  *      is being done for a regular file, then the create hook will be called
413  *      and not this hook.
414  *      @dir contains the inode structure of parent of the new file.
415  *      @dentry contains the dentry structure of the new file.
416  *      @mode contains the mode of the new file.
417  *      @dev contains the device number.
418  *      Return 0 if permission is granted.
419  * @path_mknod:
420  *      Check permissions when creating a file. Note that this hook is called
421  *      even if mknod operation is being done for a regular file.
422  *      @dir contains the path structure of parent of the new file.
423  *      @dentry contains the dentry structure of the new file.
424  *      @mode contains the mode of the new file.
425  *      @dev contains the undecoded device number. Use new_decode_dev() to get
426  *      the decoded device number.
427  *      Return 0 if permission is granted.
428  * @inode_rename:
429  *      Check for permission to rename a file or directory.
430  *      @old_dir contains the inode structure for parent of the old link.
431  *      @old_dentry contains the dentry structure of the old link.
432  *      @new_dir contains the inode structure for parent of the new link.
433  *      @new_dentry contains the dentry structure of the new link.
434  *      Return 0 if permission is granted.
435  * @path_rename:
436  *      Check for permission to rename a file or directory.
437  *      @old_dir contains the path structure for parent of the old link.
438  *      @old_dentry contains the dentry structure of the old link.
439  *      @new_dir contains the path structure for parent of the new link.
440  *      @new_dentry contains the dentry structure of the new link.
441  *      Return 0 if permission is granted.
442  * @path_chmod:
443  *      Check for permission to change DAC's permission of a file or directory.
444  *      @dentry contains the dentry structure.
445  *      @mnt contains the vfsmnt structure.
446  *      @mode contains DAC's mode.
447  *      Return 0 if permission is granted.
448  * @path_chown:
449  *      Check for permission to change owner/group of a file or directory.
450  *      @path contains the path structure.
451  *      @uid contains new owner's ID.
452  *      @gid contains new group's ID.
453  *      Return 0 if permission is granted.
454  * @path_chroot:
455  *      Check for permission to change root directory.
456  *      @path contains the path structure.
457  *      Return 0 if permission is granted.
458  * @inode_readlink:
459  *      Check the permission to read the symbolic link.
460  *      @dentry contains the dentry structure for the file link.
461  *      Return 0 if permission is granted.
462  * @inode_follow_link:
463  *      Check permission to follow a symbolic link when looking up a pathname.
464  *      @dentry contains the dentry structure for the link.
465  *      @nd contains the nameidata structure for the parent directory.
466  *      Return 0 if permission is granted.
467  * @inode_permission:
468  *      Check permission before accessing an inode.  This hook is called by the
469  *      existing Linux permission function, so a security module can use it to
470  *      provide additional checking for existing Linux permission checks.
471  *      Notice that this hook is called when a file is opened (as well as many
472  *      other operations), whereas the file_security_ops permission hook is
473  *      called when the actual read/write operations are performed.
474  *      @inode contains the inode structure to check.
475  *      @mask contains the permission mask.
476  *      @nd contains the nameidata (may be NULL).
477  *      Return 0 if permission is granted.
478  * @inode_setattr:
479  *      Check permission before setting file attributes.  Note that the kernel
480  *      call to notify_change is performed from several locations, whenever
481  *      file attributes change (such as when a file is truncated, chown/chmod
482  *      operations, transferring disk quotas, etc).
483  *      @dentry contains the dentry structure for the file.
484  *      @attr is the iattr structure containing the new file attributes.
485  *      Return 0 if permission is granted.
486  * @path_truncate:
487  *      Check permission before truncating a file.
488  *      @path contains the path structure for the file.
489  *      @length is the new length of the file.
490  *      @time_attrs is the flags passed to do_truncate().
491  *      Return 0 if permission is granted.
492  * @inode_getattr:
493  *      Check permission before obtaining file attributes.
494  *      @mnt is the vfsmount where the dentry was looked up
495  *      @dentry contains the dentry structure for the file.
496  *      Return 0 if permission is granted.
497  * @inode_delete:
498  *      @inode contains the inode structure for deleted inode.
499  *      This hook is called when a deleted inode is released (i.e. an inode
500  *      with no hard links has its use count drop to zero).  A security module
501  *      can use this hook to release any persistent label associated with the
502  *      inode.
503  * @inode_setxattr:
504  *      Check permission before setting the extended attributes
505  *      @value identified by @name for @dentry.
506  *      Return 0 if permission is granted.
507  * @inode_post_setxattr:
508  *      Update inode security field after successful setxattr operation.
509  *      @value identified by @name for @dentry.
510  * @inode_getxattr:
511  *      Check permission before obtaining the extended attributes
512  *      identified by @name for @dentry.
513  *      Return 0 if permission is granted.
514  * @inode_listxattr:
515  *      Check permission before obtaining the list of extended attribute
516  *      names for @dentry.
517  *      Return 0 if permission is granted.
518  * @inode_removexattr:
519  *      Check permission before removing the extended attribute
520  *      identified by @name for @dentry.
521  *      Return 0 if permission is granted.
522  * @inode_getsecurity:
523  *      Retrieve a copy of the extended attribute representation of the
524  *      security label associated with @name for @inode via @buffer.  Note that
525  *      @name is the remainder of the attribute name after the security prefix
526  *      has been removed. @alloc is used to specify of the call should return a
527  *      value via the buffer or just the value length Return size of buffer on
528  *      success.
529  * @inode_setsecurity:
530  *      Set the security label associated with @name for @inode from the
531  *      extended attribute value @value.  @size indicates the size of the
532  *      @value in bytes.  @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
533  *      Note that @name is the remainder of the attribute name after the
534  *      security. prefix has been removed.
535  *      Return 0 on success.
536  * @inode_listsecurity:
537  *      Copy the extended attribute names for the security labels
538  *      associated with @inode into @buffer.  The maximum size of @buffer
539  *      is specified by @buffer_size.  @buffer may be NULL to request
540  *      the size of the buffer required.
541  *      Returns number of bytes used/required on success.
542  * @inode_need_killpriv:
543  *      Called when an inode has been changed.
544  *      @dentry is the dentry being changed.
545  *      Return <0 on error to abort the inode change operation.
546  *      Return 0 if inode_killpriv does not need to be called.
547  *      Return >0 if inode_killpriv does need to be called.
548  * @inode_killpriv:
549  *      The setuid bit is being removed.  Remove similar security labels.
550  *      Called with the dentry->d_inode->i_mutex held.
551  *      @dentry is the dentry being changed.
552  *      Return 0 on success.  If error is returned, then the operation
553  *      causing setuid bit removal is failed.
554  * @inode_getsecid:
555  *      Get the secid associated with the node.
556  *      @inode contains a pointer to the inode.
557  *      @secid contains a pointer to the location where result will be saved.
558  *      In case of failure, @secid will be set to zero.
559  *
560  * Security hooks for file operations
561  *
562  * @file_permission:
563  *      Check file permissions before accessing an open file.  This hook is
564  *      called by various operations that read or write files.  A security
565  *      module can use this hook to perform additional checking on these
566  *      operations, e.g.  to revalidate permissions on use to support privilege
567  *      bracketing or policy changes.  Notice that this hook is used when the
568  *      actual read/write operations are performed, whereas the
569  *      inode_security_ops hook is called when a file is opened (as well as
570  *      many other operations).
571  *      Caveat:  Although this hook can be used to revalidate permissions for
572  *      various system call operations that read or write files, it does not
573  *      address the revalidation of permissions for memory-mapped files.
574  *      Security modules must handle this separately if they need such
575  *      revalidation.
576  *      @file contains the file structure being accessed.
577  *      @mask contains the requested permissions.
578  *      Return 0 if permission is granted.
579  * @file_alloc_security:
580  *      Allocate and attach a security structure to the file->f_security field.
581  *      The security field is initialized to NULL when the structure is first
582  *      created.
583  *      @file contains the file structure to secure.
584  *      Return 0 if the hook is successful and permission is granted.
585  * @file_free_security:
586  *      Deallocate and free any security structures stored in file->f_security.
587  *      @file contains the file structure being modified.
588  * @file_ioctl:
589  *      @file contains the file structure.
590  *      @cmd contains the operation to perform.
591  *      @arg contains the operational arguments.
592  *      Check permission for an ioctl operation on @file.  Note that @arg can
593  *      sometimes represents a user space pointer; in other cases, it may be a
594  *      simple integer value.  When @arg represents a user space pointer, it
595  *      should never be used by the security module.
596  *      Return 0 if permission is granted.
597  * @file_mmap :
598  *      Check permissions for a mmap operation.  The @file may be NULL, e.g.
599  *      if mapping anonymous memory.
600  *      @file contains the file structure for file to map (may be NULL).
601  *      @reqprot contains the protection requested by the application.
602  *      @prot contains the protection that will be applied by the kernel.
603  *      @flags contains the operational flags.
604  *      Return 0 if permission is granted.
605  * @file_mprotect:
606  *      Check permissions before changing memory access permissions.
607  *      @vma contains the memory region to modify.
608  *      @reqprot contains the protection requested by the application.
609  *      @prot contains the protection that will be applied by the kernel.
610  *      Return 0 if permission is granted.
611  * @file_lock:
612  *      Check permission before performing file locking operations.
613  *      Note: this hook mediates both flock and fcntl style locks.
614  *      @file contains the file structure.
615  *      @cmd contains the posix-translated lock operation to perform
616  *      (e.g. F_RDLCK, F_WRLCK).
617  *      Return 0 if permission is granted.
618  * @file_fcntl:
619  *      Check permission before allowing the file operation specified by @cmd
620  *      from being performed on the file @file.  Note that @arg can sometimes
621  *      represents a user space pointer; in other cases, it may be a simple
622  *      integer value.  When @arg represents a user space pointer, it should
623  *      never be used by the security module.
624  *      @file contains the file structure.
625  *      @cmd contains the operation to be performed.
626  *      @arg contains the operational arguments.
627  *      Return 0 if permission is granted.
628  * @file_set_fowner:
629  *      Save owner security information (typically from current->security) in
630  *      file->f_security for later use by the send_sigiotask hook.
631  *      @file contains the file structure to update.
632  *      Return 0 on success.
633  * @file_send_sigiotask:
634  *      Check permission for the file owner @fown to send SIGIO or SIGURG to the
635  *      process @tsk.  Note that this hook is sometimes called from interrupt.
636  *      Note that the fown_struct, @fown, is never outside the context of a
637  *      struct file, so the file structure (and associated security information)
638  *      can always be obtained:
639  *              container_of(fown, struct file, f_owner)
640  *      @tsk contains the structure of task receiving signal.
641  *      @fown contains the file owner information.
642  *      @sig is the signal that will be sent.  When 0, kernel sends SIGIO.
643  *      Return 0 if permission is granted.
644  * @file_receive:
645  *      This hook allows security modules to control the ability of a process
646  *      to receive an open file descriptor via socket IPC.
647  *      @file contains the file structure being received.
648  *      Return 0 if permission is granted.
649  *
650  * Security hook for dentry
651  *
652  * @dentry_open
653  *      Save open-time permission checking state for later use upon
654  *      file_permission, and recheck access if anything has changed
655  *      since inode_permission.
656  *
657  * Security hooks for task operations.
658  *
659  * @task_create:
660  *      Check permission before creating a child process.  See the clone(2)
661  *      manual page for definitions of the @clone_flags.
662  *      @clone_flags contains the flags indicating what should be shared.
663  *      Return 0 if permission is granted.
664  * @cred_alloc_blank:
665  *      @cred points to the credentials.
666  *      @gfp indicates the atomicity of any memory allocations.
667  *      Only allocate sufficient memory and attach to @cred such that
668  *      cred_transfer() will not get ENOMEM.
669  * @cred_free:
670  *      @cred points to the credentials.
671  *      Deallocate and clear the cred->security field in a set of credentials.
672  * @cred_prepare:
673  *      @new points to the new credentials.
674  *      @old points to the original credentials.
675  *      @gfp indicates the atomicity of any memory allocations.
676  *      Prepare a new set of credentials by copying the data from the old set.
677  * @cred_commit:
678  *      @new points to the new credentials.
679  *      @old points to the original credentials.
680  *      Install a new set of credentials.
681  * @cred_transfer:
682  *      @new points to the new credentials.
683  *      @old points to the original credentials.
684  *      Transfer data from original creds to new creds
685  * @kernel_act_as:
686  *      Set the credentials for a kernel service to act as (subjective context).
687  *      @new points to the credentials to be modified.
688  *      @secid specifies the security ID to be set
689  *      The current task must be the one that nominated @secid.
690  *      Return 0 if successful.
691  * @kernel_create_files_as:
692  *      Set the file creation context in a set of credentials to be the same as
693  *      the objective context of the specified inode.
694  *      @new points to the credentials to be modified.
695  *      @inode points to the inode to use as a reference.
696  *      The current task must be the one that nominated @inode.
697  *      Return 0 if successful.
698  * @kernel_module_request:
699  *      Ability to trigger the kernel to automatically upcall to userspace for
700  *      userspace to load a kernel module with the given name.
701  *      @kmod_name name of the module requested by the kernel
702  *      Return 0 if successful.
703  * @task_setuid:
704  *      Check permission before setting one or more of the user identity
705  *      attributes of the current process.  The @flags parameter indicates
706  *      which of the set*uid system calls invoked this hook and how to
707  *      interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
708  *      definitions at the beginning of this file for the @flags values and
709  *      their meanings.
710  *      @id0 contains a uid.
711  *      @id1 contains a uid.
712  *      @id2 contains a uid.
713  *      @flags contains one of the LSM_SETID_* values.
714  *      Return 0 if permission is granted.
715  * @task_fix_setuid:
716  *      Update the module's state after setting one or more of the user
717  *      identity attributes of the current process.  The @flags parameter
718  *      indicates which of the set*uid system calls invoked this hook.  If
719  *      @new is the set of credentials that will be installed.  Modifications
720  *      should be made to this rather than to @current->cred.
721  *      @old is the set of credentials that are being replaces
722  *      @flags contains one of the LSM_SETID_* values.
723  *      Return 0 on success.
724  * @task_setgid:
725  *      Check permission before setting one or more of the group identity
726  *      attributes of the current process.  The @flags parameter indicates
727  *      which of the set*gid system calls invoked this hook and how to
728  *      interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
729  *      definitions at the beginning of this file for the @flags values and
730  *      their meanings.
731  *      @id0 contains a gid.
732  *      @id1 contains a gid.
733  *      @id2 contains a gid.
734  *      @flags contains one of the LSM_SETID_* values.
735  *      Return 0 if permission is granted.
736  * @task_setpgid:
737  *      Check permission before setting the process group identifier of the
738  *      process @p to @pgid.
739  *      @p contains the task_struct for process being modified.
740  *      @pgid contains the new pgid.
741  *      Return 0 if permission is granted.
742  * @task_getpgid:
743  *      Check permission before getting the process group identifier of the
744  *      process @p.
745  *      @p contains the task_struct for the process.
746  *      Return 0 if permission is granted.
747  * @task_getsid:
748  *      Check permission before getting the session identifier of the process
749  *      @p.
750  *      @p contains the task_struct for the process.
751  *      Return 0 if permission is granted.
752  * @task_getsecid:
753  *      Retrieve the security identifier of the process @p.
754  *      @p contains the task_struct for the process and place is into @secid.
755  *      In case of failure, @secid will be set to zero.
756  *
757  * @task_setgroups:
758  *      Check permission before setting the supplementary group set of the
759  *      current process.
760  *      @group_info contains the new group information.
761  *      Return 0 if permission is granted.
762  * @task_setnice:
763  *      Check permission before setting the nice value of @p to @nice.
764  *      @p contains the task_struct of process.
765  *      @nice contains the new nice value.
766  *      Return 0 if permission is granted.
767  * @task_setioprio
768  *      Check permission before setting the ioprio value of @p to @ioprio.
769  *      @p contains the task_struct of process.
770  *      @ioprio contains the new ioprio value
771  *      Return 0 if permission is granted.
772  * @task_getioprio
773  *      Check permission before getting the ioprio value of @p.
774  *      @p contains the task_struct of process.
775  *      Return 0 if permission is granted.
776  * @task_setrlimit:
777  *      Check permission before setting the resource limits of the current
778  *      process for @resource to @new_rlim.  The old resource limit values can
779  *      be examined by dereferencing (current->signal->rlim + resource).
780  *      @resource contains the resource whose limit is being set.
781  *      @new_rlim contains the new limits for @resource.
782  *      Return 0 if permission is granted.
783  * @task_setscheduler:
784  *      Check permission before setting scheduling policy and/or parameters of
785  *      process @p based on @policy and @lp.
786  *      @p contains the task_struct for process.
787  *      @policy contains the scheduling policy.
788  *      @lp contains the scheduling parameters.
789  *      Return 0 if permission is granted.
790  * @task_getscheduler:
791  *      Check permission before obtaining scheduling information for process
792  *      @p.
793  *      @p contains the task_struct for process.
794  *      Return 0 if permission is granted.
795  * @task_movememory
796  *      Check permission before moving memory owned by process @p.
797  *      @p contains the task_struct for process.
798  *      Return 0 if permission is granted.
799  * @task_kill:
800  *      Check permission before sending signal @sig to @p.  @info can be NULL,
801  *      the constant 1, or a pointer to a siginfo structure.  If @info is 1 or
802  *      SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
803  *      from the kernel and should typically be permitted.
804  *      SIGIO signals are handled separately by the send_sigiotask hook in
805  *      file_security_ops.
806  *      @p contains the task_struct for process.
807  *      @info contains the signal information.
808  *      @sig contains the signal value.
809  *      @secid contains the sid of the process where the signal originated
810  *      Return 0 if permission is granted.
811  * @task_wait:
812  *      Check permission before allowing a process to reap a child process @p
813  *      and collect its status information.
814  *      @p contains the task_struct for process.
815  *      Return 0 if permission is granted.
816  * @task_prctl:
817  *      Check permission before performing a process control operation on the
818  *      current process.
819  *      @option contains the operation.
820  *      @arg2 contains a argument.
821  *      @arg3 contains a argument.
822  *      @arg4 contains a argument.
823  *      @arg5 contains a argument.
824  *      Return -ENOSYS if no-one wanted to handle this op, any other value to
825  *      cause prctl() to return immediately with that value.
826  * @task_to_inode:
827  *      Set the security attributes for an inode based on an associated task's
828  *      security attributes, e.g. for /proc/pid inodes.
829  *      @p contains the task_struct for the task.
830  *      @inode contains the inode structure for the inode.
831  *
832  * Security hooks for Netlink messaging.
833  *
834  * @netlink_send:
835  *      Save security information for a netlink message so that permission
836  *      checking can be performed when the message is processed.  The security
837  *      information can be saved using the eff_cap field of the
838  *      netlink_skb_parms structure.  Also may be used to provide fine
839  *      grained control over message transmission.
840  *      @sk associated sock of task sending the message.,
841  *      @skb contains the sk_buff structure for the netlink message.
842  *      Return 0 if the information was successfully saved and message
843  *      is allowed to be transmitted.
844  * @netlink_recv:
845  *      Check permission before processing the received netlink message in
846  *      @skb.
847  *      @skb contains the sk_buff structure for the netlink message.
848  *      @cap indicates the capability required
849  *      Return 0 if permission is granted.
850  *
851  * Security hooks for Unix domain networking.
852  *
853  * @unix_stream_connect:
854  *      Check permissions before establishing a Unix domain stream connection
855  *      between @sock and @other.
856  *      @sock contains the socket structure.
857  *      @other contains the peer socket structure.
858  *      Return 0 if permission is granted.
859  * @unix_may_send:
860  *      Check permissions before connecting or sending datagrams from @sock to
861  *      @other.
862  *      @sock contains the socket structure.
863  *      @sock contains the peer socket structure.
864  *      Return 0 if permission is granted.
865  *
866  * The @unix_stream_connect and @unix_may_send hooks were necessary because
867  * Linux provides an alternative to the conventional file name space for Unix
868  * domain sockets.  Whereas binding and connecting to sockets in the file name
869  * space is mediated by the typical file permissions (and caught by the mknod
870  * and permission hooks in inode_security_ops), binding and connecting to
871  * sockets in the abstract name space is completely unmediated.  Sufficient
872  * control of Unix domain sockets in the abstract name space isn't possible
873  * using only the socket layer hooks, since we need to know the actual target
874  * socket, which is not looked up until we are inside the af_unix code.
875  *
876  * Security hooks for socket operations.
877  *
878  * @socket_create:
879  *      Check permissions prior to creating a new socket.
880  *      @family contains the requested protocol family.
881  *      @type contains the requested communications type.
882  *      @protocol contains the requested protocol.
883  *      @kern set to 1 if a kernel socket.
884  *      Return 0 if permission is granted.
885  * @socket_post_create:
886  *      This hook allows a module to update or allocate a per-socket security
887  *      structure. Note that the security field was not added directly to the
888  *      socket structure, but rather, the socket security information is stored
889  *      in the associated inode.  Typically, the inode alloc_security hook will
890  *      allocate and and attach security information to
891  *      sock->inode->i_security.  This hook may be used to update the
892  *      sock->inode->i_security field with additional information that wasn't
893  *      available when the inode was allocated.
894  *      @sock contains the newly created socket structure.
895  *      @family contains the requested protocol family.
896  *      @type contains the requested communications type.
897  *      @protocol contains the requested protocol.
898  *      @kern set to 1 if a kernel socket.
899  * @socket_bind:
900  *      Check permission before socket protocol layer bind operation is
901  *      performed and the socket @sock is bound to the address specified in the
902  *      @address parameter.
903  *      @sock contains the socket structure.
904  *      @address contains the address to bind to.
905  *      @addrlen contains the length of address.
906  *      Return 0 if permission is granted.
907  * @socket_connect:
908  *      Check permission before socket protocol layer connect operation
909  *      attempts to connect socket @sock to a remote address, @address.
910  *      @sock contains the socket structure.
911  *      @address contains the address of remote endpoint.
912  *      @addrlen contains the length of address.
913  *      Return 0 if permission is granted.
914  * @socket_listen:
915  *      Check permission before socket protocol layer listen operation.
916  *      @sock contains the socket structure.
917  *      @backlog contains the maximum length for the pending connection queue.
918  *      Return 0 if permission is granted.
919  * @socket_accept:
920  *      Check permission before accepting a new connection.  Note that the new
921  *      socket, @newsock, has been created and some information copied to it,
922  *      but the accept operation has not actually been performed.
923  *      @sock contains the listening socket structure.
924  *      @newsock contains the newly created server socket for connection.
925  *      Return 0 if permission is granted.
926  * @socket_sendmsg:
927  *      Check permission before transmitting a message to another socket.
928  *      @sock contains the socket structure.
929  *      @msg contains the message to be transmitted.
930  *      @size contains the size of message.
931  *      Return 0 if permission is granted.
932  * @socket_recvmsg:
933  *      Check permission before receiving a message from a socket.
934  *      @sock contains the socket structure.
935  *      @msg contains the message structure.
936  *      @size contains the size of message structure.
937  *      @flags contains the operational flags.
938  *      Return 0 if permission is granted.
939  * @socket_getsockname:
940  *      Check permission before the local address (name) of the socket object
941  *      @sock is retrieved.
942  *      @sock contains the socket structure.
943  *      Return 0 if permission is granted.
944  * @socket_getpeername:
945  *      Check permission before the remote address (name) of a socket object
946  *      @sock is retrieved.
947  *      @sock contains the socket structure.
948  *      Return 0 if permission is granted.
949  * @socket_getsockopt:
950  *      Check permissions before retrieving the options associated with socket
951  *      @sock.
952  *      @sock contains the socket structure.
953  *      @level contains the protocol level to retrieve option from.
954  *      @optname contains the name of option to retrieve.
955  *      Return 0 if permission is granted.
956  * @socket_setsockopt:
957  *      Check permissions before setting the options associated with socket
958  *      @sock.
959  *      @sock contains the socket structure.
960  *      @level contains the protocol level to set options for.
961  *      @optname contains the name of the option to set.
962  *      Return 0 if permission is granted.
963  * @socket_shutdown:
964  *      Checks permission before all or part of a connection on the socket
965  *      @sock is shut down.
966  *      @sock contains the socket structure.
967  *      @how contains the flag indicating how future sends and receives are handled.
968  *      Return 0 if permission is granted.
969  * @socket_sock_rcv_skb:
970  *      Check permissions on incoming network packets.  This hook is distinct
971  *      from Netfilter's IP input hooks since it is the first time that the
972  *      incoming sk_buff @skb has been associated with a particular socket, @sk.
973  *      Must not sleep inside this hook because some callers hold spinlocks.
974  *      @sk contains the sock (not socket) associated with the incoming sk_buff.
975  *      @skb contains the incoming network data.
976  * @socket_getpeersec_stream:
977  *      This hook allows the security module to provide peer socket security
978  *      state for unix or connected tcp sockets to userspace via getsockopt
979  *      SO_GETPEERSEC.  For tcp sockets this can be meaningful if the
980  *      socket is associated with an ipsec SA.
981  *      @sock is the local socket.
982  *      @optval userspace memory where the security state is to be copied.
983  *      @optlen userspace int where the module should copy the actual length
984  *      of the security state.
985  *      @len as input is the maximum length to copy to userspace provided
986  *      by the caller.
987  *      Return 0 if all is well, otherwise, typical getsockopt return
988  *      values.
989  * @socket_getpeersec_dgram:
990  *      This hook allows the security module to provide peer socket security
991  *      state for udp sockets on a per-packet basis to userspace via
992  *      getsockopt SO_GETPEERSEC.  The application must first have indicated
993  *      the IP_PASSSEC option via getsockopt.  It can then retrieve the
994  *      security state returned by this hook for a packet via the SCM_SECURITY
995  *      ancillary message type.
996  *      @skb is the skbuff for the packet being queried
997  *      @secdata is a pointer to a buffer in which to copy the security data
998  *      @seclen is the maximum length for @secdata
999  *      Return 0 on success, error on failure.
1000  * @sk_alloc_security:
1001  *      Allocate and attach a security structure to the sk->sk_security field,
1002  *      which is used to copy security attributes between local stream sockets.
1003  * @sk_free_security:
1004  *      Deallocate security structure.
1005  * @sk_clone_security:
1006  *      Clone/copy security structure.
1007  * @sk_getsecid:
1008  *      Retrieve the LSM-specific secid for the sock to enable caching of network
1009  *      authorizations.
1010  * @sock_graft:
1011  *      Sets the socket's isec sid to the sock's sid.
1012  * @inet_conn_request:
1013  *      Sets the openreq's sid to socket's sid with MLS portion taken from peer sid.
1014  * @inet_csk_clone:
1015  *      Sets the new child socket's sid to the openreq sid.
1016  * @inet_conn_established:
1017  *      Sets the connection's peersid to the secmark on skb.
1018  * @req_classify_flow:
1019  *      Sets the flow's sid to the openreq sid.
1020  * @tun_dev_create:
1021  *      Check permissions prior to creating a new TUN device.
1022  * @tun_dev_post_create:
1023  *      This hook allows a module to update or allocate a per-socket security
1024  *      structure.
1025  *      @sk contains the newly created sock structure.
1026  * @tun_dev_attach:
1027  *      Check permissions prior to attaching to a persistent TUN device.  This
1028  *      hook can also be used by the module to update any security state
1029  *      associated with the TUN device's sock structure.
1030  *      @sk contains the existing sock structure.
1031  *
1032  * Security hooks for XFRM operations.
1033  *
1034  * @xfrm_policy_alloc_security:
1035  *      @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
1036  *      Database used by the XFRM system.
1037  *      @sec_ctx contains the security context information being provided by
1038  *      the user-level policy update program (e.g., setkey).
1039  *      Allocate a security structure to the xp->security field; the security
1040  *      field is initialized to NULL when the xfrm_policy is allocated.
1041  *      Return 0 if operation was successful (memory to allocate, legal context)
1042  * @xfrm_policy_clone_security:
1043  *      @old_ctx contains an existing xfrm_sec_ctx.
1044  *      @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
1045  *      Allocate a security structure in new_ctxp that contains the
1046  *      information from the old_ctx structure.
1047  *      Return 0 if operation was successful (memory to allocate).
1048  * @xfrm_policy_free_security:
1049  *      @ctx contains the xfrm_sec_ctx
1050  *      Deallocate xp->security.
1051  * @xfrm_policy_delete_security:
1052  *      @ctx contains the xfrm_sec_ctx.
1053  *      Authorize deletion of xp->security.
1054  * @xfrm_state_alloc_security:
1055  *      @x contains the xfrm_state being added to the Security Association
1056  *      Database by the XFRM system.
1057  *      @sec_ctx contains the security context information being provided by
1058  *      the user-level SA generation program (e.g., setkey or racoon).
1059  *      @secid contains the secid from which to take the mls portion of the context.
1060  *      Allocate a security structure to the x->security field; the security
1061  *      field is initialized to NULL when the xfrm_state is allocated. Set the
1062  *      context to correspond to either sec_ctx or polsec, with the mls portion
1063  *      taken from secid in the latter case.
1064  *      Return 0 if operation was successful (memory to allocate, legal context).
1065  * @xfrm_state_free_security:
1066  *      @x contains the xfrm_state.
1067  *      Deallocate x->security.
1068  * @xfrm_state_delete_security:
1069  *      @x contains the xfrm_state.
1070  *      Authorize deletion of x->security.
1071  * @xfrm_policy_lookup:
1072  *      @ctx contains the xfrm_sec_ctx for which the access control is being
1073  *      checked.
1074  *      @fl_secid contains the flow security label that is used to authorize
1075  *      access to the policy xp.
1076  *      @dir contains the direction of the flow (input or output).
1077  *      Check permission when a flow selects a xfrm_policy for processing
1078  *      XFRMs on a packet.  The hook is called when selecting either a
1079  *      per-socket policy or a generic xfrm policy.
1080  *      Return 0 if permission is granted, -ESRCH otherwise, or -errno
1081  *      on other errors.
1082  * @xfrm_state_pol_flow_match:
1083  *      @x contains the state to match.
1084  *      @xp contains the policy to check for a match.
1085  *      @fl contains the flow to check for a match.
1086  *      Return 1 if there is a match.
1087  * @xfrm_decode_session:
1088  *      @skb points to skb to decode.
1089  *      @secid points to the flow key secid to set.
1090  *      @ckall says if all xfrms used should be checked for same secid.
1091  *      Return 0 if ckall is zero or all xfrms used have the same secid.
1092  *
1093  * Security hooks affecting all Key Management operations
1094  *
1095  * @key_alloc:
1096  *      Permit allocation of a key and assign security data. Note that key does
1097  *      not have a serial number assigned at this point.
1098  *      @key points to the key.
1099  *      @flags is the allocation flags
1100  *      Return 0 if permission is granted, -ve error otherwise.
1101  * @key_free:
1102  *      Notification of destruction; free security data.
1103  *      @key points to the key.
1104  *      No return value.
1105  * @key_permission:
1106  *      See whether a specific operational right is granted to a process on a
1107  *      key.
1108  *      @key_ref refers to the key (key pointer + possession attribute bit).
1109  *      @cred points to the credentials to provide the context against which to
1110  *      evaluate the security data on the key.
1111  *      @perm describes the combination of permissions required of this key.
1112  *      Return 1 if permission granted, 0 if permission denied and -ve it the
1113  *      normal permissions model should be effected.
1114  * @key_getsecurity:
1115  *      Get a textual representation of the security context attached to a key
1116  *      for the purposes of honouring KEYCTL_GETSECURITY.  This function
1117  *      allocates the storage for the NUL-terminated string and the caller
1118  *      should free it.
1119  *      @key points to the key to be queried.
1120  *      @_buffer points to a pointer that should be set to point to the
1121  *       resulting string (if no label or an error occurs).
1122  *      Return the length of the string (including terminating NUL) or -ve if
1123  *      an error.
1124  *      May also return 0 (and a NULL buffer pointer) if there is no label.
1125  * @key_session_to_parent:
1126  *      Forcibly assign the session keyring from a process to its parent
1127  *      process.
1128  *      @cred: Pointer to process's credentials
1129  *      @parent_cred: Pointer to parent process's credentials
1130  *      @keyring: Proposed new session keyring
1131  *      Return 0 if permission is granted, -ve error otherwise.
1132  *
1133  * Security hooks affecting all System V IPC operations.
1134  *
1135  * @ipc_permission:
1136  *      Check permissions for access to IPC
1137  *      @ipcp contains the kernel IPC permission structure
1138  *      @flag contains the desired (requested) permission set
1139  *      Return 0 if permission is granted.
1140  * @ipc_getsecid:
1141  *      Get the secid associated with the ipc object.
1142  *      @ipcp contains the kernel IPC permission structure.
1143  *      @secid contains a pointer to the location where result will be saved.
1144  *      In case of failure, @secid will be set to zero.
1145  *
1146  * Security hooks for individual messages held in System V IPC message queues
1147  * @msg_msg_alloc_security:
1148  *      Allocate and attach a security structure to the msg->security field.
1149  *      The security field is initialized to NULL when the structure is first
1150  *      created.
1151  *      @msg contains the message structure to be modified.
1152  *      Return 0 if operation was successful and permission is granted.
1153  * @msg_msg_free_security:
1154  *      Deallocate the security structure for this message.
1155  *      @msg contains the message structure to be modified.
1156  *
1157  * Security hooks for System V IPC Message Queues
1158  *
1159  * @msg_queue_alloc_security:
1160  *      Allocate and attach a security structure to the
1161  *      msq->q_perm.security field. The security field is initialized to
1162  *      NULL when the structure is first created.
1163  *      @msq contains the message queue structure to be modified.
1164  *      Return 0 if operation was successful and permission is granted.
1165  * @msg_queue_free_security:
1166  *      Deallocate security structure for this message queue.
1167  *      @msq contains the message queue structure to be modified.
1168  * @msg_queue_associate:
1169  *      Check permission when a message queue is requested through the
1170  *      msgget system call.  This hook is only called when returning the
1171  *      message queue identifier for an existing message queue, not when a
1172  *      new message queue is created.
1173  *      @msq contains the message queue to act upon.
1174  *      @msqflg contains the operation control flags.
1175  *      Return 0 if permission is granted.
1176  * @msg_queue_msgctl:
1177  *      Check permission when a message control operation specified by @cmd
1178  *      is to be performed on the message queue @msq.
1179  *      The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
1180  *      @msq contains the message queue to act upon.  May be NULL.
1181  *      @cmd contains the operation to be performed.
1182  *      Return 0 if permission is granted.
1183  * @msg_queue_msgsnd:
1184  *      Check permission before a message, @msg, is enqueued on the message
1185  *      queue, @msq.
1186  *      @msq contains the message queue to send message to.
1187  *      @msg contains the message to be enqueued.
1188  *      @msqflg contains operational flags.
1189  *      Return 0 if permission is granted.
1190  * @msg_queue_msgrcv:
1191  *      Check permission before a message, @msg, is removed from the message
1192  *      queue, @msq.  The @target task structure contains a pointer to the
1193  *      process that will be receiving the message (not equal to the current
1194  *      process when inline receives are being performed).
1195  *      @msq contains the message queue to retrieve message from.
1196  *      @msg contains the message destination.
1197  *      @target contains the task structure for recipient process.
1198  *      @type contains the type of message requested.
1199  *      @mode contains the operational flags.
1200  *      Return 0 if permission is granted.
1201  *
1202  * Security hooks for System V Shared Memory Segments
1203  *
1204  * @shm_alloc_security:
1205  *      Allocate and attach a security structure to the shp->shm_perm.security
1206  *      field.  The security field is initialized to NULL when the structure is
1207  *      first created.
1208  *      @shp contains the shared memory structure to be modified.
1209  *      Return 0 if operation was successful and permission is granted.
1210  * @shm_free_security:
1211  *      Deallocate the security struct for this memory segment.
1212  *      @shp contains the shared memory structure to be modified.
1213  * @shm_associate:
1214  *      Check permission when a shared memory region is requested through the
1215  *      shmget system call.  This hook is only called when returning the shared
1216  *      memory region identifier for an existing region, not when a new shared
1217  *      memory region is created.
1218  *      @shp contains the shared memory structure to be modified.
1219  *      @shmflg contains the operation control flags.
1220  *      Return 0 if permission is granted.
1221  * @shm_shmctl:
1222  *      Check permission when a shared memory control operation specified by
1223  *      @cmd is to be performed on the shared memory region @shp.
1224  *      The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
1225  *      @shp contains shared memory structure to be modified.
1226  *      @cmd contains the operation to be performed.
1227  *      Return 0 if permission is granted.
1228  * @shm_shmat:
1229  *      Check permissions prior to allowing the shmat system call to attach the
1230  *      shared memory segment @shp to the data segment of the calling process.
1231  *      The attaching address is specified by @shmaddr.
1232  *      @shp contains the shared memory structure to be modified.
1233  *      @shmaddr contains the address to attach memory region to.
1234  *      @shmflg contains the operational flags.
1235  *      Return 0 if permission is granted.
1236  *
1237  * Security hooks for System V Semaphores
1238  *
1239  * @sem_alloc_security:
1240  *      Allocate and attach a security structure to the sma->sem_perm.security
1241  *      field.  The security field is initialized to NULL when the structure is
1242  *      first created.
1243  *      @sma contains the semaphore structure
1244  *      Return 0 if operation was successful and permission is granted.
1245  * @sem_free_security:
1246  *      deallocate security struct for this semaphore
1247  *      @sma contains the semaphore structure.
1248  * @sem_associate:
1249  *      Check permission when a semaphore is requested through the semget
1250  *      system call.  This hook is only called when returning the semaphore
1251  *      identifier for an existing semaphore, not when a new one must be
1252  *      created.
1253  *      @sma contains the semaphore structure.
1254  *      @semflg contains the operation control flags.
1255  *      Return 0 if permission is granted.
1256  * @sem_semctl:
1257  *      Check permission when a semaphore operation specified by @cmd is to be
1258  *      performed on the semaphore @sma.  The @sma may be NULL, e.g. for
1259  *      IPC_INFO or SEM_INFO.
1260  *      @sma contains the semaphore structure.  May be NULL.
1261  *      @cmd contains the operation to be performed.
1262  *      Return 0 if permission is granted.
1263  * @sem_semop
1264  *      Check permissions before performing operations on members of the
1265  *      semaphore set @sma.  If the @alter flag is nonzero, the semaphore set
1266  *      may be modified.
1267  *      @sma contains the semaphore structure.
1268  *      @sops contains the operations to perform.
1269  *      @nsops contains the number of operations to perform.
1270  *      @alter contains the flag indicating whether changes are to be made.
1271  *      Return 0 if permission is granted.
1272  *
1273  * @ptrace_access_check:
1274  *      Check permission before allowing the current process to trace the
1275  *      @child process.
1276  *      Security modules may also want to perform a process tracing check
1277  *      during an execve in the set_security or apply_creds hooks of
1278  *      tracing check during an execve in the bprm_set_creds hook of
1279  *      binprm_security_ops if the process is being traced and its security
1280  *      attributes would be changed by the execve.
1281  *      @child contains the task_struct structure for the target process.
1282  *      @mode contains the PTRACE_MODE flags indicating the form of access.
1283  *      Return 0 if permission is granted.
1284  * @ptrace_traceme:
1285  *      Check that the @parent process has sufficient permission to trace the
1286  *      current process before allowing the current process to present itself
1287  *      to the @parent process for tracing.
1288  *      The parent process will still have to undergo the ptrace_access_check
1289  *      checks before it is allowed to trace this one.
1290  *      @parent contains the task_struct structure for debugger process.
1291  *      Return 0 if permission is granted.
1292  * @capget:
1293  *      Get the @effective, @inheritable, and @permitted capability sets for
1294  *      the @target process.  The hook may also perform permission checking to
1295  *      determine if the current process is allowed to see the capability sets
1296  *      of the @target process.
1297  *      @target contains the task_struct structure for target process.
1298  *      @effective contains the effective capability set.
1299  *      @inheritable contains the inheritable capability set.
1300  *      @permitted contains the permitted capability set.
1301  *      Return 0 if the capability sets were successfully obtained.
1302  * @capset:
1303  *      Set the @effective, @inheritable, and @permitted capability sets for
1304  *      the current process.
1305  *      @new contains the new credentials structure for target process.
1306  *      @old contains the current credentials structure for target process.
1307  *      @effective contains the effective capability set.
1308  *      @inheritable contains the inheritable capability set.
1309  *      @permitted contains the permitted capability set.
1310  *      Return 0 and update @new if permission is granted.
1311  * @capable:
1312  *      Check whether the @tsk process has the @cap capability in the indicated
1313  *      credentials.
1314  *      @tsk contains the task_struct for the process.
1315  *      @cred contains the credentials to use.
1316  *      @cap contains the capability <include/linux/capability.h>.
1317  *      @audit: Whether to write an audit message or not
1318  *      Return 0 if the capability is granted for @tsk.
1319  * @acct:
1320  *      Check permission before enabling or disabling process accounting.  If
1321  *      accounting is being enabled, then @file refers to the open file used to
1322  *      store accounting records.  If accounting is being disabled, then @file
1323  *      is NULL.
1324  *      @file contains the file structure for the accounting file (may be NULL).
1325  *      Return 0 if permission is granted.
1326  * @sysctl:
1327  *      Check permission before accessing the @table sysctl variable in the
1328  *      manner specified by @op.
1329  *      @table contains the ctl_table structure for the sysctl variable.
1330  *      @op contains the operation (001 = search, 002 = write, 004 = read).
1331  *      Return 0 if permission is granted.
1332  * @syslog:
1333  *      Check permission before accessing the kernel message ring or changing
1334  *      logging to the console.
1335  *      See the syslog(2) manual page for an explanation of the @type values.
1336  *      @type contains the type of action.
1337  *      @from_file indicates the context of action (if it came from /proc).
1338  *      Return 0 if permission is granted.
1339  * @settime:
1340  *      Check permission to change the system time.
1341  *      struct timespec and timezone are defined in include/linux/time.h
1342  *      @ts contains new time
1343  *      @tz contains new timezone
1344  *      Return 0 if permission is granted.
1345  * @vm_enough_memory:
1346  *      Check permissions for allocating a new virtual mapping.
1347  *      @mm contains the mm struct it is being added to.
1348  *      @pages contains the number of pages.
1349  *      Return 0 if permission is granted.
1350  *
1351  * @secid_to_secctx:
1352  *      Convert secid to security context.
1353  *      @secid contains the security ID.
1354  *      @secdata contains the pointer that stores the converted security context.
1355  * @secctx_to_secid:
1356  *      Convert security context to secid.
1357  *      @secid contains the pointer to the generated security ID.
1358  *      @secdata contains the security context.
1359  *
1360  * @release_secctx:
1361  *      Release the security context.
1362  *      @secdata contains the security context.
1363  *      @seclen contains the length of the security context.
1364  *
1365  * Security hooks for Audit
1366  *
1367  * @audit_rule_init:
1368  *      Allocate and initialize an LSM audit rule structure.
1369  *      @field contains the required Audit action. Fields flags are defined in include/linux/audit.h
1370  *      @op contains the operator the rule uses.
1371  *      @rulestr contains the context where the rule will be applied to.
1372  *      @lsmrule contains a pointer to receive the result.
1373  *      Return 0 if @lsmrule has been successfully set,
1374  *      -EINVAL in case of an invalid rule.
1375  *
1376  * @audit_rule_known:
1377  *      Specifies whether given @rule contains any fields related to current LSM.
1378  *      @rule contains the audit rule of interest.
1379  *      Return 1 in case of relation found, 0 otherwise.
1380  *
1381  * @audit_rule_match:
1382  *      Determine if given @secid matches a rule previously approved
1383  *      by @audit_rule_known.
1384  *      @secid contains the security id in question.
1385  *      @field contains the field which relates to current LSM.
1386  *      @op contains the operator that will be used for matching.
1387  *      @rule points to the audit rule that will be checked against.
1388  *      @actx points to the audit context associated with the check.
1389  *      Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
1390  *
1391  * @audit_rule_free:
1392  *      Deallocate the LSM audit rule structure previously allocated by
1393  *      audit_rule_init.
1394  *      @rule contains the allocated rule
1395  *
1396  * @inode_notifysecctx:
1397  *      Notify the security module of what the security context of an inode
1398  *      should be.  Initializes the incore security context managed by the
1399  *      security module for this inode.  Example usage:  NFS client invokes
1400  *      this hook to initialize the security context in its incore inode to the
1401  *      value provided by the server for the file when the server returned the
1402  *      file's attributes to the client.
1403  *
1404  *      Must be called with inode->i_mutex locked.
1405  *
1406  *      @inode we wish to set the security context of.
1407  *      @ctx contains the string which we wish to set in the inode.
1408  *      @ctxlen contains the length of @ctx.
1409  *
1410  * @inode_setsecctx:
1411  *      Change the security context of an inode.  Updates the
1412  *      incore security context managed by the security module and invokes the
1413  *      fs code as needed (via __vfs_setxattr_noperm) to update any backing
1414  *      xattrs that represent the context.  Example usage:  NFS server invokes
1415  *      this hook to change the security context in its incore inode and on the
1416  *      backing filesystem to a value provided by the client on a SETATTR
1417  *      operation.
1418  *
1419  *      Must be called with inode->i_mutex locked.
1420  *
1421  *      @dentry contains the inode we wish to set the security context of.
1422  *      @ctx contains the string which we wish to set in the inode.
1423  *      @ctxlen contains the length of @ctx.
1424  *
1425  * @inode_getsecctx:
1426  *      Returns a string containing all relavent security context information
1427  *
1428  *      @inode we wish to set the security context of.
1429  *      @ctx is a pointer in which to place the allocated security context.
1430  *      @ctxlen points to the place to put the length of @ctx.
1431  * This is the main security structure.
1432  */
1433 struct security_operations {
1434         char name[SECURITY_NAME_MAX + 1];
1435
1436         int (*ptrace_access_check) (struct task_struct *child, unsigned int mode);
1437         int (*ptrace_traceme) (struct task_struct *parent);
1438         int (*capget) (struct task_struct *target,
1439                        kernel_cap_t *effective,
1440                        kernel_cap_t *inheritable, kernel_cap_t *permitted);
1441         int (*capset) (struct cred *new,
1442                        const struct cred *old,
1443                        const kernel_cap_t *effective,
1444                        const kernel_cap_t *inheritable,
1445                        const kernel_cap_t *permitted);
1446         int (*capable) (struct task_struct *tsk, const struct cred *cred,
1447                         int cap, int audit);
1448         int (*acct) (struct file *file);
1449         int (*sysctl) (struct ctl_table *table, int op);
1450         int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
1451         int (*quota_on) (struct dentry *dentry);
1452         int (*syslog) (int type, bool from_file);
1453         int (*settime) (struct timespec *ts, struct timezone *tz);
1454         int (*vm_enough_memory) (struct mm_struct *mm, long pages);
1455
1456         int (*bprm_set_creds) (struct linux_binprm *bprm);
1457         int (*bprm_check_security) (struct linux_binprm *bprm);
1458         int (*bprm_secureexec) (struct linux_binprm *bprm);
1459         void (*bprm_committing_creds) (struct linux_binprm *bprm);
1460         void (*bprm_committed_creds) (struct linux_binprm *bprm);
1461
1462         int (*sb_alloc_security) (struct super_block *sb);
1463         void (*sb_free_security) (struct super_block *sb);
1464         int (*sb_copy_data) (char *orig, char *copy);
1465         int (*sb_kern_mount) (struct super_block *sb, int flags, void *data);
1466         int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
1467         int (*sb_statfs) (struct dentry *dentry);
1468         int (*sb_mount) (char *dev_name, struct path *path,
1469                          char *type, unsigned long flags, void *data);
1470         int (*sb_umount) (struct vfsmount *mnt, int flags);
1471         void (*sb_post_remount) (struct vfsmount *mnt,
1472                                  unsigned long flags, void *data);
1473         void (*sb_post_addmount) (struct vfsmount *mnt,
1474                                   struct path *mountpoint);
1475         int (*sb_pivotroot) (struct path *old_path,
1476                              struct path *new_path);
1477         void (*sb_post_pivotroot) (struct path *old_path,
1478                                    struct path *new_path);
1479         int (*sb_set_mnt_opts) (struct super_block *sb,
1480                                 struct security_mnt_opts *opts);
1481         void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
1482                                    struct super_block *newsb);
1483         int (*sb_parse_opts_str) (char *options, struct security_mnt_opts *opts);
1484
1485 #ifdef CONFIG_SECURITY_PATH
1486         int (*path_unlink) (struct path *dir, struct dentry *dentry);
1487         int (*path_mkdir) (struct path *dir, struct dentry *dentry, int mode);
1488         int (*path_rmdir) (struct path *dir, struct dentry *dentry);
1489         int (*path_mknod) (struct path *dir, struct dentry *dentry, int mode,
1490                            unsigned int dev);
1491         int (*path_truncate) (struct path *path, loff_t length,
1492                               unsigned int time_attrs);
1493         int (*path_symlink) (struct path *dir, struct dentry *dentry,
1494                              const char *old_name);
1495         int (*path_link) (struct dentry *old_dentry, struct path *new_dir,
1496                           struct dentry *new_dentry);
1497         int (*path_rename) (struct path *old_dir, struct dentry *old_dentry,
1498                             struct path *new_dir, struct dentry *new_dentry);
1499         int (*path_chmod) (struct dentry *dentry, struct vfsmount *mnt,
1500                            mode_t mode);
1501         int (*path_chown) (struct path *path, uid_t uid, gid_t gid);
1502         int (*path_chroot) (struct path *path);
1503 #endif
1504
1505         int (*inode_alloc_security) (struct inode *inode);
1506         void (*inode_free_security) (struct inode *inode);
1507         int (*inode_init_security) (struct inode *inode, struct inode *dir,
1508                                     char **name, void **value, size_t *len);
1509         int (*inode_create) (struct inode *dir,
1510                              struct dentry *dentry, int mode);
1511         int (*inode_link) (struct dentry *old_dentry,
1512                            struct inode *dir, struct dentry *new_dentry);
1513         int (*inode_unlink) (struct inode *dir, struct dentry *dentry);
1514         int (*inode_symlink) (struct inode *dir,
1515                               struct dentry *dentry, const char *old_name);
1516         int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode);
1517         int (*inode_rmdir) (struct inode *dir, struct dentry *dentry);
1518         int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
1519                             int mode, dev_t dev);
1520         int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
1521                              struct inode *new_dir, struct dentry *new_dentry);
1522         int (*inode_readlink) (struct dentry *dentry);
1523         int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
1524         int (*inode_permission) (struct inode *inode, int mask);
1525         int (*inode_setattr)    (struct dentry *dentry, struct iattr *attr);
1526         int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
1527         void (*inode_delete) (struct inode *inode);
1528         int (*inode_setxattr) (struct dentry *dentry, const char *name,
1529                                const void *value, size_t size, int flags);
1530         void (*inode_post_setxattr) (struct dentry *dentry, const char *name,
1531                                      const void *value, size_t size, int flags);
1532         int (*inode_getxattr) (struct dentry *dentry, const char *name);
1533         int (*inode_listxattr) (struct dentry *dentry);
1534         int (*inode_removexattr) (struct dentry *dentry, const char *name);
1535         int (*inode_need_killpriv) (struct dentry *dentry);
1536         int (*inode_killpriv) (struct dentry *dentry);
1537         int (*inode_getsecurity) (const struct inode *inode, const char *name, void **buffer, bool alloc);
1538         int (*inode_setsecurity) (struct inode *inode, const char *name, const void *value, size_t size, int flags);
1539         int (*inode_listsecurity) (struct inode *inode, char *buffer, size_t buffer_size);
1540         void (*inode_getsecid) (const struct inode *inode, u32 *secid);
1541
1542         int (*file_permission) (struct file *file, int mask);
1543         int (*file_alloc_security) (struct file *file);
1544         void (*file_free_security) (struct file *file);
1545         int (*file_ioctl) (struct file *file, unsigned int cmd,
1546                            unsigned long arg);
1547         int (*file_mmap) (struct file *file,
1548                           unsigned long reqprot, unsigned long prot,
1549                           unsigned long flags, unsigned long addr,
1550                           unsigned long addr_only);
1551         int (*file_mprotect) (struct vm_area_struct *vma,
1552                               unsigned long reqprot,
1553                               unsigned long prot);
1554         int (*file_lock) (struct file *file, unsigned int cmd);
1555         int (*file_fcntl) (struct file *file, unsigned int cmd,
1556                            unsigned long arg);
1557         int (*file_set_fowner) (struct file *file);
1558         int (*file_send_sigiotask) (struct task_struct *tsk,
1559                                     struct fown_struct *fown, int sig);
1560         int (*file_receive) (struct file *file);
1561         int (*dentry_open) (struct file *file, const struct cred *cred);
1562
1563         int (*task_create) (unsigned long clone_flags);
1564         int (*cred_alloc_blank) (struct cred *cred, gfp_t gfp);
1565         void (*cred_free) (struct cred *cred);
1566         int (*cred_prepare)(struct cred *new, const struct cred *old,
1567                             gfp_t gfp);
1568         void (*cred_commit)(struct cred *new, const struct cred *old);
1569         void (*cred_transfer)(struct cred *new, const struct cred *old);
1570         int (*kernel_act_as)(struct cred *new, u32 secid);
1571         int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
1572         int (*kernel_module_request)(char *kmod_name);
1573         int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags);
1574         int (*task_fix_setuid) (struct cred *new, const struct cred *old,
1575                                 int flags);
1576         int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags);
1577         int (*task_setpgid) (struct task_struct *p, pid_t pgid);
1578         int (*task_getpgid) (struct task_struct *p);
1579         int (*task_getsid) (struct task_struct *p);
1580         void (*task_getsecid) (struct task_struct *p, u32 *secid);
1581         int (*task_setgroups) (struct group_info *group_info);
1582         int (*task_setnice) (struct task_struct *p, int nice);
1583         int (*task_setioprio) (struct task_struct *p, int ioprio);
1584         int (*task_getioprio) (struct task_struct *p);
1585         int (*task_setrlimit) (unsigned int resource, struct rlimit *new_rlim);
1586         int (*task_setscheduler) (struct task_struct *p, int policy,
1587                                   struct sched_param *lp);
1588         int (*task_getscheduler) (struct task_struct *p);
1589         int (*task_movememory) (struct task_struct *p);
1590         int (*task_kill) (struct task_struct *p,
1591                           struct siginfo *info, int sig, u32 secid);
1592         int (*task_wait) (struct task_struct *p);
1593         int (*task_prctl) (int option, unsigned long arg2,
1594                            unsigned long arg3, unsigned long arg4,
1595                            unsigned long arg5);
1596         void (*task_to_inode) (struct task_struct *p, struct inode *inode);
1597
1598         int (*ipc_permission) (struct kern_ipc_perm *ipcp, short flag);
1599         void (*ipc_getsecid) (struct kern_ipc_perm *ipcp, u32 *secid);
1600
1601         int (*msg_msg_alloc_security) (struct msg_msg *msg);
1602         void (*msg_msg_free_security) (struct msg_msg *msg);
1603
1604         int (*msg_queue_alloc_security) (struct msg_queue *msq);
1605         void (*msg_queue_free_security) (struct msg_queue *msq);
1606         int (*msg_queue_associate) (struct msg_queue *msq, int msqflg);
1607         int (*msg_queue_msgctl) (struct msg_queue *msq, int cmd);
1608         int (*msg_queue_msgsnd) (struct msg_queue *msq,
1609                                  struct msg_msg *msg, int msqflg);
1610         int (*msg_queue_msgrcv) (struct msg_queue *msq,
1611                                  struct msg_msg *msg,
1612                                  struct task_struct *target,
1613                                  long type, int mode);
1614
1615         int (*shm_alloc_security) (struct shmid_kernel *shp);
1616         void (*shm_free_security) (struct shmid_kernel *shp);
1617         int (*shm_associate) (struct shmid_kernel *shp, int shmflg);
1618         int (*shm_shmctl) (struct shmid_kernel *shp, int cmd);
1619         int (*shm_shmat) (struct shmid_kernel *shp,
1620                           char __user *shmaddr, int shmflg);
1621
1622         int (*sem_alloc_security) (struct sem_array *sma);
1623         void (*sem_free_security) (struct sem_array *sma);
1624         int (*sem_associate) (struct sem_array *sma, int semflg);
1625         int (*sem_semctl) (struct sem_array *sma, int cmd);
1626         int (*sem_semop) (struct sem_array *sma,
1627                           struct sembuf *sops, unsigned nsops, int alter);
1628
1629         int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
1630         int (*netlink_recv) (struct sk_buff *skb, int cap);
1631
1632         void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
1633
1634         int (*getprocattr) (struct task_struct *p, char *name, char **value);
1635         int (*setprocattr) (struct task_struct *p, char *name, void *value, size_t size);
1636         int (*secid_to_secctx) (u32 secid, char **secdata, u32 *seclen);
1637         int (*secctx_to_secid) (const char *secdata, u32 seclen, u32 *secid);
1638         void (*release_secctx) (char *secdata, u32 seclen);
1639
1640         int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen);
1641         int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen);
1642         int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen);
1643
1644 #ifdef CONFIG_SECURITY_NETWORK
1645         int (*unix_stream_connect) (struct socket *sock,
1646                                     struct socket *other, struct sock *newsk);
1647         int (*unix_may_send) (struct socket *sock, struct socket *other);
1648
1649         int (*socket_create) (int family, int type, int protocol, int kern);
1650         int (*socket_post_create) (struct socket *sock, int family,
1651                                    int type, int protocol, int kern);
1652         int (*socket_bind) (struct socket *sock,
1653                             struct sockaddr *address, int addrlen);
1654         int (*socket_connect) (struct socket *sock,
1655                                struct sockaddr *address, int addrlen);
1656         int (*socket_listen) (struct socket *sock, int backlog);
1657         int (*socket_accept) (struct socket *sock, struct socket *newsock);
1658         int (*socket_sendmsg) (struct socket *sock,
1659                                struct msghdr *msg, int size);
1660         int (*socket_recvmsg) (struct socket *sock,
1661                                struct msghdr *msg, int size, int flags);
1662         int (*socket_getsockname) (struct socket *sock);
1663         int (*socket_getpeername) (struct socket *sock);
1664         int (*socket_getsockopt) (struct socket *sock, int level, int optname);
1665         int (*socket_setsockopt) (struct socket *sock, int level, int optname);
1666         int (*socket_shutdown) (struct socket *sock, int how);
1667         int (*socket_sock_rcv_skb) (struct sock *sk, struct sk_buff *skb);
1668         int (*socket_getpeersec_stream) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len);
1669         int (*socket_getpeersec_dgram) (struct socket *sock, struct sk_buff *skb, u32 *secid);
1670         int (*sk_alloc_security) (struct sock *sk, int family, gfp_t priority);
1671         void (*sk_free_security) (struct sock *sk);
1672         void (*sk_clone_security) (const struct sock *sk, struct sock *newsk);
1673         void (*sk_getsecid) (struct sock *sk, u32 *secid);
1674         void (*sock_graft) (struct sock *sk, struct socket *parent);
1675         int (*inet_conn_request) (struct sock *sk, struct sk_buff *skb,
1676                                   struct request_sock *req);
1677         void (*inet_csk_clone) (struct sock *newsk, const struct request_sock *req);
1678         void (*inet_conn_established) (struct sock *sk, struct sk_buff *skb);
1679         void (*req_classify_flow) (const struct request_sock *req, struct flowi *fl);
1680         int (*tun_dev_create)(void);
1681         void (*tun_dev_post_create)(struct sock *sk);
1682         int (*tun_dev_attach)(struct sock *sk);
1683 #endif  /* CONFIG_SECURITY_NETWORK */
1684
1685 #ifdef CONFIG_SECURITY_NETWORK_XFRM
1686         int (*xfrm_policy_alloc_security) (struct xfrm_sec_ctx **ctxp,
1687                         struct xfrm_user_sec_ctx *sec_ctx);
1688         int (*xfrm_policy_clone_security) (struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctx);
1689         void (*xfrm_policy_free_security) (struct xfrm_sec_ctx *ctx);
1690         int (*xfrm_policy_delete_security) (struct xfrm_sec_ctx *ctx);
1691         int (*xfrm_state_alloc_security) (struct xfrm_state *x,
1692                 struct xfrm_user_sec_ctx *sec_ctx,
1693                 u32 secid);
1694         void (*xfrm_state_free_security) (struct xfrm_state *x);
1695         int (*xfrm_state_delete_security) (struct xfrm_state *x);
1696         int (*xfrm_policy_lookup) (struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
1697         int (*xfrm_state_pol_flow_match) (struct xfrm_state *x,
1698                                           struct xfrm_policy *xp,
1699                                           struct flowi *fl);
1700         int (*xfrm_decode_session) (struct sk_buff *skb, u32 *secid, int ckall);
1701 #endif  /* CONFIG_SECURITY_NETWORK_XFRM */
1702
1703         /* key management security hooks */
1704 #ifdef CONFIG_KEYS
1705         int (*key_alloc) (struct key *key, const struct cred *cred, unsigned long flags);
1706         void (*key_free) (struct key *key);
1707         int (*key_permission) (key_ref_t key_ref,
1708                                const struct cred *cred,
1709                                key_perm_t perm);
1710         int (*key_getsecurity)(struct key *key, char **_buffer);
1711         int (*key_session_to_parent)(const struct cred *cred,
1712                                      const struct cred *parent_cred,
1713                                      struct key *key);
1714 #endif  /* CONFIG_KEYS */
1715
1716 #ifdef CONFIG_AUDIT
1717         int (*audit_rule_init) (u32 field, u32 op, char *rulestr, void **lsmrule);
1718         int (*audit_rule_known) (struct audit_krule *krule);
1719         int (*audit_rule_match) (u32 secid, u32 field, u32 op, void *lsmrule,
1720                                  struct audit_context *actx);
1721         void (*audit_rule_free) (void *lsmrule);
1722 #endif /* CONFIG_AUDIT */
1723 };
1724
1725 /* prototypes */
1726 extern int security_init(void);
1727 extern int security_module_enable(struct security_operations *ops);
1728 extern int register_security(struct security_operations *ops);
1729
1730 /* Security operations */
1731 int security_ptrace_access_check(struct task_struct *child, unsigned int mode);
1732 int security_ptrace_traceme(struct task_struct *parent);
1733 int security_capget(struct task_struct *target,
1734                     kernel_cap_t *effective,
1735                     kernel_cap_t *inheritable,
1736                     kernel_cap_t *permitted);
1737 int security_capset(struct cred *new, const struct cred *old,
1738                     const kernel_cap_t *effective,
1739                     const kernel_cap_t *inheritable,
1740                     const kernel_cap_t *permitted);
1741 int security_capable(int cap);
1742 int security_real_capable(struct task_struct *tsk, int cap);
1743 int security_real_capable_noaudit(struct task_struct *tsk, int cap);
1744 int security_acct(struct file *file);
1745 int security_sysctl(struct ctl_table *table, int op);
1746 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
1747 int security_quota_on(struct dentry *dentry);
1748 int security_syslog(int type, bool from_file);
1749 int security_settime(struct timespec *ts, struct timezone *tz);
1750 int security_vm_enough_memory(long pages);
1751 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
1752 int security_vm_enough_memory_kern(long pages);
1753 int security_bprm_set_creds(struct linux_binprm *bprm);
1754 int security_bprm_check(struct linux_binprm *bprm);
1755 void security_bprm_committing_creds(struct linux_binprm *bprm);
1756 void security_bprm_committed_creds(struct linux_binprm *bprm);
1757 int security_bprm_secureexec(struct linux_binprm *bprm);
1758 int security_sb_alloc(struct super_block *sb);
1759 void security_sb_free(struct super_block *sb);
1760 int security_sb_copy_data(char *orig, char *copy);
1761 int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
1762 int security_sb_show_options(struct seq_file *m, struct super_block *sb);
1763 int security_sb_statfs(struct dentry *dentry);
1764 int security_sb_mount(char *dev_name, struct path *path,
1765                       char *type, unsigned long flags, void *data);
1766 int security_sb_umount(struct vfsmount *mnt, int flags);
1767 void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data);
1768 void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
1769 int security_sb_pivotroot(struct path *old_path, struct path *new_path);
1770 void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
1771 int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
1772 void security_sb_clone_mnt_opts(const struct super_block *oldsb,
1773                                 struct super_block *newsb);
1774 int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
1775
1776 int security_inode_alloc(struct inode *inode);
1777 void security_inode_free(struct inode *inode);
1778 int security_inode_init_security(struct inode *inode, struct inode *dir,
1779                                   char **name, void **value, size_t *len);
1780 int security_inode_create(struct inode *dir, struct dentry *dentry, int mode);
1781 int security_inode_link(struct dentry *old_dentry, struct inode *dir,
1782                          struct dentry *new_dentry);
1783 int security_inode_unlink(struct inode *dir, struct dentry *dentry);
1784 int security_inode_symlink(struct inode *dir, struct dentry *dentry,
1785                            const char *old_name);
1786 int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode);
1787 int security_inode_rmdir(struct inode *dir, struct dentry *dentry);
1788 int security_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
1789 int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
1790                           struct inode *new_dir, struct dentry *new_dentry);
1791 int security_inode_readlink(struct dentry *dentry);
1792 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd);
1793 int security_inode_permission(struct inode *inode, int mask);
1794 int security_inode_setattr(struct dentry *dentry, struct iattr *attr);
1795 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry);
1796 void security_inode_delete(struct inode *inode);
1797 int security_inode_setxattr(struct dentry *dentry, const char *name,
1798                             const void *value, size_t size, int flags);
1799 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
1800                                   const void *value, size_t size, int flags);
1801 int security_inode_getxattr(struct dentry *dentry, const char *name);
1802 int security_inode_listxattr(struct dentry *dentry);
1803 int security_inode_removexattr(struct dentry *dentry, const char *name);
1804 int security_inode_need_killpriv(struct dentry *dentry);
1805 int security_inode_killpriv(struct dentry *dentry);
1806 int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
1807 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
1808 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
1809 void security_inode_getsecid(const struct inode *inode, u32 *secid);
1810 int security_file_permission(struct file *file, int mask);
1811 int security_file_alloc(struct file *file);
1812 void security_file_free(struct file *file);
1813 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1814 int security_file_mmap(struct file *file, unsigned long reqprot,
1815                         unsigned long prot, unsigned long flags,
1816                         unsigned long addr, unsigned long addr_only);
1817 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
1818                            unsigned long prot);
1819 int security_file_lock(struct file *file, unsigned int cmd);
1820 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
1821 int security_file_set_fowner(struct file *file);
1822 int security_file_send_sigiotask(struct task_struct *tsk,
1823                                  struct fown_struct *fown, int sig);
1824 int security_file_receive(struct file *file);
1825 int security_dentry_open(struct file *file, const struct cred *cred);
1826 int security_task_create(unsigned long clone_flags);
1827 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
1828 void security_cred_free(struct cred *cred);
1829 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
1830 void security_commit_creds(struct cred *new, const struct cred *old);
1831 void security_transfer_creds(struct cred *new, const struct cred *old);
1832 int security_kernel_act_as(struct cred *new, u32 secid);
1833 int security_kernel_create_files_as(struct cred *new, struct inode *inode);
1834 int security_kernel_module_request(char *kmod_name);
1835 int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags);
1836 int security_task_fix_setuid(struct cred *new, const struct cred *old,
1837                              int flags);
1838 int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags);
1839 int security_task_setpgid(struct task_struct *p, pid_t pgid);
1840 int security_task_getpgid(struct task_struct *p);
1841 int security_task_getsid(struct task_struct *p);
1842 void security_task_getsecid(struct task_struct *p, u32 *secid);
1843 int security_task_setgroups(struct group_info *group_info);
1844 int security_task_setnice(struct task_struct *p, int nice);
1845 int security_task_setioprio(struct task_struct *p, int ioprio);
1846 int security_task_getioprio(struct task_struct *p);
1847 int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim);
1848 int security_task_setscheduler(struct task_struct *p,
1849                                 int policy, struct sched_param *lp);
1850 int security_task_getscheduler(struct task_struct *p);
1851 int security_task_movememory(struct task_struct *p);
1852 int security_task_kill(struct task_struct *p, struct siginfo *info,
1853                         int sig, u32 secid);
1854 int security_task_wait(struct task_struct *p);
1855 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
1856                         unsigned long arg4, unsigned long arg5);
1857 void security_task_to_inode(struct task_struct *p, struct inode *inode);
1858 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
1859 void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
1860 int security_msg_msg_alloc(struct msg_msg *msg);
1861 void security_msg_msg_free(struct msg_msg *msg);
1862 int security_msg_queue_alloc(struct msg_queue *msq);
1863 void security_msg_queue_free(struct msg_queue *msq);
1864 int security_msg_queue_associate(struct msg_queue *msq, int msqflg);
1865 int security_msg_queue_msgctl(struct msg_queue *msq, int cmd);
1866 int security_msg_queue_msgsnd(struct msg_queue *msq,
1867                               struct msg_msg *msg, int msqflg);
1868 int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1869                               struct task_struct *target, long type, int mode);
1870 int security_shm_alloc(struct shmid_kernel *shp);
1871 void security_shm_free(struct shmid_kernel *shp);
1872 int security_shm_associate(struct shmid_kernel *shp, int shmflg);
1873 int security_shm_shmctl(struct shmid_kernel *shp, int cmd);
1874 int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg);
1875 int security_sem_alloc(struct sem_array *sma);
1876 void security_sem_free(struct sem_array *sma);
1877 int security_sem_associate(struct sem_array *sma, int semflg);
1878 int security_sem_semctl(struct sem_array *sma, int cmd);
1879 int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
1880                         unsigned nsops, int alter);
1881 void security_d_instantiate(struct dentry *dentry, struct inode *inode);
1882 int security_getprocattr(struct task_struct *p, char *name, char **value);
1883 int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
1884 int security_netlink_send(struct sock *sk, struct sk_buff *skb);
1885 int security_netlink_recv(struct sk_buff *skb, int cap);
1886 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
1887 int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
1888 void security_release_secctx(char *secdata, u32 seclen);
1889
1890 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
1891 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
1892 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
1893 #else /* CONFIG_SECURITY */
1894 struct security_mnt_opts {
1895 };
1896
1897 static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
1898 {
1899 }
1900
1901 static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
1902 {
1903 }
1904
1905 /*
1906  * This is the default capabilities functionality.  Most of these functions
1907  * are just stubbed out, but a few must call the proper capable code.
1908  */
1909
1910 static inline int security_init(void)
1911 {
1912         return 0;
1913 }
1914
1915 static inline int security_ptrace_access_check(struct task_struct *child,
1916                                              unsigned int mode)
1917 {
1918         return cap_ptrace_access_check(child, mode);
1919 }
1920
1921 static inline int security_ptrace_traceme(struct task_struct *parent)
1922 {
1923         return cap_ptrace_traceme(parent);
1924 }
1925
1926 static inline int security_capget(struct task_struct *target,
1927                                    kernel_cap_t *effective,
1928                                    kernel_cap_t *inheritable,
1929                                    kernel_cap_t *permitted)
1930 {
1931         return cap_capget(target, effective, inheritable, permitted);
1932 }
1933
1934 static inline int security_capset(struct cred *new,
1935                                    const struct cred *old,
1936                                    const kernel_cap_t *effective,
1937                                    const kernel_cap_t *inheritable,
1938                                    const kernel_cap_t *permitted)
1939 {
1940         return cap_capset(new, old, effective, inheritable, permitted);
1941 }
1942
1943 static inline int security_capable(int cap)
1944 {
1945         return cap_capable(current, current_cred(), cap, SECURITY_CAP_AUDIT);
1946 }
1947
1948 static inline int security_real_capable(struct task_struct *tsk, int cap)
1949 {
1950         int ret;
1951
1952         rcu_read_lock();
1953         ret = cap_capable(tsk, __task_cred(tsk), cap, SECURITY_CAP_AUDIT);
1954         rcu_read_unlock();
1955         return ret;
1956 }
1957
1958 static inline
1959 int security_real_capable_noaudit(struct task_struct *tsk, int cap)
1960 {
1961         int ret;
1962
1963         rcu_read_lock();
1964         ret = cap_capable(tsk, __task_cred(tsk), cap,
1965                                SECURITY_CAP_NOAUDIT);
1966         rcu_read_unlock();
1967         return ret;
1968 }
1969
1970 static inline int security_acct(struct file *file)
1971 {
1972         return 0;
1973 }
1974
1975 static inline int security_sysctl(struct ctl_table *table, int op)
1976 {
1977         return 0;
1978 }
1979
1980 static inline int security_quotactl(int cmds, int type, int id,
1981                                      struct super_block *sb)
1982 {
1983         return 0;
1984 }
1985
1986 static inline int security_quota_on(struct dentry *dentry)
1987 {
1988         return 0;
1989 }
1990
1991 static inline int security_syslog(int type, bool from_file)
1992 {
1993         return cap_syslog(type, from_file);
1994 }
1995
1996 static inline int security_settime(struct timespec *ts, struct timezone *tz)
1997 {
1998         return cap_settime(ts, tz);
1999 }
2000
2001 static inline int security_vm_enough_memory(long pages)
2002 {
2003         WARN_ON(current->mm == NULL);
2004         return cap_vm_enough_memory(current->mm, pages);
2005 }
2006
2007 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
2008 {
2009         WARN_ON(mm == NULL);
2010         return cap_vm_enough_memory(mm, pages);
2011 }
2012
2013 static inline int security_vm_enough_memory_kern(long pages)
2014 {
2015         /* If current->mm is a kernel thread then we will pass NULL,
2016            for this specific case that is fine */
2017         return cap_vm_enough_memory(current->mm, pages);
2018 }
2019
2020 static inline int security_bprm_set_creds(struct linux_binprm *bprm)
2021 {
2022         return cap_bprm_set_creds(bprm);
2023 }
2024
2025 static inline int security_bprm_check(struct linux_binprm *bprm)
2026 {
2027         return 0;
2028 }
2029
2030 static inline void security_bprm_committing_creds(struct linux_binprm *bprm)
2031 {
2032 }
2033
2034 static inline void security_bprm_committed_creds(struct linux_binprm *bprm)
2035 {
2036 }
2037
2038 static inline int security_bprm_secureexec(struct linux_binprm *bprm)
2039 {
2040         return cap_bprm_secureexec(bprm);
2041 }
2042
2043 static inline int security_sb_alloc(struct super_block *sb)
2044 {
2045         return 0;
2046 }
2047
2048 static inline void security_sb_free(struct super_block *sb)
2049 { }
2050
2051 static inline int security_sb_copy_data(char *orig, char *copy)
2052 {
2053         return 0;
2054 }
2055
2056 static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
2057 {
2058         return 0;
2059 }
2060
2061 static inline int security_sb_show_options(struct seq_file *m,
2062                                            struct super_block *sb)
2063 {
2064         return 0;
2065 }
2066
2067 static inline int security_sb_statfs(struct dentry *dentry)
2068 {
2069         return 0;
2070 }
2071
2072 static inline int security_sb_mount(char *dev_name, struct path *path,
2073                                     char *type, unsigned long flags,
2074                                     void *data)
2075 {
2076         return 0;
2077 }
2078
2079 static inline int security_sb_umount(struct vfsmount *mnt, int flags)
2080 {
2081         return 0;
2082 }
2083
2084 static inline void security_sb_post_remount(struct vfsmount *mnt,
2085                                              unsigned long flags, void *data)
2086 { }
2087
2088 static inline void security_sb_post_addmount(struct vfsmount *mnt,
2089                                              struct path *mountpoint)
2090 { }
2091
2092 static inline int security_sb_pivotroot(struct path *old_path,
2093                                         struct path *new_path)
2094 {
2095         return 0;
2096 }
2097
2098 static inline void security_sb_post_pivotroot(struct path *old_path,
2099                                               struct path *new_path)
2100 { }
2101
2102 static inline int security_sb_set_mnt_opts(struct super_block *sb,
2103                                            struct security_mnt_opts *opts)
2104 {
2105         return 0;
2106 }
2107
2108 static inline void security_sb_clone_mnt_opts(const struct super_block *oldsb,
2109                                               struct super_block *newsb)
2110 { }
2111
2112 static inline int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
2113 {
2114         return 0;
2115 }
2116
2117 static inline int security_inode_alloc(struct inode *inode)
2118 {
2119         return 0;
2120 }
2121
2122 static inline void security_inode_free(struct inode *inode)
2123 { }
2124
2125 static inline int security_inode_init_security(struct inode *inode,
2126                                                 struct inode *dir,
2127                                                 char **name,
2128                                                 void **value,
2129                                                 size_t *len)
2130 {
2131         return -EOPNOTSUPP;
2132 }
2133
2134 static inline int security_inode_create(struct inode *dir,
2135                                          struct dentry *dentry,
2136                                          int mode)
2137 {
2138         return 0;
2139 }
2140
2141 static inline int security_inode_link(struct dentry *old_dentry,
2142                                        struct inode *dir,
2143                                        struct dentry *new_dentry)
2144 {
2145         return 0;
2146 }
2147
2148 static inline int security_inode_unlink(struct inode *dir,
2149                                          struct dentry *dentry)
2150 {
2151         return 0;
2152 }
2153
2154 static inline int security_inode_symlink(struct inode *dir,
2155                                           struct dentry *dentry,
2156                                           const char *old_name)
2157 {
2158         return 0;
2159 }
2160
2161 static inline int security_inode_mkdir(struct inode *dir,
2162                                         struct dentry *dentry,
2163                                         int mode)
2164 {
2165         return 0;
2166 }
2167
2168 static inline int security_inode_rmdir(struct inode *dir,
2169                                         struct dentry *dentry)
2170 {
2171         return 0;
2172 }
2173
2174 static inline int security_inode_mknod(struct inode *dir,
2175                                         struct dentry *dentry,
2176                                         int mode, dev_t dev)
2177 {
2178         return 0;
2179 }
2180
2181 static inline int security_inode_rename(struct inode *old_dir,
2182                                          struct dentry *old_dentry,
2183                                          struct inode *new_dir,
2184                                          struct dentry *new_dentry)
2185 {
2186         return 0;
2187 }
2188
2189 static inline int security_inode_readlink(struct dentry *dentry)
2190 {
2191         return 0;
2192 }
2193
2194 static inline int security_inode_follow_link(struct dentry *dentry,
2195                                               struct nameidata *nd)
2196 {
2197         return 0;
2198 }
2199
2200 static inline int security_inode_permission(struct inode *inode, int mask)
2201 {
2202         return 0;
2203 }
2204
2205 static inline int security_inode_setattr(struct dentry *dentry,
2206                                           struct iattr *attr)
2207 {
2208         return 0;
2209 }
2210
2211 static inline int security_inode_getattr(struct vfsmount *mnt,
2212                                           struct dentry *dentry)
2213 {
2214         return 0;
2215 }
2216
2217 static inline void security_inode_delete(struct inode *inode)
2218 { }
2219
2220 static inline int security_inode_setxattr(struct dentry *dentry,
2221                 const char *name, const void *value, size_t size, int flags)
2222 {
2223         return cap_inode_setxattr(dentry, name, value, size, flags);
2224 }
2225
2226 static inline void security_inode_post_setxattr(struct dentry *dentry,
2227                 const char *name, const void *value, size_t size, int flags)
2228 { }
2229
2230 static inline int security_inode_getxattr(struct dentry *dentry,
2231                         const char *name)
2232 {
2233         return 0;
2234 }
2235
2236 static inline int security_inode_listxattr(struct dentry *dentry)
2237 {
2238         return 0;
2239 }
2240
2241 static inline int security_inode_removexattr(struct dentry *dentry,
2242                         const char *name)
2243 {
2244         return cap_inode_removexattr(dentry, name);
2245 }
2246
2247 static inline int security_inode_need_killpriv(struct dentry *dentry)
2248 {
2249         return cap_inode_need_killpriv(dentry);
2250 }
2251
2252 static inline int security_inode_killpriv(struct dentry *dentry)
2253 {
2254         return cap_inode_killpriv(dentry);
2255 }
2256
2257 static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
2258 {
2259         return -EOPNOTSUPP;
2260 }
2261
2262 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
2263 {
2264         return -EOPNOTSUPP;
2265 }
2266
2267 static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
2268 {
2269         return 0;
2270 }
2271
2272 static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
2273 {
2274         *secid = 0;
2275 }
2276
2277 static inline int security_file_permission(struct file *file, int mask)
2278 {
2279         return 0;
2280 }
2281
2282 static inline int security_file_alloc(struct file *file)
2283 {
2284         return 0;
2285 }
2286
2287 static inline void security_file_free(struct file *file)
2288 { }
2289
2290 static inline int security_file_ioctl(struct file *file, unsigned int cmd,
2291                                       unsigned long arg)
2292 {
2293         return 0;
2294 }
2295
2296 static inline int security_file_mmap(struct file *file, unsigned long reqprot,
2297                                      unsigned long prot,
2298                                      unsigned long flags,
2299                                      unsigned long addr,
2300                                      unsigned long addr_only)
2301 {
2302         return cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
2303 }
2304
2305 static inline int security_file_mprotect(struct vm_area_struct *vma,
2306                                          unsigned long reqprot,
2307                                          unsigned long prot)
2308 {
2309         return 0;
2310 }
2311
2312 static inline int security_file_lock(struct file *file, unsigned int cmd)
2313 {
2314         return 0;
2315 }
2316
2317 static inline int security_file_fcntl(struct file *file, unsigned int cmd,
2318                                       unsigned long arg)
2319 {
2320         return 0;
2321 }
2322
2323 static inline int security_file_set_fowner(struct file *file)
2324 {
2325         return 0;
2326 }
2327
2328 static inline int security_file_send_sigiotask(struct task_struct *tsk,
2329                                                struct fown_struct *fown,
2330                                                int sig)
2331 {
2332         return 0;
2333 }
2334
2335 static inline int security_file_receive(struct file *file)
2336 {
2337         return 0;
2338 }
2339
2340 static inline int security_dentry_open(struct file *file,
2341                                        const struct cred *cred)
2342 {
2343         return 0;
2344 }
2345
2346 static inline int security_task_create(unsigned long clone_flags)
2347 {
2348         return 0;
2349 }
2350
2351 static inline int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
2352 {
2353         return 0;
2354 }
2355
2356 static inline void security_cred_free(struct cred *cred)
2357 { }
2358
2359 static inline int security_prepare_creds(struct cred *new,
2360                                          const struct cred *old,
2361                                          gfp_t gfp)
2362 {
2363         return 0;
2364 }
2365
2366 static inline void security_commit_creds(struct cred *new,
2367                                          const struct cred *old)
2368 {
2369 }
2370
2371 static inline void security_transfer_creds(struct cred *new,
2372                                            const struct cred *old)
2373 {
2374 }
2375
2376 static inline int security_kernel_act_as(struct cred *cred, u32 secid)
2377 {
2378         return 0;
2379 }
2380
2381 static inline int security_kernel_create_files_as(struct cred *cred,
2382                                                   struct inode *inode)
2383 {
2384         return 0;
2385 }
2386
2387 static inline int security_kernel_module_request(char *kmod_name)
2388 {
2389         return 0;
2390 }
2391
2392 static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2,
2393                                        int flags)
2394 {
2395         return 0;
2396 }
2397
2398 static inline int security_task_fix_setuid(struct cred *new,
2399                                            const struct cred *old,
2400                                            int flags)
2401 {
2402         return cap_task_fix_setuid(new, old, flags);
2403 }
2404
2405 static inline int security_task_setgid(gid_t id0, gid_t id1, gid_t id2,
2406                                        int flags)
2407 {
2408         return 0;
2409 }
2410
2411 static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
2412 {
2413         return 0;
2414 }
2415
2416 static inline int security_task_getpgid(struct task_struct *p)
2417 {
2418         return 0;
2419 }
2420
2421 static inline int security_task_getsid(struct task_struct *p)
2422 {
2423         return 0;
2424 }
2425
2426 static inline void security_task_getsecid(struct task_struct *p, u32 *secid)
2427 {
2428         *secid = 0;
2429 }
2430
2431 static inline int security_task_setgroups(struct group_info *group_info)
2432 {
2433         return 0;
2434 }
2435
2436 static inline int security_task_setnice(struct task_struct *p, int nice)
2437 {
2438         return cap_task_setnice(p, nice);
2439 }
2440
2441 static inline int security_task_setioprio(struct task_struct *p, int ioprio)
2442 {
2443         return cap_task_setioprio(p, ioprio);
2444 }
2445
2446 static inline int security_task_getioprio(struct task_struct *p)
2447 {
2448         return 0;
2449 }
2450
2451 static inline int security_task_setrlimit(unsigned int resource,
2452                                           struct rlimit *new_rlim)
2453 {
2454         return 0;
2455 }
2456
2457 static inline int security_task_setscheduler(struct task_struct *p,
2458                                              int policy,
2459                                              struct sched_param *lp)
2460 {
2461         return cap_task_setscheduler(p, policy, lp);
2462 }
2463
2464 static inline int security_task_getscheduler(struct task_struct *p)
2465 {
2466         return 0;
2467 }
2468
2469 static inline int security_task_movememory(struct task_struct *p)
2470 {
2471         return 0;
2472 }
2473
2474 static inline int security_task_kill(struct task_struct *p,
2475                                      struct siginfo *info, int sig,
2476                                      u32 secid)
2477 {
2478         return 0;
2479 }
2480
2481 static inline int security_task_wait(struct task_struct *p)
2482 {
2483         return 0;
2484 }
2485
2486 static inline int security_task_prctl(int option, unsigned long arg2,
2487                                       unsigned long arg3,
2488                                       unsigned long arg4,
2489                                       unsigned long arg5)
2490 {
2491         return cap_task_prctl(option, arg2, arg3, arg3, arg5);
2492 }
2493
2494 static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
2495 { }
2496
2497 static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
2498                                           short flag)
2499 {
2500         return 0;
2501 }
2502
2503 static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
2504 {
2505         *secid = 0;
2506 }
2507
2508 static inline int security_msg_msg_alloc(struct msg_msg *msg)
2509 {
2510         return 0;
2511 }
2512
2513 static inline void security_msg_msg_free(struct msg_msg *msg)
2514 { }
2515
2516 static inline int security_msg_queue_alloc(struct msg_queue *msq)
2517 {
2518         return 0;
2519 }
2520
2521 static inline void security_msg_queue_free(struct msg_queue *msq)
2522 { }
2523
2524 static inline int security_msg_queue_associate(struct msg_queue *msq,
2525                                                int msqflg)
2526 {
2527         return 0;
2528 }
2529
2530 static inline int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2531 {
2532         return 0;
2533 }
2534
2535 static inline int security_msg_queue_msgsnd(struct msg_queue *msq,
2536                                             struct msg_msg *msg, int msqflg)
2537 {
2538         return 0;
2539 }
2540
2541 static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
2542                                             struct msg_msg *msg,
2543                                             struct task_struct *target,
2544                                             long type, int mode)
2545 {
2546         return 0;
2547 }
2548
2549 static inline int security_shm_alloc(struct shmid_kernel *shp)
2550 {
2551         return 0;
2552 }
2553
2554 static inline void security_shm_free(struct shmid_kernel *shp)
2555 { }
2556
2557 static inline int security_shm_associate(struct shmid_kernel *shp,
2558                                          int shmflg)
2559 {
2560         return 0;
2561 }
2562
2563 static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
2564 {
2565         return 0;
2566 }
2567
2568 static inline int security_shm_shmat(struct shmid_kernel *shp,
2569                                      char __user *shmaddr, int shmflg)
2570 {
2571         return 0;
2572 }
2573
2574 static inline int security_sem_alloc(struct sem_array *sma)
2575 {
2576         return 0;
2577 }
2578
2579 static inline void security_sem_free(struct sem_array *sma)
2580 { }
2581
2582 static inline int security_sem_associate(struct sem_array *sma, int semflg)
2583 {
2584         return 0;
2585 }
2586
2587 static inline int security_sem_semctl(struct sem_array *sma, int cmd)
2588 {
2589         return 0;
2590 }
2591
2592 static inline int security_sem_semop(struct sem_array *sma,
2593                                      struct sembuf *sops, unsigned nsops,
2594                                      int alter)
2595 {
2596         return 0;
2597 }
2598
2599 static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode)
2600 { }
2601
2602 static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
2603 {
2604         return -EINVAL;
2605 }
2606
2607 static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
2608 {
2609         return -EINVAL;
2610 }
2611
2612 static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
2613 {
2614         return cap_netlink_send(sk, skb);
2615 }
2616
2617 static inline int security_netlink_recv(struct sk_buff *skb, int cap)
2618 {
2619         return cap_netlink_recv(skb, cap);
2620 }
2621
2622 static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2623 {
2624         return -EOPNOTSUPP;
2625 }
2626
2627 static inline int security_secctx_to_secid(const char *secdata,
2628                                            u32 seclen,
2629                                            u32 *secid)
2630 {
2631         return -EOPNOTSUPP;
2632 }
2633
2634 static inline void security_release_secctx(char *secdata, u32 seclen)
2635 {
2636 }
2637
2638 static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
2639 {
2640         return -EOPNOTSUPP;
2641 }
2642 static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
2643 {
2644         return -EOPNOTSUPP;
2645 }
2646 static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
2647 {
2648         return -EOPNOTSUPP;
2649 }
2650 #endif  /* CONFIG_SECURITY */
2651
2652 #ifdef CONFIG_SECURITY_NETWORK
2653
2654 int security_unix_stream_connect(struct socket *sock, struct socket *other,
2655                                  struct sock *newsk);
2656 int security_unix_may_send(struct socket *sock,  struct socket *other);
2657 int security_socket_create(int family, int type, int protocol, int kern);
2658 int security_socket_post_create(struct socket *sock, int family,
2659                                 int type, int protocol, int kern);
2660 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen);
2661 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen);
2662 int security_socket_listen(struct socket *sock, int backlog);
2663 int security_socket_accept(struct socket *sock, struct socket *newsock);
2664 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size);
2665 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
2666                             int size, int flags);
2667 int security_socket_getsockname(struct socket *sock);
2668 int security_socket_getpeername(struct socket *sock);
2669 int security_socket_getsockopt(struct socket *sock, int level, int optname);
2670 int security_socket_setsockopt(struct socket *sock, int level, int optname);
2671 int security_socket_shutdown(struct socket *sock, int how);
2672 int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb);
2673 int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2674                                       int __user *optlen, unsigned len);
2675 int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid);
2676 int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
2677 void security_sk_free(struct sock *sk);
2678 void security_sk_clone(const struct sock *sk, struct sock *newsk);
2679 void security_sk_classify_flow(struct sock *sk, struct flowi *fl);
2680 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl);
2681 void security_sock_graft(struct sock*sk, struct socket *parent);
2682 int security_inet_conn_request(struct sock *sk,
2683                         struct sk_buff *skb, struct request_sock *req);
2684 void security_inet_csk_clone(struct sock *newsk,
2685                         const struct request_sock *req);
2686 void security_inet_conn_established(struct sock *sk,
2687                         struct sk_buff *skb);
2688 int security_tun_dev_create(void);
2689 void security_tun_dev_post_create(struct sock *sk);
2690 int security_tun_dev_attach(struct sock *sk);
2691
2692 #else   /* CONFIG_SECURITY_NETWORK */
2693 static inline int security_unix_stream_connect(struct socket *sock,
2694                                                struct socket *other,
2695                                                struct sock *newsk)
2696 {
2697         return 0;
2698 }
2699
2700 static inline int security_unix_may_send(struct socket *sock,
2701                                          struct socket *other)
2702 {
2703         return 0;
2704 }
2705
2706 static inline int security_socket_create(int family, int type,
2707                                          int protocol, int kern)
2708 {
2709         return 0;
2710 }
2711
2712 static inline int security_socket_post_create(struct socket *sock,
2713                                               int family,
2714                                               int type,
2715                                               int protocol, int kern)
2716 {
2717         return 0;
2718 }
2719
2720 static inline int security_socket_bind(struct socket *sock,
2721                                        struct sockaddr *address,
2722                                        int addrlen)
2723 {
2724         return 0;
2725 }
2726
2727 static inline int security_socket_connect(struct socket *sock,
2728                                           struct sockaddr *address,
2729                                           int addrlen)
2730 {
2731         return 0;
2732 }
2733
2734 static inline int security_socket_listen(struct socket *sock, int backlog)
2735 {
2736         return 0;
2737 }
2738
2739 static inline int security_socket_accept(struct socket *sock,
2740                                          struct socket *newsock)
2741 {
2742         return 0;
2743 }
2744
2745 static inline int security_socket_sendmsg(struct socket *sock,
2746                                           struct msghdr *msg, int size)
2747 {
2748         return 0;
2749 }
2750
2751 static inline int security_socket_recvmsg(struct socket *sock,
2752                                           struct msghdr *msg, int size,
2753                                           int flags)
2754 {
2755         return 0;
2756 }
2757
2758 static inline int security_socket_getsockname(struct socket *sock)
2759 {
2760         return 0;
2761 }
2762
2763 static inline int security_socket_getpeername(struct socket *sock)
2764 {
2765         return 0;
2766 }
2767
2768 static inline int security_socket_getsockopt(struct socket *sock,
2769                                              int level, int optname)
2770 {
2771         return 0;
2772 }
2773
2774 static inline int security_socket_setsockopt(struct socket *sock,
2775                                              int level, int optname)
2776 {
2777         return 0;
2778 }
2779
2780 static inline int security_socket_shutdown(struct socket *sock, int how)
2781 {
2782         return 0;
2783 }
2784 static inline int security_sock_rcv_skb(struct sock *sk,
2785                                         struct sk_buff *skb)
2786 {
2787         return 0;
2788 }
2789
2790 static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2791                                                     int __user *optlen, unsigned len)
2792 {
2793         return -ENOPROTOOPT;
2794 }
2795
2796 static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
2797 {
2798         return -ENOPROTOOPT;
2799 }
2800
2801 static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
2802 {
2803         return 0;
2804 }
2805
2806 static inline void security_sk_free(struct sock *sk)
2807 {
2808 }
2809
2810 static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
2811 {
2812 }
2813
2814 static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
2815 {
2816 }
2817
2818 static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
2819 {
2820 }
2821
2822 static inline void security_sock_graft(struct sock *sk, struct socket *parent)
2823 {
2824 }
2825
2826 static inline int security_inet_conn_request(struct sock *sk,
2827                         struct sk_buff *skb, struct request_sock *req)
2828 {
2829         return 0;
2830 }
2831
2832 static inline void security_inet_csk_clone(struct sock *newsk,
2833                         const struct request_sock *req)
2834 {
2835 }
2836
2837 static inline void security_inet_conn_established(struct sock *sk,
2838                         struct sk_buff *skb)
2839 {
2840 }
2841
2842 static inline int security_tun_dev_create(void)
2843 {
2844         return 0;
2845 }
2846
2847 static inline void security_tun_dev_post_create(struct sock *sk)
2848 {
2849 }
2850
2851 static inline int security_tun_dev_attach(struct sock *sk)
2852 {
2853         return 0;
2854 }
2855 #endif  /* CONFIG_SECURITY_NETWORK */
2856
2857 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2858
2859 int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx);
2860 int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp);
2861 void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
2862 int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
2863 int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx);
2864 int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
2865                                       struct xfrm_sec_ctx *polsec, u32 secid);
2866 int security_xfrm_state_delete(struct xfrm_state *x);
2867 void security_xfrm_state_free(struct xfrm_state *x);
2868 int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
2869 int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
2870                                        struct xfrm_policy *xp, struct flowi *fl);
2871 int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid);
2872 void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl);
2873
2874 #else   /* CONFIG_SECURITY_NETWORK_XFRM */
2875
2876 static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx)
2877 {
2878         return 0;
2879 }
2880
2881 static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp)
2882 {
2883         return 0;
2884 }
2885
2886 static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
2887 {
2888 }
2889
2890 static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
2891 {
2892         return 0;
2893 }
2894
2895 static inline int security_xfrm_state_alloc(struct xfrm_state *x,
2896                                         struct xfrm_user_sec_ctx *sec_ctx)
2897 {
2898         return 0;
2899 }
2900
2901 static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
2902                                         struct xfrm_sec_ctx *polsec, u32 secid)
2903 {
2904         return 0;
2905 }
2906
2907 static inline void security_xfrm_state_free(struct xfrm_state *x)
2908 {
2909 }
2910
2911 static inline int security_xfrm_state_delete(struct xfrm_state *x)
2912 {
2913         return 0;
2914 }
2915
2916 static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
2917 {
2918         return 0;
2919 }
2920
2921 static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
2922                         struct xfrm_policy *xp, struct flowi *fl)
2923 {
2924         return 1;
2925 }
2926
2927 static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
2928 {
2929         return 0;
2930 }
2931
2932 static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
2933 {
2934 }
2935
2936 #endif  /* CONFIG_SECURITY_NETWORK_XFRM */
2937
2938 #ifdef CONFIG_SECURITY_PATH
2939 int security_path_unlink(struct path *dir, struct dentry *dentry);
2940 int security_path_mkdir(struct path *dir, struct dentry *dentry, int mode);
2941 int security_path_rmdir(struct path *dir, struct dentry *dentry);
2942 int security_path_mknod(struct path *dir, struct dentry *dentry, int mode,
2943                         unsigned int dev);
2944 int security_path_truncate(struct path *path, loff_t length,
2945                            unsigned int time_attrs);
2946 int security_path_symlink(struct path *dir, struct dentry *dentry,
2947                           const char *old_name);
2948 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
2949                        struct dentry *new_dentry);
2950 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
2951                          struct path *new_dir, struct dentry *new_dentry);
2952 int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
2953                         mode_t mode);
2954 int security_path_chown(struct path *path, uid_t uid, gid_t gid);
2955 int security_path_chroot(struct path *path);
2956 #else   /* CONFIG_SECURITY_PATH */
2957 static inline int security_path_unlink(struct path *dir, struct dentry *dentry)
2958 {
2959         return 0;
2960 }
2961
2962 static inline int security_path_mkdir(struct path *dir, struct dentry *dentry,
2963                                       int mode)
2964 {
2965         return 0;
2966 }
2967
2968 static inline int security_path_rmdir(struct path *dir, struct dentry *dentry)
2969 {
2970         return 0;
2971 }
2972
2973 static inline int security_path_mknod(struct path *dir, struct dentry *dentry,
2974                                       int mode, unsigned int dev)
2975 {
2976         return 0;
2977 }
2978
2979 static inline int security_path_truncate(struct path *path, loff_t length,
2980                                          unsigned int time_attrs)
2981 {
2982         return 0;
2983 }
2984
2985 static inline int security_path_symlink(struct path *dir, struct dentry *dentry,
2986                                         const char *old_name)
2987 {
2988         return 0;
2989 }
2990
2991 static inline int security_path_link(struct dentry *old_dentry,
2992                                      struct path *new_dir,
2993                                      struct dentry *new_dentry)
2994 {
2995         return 0;
2996 }
2997
2998 static inline int security_path_rename(struct path *old_dir,
2999                                        struct dentry *old_dentry,
3000                                        struct path *new_dir,
3001                                        struct dentry *new_dentry)
3002 {
3003         return 0;
3004 }
3005
3006 static inline int security_path_chmod(struct dentry *dentry,
3007                                       struct vfsmount *mnt,
3008                                       mode_t mode)
3009 {
3010         return 0;
3011 }
3012
3013 static inline int security_path_chown(struct path *path, uid_t uid, gid_t gid)
3014 {
3015         return 0;
3016 }
3017
3018 static inline int security_path_chroot(struct path *path)
3019 {
3020         return 0;
3021 }
3022 #endif  /* CONFIG_SECURITY_PATH */
3023
3024 #ifdef CONFIG_KEYS
3025 #ifdef CONFIG_SECURITY
3026
3027 int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags);
3028 void security_key_free(struct key *key);
3029 int security_key_permission(key_ref_t key_ref,
3030                             const struct cred *cred, key_perm_t perm);
3031 int security_key_getsecurity(struct key *key, char **_buffer);
3032 int security_key_session_to_parent(const struct cred *cred,
3033                                    const struct cred *parent_cred,
3034                                    struct key *key);
3035
3036 #else
3037
3038 static inline int security_key_alloc(struct key *key,
3039                                      const struct cred *cred,
3040                                      unsigned long flags)
3041 {
3042         return 0;
3043 }
3044
3045 static inline void security_key_free(struct key *key)
3046 {
3047 }
3048
3049 static inline int security_key_permission(key_ref_t key_ref,
3050                                           const struct cred *cred,
3051                                           key_perm_t perm)
3052 {
3053         return 0;
3054 }
3055
3056 static inline int security_key_getsecurity(struct key *key, char **_buffer)
3057 {
3058         *_buffer = NULL;
3059         return 0;
3060 }
3061
3062 static inline int security_key_session_to_parent(const struct cred *cred,
3063                                                  const struct cred *parent_cred,
3064                                                  struct key *key)
3065 {
3066         return 0;
3067 }
3068
3069 #endif
3070 #endif /* CONFIG_KEYS */
3071
3072 #ifdef CONFIG_AUDIT
3073 #ifdef CONFIG_SECURITY
3074 int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule);
3075 int security_audit_rule_known(struct audit_krule *krule);
3076 int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
3077                               struct audit_context *actx);
3078 void security_audit_rule_free(void *lsmrule);
3079
3080 #else
3081
3082 static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
3083                                            void **lsmrule)
3084 {
3085         return 0;
3086 }
3087
3088 static inline int security_audit_rule_known(struct audit_krule *krule)
3089 {
3090         return 0;
3091 }
3092
3093 static inline int security_audit_rule_match(u32 secid, u32 field, u32 op,
3094                                    void *lsmrule, struct audit_context *actx)
3095 {
3096         return 0;
3097 }
3098
3099 static inline void security_audit_rule_free(void *lsmrule)
3100 { }
3101
3102 #endif /* CONFIG_SECURITY */
3103 #endif /* CONFIG_AUDIT */
3104
3105 #ifdef CONFIG_SECURITYFS
3106
3107 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
3108                                              struct dentry *parent, void *data,
3109                                              const struct file_operations *fops);
3110 extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
3111 extern void securityfs_remove(struct dentry *dentry);
3112
3113 #else /* CONFIG_SECURITYFS */
3114
3115 static inline struct dentry *securityfs_create_dir(const char *name,
3116                                                    struct dentry *parent)
3117 {
3118         return ERR_PTR(-ENODEV);
3119 }
3120
3121 static inline struct dentry *securityfs_create_file(const char *name,
3122                                                     mode_t mode,
3123                                                     struct dentry *parent,
3124                                                     void *data,
3125                                                     const struct file_operations *fops)
3126 {
3127         return ERR_PTR(-ENODEV);
3128 }
3129
3130 static inline void securityfs_remove(struct dentry *dentry)
3131 {}
3132
3133 #endif
3134
3135 #ifdef CONFIG_SECURITY
3136
3137 static inline char *alloc_secdata(void)
3138 {
3139         return (char *)get_zeroed_page(GFP_KERNEL);
3140 }
3141
3142 static inline void free_secdata(void *secdata)
3143 {
3144         free_page((unsigned long)secdata);
3145 }
3146
3147 #else
3148
3149 static inline char *alloc_secdata(void)
3150 {
3151         return (char *)1;
3152 }
3153
3154 static inline void free_secdata(void *secdata)
3155 { }
3156 #endif /* CONFIG_SECURITY */
3157
3158 #endif /* ! __LINUX_SECURITY_H */
3159