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