blob: 84cebcdb3f833e0f6fb061ed724123f32095e3c3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
David Howells29db9192005-10-30 15:02:44 -080033#include <linux/key.h>
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070034#include <linux/xfrm.h>
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -070035#include <net/flow.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37struct ctl_table;
38
39/*
40 * These functions are in security/capability.c and are used
41 * as the default capabilities functions
42 */
43extern int cap_capable (struct task_struct *tsk, int cap);
44extern int cap_settime (struct timespec *ts, struct timezone *tz);
45extern int cap_ptrace (struct task_struct *parent, struct task_struct *child);
46extern int cap_capget (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
47extern int cap_capset_check (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
48extern void cap_capset_set (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
49extern int cap_bprm_set_security (struct linux_binprm *bprm);
50extern void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe);
51extern int cap_bprm_secureexec(struct linux_binprm *bprm);
52extern int cap_inode_setxattr(struct dentry *dentry, char *name, void *value, size_t size, int flags);
53extern int cap_inode_removexattr(struct dentry *dentry, char *name);
54extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
55extern void cap_task_reparent_to_init (struct task_struct *p);
56extern int cap_syslog (int type);
57extern int cap_vm_enough_memory (long pages);
58
59struct msghdr;
60struct sk_buff;
61struct sock;
62struct sockaddr;
63struct socket;
Trent Jaegerdf718372005-12-13 23:12:27 -080064struct flowi;
65struct dst_entry;
66struct xfrm_selector;
67struct xfrm_policy;
68struct xfrm_state;
69struct xfrm_user_sec_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
Darrel Goeddelc7bdb542006-06-27 13:26:11 -070072extern int cap_netlink_recv(struct sk_buff *skb, int cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * Values used in the task_security_ops calls
76 */
77/* setuid or setgid, id0 == uid or gid */
78#define LSM_SETID_ID 1
79
80/* setreuid or setregid, id0 == real, id1 == eff */
81#define LSM_SETID_RE 2
82
83/* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
84#define LSM_SETID_RES 4
85
86/* setfsuid or setfsgid, id0 == fsuid or fsgid */
87#define LSM_SETID_FS 8
88
89/* forward declares to avoid warnings */
90struct nfsctl_arg;
91struct sched_param;
92struct swap_info_struct;
Venkat Yekkirala4237c752006-07-24 23:32:50 -070093struct request_sock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/* bprm_apply_creds unsafe reasons */
96#define LSM_UNSAFE_SHARE 1
97#define LSM_UNSAFE_PTRACE 2
98#define LSM_UNSAFE_PTRACE_CAP 4
99
100#ifdef CONFIG_SECURITY
101
102/**
103 * struct security_operations - main security structure
104 *
105 * Security hooks for program execution operations.
106 *
107 * @bprm_alloc_security:
108 * Allocate and attach a security structure to the @bprm->security field.
109 * The security field is initialized to NULL when the bprm structure is
110 * allocated.
111 * @bprm contains the linux_binprm structure to be modified.
112 * Return 0 if operation was successful.
113 * @bprm_free_security:
114 * @bprm contains the linux_binprm structure to be modified.
115 * Deallocate and clear the @bprm->security field.
116 * @bprm_apply_creds:
117 * Compute and set the security attributes of a process being transformed
118 * by an execve operation based on the old attributes (current->security)
119 * and the information saved in @bprm->security by the set_security hook.
120 * Since this hook function (and its caller) are void, this hook can not
121 * return an error. However, it can leave the security attributes of the
122 * process unchanged if an access failure occurs at this point.
123 * bprm_apply_creds is called under task_lock. @unsafe indicates various
124 * reasons why it may be unsafe to change security state.
125 * @bprm contains the linux_binprm structure.
126 * @bprm_post_apply_creds:
127 * Runs after bprm_apply_creds with the task_lock dropped, so that
128 * functions which cannot be called safely under the task_lock can
129 * be used. This hook is a good place to perform state changes on
130 * the process such as closing open file descriptors to which access
131 * is no longer granted if the attributes were changed.
132 * Note that a security module might need to save state between
133 * bprm_apply_creds and bprm_post_apply_creds to store the decision
134 * on whether the process may proceed.
135 * @bprm contains the linux_binprm structure.
136 * @bprm_set_security:
137 * Save security information in the bprm->security field, typically based
138 * on information about the bprm->file, for later use by the apply_creds
139 * hook. This hook may also optionally check permissions (e.g. for
140 * transitions between security domains).
141 * This hook may be called multiple times during a single execve, e.g. for
142 * interpreters. The hook can tell whether it has already been called by
143 * checking to see if @bprm->security is non-NULL. If so, then the hook
144 * may decide either to retain the security information saved earlier or
145 * to replace it.
146 * @bprm contains the linux_binprm structure.
147 * Return 0 if the hook is successful and permission is granted.
148 * @bprm_check_security:
149 * This hook mediates the point when a search for a binary handler will
150 * begin. It allows a check the @bprm->security value which is set in
151 * the preceding set_security call. The primary difference from
152 * set_security is that the argv list and envp list are reliably
153 * available in @bprm. This hook may be called multiple times
154 * during a single execve; and in each pass set_security is called
155 * first.
156 * @bprm contains the linux_binprm structure.
157 * Return 0 if the hook is successful and permission is granted.
158 * @bprm_secureexec:
159 * Return a boolean value (0 or 1) indicating whether a "secure exec"
160 * is required. The flag is passed in the auxiliary table
161 * on the initial stack to the ELF interpreter to indicate whether libc
162 * should enable secure mode.
163 * @bprm contains the linux_binprm structure.
164 *
165 * Security hooks for filesystem operations.
166 *
167 * @sb_alloc_security:
168 * Allocate and attach a security structure to the sb->s_security field.
169 * The s_security field is initialized to NULL when the structure is
170 * allocated.
171 * @sb contains the super_block structure to be modified.
172 * Return 0 if operation was successful.
173 * @sb_free_security:
174 * Deallocate and clear the sb->s_security field.
175 * @sb contains the super_block structure to be modified.
176 * @sb_statfs:
David Howells726c3342006-06-23 02:02:58 -0700177 * Check permission before obtaining filesystem statistics for the @mnt
178 * mountpoint.
179 * @dentry is a handle on the superblock for the filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 * Return 0 if permission is granted.
181 * @sb_mount:
182 * Check permission before an object specified by @dev_name is mounted on
183 * the mount point named by @nd. For an ordinary mount, @dev_name
184 * identifies a device if the file system type requires a device. For a
185 * remount (@flags & MS_REMOUNT), @dev_name is irrelevant. For a
186 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
187 * pathname of the object being mounted.
188 * @dev_name contains the name for object being mounted.
189 * @nd contains the nameidata structure for mount point object.
190 * @type contains the filesystem type.
191 * @flags contains the mount flags.
192 * @data contains the filesystem-specific data.
193 * Return 0 if permission is granted.
194 * @sb_copy_data:
195 * Allow mount option data to be copied prior to parsing by the filesystem,
196 * so that the security module can extract security-specific mount
197 * options cleanly (a filesystem may modify the data e.g. with strsep()).
198 * This also allows the original mount data to be stripped of security-
199 * specific options to avoid having to make filesystems aware of them.
200 * @type the type of filesystem being mounted.
201 * @orig the original mount data copied from userspace.
202 * @copy copied data which will be passed to the security module.
203 * Returns 0 if the copy was successful.
204 * @sb_check_sb:
205 * Check permission before the device with superblock @mnt->sb is mounted
206 * on the mount point named by @nd.
207 * @mnt contains the vfsmount for device being mounted.
208 * @nd contains the nameidata object for the mount point.
209 * Return 0 if permission is granted.
210 * @sb_umount:
211 * Check permission before the @mnt file system is unmounted.
212 * @mnt contains the mounted file system.
213 * @flags contains the unmount flags, e.g. MNT_FORCE.
214 * Return 0 if permission is granted.
215 * @sb_umount_close:
216 * Close any files in the @mnt mounted filesystem that are held open by
217 * the security module. This hook is called during an umount operation
218 * prior to checking whether the filesystem is still busy.
219 * @mnt contains the mounted filesystem.
220 * @sb_umount_busy:
221 * Handle a failed umount of the @mnt mounted filesystem, e.g. re-opening
222 * any files that were closed by umount_close. This hook is called during
223 * an umount operation if the umount fails after a call to the
224 * umount_close hook.
225 * @mnt contains the mounted filesystem.
226 * @sb_post_remount:
227 * Update the security module's state when a filesystem is remounted.
228 * This hook is only called if the remount was successful.
229 * @mnt contains the mounted file system.
230 * @flags contains the new filesystem flags.
231 * @data contains the filesystem-specific data.
232 * @sb_post_mountroot:
233 * Update the security module's state when the root filesystem is mounted.
234 * This hook is only called if the mount was successful.
235 * @sb_post_addmount:
236 * Update the security module's state when a filesystem is mounted.
237 * This hook is called any time a mount is successfully grafetd to
238 * the tree.
239 * @mnt contains the mounted filesystem.
240 * @mountpoint_nd contains the nameidata structure for the mount point.
241 * @sb_pivotroot:
242 * Check permission before pivoting the root filesystem.
243 * @old_nd contains the nameidata structure for the new location of the current root (put_old).
244 * @new_nd contains the nameidata structure for the new root (new_root).
245 * Return 0 if permission is granted.
246 * @sb_post_pivotroot:
247 * Update module state after a successful pivot.
248 * @old_nd contains the nameidata structure for the old root.
249 * @new_nd contains the nameidata structure for the new root.
250 *
251 * Security hooks for inode operations.
252 *
253 * @inode_alloc_security:
254 * Allocate and attach a security structure to @inode->i_security. The
255 * i_security field is initialized to NULL when the inode structure is
256 * allocated.
257 * @inode contains the inode structure.
258 * Return 0 if operation was successful.
259 * @inode_free_security:
260 * @inode contains the inode structure.
261 * Deallocate the inode security structure and set @inode->i_security to
262 * NULL.
Stephen Smalley5e41ff92005-09-09 13:01:35 -0700263 * @inode_init_security:
264 * Obtain the security attribute name suffix and value to set on a newly
265 * created inode and set up the incore security field for the new inode.
266 * This hook is called by the fs code as part of the inode creation
267 * transaction and provides for atomic labeling of the inode, unlike
268 * the post_create/mkdir/... hooks called by the VFS. The hook function
269 * is expected to allocate the name and value via kmalloc, with the caller
270 * being responsible for calling kfree after using them.
271 * If the security module does not use security attributes or does
272 * not wish to put a security attribute on this particular inode,
273 * then it should return -EOPNOTSUPP to skip this processing.
274 * @inode contains the inode structure of the newly created inode.
275 * @dir contains the inode structure of the parent directory.
276 * @name will be set to the allocated name suffix (e.g. selinux).
277 * @value will be set to the allocated attribute value.
278 * @len will be set to the length of the value.
279 * Returns 0 if @name and @value have been successfully set,
280 * -EOPNOTSUPP if no security attribute is needed, or
281 * -ENOMEM on memory allocation failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 * @inode_create:
283 * Check permission to create a regular file.
284 * @dir contains inode structure of the parent of the new file.
285 * @dentry contains the dentry structure for the file to be created.
286 * @mode contains the file mode of the file to be created.
287 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 * @inode_link:
289 * Check permission before creating a new hard link to a file.
290 * @old_dentry contains the dentry structure for an existing link to the file.
291 * @dir contains the inode structure of the parent directory of the new link.
292 * @new_dentry contains the dentry structure for the new link.
293 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 * @inode_unlink:
295 * Check the permission to remove a hard link to a file.
296 * @dir contains the inode structure of parent directory of the file.
297 * @dentry contains the dentry structure for file to be unlinked.
298 * Return 0 if permission is granted.
299 * @inode_symlink:
300 * Check the permission to create a symbolic link to a file.
301 * @dir contains the inode structure of parent directory of the symbolic link.
302 * @dentry contains the dentry structure of the symbolic link.
303 * @old_name contains the pathname of file.
304 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 * @inode_mkdir:
306 * Check permissions to create a new directory in the existing directory
307 * associated with inode strcture @dir.
308 * @dir containst the inode structure of parent of the directory to be created.
309 * @dentry contains the dentry structure of new directory.
310 * @mode contains the mode of new directory.
311 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 * @inode_rmdir:
313 * Check the permission to remove a directory.
314 * @dir contains the inode structure of parent of the directory to be removed.
315 * @dentry contains the dentry structure of directory to be removed.
316 * Return 0 if permission is granted.
317 * @inode_mknod:
318 * Check permissions when creating a special file (or a socket or a fifo
319 * file created via the mknod system call). Note that if mknod operation
320 * is being done for a regular file, then the create hook will be called
321 * and not this hook.
322 * @dir contains the inode structure of parent of the new file.
323 * @dentry contains the dentry structure of the new file.
324 * @mode contains the mode of the new file.
325 * @dev contains the the device number.
326 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 * @inode_rename:
328 * Check for permission to rename a file or directory.
329 * @old_dir contains the inode structure for parent of the old link.
330 * @old_dentry contains the dentry structure of the old link.
331 * @new_dir contains the inode structure for parent of the new link.
332 * @new_dentry contains the dentry structure of the new link.
333 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 * @inode_readlink:
335 * Check the permission to read the symbolic link.
336 * @dentry contains the dentry structure for the file link.
337 * Return 0 if permission is granted.
338 * @inode_follow_link:
339 * Check permission to follow a symbolic link when looking up a pathname.
340 * @dentry contains the dentry structure for the link.
341 * @nd contains the nameidata structure for the parent directory.
342 * Return 0 if permission is granted.
343 * @inode_permission:
344 * Check permission before accessing an inode. This hook is called by the
345 * existing Linux permission function, so a security module can use it to
346 * provide additional checking for existing Linux permission checks.
347 * Notice that this hook is called when a file is opened (as well as many
348 * other operations), whereas the file_security_ops permission hook is
349 * called when the actual read/write operations are performed.
350 * @inode contains the inode structure to check.
351 * @mask contains the permission mask.
352 * @nd contains the nameidata (may be NULL).
353 * Return 0 if permission is granted.
354 * @inode_setattr:
355 * Check permission before setting file attributes. Note that the kernel
356 * call to notify_change is performed from several locations, whenever
357 * file attributes change (such as when a file is truncated, chown/chmod
358 * operations, transferring disk quotas, etc).
359 * @dentry contains the dentry structure for the file.
360 * @attr is the iattr structure containing the new file attributes.
361 * Return 0 if permission is granted.
362 * @inode_getattr:
363 * Check permission before obtaining file attributes.
364 * @mnt is the vfsmount where the dentry was looked up
365 * @dentry contains the dentry structure for the file.
366 * Return 0 if permission is granted.
367 * @inode_delete:
368 * @inode contains the inode structure for deleted inode.
369 * This hook is called when a deleted inode is released (i.e. an inode
370 * with no hard links has its use count drop to zero). A security module
371 * can use this hook to release any persistent label associated with the
372 * inode.
373 * @inode_setxattr:
374 * Check permission before setting the extended attributes
375 * @value identified by @name for @dentry.
376 * Return 0 if permission is granted.
377 * @inode_post_setxattr:
378 * Update inode security field after successful setxattr operation.
379 * @value identified by @name for @dentry.
380 * @inode_getxattr:
381 * Check permission before obtaining the extended attributes
382 * identified by @name for @dentry.
383 * Return 0 if permission is granted.
384 * @inode_listxattr:
385 * Check permission before obtaining the list of extended attribute
386 * names for @dentry.
387 * Return 0 if permission is granted.
388 * @inode_removexattr:
389 * Check permission before removing the extended attribute
390 * identified by @name for @dentry.
391 * Return 0 if permission is granted.
392 * @inode_getsecurity:
393 * Copy the extended attribute representation of the security label
394 * associated with @name for @inode into @buffer. @buffer may be
395 * NULL to request the size of the buffer required. @size indicates
396 * the size of @buffer in bytes. Note that @name is the remainder
397 * of the attribute name after the security. prefix has been removed.
James Morrisd381d8a2005-10-30 14:59:22 -0800398 * @err is the return value from the preceding fs getxattr call,
399 * and can be used by the security module to determine whether it
400 * should try and canonicalize the attribute value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 * Return number of bytes used/required on success.
402 * @inode_setsecurity:
403 * Set the security label associated with @name for @inode from the
404 * extended attribute value @value. @size indicates the size of the
405 * @value in bytes. @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
406 * Note that @name is the remainder of the attribute name after the
407 * security. prefix has been removed.
408 * Return 0 on success.
409 * @inode_listsecurity:
410 * Copy the extended attribute names for the security labels
411 * associated with @inode into @buffer. The maximum size of @buffer
412 * is specified by @buffer_size. @buffer may be NULL to request
413 * the size of the buffer required.
414 * Returns number of bytes used/required on success.
415 *
416 * Security hooks for file operations
417 *
418 * @file_permission:
419 * Check file permissions before accessing an open file. This hook is
420 * called by various operations that read or write files. A security
421 * module can use this hook to perform additional checking on these
422 * operations, e.g. to revalidate permissions on use to support privilege
423 * bracketing or policy changes. Notice that this hook is used when the
424 * actual read/write operations are performed, whereas the
425 * inode_security_ops hook is called when a file is opened (as well as
426 * many other operations).
427 * Caveat: Although this hook can be used to revalidate permissions for
428 * various system call operations that read or write files, it does not
429 * address the revalidation of permissions for memory-mapped files.
430 * Security modules must handle this separately if they need such
431 * revalidation.
432 * @file contains the file structure being accessed.
433 * @mask contains the requested permissions.
434 * Return 0 if permission is granted.
435 * @file_alloc_security:
436 * Allocate and attach a security structure to the file->f_security field.
437 * The security field is initialized to NULL when the structure is first
438 * created.
439 * @file contains the file structure to secure.
440 * Return 0 if the hook is successful and permission is granted.
441 * @file_free_security:
442 * Deallocate and free any security structures stored in file->f_security.
443 * @file contains the file structure being modified.
444 * @file_ioctl:
445 * @file contains the file structure.
446 * @cmd contains the operation to perform.
447 * @arg contains the operational arguments.
448 * Check permission for an ioctl operation on @file. Note that @arg can
449 * sometimes represents a user space pointer; in other cases, it may be a
450 * simple integer value. When @arg represents a user space pointer, it
451 * should never be used by the security module.
452 * Return 0 if permission is granted.
453 * @file_mmap :
454 * Check permissions for a mmap operation. The @file may be NULL, e.g.
455 * if mapping anonymous memory.
456 * @file contains the file structure for file to map (may be NULL).
457 * @reqprot contains the protection requested by the application.
458 * @prot contains the protection that will be applied by the kernel.
459 * @flags contains the operational flags.
460 * Return 0 if permission is granted.
461 * @file_mprotect:
462 * Check permissions before changing memory access permissions.
463 * @vma contains the memory region to modify.
464 * @reqprot contains the protection requested by the application.
465 * @prot contains the protection that will be applied by the kernel.
466 * Return 0 if permission is granted.
467 * @file_lock:
468 * Check permission before performing file locking operations.
469 * Note: this hook mediates both flock and fcntl style locks.
470 * @file contains the file structure.
471 * @cmd contains the posix-translated lock operation to perform
472 * (e.g. F_RDLCK, F_WRLCK).
473 * Return 0 if permission is granted.
474 * @file_fcntl:
475 * Check permission before allowing the file operation specified by @cmd
476 * from being performed on the file @file. Note that @arg can sometimes
477 * represents a user space pointer; in other cases, it may be a simple
478 * integer value. When @arg represents a user space pointer, it should
479 * never be used by the security module.
480 * @file contains the file structure.
481 * @cmd contains the operation to be performed.
482 * @arg contains the operational arguments.
483 * Return 0 if permission is granted.
484 * @file_set_fowner:
485 * Save owner security information (typically from current->security) in
486 * file->f_security for later use by the send_sigiotask hook.
487 * @file contains the file structure to update.
488 * Return 0 on success.
489 * @file_send_sigiotask:
490 * Check permission for the file owner @fown to send SIGIO or SIGURG to the
491 * process @tsk. Note that this hook is sometimes called from interrupt.
492 * Note that the fown_struct, @fown, is never outside the context of a
493 * struct file, so the file structure (and associated security information)
494 * can always be obtained:
495 * (struct file *)((long)fown - offsetof(struct file,f_owner));
496 * @tsk contains the structure of task receiving signal.
497 * @fown contains the file owner information.
498 * @sig is the signal that will be sent. When 0, kernel sends SIGIO.
499 * Return 0 if permission is granted.
500 * @file_receive:
501 * This hook allows security modules to control the ability of a process
502 * to receive an open file descriptor via socket IPC.
503 * @file contains the file structure being received.
504 * Return 0 if permission is granted.
505 *
506 * Security hooks for task operations.
507 *
508 * @task_create:
509 * Check permission before creating a child process. See the clone(2)
510 * manual page for definitions of the @clone_flags.
511 * @clone_flags contains the flags indicating what should be shared.
512 * Return 0 if permission is granted.
513 * @task_alloc_security:
514 * @p contains the task_struct for child process.
515 * Allocate and attach a security structure to the p->security field. The
516 * security field is initialized to NULL when the task structure is
517 * allocated.
518 * Return 0 if operation was successful.
519 * @task_free_security:
520 * @p contains the task_struct for process.
521 * Deallocate and clear the p->security field.
522 * @task_setuid:
523 * Check permission before setting one or more of the user identity
524 * attributes of the current process. The @flags parameter indicates
525 * which of the set*uid system calls invoked this hook and how to
526 * interpret the @id0, @id1, and @id2 parameters. See the LSM_SETID
527 * definitions at the beginning of this file for the @flags values and
528 * their meanings.
529 * @id0 contains a uid.
530 * @id1 contains a uid.
531 * @id2 contains a uid.
532 * @flags contains one of the LSM_SETID_* values.
533 * Return 0 if permission is granted.
534 * @task_post_setuid:
535 * Update the module's state after setting one or more of the user
536 * identity attributes of the current process. The @flags parameter
537 * indicates which of the set*uid system calls invoked this hook. If
538 * @flags is LSM_SETID_FS, then @old_ruid is the old fs uid and the other
539 * parameters are not used.
540 * @old_ruid contains the old real uid (or fs uid if LSM_SETID_FS).
541 * @old_euid contains the old effective uid (or -1 if LSM_SETID_FS).
542 * @old_suid contains the old saved uid (or -1 if LSM_SETID_FS).
543 * @flags contains one of the LSM_SETID_* values.
544 * Return 0 on success.
545 * @task_setgid:
546 * Check permission before setting one or more of the group identity
547 * attributes of the current process. The @flags parameter indicates
548 * which of the set*gid system calls invoked this hook and how to
549 * interpret the @id0, @id1, and @id2 parameters. See the LSM_SETID
550 * definitions at the beginning of this file for the @flags values and
551 * their meanings.
552 * @id0 contains a gid.
553 * @id1 contains a gid.
554 * @id2 contains a gid.
555 * @flags contains one of the LSM_SETID_* values.
556 * Return 0 if permission is granted.
557 * @task_setpgid:
558 * Check permission before setting the process group identifier of the
559 * process @p to @pgid.
560 * @p contains the task_struct for process being modified.
561 * @pgid contains the new pgid.
562 * Return 0 if permission is granted.
563 * @task_getpgid:
564 * Check permission before getting the process group identifier of the
565 * process @p.
566 * @p contains the task_struct for the process.
567 * Return 0 if permission is granted.
568 * @task_getsid:
569 * Check permission before getting the session identifier of the process
570 * @p.
571 * @p contains the task_struct for the process.
572 * Return 0 if permission is granted.
David Quigleyf9008e42006-06-30 01:55:46 -0700573 * @task_getsecid:
574 * Retrieve the security identifier of the process @p.
575 * @p contains the task_struct for the process and place is into @secid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 * @task_setgroups:
577 * Check permission before setting the supplementary group set of the
578 * current process.
579 * @group_info contains the new group information.
580 * Return 0 if permission is granted.
581 * @task_setnice:
582 * Check permission before setting the nice value of @p to @nice.
583 * @p contains the task_struct of process.
584 * @nice contains the new nice value.
585 * Return 0 if permission is granted.
James Morris03e68062006-06-23 02:03:58 -0700586 * @task_setioprio
587 * Check permission before setting the ioprio value of @p to @ioprio.
588 * @p contains the task_struct of process.
589 * @ioprio contains the new ioprio value
590 * Return 0 if permission is granted.
David Quigleya1836a42006-06-30 01:55:49 -0700591 * @task_getioprio
592 * Check permission before getting the ioprio value of @p.
593 * @p contains the task_struct of process.
594 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 * @task_setrlimit:
596 * Check permission before setting the resource limits of the current
597 * process for @resource to @new_rlim. The old resource limit values can
598 * be examined by dereferencing (current->signal->rlim + resource).
599 * @resource contains the resource whose limit is being set.
600 * @new_rlim contains the new limits for @resource.
601 * Return 0 if permission is granted.
602 * @task_setscheduler:
603 * Check permission before setting scheduling policy and/or parameters of
604 * process @p based on @policy and @lp.
605 * @p contains the task_struct for process.
606 * @policy contains the scheduling policy.
607 * @lp contains the scheduling parameters.
608 * Return 0 if permission is granted.
609 * @task_getscheduler:
610 * Check permission before obtaining scheduling information for process
611 * @p.
612 * @p contains the task_struct for process.
613 * Return 0 if permission is granted.
David Quigley35601542006-06-23 02:04:01 -0700614 * @task_movememory
615 * Check permission before moving memory owned by process @p.
616 * @p contains the task_struct for process.
617 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 * @task_kill:
619 * Check permission before sending signal @sig to @p. @info can be NULL,
620 * the constant 1, or a pointer to a siginfo structure. If @info is 1 or
621 * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
622 * from the kernel and should typically be permitted.
623 * SIGIO signals are handled separately by the send_sigiotask hook in
624 * file_security_ops.
625 * @p contains the task_struct for process.
626 * @info contains the signal information.
627 * @sig contains the signal value.
David Quigleyf9008e42006-06-30 01:55:46 -0700628 * @secid contains the sid of the process where the signal originated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 * Return 0 if permission is granted.
630 * @task_wait:
631 * Check permission before allowing a process to reap a child process @p
632 * and collect its status information.
633 * @p contains the task_struct for process.
634 * Return 0 if permission is granted.
635 * @task_prctl:
636 * Check permission before performing a process control operation on the
637 * current process.
638 * @option contains the operation.
639 * @arg2 contains a argument.
640 * @arg3 contains a argument.
641 * @arg4 contains a argument.
642 * @arg5 contains a argument.
643 * Return 0 if permission is granted.
644 * @task_reparent_to_init:
645 * Set the security attributes in @p->security for a kernel thread that
646 * is being reparented to the init task.
647 * @p contains the task_struct for the kernel thread.
648 * @task_to_inode:
649 * Set the security attributes for an inode based on an associated task's
650 * security attributes, e.g. for /proc/pid inodes.
651 * @p contains the task_struct for the task.
652 * @inode contains the inode structure for the inode.
653 *
654 * Security hooks for Netlink messaging.
655 *
656 * @netlink_send:
657 * Save security information for a netlink message so that permission
658 * checking can be performed when the message is processed. The security
659 * information can be saved using the eff_cap field of the
660 * netlink_skb_parms structure. Also may be used to provide fine
661 * grained control over message transmission.
662 * @sk associated sock of task sending the message.,
663 * @skb contains the sk_buff structure for the netlink message.
664 * Return 0 if the information was successfully saved and message
665 * is allowed to be transmitted.
666 * @netlink_recv:
667 * Check permission before processing the received netlink message in
668 * @skb.
669 * @skb contains the sk_buff structure for the netlink message.
Darrel Goeddelc7bdb542006-06-27 13:26:11 -0700670 * @cap indicates the capability required
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 * Return 0 if permission is granted.
672 *
673 * Security hooks for Unix domain networking.
674 *
675 * @unix_stream_connect:
676 * Check permissions before establishing a Unix domain stream connection
677 * between @sock and @other.
678 * @sock contains the socket structure.
679 * @other contains the peer socket structure.
680 * Return 0 if permission is granted.
681 * @unix_may_send:
682 * Check permissions before connecting or sending datagrams from @sock to
683 * @other.
684 * @sock contains the socket structure.
685 * @sock contains the peer socket structure.
686 * Return 0 if permission is granted.
687 *
688 * The @unix_stream_connect and @unix_may_send hooks were necessary because
689 * Linux provides an alternative to the conventional file name space for Unix
690 * domain sockets. Whereas binding and connecting to sockets in the file name
691 * space is mediated by the typical file permissions (and caught by the mknod
692 * and permission hooks in inode_security_ops), binding and connecting to
693 * sockets in the abstract name space is completely unmediated. Sufficient
694 * control of Unix domain sockets in the abstract name space isn't possible
695 * using only the socket layer hooks, since we need to know the actual target
696 * socket, which is not looked up until we are inside the af_unix code.
697 *
698 * Security hooks for socket operations.
699 *
700 * @socket_create:
701 * Check permissions prior to creating a new socket.
702 * @family contains the requested protocol family.
703 * @type contains the requested communications type.
704 * @protocol contains the requested protocol.
705 * @kern set to 1 if a kernel socket.
706 * Return 0 if permission is granted.
707 * @socket_post_create:
708 * This hook allows a module to update or allocate a per-socket security
709 * structure. Note that the security field was not added directly to the
710 * socket structure, but rather, the socket security information is stored
711 * in the associated inode. Typically, the inode alloc_security hook will
712 * allocate and and attach security information to
713 * sock->inode->i_security. This hook may be used to update the
714 * sock->inode->i_security field with additional information that wasn't
715 * available when the inode was allocated.
716 * @sock contains the newly created socket structure.
717 * @family contains the requested protocol family.
718 * @type contains the requested communications type.
719 * @protocol contains the requested protocol.
720 * @kern set to 1 if a kernel socket.
721 * @socket_bind:
722 * Check permission before socket protocol layer bind operation is
723 * performed and the socket @sock is bound to the address specified in the
724 * @address parameter.
725 * @sock contains the socket structure.
726 * @address contains the address to bind to.
727 * @addrlen contains the length of address.
728 * Return 0 if permission is granted.
729 * @socket_connect:
730 * Check permission before socket protocol layer connect operation
731 * attempts to connect socket @sock to a remote address, @address.
732 * @sock contains the socket structure.
733 * @address contains the address of remote endpoint.
734 * @addrlen contains the length of address.
735 * Return 0 if permission is granted.
736 * @socket_listen:
737 * Check permission before socket protocol layer listen operation.
738 * @sock contains the socket structure.
739 * @backlog contains the maximum length for the pending connection queue.
740 * Return 0 if permission is granted.
741 * @socket_accept:
742 * Check permission before accepting a new connection. Note that the new
743 * socket, @newsock, has been created and some information copied to it,
744 * but the accept operation has not actually been performed.
745 * @sock contains the listening socket structure.
746 * @newsock contains the newly created server socket for connection.
747 * Return 0 if permission is granted.
748 * @socket_post_accept:
749 * This hook allows a security module to copy security
750 * information into the newly created socket's inode.
751 * @sock contains the listening socket structure.
752 * @newsock contains the newly created server socket for connection.
753 * @socket_sendmsg:
754 * Check permission before transmitting a message to another socket.
755 * @sock contains the socket structure.
756 * @msg contains the message to be transmitted.
757 * @size contains the size of message.
758 * Return 0 if permission is granted.
759 * @socket_recvmsg:
760 * Check permission before receiving a message from a socket.
761 * @sock contains the socket structure.
762 * @msg contains the message structure.
763 * @size contains the size of message structure.
764 * @flags contains the operational flags.
765 * Return 0 if permission is granted.
766 * @socket_getsockname:
767 * Check permission before the local address (name) of the socket object
768 * @sock is retrieved.
769 * @sock contains the socket structure.
770 * Return 0 if permission is granted.
771 * @socket_getpeername:
772 * Check permission before the remote address (name) of a socket object
773 * @sock is retrieved.
774 * @sock contains the socket structure.
775 * Return 0 if permission is granted.
776 * @socket_getsockopt:
777 * Check permissions before retrieving the options associated with socket
778 * @sock.
779 * @sock contains the socket structure.
780 * @level contains the protocol level to retrieve option from.
781 * @optname contains the name of option to retrieve.
782 * Return 0 if permission is granted.
783 * @socket_setsockopt:
784 * Check permissions before setting the options associated with socket
785 * @sock.
786 * @sock contains the socket structure.
787 * @level contains the protocol level to set options for.
788 * @optname contains the name of the option to set.
789 * Return 0 if permission is granted.
790 * @socket_shutdown:
791 * Checks permission before all or part of a connection on the socket
792 * @sock is shut down.
793 * @sock contains the socket structure.
794 * @how contains the flag indicating how future sends and receives are handled.
795 * Return 0 if permission is granted.
796 * @socket_sock_rcv_skb:
797 * Check permissions on incoming network packets. This hook is distinct
798 * from Netfilter's IP input hooks since it is the first time that the
799 * incoming sk_buff @skb has been associated with a particular socket, @sk.
800 * @sk contains the sock (not socket) associated with the incoming sk_buff.
801 * @skb contains the incoming network data.
802 * @socket_getpeersec:
803 * This hook allows the security module to provide peer socket security
804 * state to userspace via getsockopt SO_GETPEERSEC.
805 * @sock is the local socket.
806 * @optval userspace memory where the security state is to be copied.
807 * @optlen userspace int where the module should copy the actual length
808 * of the security state.
809 * @len as input is the maximum length to copy to userspace provided
810 * by the caller.
811 * Return 0 if all is well, otherwise, typical getsockopt return
812 * values.
813 * @sk_alloc_security:
814 * Allocate and attach a security structure to the sk->sk_security field,
815 * which is used to copy security attributes between local stream sockets.
816 * @sk_free_security:
817 * Deallocate security structure.
Venkat Yekkirala892c1412006-08-04 23:08:56 -0700818 * @sk_clone_security:
819 * Clone/copy security structure.
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -0700820 * @sk_getsecid:
821 * Retrieve the LSM-specific secid for the sock to enable caching of network
Trent Jaegerdf718372005-12-13 23:12:27 -0800822 * authorizations.
Venkat Yekkirala4237c752006-07-24 23:32:50 -0700823 * @sock_graft:
824 * Sets the socket's isec sid to the sock's sid.
825 * @inet_conn_request:
826 * Sets the openreq's sid to socket's sid with MLS portion taken from peer sid.
827 * @inet_csk_clone:
828 * Sets the new child socket's sid to the openreq sid.
Venkat Yekkirala6b877692006-11-08 17:04:09 -0600829 * @inet_conn_established:
830 * Sets the connection's peersid to the secmark on skb.
Venkat Yekkirala4237c752006-07-24 23:32:50 -0700831 * @req_classify_flow:
832 * Sets the flow's sid to the openreq sid.
Trent Jaegerdf718372005-12-13 23:12:27 -0800833 *
834 * Security hooks for XFRM operations.
835 *
836 * @xfrm_policy_alloc_security:
837 * @xp contains the xfrm_policy being added to Security Policy Database
838 * used by the XFRM system.
839 * @sec_ctx contains the security context information being provided by
840 * the user-level policy update program (e.g., setkey).
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700841 * Allocate a security structure to the xp->security field; the security
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -0600842 * field is initialized to NULL when the xfrm_policy is allocated.
Trent Jaegerdf718372005-12-13 23:12:27 -0800843 * Return 0 if operation was successful (memory to allocate, legal context)
844 * @xfrm_policy_clone_security:
845 * @old contains an existing xfrm_policy in the SPD.
846 * @new contains a new xfrm_policy being cloned from old.
Catherine Zhangc8c05a82006-06-08 23:39:49 -0700847 * Allocate a security structure to the new->security field
848 * that contains the information from the old->security field.
Trent Jaegerdf718372005-12-13 23:12:27 -0800849 * Return 0 if operation was successful (memory to allocate).
850 * @xfrm_policy_free_security:
851 * @xp contains the xfrm_policy
Catherine Zhangc8c05a82006-06-08 23:39:49 -0700852 * Deallocate xp->security.
853 * @xfrm_policy_delete_security:
854 * @xp contains the xfrm_policy.
855 * Authorize deletion of xp->security.
Trent Jaegerdf718372005-12-13 23:12:27 -0800856 * @xfrm_state_alloc_security:
857 * @x contains the xfrm_state being added to the Security Association
858 * Database by the XFRM system.
859 * @sec_ctx contains the security context information being provided by
860 * the user-level SA generation program (e.g., setkey or racoon).
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700861 * @secid contains the secid from which to take the mls portion of the context.
862 * Allocate a security structure to the x->security field; the security
863 * field is initialized to NULL when the xfrm_state is allocated. Set the
864 * context to correspond to either sec_ctx or polsec, with the mls portion
865 * taken from secid in the latter case.
Trent Jaegerdf718372005-12-13 23:12:27 -0800866 * Return 0 if operation was successful (memory to allocate, legal context).
867 * @xfrm_state_free_security:
868 * @x contains the xfrm_state.
Catherine Zhangc8c05a82006-06-08 23:39:49 -0700869 * Deallocate x->security.
870 * @xfrm_state_delete_security:
871 * @x contains the xfrm_state.
872 * Authorize deletion of x->security.
Trent Jaegerdf718372005-12-13 23:12:27 -0800873 * @xfrm_policy_lookup:
874 * @xp contains the xfrm_policy for which the access control is being
875 * checked.
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700876 * @fl_secid contains the flow security label that is used to authorize
Trent Jaegerdf718372005-12-13 23:12:27 -0800877 * access to the policy xp.
878 * @dir contains the direction of the flow (input or output).
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700879 * Check permission when a flow selects a xfrm_policy for processing
Trent Jaegerdf718372005-12-13 23:12:27 -0800880 * XFRMs on a packet. The hook is called when selecting either a
881 * per-socket policy or a generic xfrm policy.
Venkat Yekkirala5b368e62006-10-05 15:42:18 -0500882 * Return 0 if permission is granted, -ESRCH otherwise, or -errno
883 * on other errors.
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700884 * @xfrm_state_pol_flow_match:
885 * @x contains the state to match.
886 * @xp contains the policy to check for a match.
887 * @fl contains the flow to check for a match.
888 * Return 1 if there is a match.
889 * @xfrm_flow_state_match:
890 * @fl contains the flow key to match.
891 * @xfrm points to the xfrm_state to match.
Venkat Yekkirala5b368e62006-10-05 15:42:18 -0500892 * @xp points to the xfrm_policy to match.
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -0700893 * Return 1 if there is a match.
894 * @xfrm_decode_session:
895 * @skb points to skb to decode.
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -0700896 * @secid points to the flow key secid to set.
897 * @ckall says if all xfrms used should be checked for same secid.
898 * Return 0 if ckall is zero or all xfrms used have the same secid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 *
David Howells29db9192005-10-30 15:02:44 -0800900 * Security hooks affecting all Key Management operations
901 *
902 * @key_alloc:
903 * Permit allocation of a key and assign security data. Note that key does
904 * not have a serial number assigned at this point.
905 * @key points to the key.
David Howells7e047ef2006-06-26 00:24:50 -0700906 * @flags is the allocation flags
David Howells29db9192005-10-30 15:02:44 -0800907 * Return 0 if permission is granted, -ve error otherwise.
908 * @key_free:
909 * Notification of destruction; free security data.
910 * @key points to the key.
911 * No return value.
912 * @key_permission:
913 * See whether a specific operational right is granted to a process on a
914 * key.
915 * @key_ref refers to the key (key pointer + possession attribute bit).
916 * @context points to the process to provide the context against which to
917 * evaluate the security data on the key.
918 * @perm describes the combination of permissions required of this key.
919 * Return 1 if permission granted, 0 if permission denied and -ve it the
920 * normal permissions model should be effected.
921 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 * Security hooks affecting all System V IPC operations.
923 *
924 * @ipc_permission:
925 * Check permissions for access to IPC
926 * @ipcp contains the kernel IPC permission structure
927 * @flag contains the desired (requested) permission set
928 * Return 0 if permission is granted.
929 *
930 * Security hooks for individual messages held in System V IPC message queues
931 * @msg_msg_alloc_security:
932 * Allocate and attach a security structure to the msg->security field.
933 * The security field is initialized to NULL when the structure is first
934 * created.
935 * @msg contains the message structure to be modified.
936 * Return 0 if operation was successful and permission is granted.
937 * @msg_msg_free_security:
938 * Deallocate the security structure for this message.
939 * @msg contains the message structure to be modified.
940 *
941 * Security hooks for System V IPC Message Queues
942 *
943 * @msg_queue_alloc_security:
944 * Allocate and attach a security structure to the
945 * msq->q_perm.security field. The security field is initialized to
946 * NULL when the structure is first created.
947 * @msq contains the message queue structure to be modified.
948 * Return 0 if operation was successful and permission is granted.
949 * @msg_queue_free_security:
950 * Deallocate security structure for this message queue.
951 * @msq contains the message queue structure to be modified.
952 * @msg_queue_associate:
953 * Check permission when a message queue is requested through the
954 * msgget system call. This hook is only called when returning the
955 * message queue identifier for an existing message queue, not when a
956 * new message queue is created.
957 * @msq contains the message queue to act upon.
958 * @msqflg contains the operation control flags.
959 * Return 0 if permission is granted.
960 * @msg_queue_msgctl:
961 * Check permission when a message control operation specified by @cmd
962 * is to be performed on the message queue @msq.
963 * The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
964 * @msq contains the message queue to act upon. May be NULL.
965 * @cmd contains the operation to be performed.
966 * Return 0 if permission is granted.
967 * @msg_queue_msgsnd:
968 * Check permission before a message, @msg, is enqueued on the message
969 * queue, @msq.
970 * @msq contains the message queue to send message to.
971 * @msg contains the message to be enqueued.
972 * @msqflg contains operational flags.
973 * Return 0 if permission is granted.
974 * @msg_queue_msgrcv:
975 * Check permission before a message, @msg, is removed from the message
976 * queue, @msq. The @target task structure contains a pointer to the
977 * process that will be receiving the message (not equal to the current
978 * process when inline receives are being performed).
979 * @msq contains the message queue to retrieve message from.
980 * @msg contains the message destination.
981 * @target contains the task structure for recipient process.
982 * @type contains the type of message requested.
983 * @mode contains the operational flags.
984 * Return 0 if permission is granted.
985 *
986 * Security hooks for System V Shared Memory Segments
987 *
988 * @shm_alloc_security:
989 * Allocate and attach a security structure to the shp->shm_perm.security
990 * field. The security field is initialized to NULL when the structure is
991 * first created.
992 * @shp contains the shared memory structure to be modified.
993 * Return 0 if operation was successful and permission is granted.
994 * @shm_free_security:
995 * Deallocate the security struct for this memory segment.
996 * @shp contains the shared memory structure to be modified.
997 * @shm_associate:
998 * Check permission when a shared memory region is requested through the
999 * shmget system call. This hook is only called when returning the shared
1000 * memory region identifier for an existing region, not when a new shared
1001 * memory region is created.
1002 * @shp contains the shared memory structure to be modified.
1003 * @shmflg contains the operation control flags.
1004 * Return 0 if permission is granted.
1005 * @shm_shmctl:
1006 * Check permission when a shared memory control operation specified by
1007 * @cmd is to be performed on the shared memory region @shp.
1008 * The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
1009 * @shp contains shared memory structure to be modified.
1010 * @cmd contains the operation to be performed.
1011 * Return 0 if permission is granted.
1012 * @shm_shmat:
1013 * Check permissions prior to allowing the shmat system call to attach the
1014 * shared memory segment @shp to the data segment of the calling process.
1015 * The attaching address is specified by @shmaddr.
1016 * @shp contains the shared memory structure to be modified.
1017 * @shmaddr contains the address to attach memory region to.
1018 * @shmflg contains the operational flags.
1019 * Return 0 if permission is granted.
1020 *
1021 * Security hooks for System V Semaphores
1022 *
1023 * @sem_alloc_security:
1024 * Allocate and attach a security structure to the sma->sem_perm.security
1025 * field. The security field is initialized to NULL when the structure is
1026 * first created.
1027 * @sma contains the semaphore structure
1028 * Return 0 if operation was successful and permission is granted.
1029 * @sem_free_security:
1030 * deallocate security struct for this semaphore
1031 * @sma contains the semaphore structure.
1032 * @sem_associate:
1033 * Check permission when a semaphore is requested through the semget
1034 * system call. This hook is only called when returning the semaphore
1035 * identifier for an existing semaphore, not when a new one must be
1036 * created.
1037 * @sma contains the semaphore structure.
1038 * @semflg contains the operation control flags.
1039 * Return 0 if permission is granted.
1040 * @sem_semctl:
1041 * Check permission when a semaphore operation specified by @cmd is to be
1042 * performed on the semaphore @sma. The @sma may be NULL, e.g. for
1043 * IPC_INFO or SEM_INFO.
1044 * @sma contains the semaphore structure. May be NULL.
1045 * @cmd contains the operation to be performed.
1046 * Return 0 if permission is granted.
1047 * @sem_semop
1048 * Check permissions before performing operations on members of the
1049 * semaphore set @sma. If the @alter flag is nonzero, the semaphore set
1050 * may be modified.
1051 * @sma contains the semaphore structure.
1052 * @sops contains the operations to perform.
1053 * @nsops contains the number of operations to perform.
1054 * @alter contains the flag indicating whether changes are to be made.
1055 * Return 0 if permission is granted.
1056 *
1057 * @ptrace:
1058 * Check permission before allowing the @parent process to trace the
1059 * @child process.
1060 * Security modules may also want to perform a process tracing check
1061 * during an execve in the set_security or apply_creds hooks of
1062 * binprm_security_ops if the process is being traced and its security
1063 * attributes would be changed by the execve.
1064 * @parent contains the task_struct structure for parent process.
1065 * @child contains the task_struct structure for child process.
1066 * Return 0 if permission is granted.
1067 * @capget:
1068 * Get the @effective, @inheritable, and @permitted capability sets for
1069 * the @target process. The hook may also perform permission checking to
1070 * determine if the current process is allowed to see the capability sets
1071 * of the @target process.
1072 * @target contains the task_struct structure for target process.
1073 * @effective contains the effective capability set.
1074 * @inheritable contains the inheritable capability set.
1075 * @permitted contains the permitted capability set.
1076 * Return 0 if the capability sets were successfully obtained.
1077 * @capset_check:
1078 * Check permission before setting the @effective, @inheritable, and
1079 * @permitted capability sets for the @target process.
1080 * Caveat: @target is also set to current if a set of processes is
1081 * specified (i.e. all processes other than current and init or a
1082 * particular process group). Hence, the capset_set hook may need to
1083 * revalidate permission to the actual target process.
1084 * @target contains the task_struct structure for target process.
1085 * @effective contains the effective capability set.
1086 * @inheritable contains the inheritable capability set.
1087 * @permitted contains the permitted capability set.
1088 * Return 0 if permission is granted.
1089 * @capset_set:
1090 * Set the @effective, @inheritable, and @permitted capability sets for
1091 * the @target process. Since capset_check cannot always check permission
1092 * to the real @target process, this hook may also perform permission
1093 * checking to determine if the current process is allowed to set the
1094 * capability sets of the @target process. However, this hook has no way
1095 * of returning an error due to the structure of the sys_capset code.
1096 * @target contains the task_struct structure for target process.
1097 * @effective contains the effective capability set.
1098 * @inheritable contains the inheritable capability set.
1099 * @permitted contains the permitted capability set.
Chris Wright12b59892006-03-25 03:07:41 -08001100 * @capable:
1101 * Check whether the @tsk process has the @cap capability.
1102 * @tsk contains the task_struct for the process.
1103 * @cap contains the capability <include/linux/capability.h>.
1104 * Return 0 if the capability is granted for @tsk.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 * @acct:
1106 * Check permission before enabling or disabling process accounting. If
1107 * accounting is being enabled, then @file refers to the open file used to
1108 * store accounting records. If accounting is being disabled, then @file
1109 * is NULL.
1110 * @file contains the file structure for the accounting file (may be NULL).
1111 * Return 0 if permission is granted.
1112 * @sysctl:
1113 * Check permission before accessing the @table sysctl variable in the
1114 * manner specified by @op.
1115 * @table contains the ctl_table structure for the sysctl variable.
1116 * @op contains the operation (001 = search, 002 = write, 004 = read).
1117 * Return 0 if permission is granted.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 * @syslog:
1119 * Check permission before accessing the kernel message ring or changing
1120 * logging to the console.
1121 * See the syslog(2) manual page for an explanation of the @type values.
1122 * @type contains the type of action.
1123 * Return 0 if permission is granted.
1124 * @settime:
1125 * Check permission to change the system time.
1126 * struct timespec and timezone are defined in include/linux/time.h
1127 * @ts contains new time
1128 * @tz contains new timezone
1129 * Return 0 if permission is granted.
1130 * @vm_enough_memory:
1131 * Check permissions for allocating a new virtual mapping.
1132 * @pages contains the number of pages.
1133 * Return 0 if permission is granted.
1134 *
1135 * @register_security:
1136 * allow module stacking.
1137 * @name contains the name of the security module being stacked.
1138 * @ops contains a pointer to the struct security_operations of the module to stack.
1139 * @unregister_security:
1140 * remove a stacked module.
1141 * @name contains the name of the security module being unstacked.
1142 * @ops contains a pointer to the struct security_operations of the module to unstack.
1143 *
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07001144 * @secid_to_secctx:
1145 * Convert secid to security context.
1146 * @secid contains the security ID.
1147 * @secdata contains the pointer that stores the converted security context.
1148 *
1149 * @release_secctx:
1150 * Release the security context.
1151 * @secdata contains the security context.
1152 * @seclen contains the length of the security context.
1153 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 * This is the main security structure.
1155 */
1156struct security_operations {
1157 int (*ptrace) (struct task_struct * parent, struct task_struct * child);
1158 int (*capget) (struct task_struct * target,
1159 kernel_cap_t * effective,
1160 kernel_cap_t * inheritable, kernel_cap_t * permitted);
1161 int (*capset_check) (struct task_struct * target,
1162 kernel_cap_t * effective,
1163 kernel_cap_t * inheritable,
1164 kernel_cap_t * permitted);
1165 void (*capset_set) (struct task_struct * target,
1166 kernel_cap_t * effective,
1167 kernel_cap_t * inheritable,
1168 kernel_cap_t * permitted);
Chris Wright12b59892006-03-25 03:07:41 -08001169 int (*capable) (struct task_struct * tsk, int cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 int (*acct) (struct file * file);
1171 int (*sysctl) (struct ctl_table * table, int op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 int (*quotactl) (int cmds, int type, int id, struct super_block * sb);
1173 int (*quota_on) (struct dentry * dentry);
1174 int (*syslog) (int type);
1175 int (*settime) (struct timespec *ts, struct timezone *tz);
1176 int (*vm_enough_memory) (long pages);
1177
1178 int (*bprm_alloc_security) (struct linux_binprm * bprm);
1179 void (*bprm_free_security) (struct linux_binprm * bprm);
1180 void (*bprm_apply_creds) (struct linux_binprm * bprm, int unsafe);
1181 void (*bprm_post_apply_creds) (struct linux_binprm * bprm);
1182 int (*bprm_set_security) (struct linux_binprm * bprm);
1183 int (*bprm_check_security) (struct linux_binprm * bprm);
1184 int (*bprm_secureexec) (struct linux_binprm * bprm);
1185
1186 int (*sb_alloc_security) (struct super_block * sb);
1187 void (*sb_free_security) (struct super_block * sb);
1188 int (*sb_copy_data)(struct file_system_type *type,
1189 void *orig, void *copy);
1190 int (*sb_kern_mount) (struct super_block *sb, void *data);
David Howells726c3342006-06-23 02:02:58 -07001191 int (*sb_statfs) (struct dentry *dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 int (*sb_mount) (char *dev_name, struct nameidata * nd,
1193 char *type, unsigned long flags, void *data);
1194 int (*sb_check_sb) (struct vfsmount * mnt, struct nameidata * nd);
1195 int (*sb_umount) (struct vfsmount * mnt, int flags);
1196 void (*sb_umount_close) (struct vfsmount * mnt);
1197 void (*sb_umount_busy) (struct vfsmount * mnt);
1198 void (*sb_post_remount) (struct vfsmount * mnt,
1199 unsigned long flags, void *data);
1200 void (*sb_post_mountroot) (void);
1201 void (*sb_post_addmount) (struct vfsmount * mnt,
1202 struct nameidata * mountpoint_nd);
1203 int (*sb_pivotroot) (struct nameidata * old_nd,
1204 struct nameidata * new_nd);
1205 void (*sb_post_pivotroot) (struct nameidata * old_nd,
1206 struct nameidata * new_nd);
1207
1208 int (*inode_alloc_security) (struct inode *inode);
1209 void (*inode_free_security) (struct inode *inode);
Stephen Smalley5e41ff92005-09-09 13:01:35 -07001210 int (*inode_init_security) (struct inode *inode, struct inode *dir,
1211 char **name, void **value, size_t *len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 int (*inode_create) (struct inode *dir,
1213 struct dentry *dentry, int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 int (*inode_link) (struct dentry *old_dentry,
1215 struct inode *dir, struct dentry *new_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 int (*inode_unlink) (struct inode *dir, struct dentry *dentry);
1217 int (*inode_symlink) (struct inode *dir,
1218 struct dentry *dentry, const char *old_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 int (*inode_mkdir) (struct inode *dir, struct dentry *dentry, int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 int (*inode_rmdir) (struct inode *dir, struct dentry *dentry);
1221 int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
1222 int mode, dev_t dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
1224 struct inode *new_dir, struct dentry *new_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 int (*inode_readlink) (struct dentry *dentry);
1226 int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
1227 int (*inode_permission) (struct inode *inode, int mask, struct nameidata *nd);
1228 int (*inode_setattr) (struct dentry *dentry, struct iattr *attr);
1229 int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
1230 void (*inode_delete) (struct inode *inode);
1231 int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
1232 size_t size, int flags);
1233 void (*inode_post_setxattr) (struct dentry *dentry, char *name, void *value,
1234 size_t size, int flags);
1235 int (*inode_getxattr) (struct dentry *dentry, char *name);
1236 int (*inode_listxattr) (struct dentry *dentry);
1237 int (*inode_removexattr) (struct dentry *dentry, char *name);
Dustin Kirkland7306a0b2005-11-16 15:53:13 +00001238 const char *(*inode_xattr_getsuffix) (void);
1239 int (*inode_getsecurity)(const struct inode *inode, const char *name, void *buffer, size_t size, int err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
1241 int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
1242
1243 int (*file_permission) (struct file * file, int mask);
1244 int (*file_alloc_security) (struct file * file);
1245 void (*file_free_security) (struct file * file);
1246 int (*file_ioctl) (struct file * file, unsigned int cmd,
1247 unsigned long arg);
1248 int (*file_mmap) (struct file * file,
1249 unsigned long reqprot,
1250 unsigned long prot, unsigned long flags);
1251 int (*file_mprotect) (struct vm_area_struct * vma,
1252 unsigned long reqprot,
1253 unsigned long prot);
1254 int (*file_lock) (struct file * file, unsigned int cmd);
1255 int (*file_fcntl) (struct file * file, unsigned int cmd,
1256 unsigned long arg);
1257 int (*file_set_fowner) (struct file * file);
1258 int (*file_send_sigiotask) (struct task_struct * tsk,
1259 struct fown_struct * fown, int sig);
1260 int (*file_receive) (struct file * file);
1261
1262 int (*task_create) (unsigned long clone_flags);
1263 int (*task_alloc_security) (struct task_struct * p);
1264 void (*task_free_security) (struct task_struct * p);
1265 int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags);
1266 int (*task_post_setuid) (uid_t old_ruid /* or fsuid */ ,
1267 uid_t old_euid, uid_t old_suid, int flags);
1268 int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags);
1269 int (*task_setpgid) (struct task_struct * p, pid_t pgid);
1270 int (*task_getpgid) (struct task_struct * p);
1271 int (*task_getsid) (struct task_struct * p);
David Quigleyf9008e42006-06-30 01:55:46 -07001272 void (*task_getsecid) (struct task_struct * p, u32 * secid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 int (*task_setgroups) (struct group_info *group_info);
1274 int (*task_setnice) (struct task_struct * p, int nice);
James Morris03e68062006-06-23 02:03:58 -07001275 int (*task_setioprio) (struct task_struct * p, int ioprio);
David Quigleya1836a42006-06-30 01:55:49 -07001276 int (*task_getioprio) (struct task_struct * p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 int (*task_setrlimit) (unsigned int resource, struct rlimit * new_rlim);
1278 int (*task_setscheduler) (struct task_struct * p, int policy,
1279 struct sched_param * lp);
1280 int (*task_getscheduler) (struct task_struct * p);
David Quigley35601542006-06-23 02:04:01 -07001281 int (*task_movememory) (struct task_struct * p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 int (*task_kill) (struct task_struct * p,
David Quigleyf9008e42006-06-30 01:55:46 -07001283 struct siginfo * info, int sig, u32 secid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 int (*task_wait) (struct task_struct * p);
1285 int (*task_prctl) (int option, unsigned long arg2,
1286 unsigned long arg3, unsigned long arg4,
1287 unsigned long arg5);
1288 void (*task_reparent_to_init) (struct task_struct * p);
1289 void (*task_to_inode)(struct task_struct *p, struct inode *inode);
1290
1291 int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag);
1292
1293 int (*msg_msg_alloc_security) (struct msg_msg * msg);
1294 void (*msg_msg_free_security) (struct msg_msg * msg);
1295
1296 int (*msg_queue_alloc_security) (struct msg_queue * msq);
1297 void (*msg_queue_free_security) (struct msg_queue * msq);
1298 int (*msg_queue_associate) (struct msg_queue * msq, int msqflg);
1299 int (*msg_queue_msgctl) (struct msg_queue * msq, int cmd);
1300 int (*msg_queue_msgsnd) (struct msg_queue * msq,
1301 struct msg_msg * msg, int msqflg);
1302 int (*msg_queue_msgrcv) (struct msg_queue * msq,
1303 struct msg_msg * msg,
1304 struct task_struct * target,
1305 long type, int mode);
1306
1307 int (*shm_alloc_security) (struct shmid_kernel * shp);
1308 void (*shm_free_security) (struct shmid_kernel * shp);
1309 int (*shm_associate) (struct shmid_kernel * shp, int shmflg);
1310 int (*shm_shmctl) (struct shmid_kernel * shp, int cmd);
1311 int (*shm_shmat) (struct shmid_kernel * shp,
1312 char __user *shmaddr, int shmflg);
1313
1314 int (*sem_alloc_security) (struct sem_array * sma);
1315 void (*sem_free_security) (struct sem_array * sma);
1316 int (*sem_associate) (struct sem_array * sma, int semflg);
1317 int (*sem_semctl) (struct sem_array * sma, int cmd);
1318 int (*sem_semop) (struct sem_array * sma,
1319 struct sembuf * sops, unsigned nsops, int alter);
1320
1321 int (*netlink_send) (struct sock * sk, struct sk_buff * skb);
Darrel Goeddelc7bdb542006-06-27 13:26:11 -07001322 int (*netlink_recv) (struct sk_buff * skb, int cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 /* allow module stacking */
1325 int (*register_security) (const char *name,
1326 struct security_operations *ops);
1327 int (*unregister_security) (const char *name,
1328 struct security_operations *ops);
1329
1330 void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
1331
1332 int (*getprocattr)(struct task_struct *p, char *name, void *value, size_t size);
1333 int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t size);
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07001334 int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
1335 void (*release_secctx)(char *secdata, u32 seclen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337#ifdef CONFIG_SECURITY_NETWORK
1338 int (*unix_stream_connect) (struct socket * sock,
1339 struct socket * other, struct sock * newsk);
1340 int (*unix_may_send) (struct socket * sock, struct socket * other);
1341
1342 int (*socket_create) (int family, int type, int protocol, int kern);
Venkat Yekkirala7420ed22006-08-04 23:17:57 -07001343 int (*socket_post_create) (struct socket * sock, int family,
1344 int type, int protocol, int kern);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 int (*socket_bind) (struct socket * sock,
1346 struct sockaddr * address, int addrlen);
1347 int (*socket_connect) (struct socket * sock,
1348 struct sockaddr * address, int addrlen);
1349 int (*socket_listen) (struct socket * sock, int backlog);
1350 int (*socket_accept) (struct socket * sock, struct socket * newsock);
1351 void (*socket_post_accept) (struct socket * sock,
1352 struct socket * newsock);
1353 int (*socket_sendmsg) (struct socket * sock,
1354 struct msghdr * msg, int size);
1355 int (*socket_recvmsg) (struct socket * sock,
1356 struct msghdr * msg, int size, int flags);
1357 int (*socket_getsockname) (struct socket * sock);
1358 int (*socket_getpeername) (struct socket * sock);
1359 int (*socket_getsockopt) (struct socket * sock, int level, int optname);
1360 int (*socket_setsockopt) (struct socket * sock, int level, int optname);
1361 int (*socket_shutdown) (struct socket * sock, int how);
1362 int (*socket_sock_rcv_skb) (struct sock * sk, struct sk_buff * skb);
Catherine Zhang2c7946a2006-03-20 22:41:23 -08001363 int (*socket_getpeersec_stream) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len);
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07001364 int (*socket_getpeersec_dgram) (struct socket *sock, struct sk_buff *skb, u32 *secid);
Al Viro7d877f32005-10-21 03:20:43 -04001365 int (*sk_alloc_security) (struct sock *sk, int family, gfp_t priority);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 void (*sk_free_security) (struct sock *sk);
Venkat Yekkirala892c1412006-08-04 23:08:56 -07001367 void (*sk_clone_security) (const struct sock *sk, struct sock *newsk);
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07001368 void (*sk_getsecid) (struct sock *sk, u32 *secid);
Venkat Yekkirala4237c752006-07-24 23:32:50 -07001369 void (*sock_graft)(struct sock* sk, struct socket *parent);
1370 int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb,
1371 struct request_sock *req);
1372 void (*inet_csk_clone)(struct sock *newsk, const struct request_sock *req);
Venkat Yekkirala6b877692006-11-08 17:04:09 -06001373 void (*inet_conn_established)(struct sock *sk, struct sk_buff *skb);
Venkat Yekkirala4237c752006-07-24 23:32:50 -07001374 void (*req_classify_flow)(const struct request_sock *req, struct flowi *fl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375#endif /* CONFIG_SECURITY_NETWORK */
David Howells29db9192005-10-30 15:02:44 -08001376
Trent Jaegerdf718372005-12-13 23:12:27 -08001377#ifdef CONFIG_SECURITY_NETWORK_XFRM
Venkat Yekkiralacb969f02006-07-24 23:32:20 -07001378 int (*xfrm_policy_alloc_security) (struct xfrm_policy *xp,
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -06001379 struct xfrm_user_sec_ctx *sec_ctx);
Trent Jaegerdf718372005-12-13 23:12:27 -08001380 int (*xfrm_policy_clone_security) (struct xfrm_policy *old, struct xfrm_policy *new);
1381 void (*xfrm_policy_free_security) (struct xfrm_policy *xp);
Catherine Zhangc8c05a82006-06-08 23:39:49 -07001382 int (*xfrm_policy_delete_security) (struct xfrm_policy *xp);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07001383 int (*xfrm_state_alloc_security) (struct xfrm_state *x,
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -06001384 struct xfrm_user_sec_ctx *sec_ctx,
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07001385 u32 secid);
Trent Jaegerdf718372005-12-13 23:12:27 -08001386 void (*xfrm_state_free_security) (struct xfrm_state *x);
Catherine Zhangc8c05a82006-06-08 23:39:49 -07001387 int (*xfrm_state_delete_security) (struct xfrm_state *x);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07001388 int (*xfrm_policy_lookup)(struct xfrm_policy *xp, u32 fl_secid, u8 dir);
1389 int (*xfrm_state_pol_flow_match)(struct xfrm_state *x,
1390 struct xfrm_policy *xp, struct flowi *fl);
Venkat Yekkirala5b368e62006-10-05 15:42:18 -05001391 int (*xfrm_flow_state_match)(struct flowi *fl, struct xfrm_state *xfrm,
1392 struct xfrm_policy *xp);
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07001393 int (*xfrm_decode_session)(struct sk_buff *skb, u32 *secid, int ckall);
Trent Jaegerdf718372005-12-13 23:12:27 -08001394#endif /* CONFIG_SECURITY_NETWORK_XFRM */
1395
David Howells29db9192005-10-30 15:02:44 -08001396 /* key management security hooks */
1397#ifdef CONFIG_KEYS
David Howells7e047ef2006-06-26 00:24:50 -07001398 int (*key_alloc)(struct key *key, struct task_struct *tsk, unsigned long flags);
David Howells29db9192005-10-30 15:02:44 -08001399 void (*key_free)(struct key *key);
1400 int (*key_permission)(key_ref_t key_ref,
1401 struct task_struct *context,
1402 key_perm_t perm);
1403
1404#endif /* CONFIG_KEYS */
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406};
1407
1408/* global variables */
1409extern struct security_operations *security_ops;
1410
1411/* inline stuff */
1412static inline int security_ptrace (struct task_struct * parent, struct task_struct * child)
1413{
1414 return security_ops->ptrace (parent, child);
1415}
1416
1417static inline int security_capget (struct task_struct *target,
1418 kernel_cap_t *effective,
1419 kernel_cap_t *inheritable,
1420 kernel_cap_t *permitted)
1421{
1422 return security_ops->capget (target, effective, inheritable, permitted);
1423}
1424
1425static inline int security_capset_check (struct task_struct *target,
1426 kernel_cap_t *effective,
1427 kernel_cap_t *inheritable,
1428 kernel_cap_t *permitted)
1429{
1430 return security_ops->capset_check (target, effective, inheritable, permitted);
1431}
1432
1433static inline void security_capset_set (struct task_struct *target,
1434 kernel_cap_t *effective,
1435 kernel_cap_t *inheritable,
1436 kernel_cap_t *permitted)
1437{
1438 security_ops->capset_set (target, effective, inheritable, permitted);
1439}
1440
Chris Wright12b59892006-03-25 03:07:41 -08001441static inline int security_capable(struct task_struct *tsk, int cap)
1442{
1443 return security_ops->capable(tsk, cap);
1444}
1445
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446static inline int security_acct (struct file *file)
1447{
1448 return security_ops->acct (file);
1449}
1450
1451static inline int security_sysctl(struct ctl_table *table, int op)
1452{
1453 return security_ops->sysctl(table, op);
1454}
1455
1456static inline int security_quotactl (int cmds, int type, int id,
1457 struct super_block *sb)
1458{
1459 return security_ops->quotactl (cmds, type, id, sb);
1460}
1461
1462static inline int security_quota_on (struct dentry * dentry)
1463{
1464 return security_ops->quota_on (dentry);
1465}
1466
1467static inline int security_syslog(int type)
1468{
1469 return security_ops->syslog(type);
1470}
1471
1472static inline int security_settime(struct timespec *ts, struct timezone *tz)
1473{
1474 return security_ops->settime(ts, tz);
1475}
1476
1477
1478static inline int security_vm_enough_memory(long pages)
1479{
1480 return security_ops->vm_enough_memory(pages);
1481}
1482
1483static inline int security_bprm_alloc (struct linux_binprm *bprm)
1484{
1485 return security_ops->bprm_alloc_security (bprm);
1486}
1487static inline void security_bprm_free (struct linux_binprm *bprm)
1488{
1489 security_ops->bprm_free_security (bprm);
1490}
1491static inline void security_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
1492{
1493 security_ops->bprm_apply_creds (bprm, unsafe);
1494}
1495static inline void security_bprm_post_apply_creds (struct linux_binprm *bprm)
1496{
1497 security_ops->bprm_post_apply_creds (bprm);
1498}
1499static inline int security_bprm_set (struct linux_binprm *bprm)
1500{
1501 return security_ops->bprm_set_security (bprm);
1502}
1503
1504static inline int security_bprm_check (struct linux_binprm *bprm)
1505{
1506 return security_ops->bprm_check_security (bprm);
1507}
1508
1509static inline int security_bprm_secureexec (struct linux_binprm *bprm)
1510{
1511 return security_ops->bprm_secureexec (bprm);
1512}
1513
1514static inline int security_sb_alloc (struct super_block *sb)
1515{
1516 return security_ops->sb_alloc_security (sb);
1517}
1518
1519static inline void security_sb_free (struct super_block *sb)
1520{
1521 security_ops->sb_free_security (sb);
1522}
1523
1524static inline int security_sb_copy_data (struct file_system_type *type,
1525 void *orig, void *copy)
1526{
1527 return security_ops->sb_copy_data (type, orig, copy);
1528}
1529
1530static inline int security_sb_kern_mount (struct super_block *sb, void *data)
1531{
1532 return security_ops->sb_kern_mount (sb, data);
1533}
1534
David Howells726c3342006-06-23 02:02:58 -07001535static inline int security_sb_statfs (struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
David Howells726c3342006-06-23 02:02:58 -07001537 return security_ops->sb_statfs (dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
1540static inline int security_sb_mount (char *dev_name, struct nameidata *nd,
1541 char *type, unsigned long flags,
1542 void *data)
1543{
1544 return security_ops->sb_mount (dev_name, nd, type, flags, data);
1545}
1546
1547static inline int security_sb_check_sb (struct vfsmount *mnt,
1548 struct nameidata *nd)
1549{
1550 return security_ops->sb_check_sb (mnt, nd);
1551}
1552
1553static inline int security_sb_umount (struct vfsmount *mnt, int flags)
1554{
1555 return security_ops->sb_umount (mnt, flags);
1556}
1557
1558static inline void security_sb_umount_close (struct vfsmount *mnt)
1559{
1560 security_ops->sb_umount_close (mnt);
1561}
1562
1563static inline void security_sb_umount_busy (struct vfsmount *mnt)
1564{
1565 security_ops->sb_umount_busy (mnt);
1566}
1567
1568static inline void security_sb_post_remount (struct vfsmount *mnt,
1569 unsigned long flags, void *data)
1570{
1571 security_ops->sb_post_remount (mnt, flags, data);
1572}
1573
1574static inline void security_sb_post_mountroot (void)
1575{
1576 security_ops->sb_post_mountroot ();
1577}
1578
1579static inline void security_sb_post_addmount (struct vfsmount *mnt,
1580 struct nameidata *mountpoint_nd)
1581{
1582 security_ops->sb_post_addmount (mnt, mountpoint_nd);
1583}
1584
1585static inline int security_sb_pivotroot (struct nameidata *old_nd,
1586 struct nameidata *new_nd)
1587{
1588 return security_ops->sb_pivotroot (old_nd, new_nd);
1589}
1590
1591static inline void security_sb_post_pivotroot (struct nameidata *old_nd,
1592 struct nameidata *new_nd)
1593{
1594 security_ops->sb_post_pivotroot (old_nd, new_nd);
1595}
1596
1597static inline int security_inode_alloc (struct inode *inode)
1598{
Alexey Dobriyan50462062006-09-29 02:00:01 -07001599 inode->i_security = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 return security_ops->inode_alloc_security (inode);
1601}
1602
1603static inline void security_inode_free (struct inode *inode)
1604{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 security_ops->inode_free_security (inode);
1606}
Stephen Smalley5e41ff92005-09-09 13:01:35 -07001607
1608static inline int security_inode_init_security (struct inode *inode,
1609 struct inode *dir,
1610 char **name,
1611 void **value,
1612 size_t *len)
1613{
1614 if (unlikely (IS_PRIVATE (inode)))
1615 return -EOPNOTSUPP;
1616 return security_ops->inode_init_security (inode, dir, name, value, len);
1617}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619static inline int security_inode_create (struct inode *dir,
1620 struct dentry *dentry,
1621 int mode)
1622{
1623 if (unlikely (IS_PRIVATE (dir)))
1624 return 0;
1625 return security_ops->inode_create (dir, dentry, mode);
1626}
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628static inline int security_inode_link (struct dentry *old_dentry,
1629 struct inode *dir,
1630 struct dentry *new_dentry)
1631{
1632 if (unlikely (IS_PRIVATE (old_dentry->d_inode)))
1633 return 0;
1634 return security_ops->inode_link (old_dentry, dir, new_dentry);
1635}
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637static inline int security_inode_unlink (struct inode *dir,
1638 struct dentry *dentry)
1639{
1640 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1641 return 0;
1642 return security_ops->inode_unlink (dir, dentry);
1643}
1644
1645static inline int security_inode_symlink (struct inode *dir,
1646 struct dentry *dentry,
1647 const char *old_name)
1648{
1649 if (unlikely (IS_PRIVATE (dir)))
1650 return 0;
1651 return security_ops->inode_symlink (dir, dentry, old_name);
1652}
1653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654static inline int security_inode_mkdir (struct inode *dir,
1655 struct dentry *dentry,
1656 int mode)
1657{
1658 if (unlikely (IS_PRIVATE (dir)))
1659 return 0;
1660 return security_ops->inode_mkdir (dir, dentry, mode);
1661}
1662
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663static inline int security_inode_rmdir (struct inode *dir,
1664 struct dentry *dentry)
1665{
1666 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1667 return 0;
1668 return security_ops->inode_rmdir (dir, dentry);
1669}
1670
1671static inline int security_inode_mknod (struct inode *dir,
1672 struct dentry *dentry,
1673 int mode, dev_t dev)
1674{
1675 if (unlikely (IS_PRIVATE (dir)))
1676 return 0;
1677 return security_ops->inode_mknod (dir, dentry, mode, dev);
1678}
1679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680static inline int security_inode_rename (struct inode *old_dir,
1681 struct dentry *old_dentry,
1682 struct inode *new_dir,
1683 struct dentry *new_dentry)
1684{
1685 if (unlikely (IS_PRIVATE (old_dentry->d_inode) ||
1686 (new_dentry->d_inode && IS_PRIVATE (new_dentry->d_inode))))
1687 return 0;
1688 return security_ops->inode_rename (old_dir, old_dentry,
1689 new_dir, new_dentry);
1690}
1691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692static inline int security_inode_readlink (struct dentry *dentry)
1693{
1694 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1695 return 0;
1696 return security_ops->inode_readlink (dentry);
1697}
1698
1699static inline int security_inode_follow_link (struct dentry *dentry,
1700 struct nameidata *nd)
1701{
1702 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1703 return 0;
1704 return security_ops->inode_follow_link (dentry, nd);
1705}
1706
1707static inline int security_inode_permission (struct inode *inode, int mask,
1708 struct nameidata *nd)
1709{
1710 if (unlikely (IS_PRIVATE (inode)))
1711 return 0;
1712 return security_ops->inode_permission (inode, mask, nd);
1713}
1714
1715static inline int security_inode_setattr (struct dentry *dentry,
1716 struct iattr *attr)
1717{
1718 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1719 return 0;
1720 return security_ops->inode_setattr (dentry, attr);
1721}
1722
1723static inline int security_inode_getattr (struct vfsmount *mnt,
1724 struct dentry *dentry)
1725{
1726 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1727 return 0;
1728 return security_ops->inode_getattr (mnt, dentry);
1729}
1730
1731static inline void security_inode_delete (struct inode *inode)
1732{
1733 if (unlikely (IS_PRIVATE (inode)))
1734 return;
1735 security_ops->inode_delete (inode);
1736}
1737
1738static inline int security_inode_setxattr (struct dentry *dentry, char *name,
1739 void *value, size_t size, int flags)
1740{
1741 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1742 return 0;
1743 return security_ops->inode_setxattr (dentry, name, value, size, flags);
1744}
1745
1746static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
1747 void *value, size_t size, int flags)
1748{
1749 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1750 return;
1751 security_ops->inode_post_setxattr (dentry, name, value, size, flags);
1752}
1753
1754static inline int security_inode_getxattr (struct dentry *dentry, char *name)
1755{
1756 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1757 return 0;
1758 return security_ops->inode_getxattr (dentry, name);
1759}
1760
1761static inline int security_inode_listxattr (struct dentry *dentry)
1762{
1763 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1764 return 0;
1765 return security_ops->inode_listxattr (dentry);
1766}
1767
1768static inline int security_inode_removexattr (struct dentry *dentry, char *name)
1769{
1770 if (unlikely (IS_PRIVATE (dentry->d_inode)))
1771 return 0;
1772 return security_ops->inode_removexattr (dentry, name);
1773}
1774
Dustin Kirkland8c8570f2005-11-03 17:15:16 +00001775static inline const char *security_inode_xattr_getsuffix(void)
1776{
1777 return security_ops->inode_xattr_getsuffix();
1778}
1779
Dustin Kirkland7306a0b2005-11-16 15:53:13 +00001780static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 if (unlikely (IS_PRIVATE (inode)))
1783 return 0;
James Morrisd381d8a2005-10-30 14:59:22 -08001784 return security_ops->inode_getsecurity(inode, name, buffer, size, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}
1786
1787static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
1788{
1789 if (unlikely (IS_PRIVATE (inode)))
1790 return 0;
1791 return security_ops->inode_setsecurity(inode, name, value, size, flags);
1792}
1793
1794static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
1795{
1796 if (unlikely (IS_PRIVATE (inode)))
1797 return 0;
1798 return security_ops->inode_listsecurity(inode, buffer, buffer_size);
1799}
1800
1801static inline int security_file_permission (struct file *file, int mask)
1802{
1803 return security_ops->file_permission (file, mask);
1804}
1805
1806static inline int security_file_alloc (struct file *file)
1807{
1808 return security_ops->file_alloc_security (file);
1809}
1810
1811static inline void security_file_free (struct file *file)
1812{
1813 security_ops->file_free_security (file);
1814}
1815
1816static inline int security_file_ioctl (struct file *file, unsigned int cmd,
1817 unsigned long arg)
1818{
1819 return security_ops->file_ioctl (file, cmd, arg);
1820}
1821
1822static inline int security_file_mmap (struct file *file, unsigned long reqprot,
1823 unsigned long prot,
1824 unsigned long flags)
1825{
1826 return security_ops->file_mmap (file, reqprot, prot, flags);
1827}
1828
1829static inline int security_file_mprotect (struct vm_area_struct *vma,
1830 unsigned long reqprot,
1831 unsigned long prot)
1832{
1833 return security_ops->file_mprotect (vma, reqprot, prot);
1834}
1835
1836static inline int security_file_lock (struct file *file, unsigned int cmd)
1837{
1838 return security_ops->file_lock (file, cmd);
1839}
1840
1841static inline int security_file_fcntl (struct file *file, unsigned int cmd,
1842 unsigned long arg)
1843{
1844 return security_ops->file_fcntl (file, cmd, arg);
1845}
1846
1847static inline int security_file_set_fowner (struct file *file)
1848{
1849 return security_ops->file_set_fowner (file);
1850}
1851
1852static inline int security_file_send_sigiotask (struct task_struct *tsk,
1853 struct fown_struct *fown,
1854 int sig)
1855{
1856 return security_ops->file_send_sigiotask (tsk, fown, sig);
1857}
1858
1859static inline int security_file_receive (struct file *file)
1860{
1861 return security_ops->file_receive (file);
1862}
1863
1864static inline int security_task_create (unsigned long clone_flags)
1865{
1866 return security_ops->task_create (clone_flags);
1867}
1868
1869static inline int security_task_alloc (struct task_struct *p)
1870{
1871 return security_ops->task_alloc_security (p);
1872}
1873
1874static inline void security_task_free (struct task_struct *p)
1875{
1876 security_ops->task_free_security (p);
1877}
1878
1879static inline int security_task_setuid (uid_t id0, uid_t id1, uid_t id2,
1880 int flags)
1881{
1882 return security_ops->task_setuid (id0, id1, id2, flags);
1883}
1884
1885static inline int security_task_post_setuid (uid_t old_ruid, uid_t old_euid,
1886 uid_t old_suid, int flags)
1887{
1888 return security_ops->task_post_setuid (old_ruid, old_euid, old_suid, flags);
1889}
1890
1891static inline int security_task_setgid (gid_t id0, gid_t id1, gid_t id2,
1892 int flags)
1893{
1894 return security_ops->task_setgid (id0, id1, id2, flags);
1895}
1896
1897static inline int security_task_setpgid (struct task_struct *p, pid_t pgid)
1898{
1899 return security_ops->task_setpgid (p, pgid);
1900}
1901
1902static inline int security_task_getpgid (struct task_struct *p)
1903{
1904 return security_ops->task_getpgid (p);
1905}
1906
1907static inline int security_task_getsid (struct task_struct *p)
1908{
1909 return security_ops->task_getsid (p);
1910}
1911
David Quigleyf9008e42006-06-30 01:55:46 -07001912static inline void security_task_getsecid (struct task_struct *p, u32 *secid)
1913{
1914 security_ops->task_getsecid (p, secid);
1915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917static inline int security_task_setgroups (struct group_info *group_info)
1918{
1919 return security_ops->task_setgroups (group_info);
1920}
1921
1922static inline int security_task_setnice (struct task_struct *p, int nice)
1923{
1924 return security_ops->task_setnice (p, nice);
1925}
1926
James Morris03e68062006-06-23 02:03:58 -07001927static inline int security_task_setioprio (struct task_struct *p, int ioprio)
1928{
1929 return security_ops->task_setioprio (p, ioprio);
1930}
1931
David Quigleya1836a42006-06-30 01:55:49 -07001932static inline int security_task_getioprio (struct task_struct *p)
1933{
1934 return security_ops->task_getioprio (p);
1935}
1936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937static inline int security_task_setrlimit (unsigned int resource,
1938 struct rlimit *new_rlim)
1939{
1940 return security_ops->task_setrlimit (resource, new_rlim);
1941}
1942
1943static inline int security_task_setscheduler (struct task_struct *p,
1944 int policy,
1945 struct sched_param *lp)
1946{
1947 return security_ops->task_setscheduler (p, policy, lp);
1948}
1949
1950static inline int security_task_getscheduler (struct task_struct *p)
1951{
1952 return security_ops->task_getscheduler (p);
1953}
1954
David Quigley35601542006-06-23 02:04:01 -07001955static inline int security_task_movememory (struct task_struct *p)
1956{
1957 return security_ops->task_movememory (p);
1958}
1959
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960static inline int security_task_kill (struct task_struct *p,
David Quigleyf9008e42006-06-30 01:55:46 -07001961 struct siginfo *info, int sig,
1962 u32 secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
David Quigleyf9008e42006-06-30 01:55:46 -07001964 return security_ops->task_kill (p, info, sig, secid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}
1966
1967static inline int security_task_wait (struct task_struct *p)
1968{
1969 return security_ops->task_wait (p);
1970}
1971
1972static inline int security_task_prctl (int option, unsigned long arg2,
1973 unsigned long arg3,
1974 unsigned long arg4,
1975 unsigned long arg5)
1976{
1977 return security_ops->task_prctl (option, arg2, arg3, arg4, arg5);
1978}
1979
1980static inline void security_task_reparent_to_init (struct task_struct *p)
1981{
1982 security_ops->task_reparent_to_init (p);
1983}
1984
1985static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
1986{
1987 security_ops->task_to_inode(p, inode);
1988}
1989
1990static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
1991 short flag)
1992{
1993 return security_ops->ipc_permission (ipcp, flag);
1994}
1995
1996static inline int security_msg_msg_alloc (struct msg_msg * msg)
1997{
1998 return security_ops->msg_msg_alloc_security (msg);
1999}
2000
2001static inline void security_msg_msg_free (struct msg_msg * msg)
2002{
2003 security_ops->msg_msg_free_security(msg);
2004}
2005
2006static inline int security_msg_queue_alloc (struct msg_queue *msq)
2007{
2008 return security_ops->msg_queue_alloc_security (msq);
2009}
2010
2011static inline void security_msg_queue_free (struct msg_queue *msq)
2012{
2013 security_ops->msg_queue_free_security (msq);
2014}
2015
2016static inline int security_msg_queue_associate (struct msg_queue * msq,
2017 int msqflg)
2018{
2019 return security_ops->msg_queue_associate (msq, msqflg);
2020}
2021
2022static inline int security_msg_queue_msgctl (struct msg_queue * msq, int cmd)
2023{
2024 return security_ops->msg_queue_msgctl (msq, cmd);
2025}
2026
2027static inline int security_msg_queue_msgsnd (struct msg_queue * msq,
2028 struct msg_msg * msg, int msqflg)
2029{
2030 return security_ops->msg_queue_msgsnd (msq, msg, msqflg);
2031}
2032
2033static inline int security_msg_queue_msgrcv (struct msg_queue * msq,
2034 struct msg_msg * msg,
2035 struct task_struct * target,
2036 long type, int mode)
2037{
2038 return security_ops->msg_queue_msgrcv (msq, msg, target, type, mode);
2039}
2040
2041static inline int security_shm_alloc (struct shmid_kernel *shp)
2042{
2043 return security_ops->shm_alloc_security (shp);
2044}
2045
2046static inline void security_shm_free (struct shmid_kernel *shp)
2047{
2048 security_ops->shm_free_security (shp);
2049}
2050
2051static inline int security_shm_associate (struct shmid_kernel * shp,
2052 int shmflg)
2053{
2054 return security_ops->shm_associate(shp, shmflg);
2055}
2056
2057static inline int security_shm_shmctl (struct shmid_kernel * shp, int cmd)
2058{
2059 return security_ops->shm_shmctl (shp, cmd);
2060}
2061
2062static inline int security_shm_shmat (struct shmid_kernel * shp,
2063 char __user *shmaddr, int shmflg)
2064{
2065 return security_ops->shm_shmat(shp, shmaddr, shmflg);
2066}
2067
2068static inline int security_sem_alloc (struct sem_array *sma)
2069{
2070 return security_ops->sem_alloc_security (sma);
2071}
2072
2073static inline void security_sem_free (struct sem_array *sma)
2074{
2075 security_ops->sem_free_security (sma);
2076}
2077
2078static inline int security_sem_associate (struct sem_array * sma, int semflg)
2079{
2080 return security_ops->sem_associate (sma, semflg);
2081}
2082
2083static inline int security_sem_semctl (struct sem_array * sma, int cmd)
2084{
2085 return security_ops->sem_semctl(sma, cmd);
2086}
2087
2088static inline int security_sem_semop (struct sem_array * sma,
2089 struct sembuf * sops, unsigned nsops,
2090 int alter)
2091{
2092 return security_ops->sem_semop(sma, sops, nsops, alter);
2093}
2094
2095static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
2096{
2097 if (unlikely (inode && IS_PRIVATE (inode)))
2098 return;
2099 security_ops->d_instantiate (dentry, inode);
2100}
2101
2102static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
2103{
2104 return security_ops->getprocattr(p, name, value, size);
2105}
2106
2107static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
2108{
2109 return security_ops->setprocattr(p, name, value, size);
2110}
2111
2112static inline int security_netlink_send(struct sock *sk, struct sk_buff * skb)
2113{
2114 return security_ops->netlink_send(sk, skb);
2115}
2116
Darrel Goeddelc7bdb542006-06-27 13:26:11 -07002117static inline int security_netlink_recv(struct sk_buff * skb, int cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Darrel Goeddelc7bdb542006-06-27 13:26:11 -07002119 return security_ops->netlink_recv(skb, cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07002122static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2123{
2124 return security_ops->secid_to_secctx(secid, secdata, seclen);
2125}
2126
2127static inline void security_release_secctx(char *secdata, u32 seclen)
2128{
2129 return security_ops->release_secctx(secdata, seclen);
2130}
2131
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132/* prototypes */
2133extern int security_init (void);
2134extern int register_security (struct security_operations *ops);
2135extern int unregister_security (struct security_operations *ops);
2136extern int mod_reg_security (const char *name, struct security_operations *ops);
2137extern int mod_unreg_security (const char *name, struct security_operations *ops);
Greg KHb67dbf92005-07-07 14:37:53 -07002138extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
2139 struct dentry *parent, void *data,
2140 struct file_operations *fops);
2141extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
2142extern void securityfs_remove(struct dentry *dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144
2145#else /* CONFIG_SECURITY */
2146
2147/*
2148 * This is the default capabilities functionality. Most of these functions
2149 * are just stubbed out, but a few must call the proper capable code.
2150 */
2151
2152static inline int security_init(void)
2153{
2154 return 0;
2155}
2156
2157static inline int security_ptrace (struct task_struct *parent, struct task_struct * child)
2158{
2159 return cap_ptrace (parent, child);
2160}
2161
2162static inline int security_capget (struct task_struct *target,
2163 kernel_cap_t *effective,
2164 kernel_cap_t *inheritable,
2165 kernel_cap_t *permitted)
2166{
2167 return cap_capget (target, effective, inheritable, permitted);
2168}
2169
2170static inline int security_capset_check (struct task_struct *target,
2171 kernel_cap_t *effective,
2172 kernel_cap_t *inheritable,
2173 kernel_cap_t *permitted)
2174{
2175 return cap_capset_check (target, effective, inheritable, permitted);
2176}
2177
2178static inline void security_capset_set (struct task_struct *target,
2179 kernel_cap_t *effective,
2180 kernel_cap_t *inheritable,
2181 kernel_cap_t *permitted)
2182{
2183 cap_capset_set (target, effective, inheritable, permitted);
2184}
2185
Chris Wright12b59892006-03-25 03:07:41 -08002186static inline int security_capable(struct task_struct *tsk, int cap)
2187{
2188 return cap_capable(tsk, cap);
2189}
2190
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191static inline int security_acct (struct file *file)
2192{
2193 return 0;
2194}
2195
2196static inline int security_sysctl(struct ctl_table *table, int op)
2197{
2198 return 0;
2199}
2200
2201static inline int security_quotactl (int cmds, int type, int id,
2202 struct super_block * sb)
2203{
2204 return 0;
2205}
2206
2207static inline int security_quota_on (struct dentry * dentry)
2208{
2209 return 0;
2210}
2211
2212static inline int security_syslog(int type)
2213{
2214 return cap_syslog(type);
2215}
2216
2217static inline int security_settime(struct timespec *ts, struct timezone *tz)
2218{
2219 return cap_settime(ts, tz);
2220}
2221
2222static inline int security_vm_enough_memory(long pages)
2223{
2224 return cap_vm_enough_memory(pages);
2225}
2226
2227static inline int security_bprm_alloc (struct linux_binprm *bprm)
2228{
2229 return 0;
2230}
2231
2232static inline void security_bprm_free (struct linux_binprm *bprm)
2233{ }
2234
2235static inline void security_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
2236{
2237 cap_bprm_apply_creds (bprm, unsafe);
2238}
2239
2240static inline void security_bprm_post_apply_creds (struct linux_binprm *bprm)
2241{
2242 return;
2243}
2244
2245static inline int security_bprm_set (struct linux_binprm *bprm)
2246{
2247 return cap_bprm_set_security (bprm);
2248}
2249
2250static inline int security_bprm_check (struct linux_binprm *bprm)
2251{
2252 return 0;
2253}
2254
2255static inline int security_bprm_secureexec (struct linux_binprm *bprm)
2256{
2257 return cap_bprm_secureexec(bprm);
2258}
2259
2260static inline int security_sb_alloc (struct super_block *sb)
2261{
2262 return 0;
2263}
2264
2265static inline void security_sb_free (struct super_block *sb)
2266{ }
2267
2268static inline int security_sb_copy_data (struct file_system_type *type,
2269 void *orig, void *copy)
2270{
2271 return 0;
2272}
2273
2274static inline int security_sb_kern_mount (struct super_block *sb, void *data)
2275{
2276 return 0;
2277}
2278
David Howells726c3342006-06-23 02:02:58 -07002279static inline int security_sb_statfs (struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
2281 return 0;
2282}
2283
2284static inline int security_sb_mount (char *dev_name, struct nameidata *nd,
2285 char *type, unsigned long flags,
2286 void *data)
2287{
2288 return 0;
2289}
2290
2291static inline int security_sb_check_sb (struct vfsmount *mnt,
2292 struct nameidata *nd)
2293{
2294 return 0;
2295}
2296
2297static inline int security_sb_umount (struct vfsmount *mnt, int flags)
2298{
2299 return 0;
2300}
2301
2302static inline void security_sb_umount_close (struct vfsmount *mnt)
2303{ }
2304
2305static inline void security_sb_umount_busy (struct vfsmount *mnt)
2306{ }
2307
2308static inline void security_sb_post_remount (struct vfsmount *mnt,
2309 unsigned long flags, void *data)
2310{ }
2311
2312static inline void security_sb_post_mountroot (void)
2313{ }
2314
2315static inline void security_sb_post_addmount (struct vfsmount *mnt,
2316 struct nameidata *mountpoint_nd)
2317{ }
2318
2319static inline int security_sb_pivotroot (struct nameidata *old_nd,
2320 struct nameidata *new_nd)
2321{
2322 return 0;
2323}
2324
2325static inline void security_sb_post_pivotroot (struct nameidata *old_nd,
2326 struct nameidata *new_nd)
2327{ }
2328
2329static inline int security_inode_alloc (struct inode *inode)
2330{
2331 return 0;
2332}
2333
2334static inline void security_inode_free (struct inode *inode)
2335{ }
Stephen Smalley5e41ff92005-09-09 13:01:35 -07002336
2337static inline int security_inode_init_security (struct inode *inode,
2338 struct inode *dir,
2339 char **name,
2340 void **value,
2341 size_t *len)
2342{
2343 return -EOPNOTSUPP;
2344}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346static inline int security_inode_create (struct inode *dir,
2347 struct dentry *dentry,
2348 int mode)
2349{
2350 return 0;
2351}
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353static inline int security_inode_link (struct dentry *old_dentry,
2354 struct inode *dir,
2355 struct dentry *new_dentry)
2356{
2357 return 0;
2358}
2359
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360static inline int security_inode_unlink (struct inode *dir,
2361 struct dentry *dentry)
2362{
2363 return 0;
2364}
2365
2366static inline int security_inode_symlink (struct inode *dir,
2367 struct dentry *dentry,
2368 const char *old_name)
2369{
2370 return 0;
2371}
2372
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373static inline int security_inode_mkdir (struct inode *dir,
2374 struct dentry *dentry,
2375 int mode)
2376{
2377 return 0;
2378}
2379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380static inline int security_inode_rmdir (struct inode *dir,
2381 struct dentry *dentry)
2382{
2383 return 0;
2384}
2385
2386static inline int security_inode_mknod (struct inode *dir,
2387 struct dentry *dentry,
2388 int mode, dev_t dev)
2389{
2390 return 0;
2391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393static inline int security_inode_rename (struct inode *old_dir,
2394 struct dentry *old_dentry,
2395 struct inode *new_dir,
2396 struct dentry *new_dentry)
2397{
2398 return 0;
2399}
2400
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401static inline int security_inode_readlink (struct dentry *dentry)
2402{
2403 return 0;
2404}
2405
2406static inline int security_inode_follow_link (struct dentry *dentry,
2407 struct nameidata *nd)
2408{
2409 return 0;
2410}
2411
2412static inline int security_inode_permission (struct inode *inode, int mask,
2413 struct nameidata *nd)
2414{
2415 return 0;
2416}
2417
2418static inline int security_inode_setattr (struct dentry *dentry,
2419 struct iattr *attr)
2420{
2421 return 0;
2422}
2423
2424static inline int security_inode_getattr (struct vfsmount *mnt,
2425 struct dentry *dentry)
2426{
2427 return 0;
2428}
2429
2430static inline void security_inode_delete (struct inode *inode)
2431{ }
2432
2433static inline int security_inode_setxattr (struct dentry *dentry, char *name,
2434 void *value, size_t size, int flags)
2435{
2436 return cap_inode_setxattr(dentry, name, value, size, flags);
2437}
2438
2439static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
2440 void *value, size_t size, int flags)
2441{ }
2442
2443static inline int security_inode_getxattr (struct dentry *dentry, char *name)
2444{
2445 return 0;
2446}
2447
2448static inline int security_inode_listxattr (struct dentry *dentry)
2449{
2450 return 0;
2451}
2452
2453static inline int security_inode_removexattr (struct dentry *dentry, char *name)
2454{
2455 return cap_inode_removexattr(dentry, name);
2456}
2457
Dustin Kirkland8c8570f2005-11-03 17:15:16 +00002458static inline const char *security_inode_xattr_getsuffix (void)
2459{
2460 return NULL ;
2461}
2462
Dustin Kirkland7306a0b2005-11-16 15:53:13 +00002463static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
2465 return -EOPNOTSUPP;
2466}
2467
2468static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
2469{
2470 return -EOPNOTSUPP;
2471}
2472
2473static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
2474{
2475 return 0;
2476}
2477
2478static inline int security_file_permission (struct file *file, int mask)
2479{
2480 return 0;
2481}
2482
2483static inline int security_file_alloc (struct file *file)
2484{
2485 return 0;
2486}
2487
2488static inline void security_file_free (struct file *file)
2489{ }
2490
2491static inline int security_file_ioctl (struct file *file, unsigned int cmd,
2492 unsigned long arg)
2493{
2494 return 0;
2495}
2496
2497static inline int security_file_mmap (struct file *file, unsigned long reqprot,
2498 unsigned long prot,
2499 unsigned long flags)
2500{
2501 return 0;
2502}
2503
2504static inline int security_file_mprotect (struct vm_area_struct *vma,
2505 unsigned long reqprot,
2506 unsigned long prot)
2507{
2508 return 0;
2509}
2510
2511static inline int security_file_lock (struct file *file, unsigned int cmd)
2512{
2513 return 0;
2514}
2515
2516static inline int security_file_fcntl (struct file *file, unsigned int cmd,
2517 unsigned long arg)
2518{
2519 return 0;
2520}
2521
2522static inline int security_file_set_fowner (struct file *file)
2523{
2524 return 0;
2525}
2526
2527static inline int security_file_send_sigiotask (struct task_struct *tsk,
2528 struct fown_struct *fown,
2529 int sig)
2530{
2531 return 0;
2532}
2533
2534static inline int security_file_receive (struct file *file)
2535{
2536 return 0;
2537}
2538
2539static inline int security_task_create (unsigned long clone_flags)
2540{
2541 return 0;
2542}
2543
2544static inline int security_task_alloc (struct task_struct *p)
2545{
2546 return 0;
2547}
2548
2549static inline void security_task_free (struct task_struct *p)
2550{ }
2551
2552static inline int security_task_setuid (uid_t id0, uid_t id1, uid_t id2,
2553 int flags)
2554{
2555 return 0;
2556}
2557
2558static inline int security_task_post_setuid (uid_t old_ruid, uid_t old_euid,
2559 uid_t old_suid, int flags)
2560{
2561 return cap_task_post_setuid (old_ruid, old_euid, old_suid, flags);
2562}
2563
2564static inline int security_task_setgid (gid_t id0, gid_t id1, gid_t id2,
2565 int flags)
2566{
2567 return 0;
2568}
2569
2570static inline int security_task_setpgid (struct task_struct *p, pid_t pgid)
2571{
2572 return 0;
2573}
2574
2575static inline int security_task_getpgid (struct task_struct *p)
2576{
2577 return 0;
2578}
2579
2580static inline int security_task_getsid (struct task_struct *p)
2581{
2582 return 0;
2583}
2584
David Quigleyf9008e42006-06-30 01:55:46 -07002585static inline void security_task_getsecid (struct task_struct *p, u32 *secid)
2586{ }
2587
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588static inline int security_task_setgroups (struct group_info *group_info)
2589{
2590 return 0;
2591}
2592
2593static inline int security_task_setnice (struct task_struct *p, int nice)
2594{
2595 return 0;
2596}
2597
James Morris03e68062006-06-23 02:03:58 -07002598static inline int security_task_setioprio (struct task_struct *p, int ioprio)
2599{
2600 return 0;
2601}
2602
David Quigleya1836a42006-06-30 01:55:49 -07002603static inline int security_task_getioprio (struct task_struct *p)
2604{
2605 return 0;
2606}
2607
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608static inline int security_task_setrlimit (unsigned int resource,
2609 struct rlimit *new_rlim)
2610{
2611 return 0;
2612}
2613
2614static inline int security_task_setscheduler (struct task_struct *p,
2615 int policy,
2616 struct sched_param *lp)
2617{
2618 return 0;
2619}
2620
2621static inline int security_task_getscheduler (struct task_struct *p)
2622{
2623 return 0;
2624}
2625
David Quigley35601542006-06-23 02:04:01 -07002626static inline int security_task_movememory (struct task_struct *p)
2627{
2628 return 0;
2629}
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631static inline int security_task_kill (struct task_struct *p,
David Quigleyf9008e42006-06-30 01:55:46 -07002632 struct siginfo *info, int sig,
2633 u32 secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
2635 return 0;
2636}
2637
2638static inline int security_task_wait (struct task_struct *p)
2639{
2640 return 0;
2641}
2642
2643static inline int security_task_prctl (int option, unsigned long arg2,
2644 unsigned long arg3,
2645 unsigned long arg4,
2646 unsigned long arg5)
2647{
2648 return 0;
2649}
2650
2651static inline void security_task_reparent_to_init (struct task_struct *p)
2652{
2653 cap_task_reparent_to_init (p);
2654}
2655
2656static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
2657{ }
2658
2659static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
2660 short flag)
2661{
2662 return 0;
2663}
2664
2665static inline int security_msg_msg_alloc (struct msg_msg * msg)
2666{
2667 return 0;
2668}
2669
2670static inline void security_msg_msg_free (struct msg_msg * msg)
2671{ }
2672
2673static inline int security_msg_queue_alloc (struct msg_queue *msq)
2674{
2675 return 0;
2676}
2677
2678static inline void security_msg_queue_free (struct msg_queue *msq)
2679{ }
2680
2681static inline int security_msg_queue_associate (struct msg_queue * msq,
2682 int msqflg)
2683{
2684 return 0;
2685}
2686
2687static inline int security_msg_queue_msgctl (struct msg_queue * msq, int cmd)
2688{
2689 return 0;
2690}
2691
2692static inline int security_msg_queue_msgsnd (struct msg_queue * msq,
2693 struct msg_msg * msg, int msqflg)
2694{
2695 return 0;
2696}
2697
2698static inline int security_msg_queue_msgrcv (struct msg_queue * msq,
2699 struct msg_msg * msg,
2700 struct task_struct * target,
2701 long type, int mode)
2702{
2703 return 0;
2704}
2705
2706static inline int security_shm_alloc (struct shmid_kernel *shp)
2707{
2708 return 0;
2709}
2710
2711static inline void security_shm_free (struct shmid_kernel *shp)
2712{ }
2713
2714static inline int security_shm_associate (struct shmid_kernel * shp,
2715 int shmflg)
2716{
2717 return 0;
2718}
2719
2720static inline int security_shm_shmctl (struct shmid_kernel * shp, int cmd)
2721{
2722 return 0;
2723}
2724
2725static inline int security_shm_shmat (struct shmid_kernel * shp,
2726 char __user *shmaddr, int shmflg)
2727{
2728 return 0;
2729}
2730
2731static inline int security_sem_alloc (struct sem_array *sma)
2732{
2733 return 0;
2734}
2735
2736static inline void security_sem_free (struct sem_array *sma)
2737{ }
2738
2739static inline int security_sem_associate (struct sem_array * sma, int semflg)
2740{
2741 return 0;
2742}
2743
2744static inline int security_sem_semctl (struct sem_array * sma, int cmd)
2745{
2746 return 0;
2747}
2748
2749static inline int security_sem_semop (struct sem_array * sma,
2750 struct sembuf * sops, unsigned nsops,
2751 int alter)
2752{
2753 return 0;
2754}
2755
2756static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
2757{ }
2758
2759static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
2760{
2761 return -EINVAL;
2762}
2763
2764static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
2765{
2766 return -EINVAL;
2767}
2768
2769static inline int security_netlink_send (struct sock *sk, struct sk_buff *skb)
2770{
2771 return cap_netlink_send (sk, skb);
2772}
2773
Darrel Goeddelc7bdb542006-06-27 13:26:11 -07002774static inline int security_netlink_recv (struct sk_buff *skb, int cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775{
Darrel Goeddelc7bdb542006-06-27 13:26:11 -07002776 return cap_netlink_recv (skb, cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777}
2778
Randy Dunlaped5a9272006-02-01 03:05:00 -08002779static inline struct dentry *securityfs_create_dir(const char *name,
2780 struct dentry *parent)
2781{
2782 return ERR_PTR(-ENODEV);
2783}
2784
2785static inline struct dentry *securityfs_create_file(const char *name,
2786 mode_t mode,
2787 struct dentry *parent,
2788 void *data,
2789 struct file_operations *fops)
2790{
2791 return ERR_PTR(-ENODEV);
2792}
2793
2794static inline void securityfs_remove(struct dentry *dentry)
2795{
2796}
2797
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07002798static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2799{
2800 return -EOPNOTSUPP;
2801}
2802
2803static inline void security_release_secctx(char *secdata, u32 seclen)
2804{
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07002805}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806#endif /* CONFIG_SECURITY */
2807
2808#ifdef CONFIG_SECURITY_NETWORK
2809static inline int security_unix_stream_connect(struct socket * sock,
2810 struct socket * other,
2811 struct sock * newsk)
2812{
2813 return security_ops->unix_stream_connect(sock, other, newsk);
2814}
2815
2816
2817static inline int security_unix_may_send(struct socket * sock,
2818 struct socket * other)
2819{
2820 return security_ops->unix_may_send(sock, other);
2821}
2822
2823static inline int security_socket_create (int family, int type,
2824 int protocol, int kern)
2825{
2826 return security_ops->socket_create(family, type, protocol, kern);
2827}
2828
Venkat Yekkirala7420ed22006-08-04 23:17:57 -07002829static inline int security_socket_post_create(struct socket * sock,
2830 int family,
2831 int type,
2832 int protocol, int kern)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833{
Venkat Yekkirala7420ed22006-08-04 23:17:57 -07002834 return security_ops->socket_post_create(sock, family, type,
2835 protocol, kern);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836}
2837
2838static inline int security_socket_bind(struct socket * sock,
2839 struct sockaddr * address,
2840 int addrlen)
2841{
2842 return security_ops->socket_bind(sock, address, addrlen);
2843}
2844
2845static inline int security_socket_connect(struct socket * sock,
2846 struct sockaddr * address,
2847 int addrlen)
2848{
2849 return security_ops->socket_connect(sock, address, addrlen);
2850}
2851
2852static inline int security_socket_listen(struct socket * sock, int backlog)
2853{
2854 return security_ops->socket_listen(sock, backlog);
2855}
2856
2857static inline int security_socket_accept(struct socket * sock,
2858 struct socket * newsock)
2859{
2860 return security_ops->socket_accept(sock, newsock);
2861}
2862
2863static inline void security_socket_post_accept(struct socket * sock,
2864 struct socket * newsock)
2865{
2866 security_ops->socket_post_accept(sock, newsock);
2867}
2868
2869static inline int security_socket_sendmsg(struct socket * sock,
2870 struct msghdr * msg, int size)
2871{
2872 return security_ops->socket_sendmsg(sock, msg, size);
2873}
2874
2875static inline int security_socket_recvmsg(struct socket * sock,
2876 struct msghdr * msg, int size,
2877 int flags)
2878{
2879 return security_ops->socket_recvmsg(sock, msg, size, flags);
2880}
2881
2882static inline int security_socket_getsockname(struct socket * sock)
2883{
2884 return security_ops->socket_getsockname(sock);
2885}
2886
2887static inline int security_socket_getpeername(struct socket * sock)
2888{
2889 return security_ops->socket_getpeername(sock);
2890}
2891
2892static inline int security_socket_getsockopt(struct socket * sock,
2893 int level, int optname)
2894{
2895 return security_ops->socket_getsockopt(sock, level, optname);
2896}
2897
2898static inline int security_socket_setsockopt(struct socket * sock,
2899 int level, int optname)
2900{
2901 return security_ops->socket_setsockopt(sock, level, optname);
2902}
2903
2904static inline int security_socket_shutdown(struct socket * sock, int how)
2905{
2906 return security_ops->socket_shutdown(sock, how);
2907}
2908
2909static inline int security_sock_rcv_skb (struct sock * sk,
2910 struct sk_buff * skb)
2911{
2912 return security_ops->socket_sock_rcv_skb (sk, skb);
2913}
2914
Catherine Zhang2c7946a2006-03-20 22:41:23 -08002915static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2916 int __user *optlen, unsigned len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917{
Catherine Zhang2c7946a2006-03-20 22:41:23 -08002918 return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
2919}
2920
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07002921static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
Catherine Zhang2c7946a2006-03-20 22:41:23 -08002922{
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07002923 return security_ops->socket_getpeersec_dgram(sock, skb, secid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924}
2925
Al Virodd0fc662005-10-07 07:46:04 +01002926static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927{
2928 return security_ops->sk_alloc_security(sk, family, priority);
2929}
2930
2931static inline void security_sk_free(struct sock *sk)
2932{
2933 return security_ops->sk_free_security(sk);
2934}
Trent Jaegerdf718372005-12-13 23:12:27 -08002935
Venkat Yekkirala892c1412006-08-04 23:08:56 -07002936static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
2937{
2938 return security_ops->sk_clone_security(sk, newsk);
2939}
2940
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07002941static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
Trent Jaegerdf718372005-12-13 23:12:27 -08002942{
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07002943 security_ops->sk_getsecid(sk, &fl->secid);
Trent Jaegerdf718372005-12-13 23:12:27 -08002944}
Venkat Yekkirala4237c752006-07-24 23:32:50 -07002945
2946static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
2947{
2948 security_ops->req_classify_flow(req, fl);
2949}
2950
2951static inline void security_sock_graft(struct sock* sk, struct socket *parent)
2952{
2953 security_ops->sock_graft(sk, parent);
2954}
2955
2956static inline int security_inet_conn_request(struct sock *sk,
2957 struct sk_buff *skb, struct request_sock *req)
2958{
2959 return security_ops->inet_conn_request(sk, skb, req);
2960}
2961
2962static inline void security_inet_csk_clone(struct sock *newsk,
2963 const struct request_sock *req)
2964{
2965 security_ops->inet_csk_clone(newsk, req);
2966}
Venkat Yekkirala6b877692006-11-08 17:04:09 -06002967
2968static inline void security_inet_conn_established(struct sock *sk,
2969 struct sk_buff *skb)
2970{
2971 security_ops->inet_conn_established(sk, skb);
2972}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973#else /* CONFIG_SECURITY_NETWORK */
2974static inline int security_unix_stream_connect(struct socket * sock,
Venkat Yekkirala6b877692006-11-08 17:04:09 -06002975 struct socket * other,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 struct sock * newsk)
2977{
2978 return 0;
2979}
2980
2981static inline int security_unix_may_send(struct socket * sock,
2982 struct socket * other)
2983{
2984 return 0;
2985}
2986
2987static inline int security_socket_create (int family, int type,
2988 int protocol, int kern)
2989{
2990 return 0;
2991}
2992
Venkat Yekkirala7420ed22006-08-04 23:17:57 -07002993static inline int security_socket_post_create(struct socket * sock,
2994 int family,
2995 int type,
2996 int protocol, int kern)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997{
Venkat Yekkirala7420ed22006-08-04 23:17:57 -07002998 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999}
3000
3001static inline int security_socket_bind(struct socket * sock,
3002 struct sockaddr * address,
3003 int addrlen)
3004{
3005 return 0;
3006}
3007
3008static inline int security_socket_connect(struct socket * sock,
3009 struct sockaddr * address,
3010 int addrlen)
3011{
3012 return 0;
3013}
3014
3015static inline int security_socket_listen(struct socket * sock, int backlog)
3016{
3017 return 0;
3018}
3019
3020static inline int security_socket_accept(struct socket * sock,
3021 struct socket * newsock)
3022{
3023 return 0;
3024}
3025
3026static inline void security_socket_post_accept(struct socket * sock,
3027 struct socket * newsock)
3028{
3029}
3030
3031static inline int security_socket_sendmsg(struct socket * sock,
3032 struct msghdr * msg, int size)
3033{
3034 return 0;
3035}
3036
3037static inline int security_socket_recvmsg(struct socket * sock,
3038 struct msghdr * msg, int size,
3039 int flags)
3040{
3041 return 0;
3042}
3043
3044static inline int security_socket_getsockname(struct socket * sock)
3045{
3046 return 0;
3047}
3048
3049static inline int security_socket_getpeername(struct socket * sock)
3050{
3051 return 0;
3052}
3053
3054static inline int security_socket_getsockopt(struct socket * sock,
3055 int level, int optname)
3056{
3057 return 0;
3058}
3059
3060static inline int security_socket_setsockopt(struct socket * sock,
3061 int level, int optname)
3062{
3063 return 0;
3064}
3065
3066static inline int security_socket_shutdown(struct socket * sock, int how)
3067{
3068 return 0;
3069}
3070static inline int security_sock_rcv_skb (struct sock * sk,
3071 struct sk_buff * skb)
3072{
3073 return 0;
3074}
3075
Catherine Zhang2c7946a2006-03-20 22:41:23 -08003076static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
3077 int __user *optlen, unsigned len)
3078{
3079 return -ENOPROTOOPT;
3080}
3081
Catherine Zhangdc49c1f2006-08-02 14:12:06 -07003082static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083{
3084 return -ENOPROTOOPT;
3085}
3086
Al Virodd0fc662005-10-07 07:46:04 +01003087static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088{
3089 return 0;
3090}
3091
3092static inline void security_sk_free(struct sock *sk)
3093{
3094}
Trent Jaegerdf718372005-12-13 23:12:27 -08003095
Venkat Yekkirala892c1412006-08-04 23:08:56 -07003096static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
3097{
3098}
3099
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07003100static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
Trent Jaegerdf718372005-12-13 23:12:27 -08003101{
Trent Jaegerdf718372005-12-13 23:12:27 -08003102}
Venkat Yekkirala4237c752006-07-24 23:32:50 -07003103
3104static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
3105{
3106}
3107
3108static inline void security_sock_graft(struct sock* sk, struct socket *parent)
3109{
3110}
3111
3112static inline int security_inet_conn_request(struct sock *sk,
3113 struct sk_buff *skb, struct request_sock *req)
3114{
3115 return 0;
3116}
3117
3118static inline void security_inet_csk_clone(struct sock *newsk,
3119 const struct request_sock *req)
3120{
3121}
Venkat Yekkirala6b877692006-11-08 17:04:09 -06003122
3123static inline void security_inet_conn_established(struct sock *sk,
3124 struct sk_buff *skb)
3125{
3126}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127#endif /* CONFIG_SECURITY_NETWORK */
3128
Trent Jaegerdf718372005-12-13 23:12:27 -08003129#ifdef CONFIG_SECURITY_NETWORK_XFRM
3130static inline int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx)
3131{
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -06003132 return security_ops->xfrm_policy_alloc_security(xp, sec_ctx);
Venkat Yekkiralacb969f02006-07-24 23:32:20 -07003133}
3134
Trent Jaegerdf718372005-12-13 23:12:27 -08003135static inline int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new)
3136{
3137 return security_ops->xfrm_policy_clone_security(old, new);
3138}
3139
3140static inline void security_xfrm_policy_free(struct xfrm_policy *xp)
3141{
3142 security_ops->xfrm_policy_free_security(xp);
3143}
3144
Catherine Zhangc8c05a82006-06-08 23:39:49 -07003145static inline int security_xfrm_policy_delete(struct xfrm_policy *xp)
3146{
3147 return security_ops->xfrm_policy_delete_security(xp);
3148}
3149
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003150static inline int security_xfrm_state_alloc(struct xfrm_state *x,
3151 struct xfrm_user_sec_ctx *sec_ctx)
Trent Jaegerdf718372005-12-13 23:12:27 -08003152{
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -06003153 return security_ops->xfrm_state_alloc_security(x, sec_ctx, 0);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003154}
3155
3156static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
3157 struct xfrm_sec_ctx *polsec, u32 secid)
3158{
3159 if (!polsec)
3160 return 0;
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -06003161 /*
3162 * We want the context to be taken from secid which is usually
3163 * from the sock.
3164 */
3165 return security_ops->xfrm_state_alloc_security(x, NULL, secid);
Trent Jaegerdf718372005-12-13 23:12:27 -08003166}
3167
Catherine Zhangc8c05a82006-06-08 23:39:49 -07003168static inline int security_xfrm_state_delete(struct xfrm_state *x)
3169{
3170 return security_ops->xfrm_state_delete_security(x);
3171}
3172
Trent Jaegerdf718372005-12-13 23:12:27 -08003173static inline void security_xfrm_state_free(struct xfrm_state *x)
3174{
3175 security_ops->xfrm_state_free_security(x);
3176}
3177
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003178static inline int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir)
Trent Jaegerdf718372005-12-13 23:12:27 -08003179{
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003180 return security_ops->xfrm_policy_lookup(xp, fl_secid, dir);
3181}
3182
3183static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
3184 struct xfrm_policy *xp, struct flowi *fl)
3185{
3186 return security_ops->xfrm_state_pol_flow_match(x, xp, fl);
3187}
3188
Venkat Yekkirala5b368e62006-10-05 15:42:18 -05003189static inline int security_xfrm_flow_state_match(struct flowi *fl,
3190 struct xfrm_state *xfrm, struct xfrm_policy *xp)
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003191{
Venkat Yekkirala5b368e62006-10-05 15:42:18 -05003192 return security_ops->xfrm_flow_state_match(fl, xfrm, xp);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003193}
3194
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07003195static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003196{
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07003197 return security_ops->xfrm_decode_session(skb, secid, 1);
3198}
3199
3200static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
3201{
3202 int rc = security_ops->xfrm_decode_session(skb, &fl->secid, 0);
3203
3204 BUG_ON(rc);
Trent Jaegerdf718372005-12-13 23:12:27 -08003205}
3206#else /* CONFIG_SECURITY_NETWORK_XFRM */
3207static inline int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx)
3208{
3209 return 0;
3210}
3211
3212static inline int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new)
3213{
3214 return 0;
3215}
3216
3217static inline void security_xfrm_policy_free(struct xfrm_policy *xp)
3218{
3219}
3220
Catherine Zhangc8c05a82006-06-08 23:39:49 -07003221static inline int security_xfrm_policy_delete(struct xfrm_policy *xp)
3222{
3223 return 0;
3224}
3225
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003226static inline int security_xfrm_state_alloc(struct xfrm_state *x,
3227 struct xfrm_user_sec_ctx *sec_ctx)
3228{
3229 return 0;
3230}
3231
3232static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
3233 struct xfrm_sec_ctx *polsec, u32 secid)
Trent Jaegerdf718372005-12-13 23:12:27 -08003234{
3235 return 0;
3236}
3237
3238static inline void security_xfrm_state_free(struct xfrm_state *x)
3239{
3240}
3241
David S. Miller6f68dc32006-06-08 23:58:52 -07003242static inline int security_xfrm_state_delete(struct xfrm_state *x)
Catherine Zhangc8c05a82006-06-08 23:39:49 -07003243{
3244 return 0;
3245}
3246
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003247static inline int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir)
Trent Jaegerdf718372005-12-13 23:12:27 -08003248{
3249 return 0;
3250}
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003251
3252static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
3253 struct xfrm_policy *xp, struct flowi *fl)
3254{
3255 return 1;
3256}
3257
3258static inline int security_xfrm_flow_state_match(struct flowi *fl,
Venkat Yekkirala5b368e62006-10-05 15:42:18 -05003259 struct xfrm_state *xfrm, struct xfrm_policy *xp)
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003260{
3261 return 1;
3262}
3263
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07003264static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07003265{
3266 return 0;
3267}
3268
Venkat Yekkiralabeb8d132006-08-04 23:12:42 -07003269static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
3270{
3271}
3272
Trent Jaegerdf718372005-12-13 23:12:27 -08003273#endif /* CONFIG_SECURITY_NETWORK_XFRM */
3274
David Howells29db9192005-10-30 15:02:44 -08003275#ifdef CONFIG_KEYS
3276#ifdef CONFIG_SECURITY
Michael LeMayd7200242006-06-22 14:47:17 -07003277static inline int security_key_alloc(struct key *key,
David Howells7e047ef2006-06-26 00:24:50 -07003278 struct task_struct *tsk,
3279 unsigned long flags)
David Howells29db9192005-10-30 15:02:44 -08003280{
David Howells7e047ef2006-06-26 00:24:50 -07003281 return security_ops->key_alloc(key, tsk, flags);
David Howells29db9192005-10-30 15:02:44 -08003282}
3283
3284static inline void security_key_free(struct key *key)
3285{
3286 security_ops->key_free(key);
3287}
3288
3289static inline int security_key_permission(key_ref_t key_ref,
3290 struct task_struct *context,
3291 key_perm_t perm)
3292{
3293 return security_ops->key_permission(key_ref, context, perm);
3294}
3295
3296#else
3297
Michael LeMayd7200242006-06-22 14:47:17 -07003298static inline int security_key_alloc(struct key *key,
David Howells7e047ef2006-06-26 00:24:50 -07003299 struct task_struct *tsk,
3300 unsigned long flags)
David Howells29db9192005-10-30 15:02:44 -08003301{
3302 return 0;
3303}
3304
3305static inline void security_key_free(struct key *key)
3306{
3307}
3308
3309static inline int security_key_permission(key_ref_t key_ref,
3310 struct task_struct *context,
3311 key_perm_t perm)
3312{
3313 return 0;
3314}
3315
3316#endif
3317#endif /* CONFIG_KEYS */
3318
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319#endif /* ! __LINUX_SECURITY_H */
3320