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