blob: 2e1b35dd2550b6cfd70980e438fbf434c421aefb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Security plug functions
3 *
4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
Randy.Dunlapc59ede72006-01-11 12:17:46 -080014#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/security.h>
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21/* things that live in dummy.c */
22extern struct security_operations dummy_security_ops;
23extern void security_fixup_ops(struct security_operations *ops);
24
25struct security_operations *security_ops; /* Initialized to NULL */
Eric Parised032182007-06-28 15:55:21 -040026unsigned long mmap_min_addr; /* 0 means no protection */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28static inline int verify(struct security_operations *ops)
29{
30 /* verify the security_operations structure exists */
31 if (!ops)
32 return -EINVAL;
33 security_fixup_ops(ops);
34 return 0;
35}
36
37static void __init do_security_initcalls(void)
38{
39 initcall_t *call;
40 call = __security_initcall_start;
41 while (call < __security_initcall_end) {
42 (*call) ();
43 call++;
44 }
45}
46
47/**
48 * security_init - initializes the security framework
49 *
50 * This should be called early in the kernel initialization sequence.
51 */
52int __init security_init(void)
53{
James Morris20510f22007-10-16 23:31:32 -070054 printk(KERN_INFO "Security Framework initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 if (verify(&dummy_security_ops)) {
57 printk(KERN_ERR "%s could not verify "
58 "dummy_security_ops structure.\n", __FUNCTION__);
59 return -EIO;
60 }
61
62 security_ops = &dummy_security_ops;
63 do_security_initcalls();
64
65 return 0;
66}
67
68/**
69 * register_security - registers a security framework with the kernel
70 * @ops: a pointer to the struct security_options that is to be registered
71 *
72 * This function is to allow a security module to register itself with the
73 * kernel security subsystem. Some rudimentary checking is done on the @ops
74 * value passed to this function. A call to unregister_security() should be
75 * done to remove this security_options structure from the kernel.
76 *
77 * If there is already a security module registered with the kernel,
78 * an error will be returned. Otherwise 0 is returned on success.
79 */
80int register_security(struct security_operations *ops)
81{
82 if (verify(ops)) {
83 printk(KERN_DEBUG "%s could not verify "
84 "security_operations structure.\n", __FUNCTION__);
85 return -EINVAL;
86 }
87
88 if (security_ops != &dummy_security_ops)
89 return -EAGAIN;
90
91 security_ops = ops;
92
93 return 0;
94}
95
96/**
97 * unregister_security - unregisters a security framework with the kernel
98 * @ops: a pointer to the struct security_options that is to be registered
99 *
100 * This function removes a struct security_operations variable that had
101 * previously been registered with a successful call to register_security().
102 *
103 * If @ops does not match the valued previously passed to register_security()
104 * an error is returned. Otherwise the default security options is set to the
105 * the dummy_security_ops structure, and 0 is returned.
106 */
107int unregister_security(struct security_operations *ops)
108{
109 if (ops != security_ops) {
110 printk(KERN_INFO "%s: trying to unregister "
111 "a security_opts structure that is not "
112 "registered, failing.\n", __FUNCTION__);
113 return -EINVAL;
114 }
115
116 security_ops = &dummy_security_ops;
117
118 return 0;
119}
120
121/**
122 * mod_reg_security - allows security modules to be "stacked"
123 * @name: a pointer to a string with the name of the security_options to be registered
124 * @ops: a pointer to the struct security_options that is to be registered
125 *
126 * This function allows security modules to be stacked if the currently loaded
127 * security module allows this to happen. It passes the @name and @ops to the
128 * register_security function of the currently loaded security module.
129 *
130 * The return value depends on the currently loaded security module, with 0 as
131 * success.
132 */
133int mod_reg_security(const char *name, struct security_operations *ops)
134{
135 if (verify(ops)) {
136 printk(KERN_INFO "%s could not verify "
137 "security operations.\n", __FUNCTION__);
138 return -EINVAL;
139 }
140
141 if (ops == security_ops) {
142 printk(KERN_INFO "%s security operations "
143 "already registered.\n", __FUNCTION__);
144 return -EINVAL;
145 }
146
147 return security_ops->register_security(name, ops);
148}
149
150/**
151 * mod_unreg_security - allows a security module registered with mod_reg_security() to be unloaded
152 * @name: a pointer to a string with the name of the security_options to be removed
153 * @ops: a pointer to the struct security_options that is to be removed
154 *
155 * This function allows security modules that have been successfully registered
156 * with a call to mod_reg_security() to be unloaded from the system.
157 * This calls the currently loaded security module's unregister_security() call
158 * with the @name and @ops variables.
159 *
160 * The return value depends on the currently loaded security module, with 0 as
161 * success.
162 */
163int mod_unreg_security(const char *name, struct security_operations *ops)
164{
165 if (ops == security_ops) {
166 printk(KERN_INFO "%s invalid attempt to unregister "
167 " primary security ops.\n", __FUNCTION__);
168 return -EINVAL;
169 }
170
171 return security_ops->unregister_security(name, ops);
172}
173
James Morris20510f22007-10-16 23:31:32 -0700174/* Security operations */
175
176int security_ptrace(struct task_struct *parent, struct task_struct *child)
177{
178 return security_ops->ptrace(parent, child);
179}
180
181int security_capget(struct task_struct *target,
182 kernel_cap_t *effective,
183 kernel_cap_t *inheritable,
184 kernel_cap_t *permitted)
185{
186 return security_ops->capget(target, effective, inheritable, permitted);
187}
188
189int security_capset_check(struct task_struct *target,
190 kernel_cap_t *effective,
191 kernel_cap_t *inheritable,
192 kernel_cap_t *permitted)
193{
194 return security_ops->capset_check(target, effective, inheritable, permitted);
195}
196
197void security_capset_set(struct task_struct *target,
198 kernel_cap_t *effective,
199 kernel_cap_t *inheritable,
200 kernel_cap_t *permitted)
201{
202 security_ops->capset_set(target, effective, inheritable, permitted);
203}
204
205int security_capable(struct task_struct *tsk, int cap)
206{
207 return security_ops->capable(tsk, cap);
208}
209
210int security_acct(struct file *file)
211{
212 return security_ops->acct(file);
213}
214
215int security_sysctl(struct ctl_table *table, int op)
216{
217 return security_ops->sysctl(table, op);
218}
219
220int security_quotactl(int cmds, int type, int id, struct super_block *sb)
221{
222 return security_ops->quotactl(cmds, type, id, sb);
223}
224
225int security_quota_on(struct dentry *dentry)
226{
227 return security_ops->quota_on(dentry);
228}
229
230int security_syslog(int type)
231{
232 return security_ops->syslog(type);
233}
234
235int security_settime(struct timespec *ts, struct timezone *tz)
236{
237 return security_ops->settime(ts, tz);
238}
239
240int security_vm_enough_memory(long pages)
241{
242 return security_ops->vm_enough_memory(current->mm, pages);
243}
244
245int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
246{
247 return security_ops->vm_enough_memory(mm, pages);
248}
249
250int security_bprm_alloc(struct linux_binprm *bprm)
251{
252 return security_ops->bprm_alloc_security(bprm);
253}
254
255void security_bprm_free(struct linux_binprm *bprm)
256{
257 security_ops->bprm_free_security(bprm);
258}
259
260void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe)
261{
262 security_ops->bprm_apply_creds(bprm, unsafe);
263}
264
265void security_bprm_post_apply_creds(struct linux_binprm *bprm)
266{
267 security_ops->bprm_post_apply_creds(bprm);
268}
269
270int security_bprm_set(struct linux_binprm *bprm)
271{
272 return security_ops->bprm_set_security(bprm);
273}
274
275int security_bprm_check(struct linux_binprm *bprm)
276{
277 return security_ops->bprm_check_security(bprm);
278}
279
280int security_bprm_secureexec(struct linux_binprm *bprm)
281{
282 return security_ops->bprm_secureexec(bprm);
283}
284
285int security_sb_alloc(struct super_block *sb)
286{
287 return security_ops->sb_alloc_security(sb);
288}
289
290void security_sb_free(struct super_block *sb)
291{
292 security_ops->sb_free_security(sb);
293}
294
295int security_sb_copy_data(struct file_system_type *type, void *orig, void *copy)
296{
297 return security_ops->sb_copy_data(type, orig, copy);
298}
299
300int security_sb_kern_mount(struct super_block *sb, void *data)
301{
302 return security_ops->sb_kern_mount(sb, data);
303}
304
305int security_sb_statfs(struct dentry *dentry)
306{
307 return security_ops->sb_statfs(dentry);
308}
309
310int security_sb_mount(char *dev_name, struct nameidata *nd,
311 char *type, unsigned long flags, void *data)
312{
313 return security_ops->sb_mount(dev_name, nd, type, flags, data);
314}
315
316int security_sb_check_sb(struct vfsmount *mnt, struct nameidata *nd)
317{
318 return security_ops->sb_check_sb(mnt, nd);
319}
320
321int security_sb_umount(struct vfsmount *mnt, int flags)
322{
323 return security_ops->sb_umount(mnt, flags);
324}
325
326void security_sb_umount_close(struct vfsmount *mnt)
327{
328 security_ops->sb_umount_close(mnt);
329}
330
331void security_sb_umount_busy(struct vfsmount *mnt)
332{
333 security_ops->sb_umount_busy(mnt);
334}
335
336void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data)
337{
338 security_ops->sb_post_remount(mnt, flags, data);
339}
340
341void security_sb_post_mountroot(void)
342{
343 security_ops->sb_post_mountroot();
344}
345
346void security_sb_post_addmount(struct vfsmount *mnt, struct nameidata *mountpoint_nd)
347{
348 security_ops->sb_post_addmount(mnt, mountpoint_nd);
349}
350
351int security_sb_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd)
352{
353 return security_ops->sb_pivotroot(old_nd, new_nd);
354}
355
356void security_sb_post_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd)
357{
358 security_ops->sb_post_pivotroot(old_nd, new_nd);
359}
360
361int security_inode_alloc(struct inode *inode)
362{
363 inode->i_security = NULL;
364 return security_ops->inode_alloc_security(inode);
365}
366
367void security_inode_free(struct inode *inode)
368{
369 security_ops->inode_free_security(inode);
370}
371
372int security_inode_init_security(struct inode *inode, struct inode *dir,
373 char **name, void **value, size_t *len)
374{
375 if (unlikely(IS_PRIVATE(inode)))
376 return -EOPNOTSUPP;
377 return security_ops->inode_init_security(inode, dir, name, value, len);
378}
379EXPORT_SYMBOL(security_inode_init_security);
380
381int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)
382{
383 if (unlikely(IS_PRIVATE(dir)))
384 return 0;
385 return security_ops->inode_create(dir, dentry, mode);
386}
387
388int security_inode_link(struct dentry *old_dentry, struct inode *dir,
389 struct dentry *new_dentry)
390{
391 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
392 return 0;
393 return security_ops->inode_link(old_dentry, dir, new_dentry);
394}
395
396int security_inode_unlink(struct inode *dir, struct dentry *dentry)
397{
398 if (unlikely(IS_PRIVATE(dentry->d_inode)))
399 return 0;
400 return security_ops->inode_unlink(dir, dentry);
401}
402
403int security_inode_symlink(struct inode *dir, struct dentry *dentry,
404 const char *old_name)
405{
406 if (unlikely(IS_PRIVATE(dir)))
407 return 0;
408 return security_ops->inode_symlink(dir, dentry, old_name);
409}
410
411int security_inode_mkdir(struct inode *dir, struct dentry *dentry, int mode)
412{
413 if (unlikely(IS_PRIVATE(dir)))
414 return 0;
415 return security_ops->inode_mkdir(dir, dentry, mode);
416}
417
418int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
419{
420 if (unlikely(IS_PRIVATE(dentry->d_inode)))
421 return 0;
422 return security_ops->inode_rmdir(dir, dentry);
423}
424
425int security_inode_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
426{
427 if (unlikely(IS_PRIVATE(dir)))
428 return 0;
429 return security_ops->inode_mknod(dir, dentry, mode, dev);
430}
431
432int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
433 struct inode *new_dir, struct dentry *new_dentry)
434{
435 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
436 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
437 return 0;
438 return security_ops->inode_rename(old_dir, old_dentry,
439 new_dir, new_dentry);
440}
441
442int security_inode_readlink(struct dentry *dentry)
443{
444 if (unlikely(IS_PRIVATE(dentry->d_inode)))
445 return 0;
446 return security_ops->inode_readlink(dentry);
447}
448
449int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
450{
451 if (unlikely(IS_PRIVATE(dentry->d_inode)))
452 return 0;
453 return security_ops->inode_follow_link(dentry, nd);
454}
455
456int security_inode_permission(struct inode *inode, int mask, struct nameidata *nd)
457{
458 if (unlikely(IS_PRIVATE(inode)))
459 return 0;
460 return security_ops->inode_permission(inode, mask, nd);
461}
462
463int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
464{
465 if (unlikely(IS_PRIVATE(dentry->d_inode)))
466 return 0;
467 return security_ops->inode_setattr(dentry, attr);
468}
469
470int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
471{
472 if (unlikely(IS_PRIVATE(dentry->d_inode)))
473 return 0;
474 return security_ops->inode_getattr(mnt, dentry);
475}
476
477void security_inode_delete(struct inode *inode)
478{
479 if (unlikely(IS_PRIVATE(inode)))
480 return;
481 security_ops->inode_delete(inode);
482}
483
484int security_inode_setxattr(struct dentry *dentry, char *name,
485 void *value, size_t size, int flags)
486{
487 if (unlikely(IS_PRIVATE(dentry->d_inode)))
488 return 0;
489 return security_ops->inode_setxattr(dentry, name, value, size, flags);
490}
491
492void security_inode_post_setxattr(struct dentry *dentry, char *name,
493 void *value, size_t size, int flags)
494{
495 if (unlikely(IS_PRIVATE(dentry->d_inode)))
496 return;
497 security_ops->inode_post_setxattr(dentry, name, value, size, flags);
498}
499
500int security_inode_getxattr(struct dentry *dentry, char *name)
501{
502 if (unlikely(IS_PRIVATE(dentry->d_inode)))
503 return 0;
504 return security_ops->inode_getxattr(dentry, name);
505}
506
507int security_inode_listxattr(struct dentry *dentry)
508{
509 if (unlikely(IS_PRIVATE(dentry->d_inode)))
510 return 0;
511 return security_ops->inode_listxattr(dentry);
512}
513
514int security_inode_removexattr(struct dentry *dentry, char *name)
515{
516 if (unlikely(IS_PRIVATE(dentry->d_inode)))
517 return 0;
518 return security_ops->inode_removexattr(dentry, name);
519}
520
Serge E. Hallynb5376772007-10-16 23:31:36 -0700521int security_inode_need_killpriv(struct dentry *dentry)
522{
523 return security_ops->inode_need_killpriv(dentry);
524}
525
526int security_inode_killpriv(struct dentry *dentry)
527{
528 return security_ops->inode_killpriv(dentry);
529}
530
James Morris20510f22007-10-16 23:31:32 -0700531const char *security_inode_xattr_getsuffix(void)
532{
533 return security_ops->inode_xattr_getsuffix();
534}
535
536int security_inode_getsecurity(const struct inode *inode, const char *name, void *buffer, size_t size, int err)
537{
538 if (unlikely(IS_PRIVATE(inode)))
539 return 0;
540 return security_ops->inode_getsecurity(inode, name, buffer, size, err);
541}
542
543int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
544{
545 if (unlikely(IS_PRIVATE(inode)))
546 return 0;
547 return security_ops->inode_setsecurity(inode, name, value, size, flags);
548}
549
550int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
551{
552 if (unlikely(IS_PRIVATE(inode)))
553 return 0;
554 return security_ops->inode_listsecurity(inode, buffer, buffer_size);
555}
556
557int security_file_permission(struct file *file, int mask)
558{
559 return security_ops->file_permission(file, mask);
560}
561
562int security_file_alloc(struct file *file)
563{
564 return security_ops->file_alloc_security(file);
565}
566
567void security_file_free(struct file *file)
568{
569 security_ops->file_free_security(file);
570}
571
572int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
573{
574 return security_ops->file_ioctl(file, cmd, arg);
575}
576
577int security_file_mmap(struct file *file, unsigned long reqprot,
578 unsigned long prot, unsigned long flags,
579 unsigned long addr, unsigned long addr_only)
580{
581 return security_ops->file_mmap(file, reqprot, prot, flags, addr, addr_only);
582}
583
584int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
585 unsigned long prot)
586{
587 return security_ops->file_mprotect(vma, reqprot, prot);
588}
589
590int security_file_lock(struct file *file, unsigned int cmd)
591{
592 return security_ops->file_lock(file, cmd);
593}
594
595int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
596{
597 return security_ops->file_fcntl(file, cmd, arg);
598}
599
600int security_file_set_fowner(struct file *file)
601{
602 return security_ops->file_set_fowner(file);
603}
604
605int security_file_send_sigiotask(struct task_struct *tsk,
606 struct fown_struct *fown, int sig)
607{
608 return security_ops->file_send_sigiotask(tsk, fown, sig);
609}
610
611int security_file_receive(struct file *file)
612{
613 return security_ops->file_receive(file);
614}
615
616int security_dentry_open(struct file *file)
617{
618 return security_ops->dentry_open(file);
619}
620
621int security_task_create(unsigned long clone_flags)
622{
623 return security_ops->task_create(clone_flags);
624}
625
626int security_task_alloc(struct task_struct *p)
627{
628 return security_ops->task_alloc_security(p);
629}
630
631void security_task_free(struct task_struct *p)
632{
633 security_ops->task_free_security(p);
634}
635
636int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
637{
638 return security_ops->task_setuid(id0, id1, id2, flags);
639}
640
641int security_task_post_setuid(uid_t old_ruid, uid_t old_euid,
642 uid_t old_suid, int flags)
643{
644 return security_ops->task_post_setuid(old_ruid, old_euid, old_suid, flags);
645}
646
647int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
648{
649 return security_ops->task_setgid(id0, id1, id2, flags);
650}
651
652int security_task_setpgid(struct task_struct *p, pid_t pgid)
653{
654 return security_ops->task_setpgid(p, pgid);
655}
656
657int security_task_getpgid(struct task_struct *p)
658{
659 return security_ops->task_getpgid(p);
660}
661
662int security_task_getsid(struct task_struct *p)
663{
664 return security_ops->task_getsid(p);
665}
666
667void security_task_getsecid(struct task_struct *p, u32 *secid)
668{
669 security_ops->task_getsecid(p, secid);
670}
671EXPORT_SYMBOL(security_task_getsecid);
672
673int security_task_setgroups(struct group_info *group_info)
674{
675 return security_ops->task_setgroups(group_info);
676}
677
678int security_task_setnice(struct task_struct *p, int nice)
679{
680 return security_ops->task_setnice(p, nice);
681}
682
683int security_task_setioprio(struct task_struct *p, int ioprio)
684{
685 return security_ops->task_setioprio(p, ioprio);
686}
687
688int security_task_getioprio(struct task_struct *p)
689{
690 return security_ops->task_getioprio(p);
691}
692
693int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
694{
695 return security_ops->task_setrlimit(resource, new_rlim);
696}
697
698int security_task_setscheduler(struct task_struct *p,
699 int policy, struct sched_param *lp)
700{
701 return security_ops->task_setscheduler(p, policy, lp);
702}
703
704int security_task_getscheduler(struct task_struct *p)
705{
706 return security_ops->task_getscheduler(p);
707}
708
709int security_task_movememory(struct task_struct *p)
710{
711 return security_ops->task_movememory(p);
712}
713
714int security_task_kill(struct task_struct *p, struct siginfo *info,
715 int sig, u32 secid)
716{
717 return security_ops->task_kill(p, info, sig, secid);
718}
719
720int security_task_wait(struct task_struct *p)
721{
722 return security_ops->task_wait(p);
723}
724
725int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
726 unsigned long arg4, unsigned long arg5)
727{
728 return security_ops->task_prctl(option, arg2, arg3, arg4, arg5);
729}
730
731void security_task_reparent_to_init(struct task_struct *p)
732{
733 security_ops->task_reparent_to_init(p);
734}
735
736void security_task_to_inode(struct task_struct *p, struct inode *inode)
737{
738 security_ops->task_to_inode(p, inode);
739}
740
741int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
742{
743 return security_ops->ipc_permission(ipcp, flag);
744}
745
746int security_msg_msg_alloc(struct msg_msg *msg)
747{
748 return security_ops->msg_msg_alloc_security(msg);
749}
750
751void security_msg_msg_free(struct msg_msg *msg)
752{
753 security_ops->msg_msg_free_security(msg);
754}
755
756int security_msg_queue_alloc(struct msg_queue *msq)
757{
758 return security_ops->msg_queue_alloc_security(msq);
759}
760
761void security_msg_queue_free(struct msg_queue *msq)
762{
763 security_ops->msg_queue_free_security(msq);
764}
765
766int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
767{
768 return security_ops->msg_queue_associate(msq, msqflg);
769}
770
771int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
772{
773 return security_ops->msg_queue_msgctl(msq, cmd);
774}
775
776int security_msg_queue_msgsnd(struct msg_queue *msq,
777 struct msg_msg *msg, int msqflg)
778{
779 return security_ops->msg_queue_msgsnd(msq, msg, msqflg);
780}
781
782int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
783 struct task_struct *target, long type, int mode)
784{
785 return security_ops->msg_queue_msgrcv(msq, msg, target, type, mode);
786}
787
788int security_shm_alloc(struct shmid_kernel *shp)
789{
790 return security_ops->shm_alloc_security(shp);
791}
792
793void security_shm_free(struct shmid_kernel *shp)
794{
795 security_ops->shm_free_security(shp);
796}
797
798int security_shm_associate(struct shmid_kernel *shp, int shmflg)
799{
800 return security_ops->shm_associate(shp, shmflg);
801}
802
803int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
804{
805 return security_ops->shm_shmctl(shp, cmd);
806}
807
808int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
809{
810 return security_ops->shm_shmat(shp, shmaddr, shmflg);
811}
812
813int security_sem_alloc(struct sem_array *sma)
814{
815 return security_ops->sem_alloc_security(sma);
816}
817
818void security_sem_free(struct sem_array *sma)
819{
820 security_ops->sem_free_security(sma);
821}
822
823int security_sem_associate(struct sem_array *sma, int semflg)
824{
825 return security_ops->sem_associate(sma, semflg);
826}
827
828int security_sem_semctl(struct sem_array *sma, int cmd)
829{
830 return security_ops->sem_semctl(sma, cmd);
831}
832
833int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
834 unsigned nsops, int alter)
835{
836 return security_ops->sem_semop(sma, sops, nsops, alter);
837}
838
839void security_d_instantiate(struct dentry *dentry, struct inode *inode)
840{
841 if (unlikely(inode && IS_PRIVATE(inode)))
842 return;
843 security_ops->d_instantiate(dentry, inode);
844}
845EXPORT_SYMBOL(security_d_instantiate);
846
847int security_getprocattr(struct task_struct *p, char *name, char **value)
848{
849 return security_ops->getprocattr(p, name, value);
850}
851
852int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
853{
854 return security_ops->setprocattr(p, name, value, size);
855}
856
857int security_netlink_send(struct sock *sk, struct sk_buff *skb)
858{
859 return security_ops->netlink_send(sk, skb);
860}
861EXPORT_SYMBOL(security_netlink_send);
862
863int security_netlink_recv(struct sk_buff *skb, int cap)
864{
865 return security_ops->netlink_recv(skb, cap);
866}
867EXPORT_SYMBOL(security_netlink_recv);
868
869int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
870{
871 return security_ops->secid_to_secctx(secid, secdata, seclen);
872}
873EXPORT_SYMBOL(security_secid_to_secctx);
874
875void security_release_secctx(char *secdata, u32 seclen)
876{
877 return security_ops->release_secctx(secdata, seclen);
878}
879EXPORT_SYMBOL(security_release_secctx);
880
881#ifdef CONFIG_SECURITY_NETWORK
882
883int security_unix_stream_connect(struct socket *sock, struct socket *other,
884 struct sock *newsk)
885{
886 return security_ops->unix_stream_connect(sock, other, newsk);
887}
888EXPORT_SYMBOL(security_unix_stream_connect);
889
890int security_unix_may_send(struct socket *sock, struct socket *other)
891{
892 return security_ops->unix_may_send(sock, other);
893}
894EXPORT_SYMBOL(security_unix_may_send);
895
896int security_socket_create(int family, int type, int protocol, int kern)
897{
898 return security_ops->socket_create(family, type, protocol, kern);
899}
900
901int security_socket_post_create(struct socket *sock, int family,
902 int type, int protocol, int kern)
903{
904 return security_ops->socket_post_create(sock, family, type,
905 protocol, kern);
906}
907
908int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
909{
910 return security_ops->socket_bind(sock, address, addrlen);
911}
912
913int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
914{
915 return security_ops->socket_connect(sock, address, addrlen);
916}
917
918int security_socket_listen(struct socket *sock, int backlog)
919{
920 return security_ops->socket_listen(sock, backlog);
921}
922
923int security_socket_accept(struct socket *sock, struct socket *newsock)
924{
925 return security_ops->socket_accept(sock, newsock);
926}
927
928void security_socket_post_accept(struct socket *sock, struct socket *newsock)
929{
930 security_ops->socket_post_accept(sock, newsock);
931}
932
933int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
934{
935 return security_ops->socket_sendmsg(sock, msg, size);
936}
937
938int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
939 int size, int flags)
940{
941 return security_ops->socket_recvmsg(sock, msg, size, flags);
942}
943
944int security_socket_getsockname(struct socket *sock)
945{
946 return security_ops->socket_getsockname(sock);
947}
948
949int security_socket_getpeername(struct socket *sock)
950{
951 return security_ops->socket_getpeername(sock);
952}
953
954int security_socket_getsockopt(struct socket *sock, int level, int optname)
955{
956 return security_ops->socket_getsockopt(sock, level, optname);
957}
958
959int security_socket_setsockopt(struct socket *sock, int level, int optname)
960{
961 return security_ops->socket_setsockopt(sock, level, optname);
962}
963
964int security_socket_shutdown(struct socket *sock, int how)
965{
966 return security_ops->socket_shutdown(sock, how);
967}
968
969int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
970{
971 return security_ops->socket_sock_rcv_skb(sk, skb);
972}
973EXPORT_SYMBOL(security_sock_rcv_skb);
974
975int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
976 int __user *optlen, unsigned len)
977{
978 return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
979}
980
981int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
982{
983 return security_ops->socket_getpeersec_dgram(sock, skb, secid);
984}
985EXPORT_SYMBOL(security_socket_getpeersec_dgram);
986
987int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
988{
989 return security_ops->sk_alloc_security(sk, family, priority);
990}
991
992void security_sk_free(struct sock *sk)
993{
994 return security_ops->sk_free_security(sk);
995}
996
997void security_sk_clone(const struct sock *sk, struct sock *newsk)
998{
999 return security_ops->sk_clone_security(sk, newsk);
1000}
1001
1002void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1003{
1004 security_ops->sk_getsecid(sk, &fl->secid);
1005}
1006EXPORT_SYMBOL(security_sk_classify_flow);
1007
1008void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1009{
1010 security_ops->req_classify_flow(req, fl);
1011}
1012EXPORT_SYMBOL(security_req_classify_flow);
1013
1014void security_sock_graft(struct sock *sk, struct socket *parent)
1015{
1016 security_ops->sock_graft(sk, parent);
1017}
1018EXPORT_SYMBOL(security_sock_graft);
1019
1020int security_inet_conn_request(struct sock *sk,
1021 struct sk_buff *skb, struct request_sock *req)
1022{
1023 return security_ops->inet_conn_request(sk, skb, req);
1024}
1025EXPORT_SYMBOL(security_inet_conn_request);
1026
1027void security_inet_csk_clone(struct sock *newsk,
1028 const struct request_sock *req)
1029{
1030 security_ops->inet_csk_clone(newsk, req);
1031}
1032
1033void security_inet_conn_established(struct sock *sk,
1034 struct sk_buff *skb)
1035{
1036 security_ops->inet_conn_established(sk, skb);
1037}
1038
1039#endif /* CONFIG_SECURITY_NETWORK */
1040
1041#ifdef CONFIG_SECURITY_NETWORK_XFRM
1042
1043int security_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx)
1044{
1045 return security_ops->xfrm_policy_alloc_security(xp, sec_ctx);
1046}
1047EXPORT_SYMBOL(security_xfrm_policy_alloc);
1048
1049int security_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new)
1050{
1051 return security_ops->xfrm_policy_clone_security(old, new);
1052}
1053
1054void security_xfrm_policy_free(struct xfrm_policy *xp)
1055{
1056 security_ops->xfrm_policy_free_security(xp);
1057}
1058EXPORT_SYMBOL(security_xfrm_policy_free);
1059
1060int security_xfrm_policy_delete(struct xfrm_policy *xp)
1061{
1062 return security_ops->xfrm_policy_delete_security(xp);
1063}
1064
1065int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx)
1066{
1067 return security_ops->xfrm_state_alloc_security(x, sec_ctx, 0);
1068}
1069EXPORT_SYMBOL(security_xfrm_state_alloc);
1070
1071int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
1072 struct xfrm_sec_ctx *polsec, u32 secid)
1073{
1074 if (!polsec)
1075 return 0;
1076 /*
1077 * We want the context to be taken from secid which is usually
1078 * from the sock.
1079 */
1080 return security_ops->xfrm_state_alloc_security(x, NULL, secid);
1081}
1082
1083int security_xfrm_state_delete(struct xfrm_state *x)
1084{
1085 return security_ops->xfrm_state_delete_security(x);
1086}
1087EXPORT_SYMBOL(security_xfrm_state_delete);
1088
1089void security_xfrm_state_free(struct xfrm_state *x)
1090{
1091 security_ops->xfrm_state_free_security(x);
1092}
1093
1094int security_xfrm_policy_lookup(struct xfrm_policy *xp, u32 fl_secid, u8 dir)
1095{
1096 return security_ops->xfrm_policy_lookup(xp, fl_secid, dir);
1097}
1098
1099int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
1100 struct xfrm_policy *xp, struct flowi *fl)
1101{
1102 return security_ops->xfrm_state_pol_flow_match(x, xp, fl);
1103}
1104
1105int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
1106{
1107 return security_ops->xfrm_decode_session(skb, secid, 1);
1108}
1109
1110void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
1111{
1112 int rc = security_ops->xfrm_decode_session(skb, &fl->secid, 0);
1113
1114 BUG_ON(rc);
1115}
1116EXPORT_SYMBOL(security_skb_classify_flow);
1117
1118#endif /* CONFIG_SECURITY_NETWORK_XFRM */
1119
1120#ifdef CONFIG_KEYS
1121
1122int security_key_alloc(struct key *key, struct task_struct *tsk, unsigned long flags)
1123{
1124 return security_ops->key_alloc(key, tsk, flags);
1125}
1126
1127void security_key_free(struct key *key)
1128{
1129 security_ops->key_free(key);
1130}
1131
1132int security_key_permission(key_ref_t key_ref,
1133 struct task_struct *context, key_perm_t perm)
1134{
1135 return security_ops->key_permission(key_ref, context, perm);
1136}
1137
1138#endif /* CONFIG_KEYS */