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