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