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