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