2 * Security plug functions
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 * Copyright (C) 2016 Mellanox Technologies
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/capability.h>
16 #include <linux/dcache.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/lsm_hooks.h>
21 #include <linux/integrity.h>
22 #include <linux/ima.h>
23 #include <linux/evm.h>
24 #include <linux/fsnotify.h>
25 #include <linux/mman.h>
26 #include <linux/mount.h>
27 #include <linux/personality.h>
28 #include <linux/backing-dev.h>
29 #include <linux/string.h>
30 #include <linux/msg.h>
34 #define MAX_LSM_EVM_XATTR 2
36 /* Maximum number of letters for an LSM name string */
37 #define SECURITY_NAME_MAX 10
39 struct security_hook_heads security_hook_heads __lsm_ro_after_init
;
40 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain
);
43 static struct lsm_blob_sizes blob_sizes
;
45 /* Boot-time LSM user choice */
46 static __initdata
char chosen_lsm
[SECURITY_NAME_MAX
+ 1] =
47 CONFIG_DEFAULT_SECURITY
;
49 static void __init
do_security_initcalls(void)
52 call
= __security_initcall_start
;
53 while (call
< __security_initcall_end
) {
60 * security_init - initializes the security framework
62 * This should be called early in the kernel initialization sequence.
64 int __init
security_init(void)
67 struct list_head
*list
= (struct list_head
*) &security_hook_heads
;
69 for (i
= 0; i
< sizeof(security_hook_heads
) / sizeof(struct list_head
);
71 INIT_LIST_HEAD(&list
[i
]);
72 pr_info("Security Framework initialized\n");
75 * Load minor LSMs, with the capability module always first.
77 capability_add_hooks();
82 * The first call to a module specific init function
83 * updates the blob size requirements.
85 do_security_initcalls();
88 * The second call to a module specific init function
89 * adds hooks to the hook lists and does any other early
90 * initializations required.
92 do_security_initcalls();
94 #ifdef CONFIG_SECURITY_LSM_DEBUG
95 pr_info("LSM: cred blob size = %d\n", blob_sizes
.lbs_cred
);
96 pr_info("LSM: file blob size = %d\n", blob_sizes
.lbs_file
);
97 pr_info("LSM: inode blob size = %d\n", blob_sizes
.lbs_inode
);
98 pr_info("LSM: ipc blob size = %d\n", blob_sizes
.lbs_ipc
);
100 pr_info("LSM: key blob size = %d\n", blob_sizes
.lbs_key
);
101 #endif /* CONFIG_KEYS */
102 pr_info("LSM: msg_msg blob size = %d\n", blob_sizes
.lbs_msg_msg
);
103 pr_info("LSM: sock blob size = %d\n", blob_sizes
.lbs_sock
);
104 pr_info("LSM: superblock blob size = %d\n", blob_sizes
.lbs_superblock
);
105 pr_info("LSM: task blob size = %d\n", blob_sizes
.lbs_task
);
106 #endif /* CONFIG_SECURITY_LSM_DEBUG */
111 /* Save user chosen LSM */
112 static int __init
choose_lsm(char *str
)
114 strncpy(chosen_lsm
, str
, SECURITY_NAME_MAX
);
117 __setup("security=", choose_lsm
);
119 static bool match_last_lsm(const char *list
, const char *lsm
)
123 if (WARN_ON(!list
|| !lsm
))
125 last
= strrchr(list
, ',');
127 /* Pass the comma, strcmp() will check for '\0' */
131 return !strcmp(last
, lsm
);
134 static int lsm_append(char *new, char **result
)
138 if (*result
== NULL
) {
139 *result
= kstrdup(new, GFP_KERNEL
);
141 /* Check if it is the last registered name */
142 if (match_last_lsm(*result
, new))
144 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *result
, new);
154 * security_module_enable - Load given security module on boot ?
155 * @module: the name of the module
157 * Each LSM must pass this method before registering its own operations
158 * to avoid security registration races. This method may also be used
159 * to check if your LSM is currently loaded during kernel initialization.
165 * - The passed LSM is the one chosen by user at boot time,
166 * - or the passed LSM is configured as the default and the user did not
167 * choose an alternate LSM at boot time.
169 * Otherwise, return false.
171 int __init
security_module_enable(const char *module
)
173 return !strcmp(module
, chosen_lsm
);
177 * security_add_hooks - Add a modules hooks to the hook lists.
178 * @hooks: the hooks to add
179 * @count: the number of hooks to add
180 * @lsm: the name of the security module
182 * Each LSM has to register its hooks with the infrastructure.
184 void __init
security_add_hooks(struct security_hook_list
*hooks
, int count
,
189 for (i
= 0; i
< count
; i
++) {
191 list_add_tail_rcu(&hooks
[i
].list
, hooks
[i
].head
);
193 if (lsm_append(lsm
, &lsm_names
) < 0)
194 panic("%s - Cannot get early memory.\n", __func__
);
197 int call_lsm_notifier(enum lsm_event event
, void *data
)
199 return atomic_notifier_call_chain(&lsm_notifier_chain
, event
, data
);
201 EXPORT_SYMBOL(call_lsm_notifier
);
203 int register_lsm_notifier(struct notifier_block
*nb
)
205 return atomic_notifier_chain_register(&lsm_notifier_chain
, nb
);
207 EXPORT_SYMBOL(register_lsm_notifier
);
209 int unregister_lsm_notifier(struct notifier_block
*nb
)
211 return atomic_notifier_chain_unregister(&lsm_notifier_chain
, nb
);
213 EXPORT_SYMBOL(unregister_lsm_notifier
);
216 * lsm_cred_alloc - allocate a composite cred blob
217 * @cred: the cred that needs a blob
218 * @gfp: allocation type
220 * Allocate the cred blob for all the modules
222 * Returns 0, or -ENOMEM if memory can't be allocated.
224 int lsm_cred_alloc(struct cred
*cred
, gfp_t gfp
)
226 #ifdef CONFIG_SECURITY_LSM_DEBUG
228 pr_info("%s: Inbound cred blob is not NULL.\n", __func__
);
230 if (blob_sizes
.lbs_cred
== 0)
233 cred
->security
= kzalloc(blob_sizes
.lbs_cred
, gfp
);
234 if (cred
->security
== NULL
)
240 * lsm_early_cred - during initialization allocate a composite cred blob
241 * @cred: the cred that needs a blob
243 * Allocate the cred blob for all the modules if it's not already there
245 void lsm_early_cred(struct cred
*cred
)
250 panic("%s: NULL cred.\n", __func__
);
251 if (cred
->security
!= NULL
)
253 rc
= lsm_cred_alloc(cred
, GFP_KERNEL
);
255 panic("%s: Early cred alloc failed.\n", __func__
);
258 static void __init
lsm_set_size(int *need
, int *lbs
)
270 * security_add_blobs - Report blob sizes
271 * @needed: the size of blobs needed by the module
273 * Each LSM has to register its blobs with the infrastructure.
274 * The "needed" data tells the infrastructure how much memory
275 * the module requires for each of its blobs. On return the
276 * structure is filled with the offset that module should use
277 * from the blob pointer.
279 void __init
security_add_blobs(struct lsm_blob_sizes
*needed
)
281 lsm_set_size(&needed
->lbs_cred
, &blob_sizes
.lbs_cred
);
282 lsm_set_size(&needed
->lbs_file
, &blob_sizes
.lbs_file
);
283 lsm_set_size(&needed
->lbs_ipc
, &blob_sizes
.lbs_ipc
);
284 lsm_set_size(&needed
->lbs_key
, &blob_sizes
.lbs_key
);
285 lsm_set_size(&needed
->lbs_msg_msg
, &blob_sizes
.lbs_msg_msg
);
286 lsm_set_size(&needed
->lbs_sock
, &blob_sizes
.lbs_sock
);
287 lsm_set_size(&needed
->lbs_superblock
, &blob_sizes
.lbs_superblock
);
288 lsm_set_size(&needed
->lbs_task
, &blob_sizes
.lbs_task
);
290 * The inode blob gets an rcu_head in addition to
291 * what the modules might need.
293 if (needed
->lbs_inode
&& blob_sizes
.lbs_inode
== 0)
294 blob_sizes
.lbs_inode
= sizeof(struct rcu_head
);
295 lsm_set_size(&needed
->lbs_inode
, &blob_sizes
.lbs_inode
);
299 * lsm_file_alloc - allocate a composite file blob
300 * @file: the file that needs a blob
302 * Allocate the file blob for all the modules
304 * Returns 0, or -ENOMEM if memory can't be allocated.
306 int lsm_file_alloc(struct file
*file
)
308 #ifdef CONFIG_SECURITY_LSM_DEBUG
309 if (file
->f_security
)
310 pr_info("%s: Inbound file blob is not NULL.\n", __func__
);
312 if (blob_sizes
.lbs_file
== 0)
315 file
->f_security
= kzalloc(blob_sizes
.lbs_file
, GFP_KERNEL
);
316 if (file
->f_security
== NULL
)
322 * lsm_task_alloc - allocate a composite task blob
323 * @task: the task that needs a blob
325 * Allocate the task blob for all the modules
327 * Returns 0, or -ENOMEM if memory can't be allocated.
329 int lsm_task_alloc(struct task_struct
*task
)
331 #ifdef CONFIG_SECURITY_LSM_DEBUG
333 pr_info("%s: Inbound task blob is not NULL.\n", __func__
);
335 if (blob_sizes
.lbs_task
== 0)
338 task
->security
= kzalloc(blob_sizes
.lbs_task
, GFP_KERNEL
);
339 if (task
->security
== NULL
)
345 * lsm_inode_alloc - allocate a composite inode blob
346 * @inode: the inode that needs a blob
348 * Allocate the inode blob for all the modules
350 * Returns 0, or -ENOMEM if memory can't be allocated.
352 int lsm_inode_alloc(struct inode
*inode
)
354 #ifdef CONFIG_SECURITY_LSM_DEBUG
355 if (inode
->i_security
)
356 pr_info("%s: Inbound inode blob is not NULL.\n", __func__
);
358 if (blob_sizes
.lbs_inode
== 0)
361 inode
->i_security
= kzalloc(blob_sizes
.lbs_inode
, GFP_KERNEL
);
362 if (inode
->i_security
== NULL
)
368 * lsm_early_inode - during initialization allocate a composite inode blob
369 * @inode: the inode that needs a blob
371 * Allocate the inode blob for all the modules if it's not already there
373 void lsm_early_inode(struct inode
*inode
)
378 panic("%s: NULL inode.\n", __func__
);
379 if (inode
->i_security
!= NULL
)
381 rc
= lsm_inode_alloc(inode
);
383 panic("%s: Early inode alloc failed.\n", __func__
);
387 * lsm_ipc_alloc - allocate a composite ipc blob
388 * @kip: the ipc that needs a blob
390 * Allocate the ipc blob for all the modules
392 * Returns 0, or -ENOMEM if memory can't be allocated.
394 int lsm_ipc_alloc(struct kern_ipc_perm
*kip
)
396 #ifdef CONFIG_SECURITY_LSM_DEBUG
398 pr_info("%s: Inbound ipc blob is not NULL.\n", __func__
);
400 if (blob_sizes
.lbs_ipc
== 0)
403 kip
->security
= kzalloc(blob_sizes
.lbs_ipc
, GFP_KERNEL
);
404 if (kip
->security
== NULL
)
411 * lsm_key_alloc - allocate a composite key blob
412 * @key: the key that needs a blob
414 * Allocate the key blob for all the modules
416 * Returns 0, or -ENOMEM if memory can't be allocated.
418 int lsm_key_alloc(struct key
*key
)
420 #ifdef CONFIG_SECURITY_LSM_DEBUG
422 pr_info("%s: Inbound key blob is not NULL.\n", __func__
);
424 if (blob_sizes
.lbs_key
== 0)
427 key
->security
= kzalloc(blob_sizes
.lbs_key
, GFP_KERNEL
);
428 if (key
->security
== NULL
)
432 #endif /* CONFIG_KEYS */
435 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
436 * @mp: the msg_msg that needs a blob
438 * Allocate the ipc blob for all the modules
440 * Returns 0, or -ENOMEM if memory can't be allocated.
442 int lsm_msg_msg_alloc(struct msg_msg
*mp
)
444 #ifdef CONFIG_SECURITY_LSM_DEBUG
446 pr_info("%s: Inbound msg_msg blob is not NULL.\n", __func__
);
448 if (blob_sizes
.lbs_msg_msg
== 0)
451 mp
->security
= kzalloc(blob_sizes
.lbs_msg_msg
, GFP_KERNEL
);
452 if (mp
->security
== NULL
)
458 * lsm_sock_alloc - allocate a composite sock blob
459 * @sock: the sock that needs a blob
460 * @priority: allocation mode
462 * Allocate the sock blob for all the modules
464 * Returns 0, or -ENOMEM if memory can't be allocated.
466 int lsm_sock_alloc(struct sock
*sock
, gfp_t priority
)
468 #ifdef CONFIG_SECURITY_LSM_DEBUG
469 if (sock
->sk_security
)
470 pr_info("%s: Inbound sock blob is not NULL.\n", __func__
);
472 if (blob_sizes
.lbs_sock
== 0)
475 sock
->sk_security
= kzalloc(blob_sizes
.lbs_sock
, priority
);
476 if (sock
->sk_security
== NULL
)
482 * lsm_superblock_alloc - allocate a composite superblock blob
483 * @sb: the superblock that needs a blob
485 * Allocate the superblock blob for all the modules
487 * Returns 0, or -ENOMEM if memory can't be allocated.
489 int lsm_superblock_alloc(struct super_block
*sb
)
491 #ifdef CONFIG_SECURITY_LSM_DEBUG
493 pr_info("%s: Inbound superblock blob is not NULL.\n", __func__
);
495 if (blob_sizes
.lbs_superblock
== 0)
498 sb
->s_security
= kzalloc(blob_sizes
.lbs_superblock
, GFP_KERNEL
);
499 if (sb
->s_security
== NULL
)
505 * Hook list operation macros.
508 * This is a hook that does not return a value.
511 * This is a hook that returns a value.
514 #define call_void_hook(FUNC, ...) \
516 struct security_hook_list *P; \
518 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
519 P->hook.FUNC(__VA_ARGS__); \
522 #define call_int_hook(FUNC, IRC, ...) ({ \
525 struct security_hook_list *P; \
527 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
528 RC = P->hook.FUNC(__VA_ARGS__); \
536 /* Security operations */
538 int security_binder_set_context_mgr(struct task_struct
*mgr
)
540 return call_int_hook(binder_set_context_mgr
, 0, mgr
);
543 int security_binder_transaction(struct task_struct
*from
,
544 struct task_struct
*to
)
546 return call_int_hook(binder_transaction
, 0, from
, to
);
549 int security_binder_transfer_binder(struct task_struct
*from
,
550 struct task_struct
*to
)
552 return call_int_hook(binder_transfer_binder
, 0, from
, to
);
555 int security_binder_transfer_file(struct task_struct
*from
,
556 struct task_struct
*to
, struct file
*file
)
558 return call_int_hook(binder_transfer_file
, 0, from
, to
, file
);
561 int security_ptrace_access_check(struct task_struct
*child
, unsigned int mode
)
563 return call_int_hook(ptrace_access_check
, 0, child
, mode
);
566 int security_ptrace_traceme(struct task_struct
*parent
)
568 return call_int_hook(ptrace_traceme
, 0, parent
);
571 int security_capget(struct task_struct
*target
,
572 kernel_cap_t
*effective
,
573 kernel_cap_t
*inheritable
,
574 kernel_cap_t
*permitted
)
576 return call_int_hook(capget
, 0, target
,
577 effective
, inheritable
, permitted
);
580 int security_capset(struct cred
*new, const struct cred
*old
,
581 const kernel_cap_t
*effective
,
582 const kernel_cap_t
*inheritable
,
583 const kernel_cap_t
*permitted
)
585 return call_int_hook(capset
, 0, new, old
,
586 effective
, inheritable
, permitted
);
589 int security_capable(const struct cred
*cred
, struct user_namespace
*ns
,
592 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_AUDIT
);
595 int security_capable_noaudit(const struct cred
*cred
, struct user_namespace
*ns
,
598 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_NOAUDIT
);
601 int security_quotactl(int cmds
, int type
, int id
, struct super_block
*sb
)
603 return call_int_hook(quotactl
, 0, cmds
, type
, id
, sb
);
606 int security_quota_on(struct dentry
*dentry
)
608 return call_int_hook(quota_on
, 0, dentry
);
611 int security_syslog(int type
)
613 return call_int_hook(syslog
, 0, type
);
616 int security_settime64(const struct timespec64
*ts
, const struct timezone
*tz
)
618 return call_int_hook(settime
, 0, ts
, tz
);
621 int security_vm_enough_memory_mm(struct mm_struct
*mm
, long pages
)
623 struct security_hook_list
*hp
;
624 int cap_sys_admin
= 1;
628 * The module will respond with a positive value if
629 * it thinks the __vm_enough_memory() call should be
630 * made with the cap_sys_admin set. If all of the modules
631 * agree that it should be set it will. If any module
632 * thinks it should not be set it won't.
634 list_for_each_entry(hp
, &security_hook_heads
.vm_enough_memory
, list
) {
635 rc
= hp
->hook
.vm_enough_memory(mm
, pages
);
641 return __vm_enough_memory(mm
, pages
, cap_sys_admin
);
644 int security_bprm_set_creds(struct linux_binprm
*bprm
)
646 return call_int_hook(bprm_set_creds
, 0, bprm
);
649 int security_bprm_check(struct linux_binprm
*bprm
)
653 ret
= call_int_hook(bprm_check_security
, 0, bprm
);
656 return ima_bprm_check(bprm
);
659 void security_bprm_committing_creds(struct linux_binprm
*bprm
)
661 call_void_hook(bprm_committing_creds
, bprm
);
664 void security_bprm_committed_creds(struct linux_binprm
*bprm
)
666 call_void_hook(bprm_committed_creds
, bprm
);
669 int security_bprm_secureexec(struct linux_binprm
*bprm
)
671 return call_int_hook(bprm_secureexec
, 0, bprm
);
674 int security_sb_alloc(struct super_block
*sb
)
676 int rc
= lsm_superblock_alloc(sb
);
680 return call_int_hook(sb_alloc_security
, 0, sb
);
683 void security_sb_free(struct super_block
*sb
)
685 call_void_hook(sb_free_security
, sb
);
686 kfree(sb
->s_security
);
687 sb
->s_security
= NULL
;
690 int security_sb_copy_data(char *orig
, char *copy
)
692 return call_int_hook(sb_copy_data
, 0, orig
, copy
);
694 EXPORT_SYMBOL(security_sb_copy_data
);
696 int security_sb_remount(struct super_block
*sb
, void *data
)
698 return call_int_hook(sb_remount
, 0, sb
, data
);
701 int security_sb_kern_mount(struct super_block
*sb
, int flags
, void *data
)
703 return call_int_hook(sb_kern_mount
, 0, sb
, flags
, data
);
706 int security_sb_show_options(struct seq_file
*m
, struct super_block
*sb
)
708 return call_int_hook(sb_show_options
, 0, m
, sb
);
711 int security_sb_statfs(struct dentry
*dentry
)
713 return call_int_hook(sb_statfs
, 0, dentry
);
716 int security_sb_mount(const char *dev_name
, const struct path
*path
,
717 const char *type
, unsigned long flags
, void *data
)
719 return call_int_hook(sb_mount
, 0, dev_name
, path
, type
, flags
, data
);
722 int security_sb_umount(struct vfsmount
*mnt
, int flags
)
724 return call_int_hook(sb_umount
, 0, mnt
, flags
);
727 int security_sb_pivotroot(const struct path
*old_path
, const struct path
*new_path
)
729 return call_int_hook(sb_pivotroot
, 0, old_path
, new_path
);
732 int security_sb_set_mnt_opts(struct super_block
*sb
,
733 struct security_mnt_opts
*opts
,
734 unsigned long kern_flags
,
735 unsigned long *set_kern_flags
)
737 return call_int_hook(sb_set_mnt_opts
,
738 opts
->num_mnt_opts
? -EOPNOTSUPP
: 0, sb
,
739 opts
, kern_flags
, set_kern_flags
);
741 EXPORT_SYMBOL(security_sb_set_mnt_opts
);
743 int security_sb_clone_mnt_opts(const struct super_block
*oldsb
,
744 struct super_block
*newsb
,
745 unsigned long kern_flags
,
746 unsigned long *set_kern_flags
)
748 return call_int_hook(sb_clone_mnt_opts
, 0, oldsb
, newsb
,
749 kern_flags
, set_kern_flags
);
751 EXPORT_SYMBOL(security_sb_clone_mnt_opts
);
753 int security_sb_parse_opts_str(char *options
, struct security_mnt_opts
*opts
)
755 return call_int_hook(sb_parse_opts_str
, 0, options
, opts
);
757 EXPORT_SYMBOL(security_sb_parse_opts_str
);
759 int security_inode_alloc(struct inode
*inode
)
761 int rc
= lsm_inode_alloc(inode
);
765 return call_int_hook(inode_alloc_security
, 0, inode
);
768 static void inode_free_by_rcu(struct rcu_head
*head
)
771 * The rcu head is at the start of the inode blob
776 void security_inode_free(struct inode
*inode
)
778 integrity_inode_free(inode
);
779 call_void_hook(inode_free_security
, inode
);
781 * The inode may still be referenced in a path walk and
782 * a call to security_inode_permission() can be made
783 * after inode_free_security() is called. Ideally, the VFS
784 * wouldn't do this, but fixing that is a much harder
785 * job. For now, simply free the i_security via RCU, and
786 * leave the current inode->i_security pointer intact.
787 * The inode will be freed after the RCU grace period too.
789 if (inode
->i_security
!= NULL
) {
790 call_rcu((struct rcu_head
*)inode
->i_security
,
792 inode
->i_security
= NULL
;
796 int security_dentry_init_security(struct dentry
*dentry
, int mode
,
797 const struct qstr
*name
, void **ctx
,
800 return call_int_hook(dentry_init_security
, -EOPNOTSUPP
, dentry
, mode
,
803 EXPORT_SYMBOL(security_dentry_init_security
);
805 int security_dentry_create_files_as(struct dentry
*dentry
, int mode
,
807 const struct cred
*old
, struct cred
*new)
809 return call_int_hook(dentry_create_files_as
, 0, dentry
, mode
,
812 EXPORT_SYMBOL(security_dentry_create_files_as
);
814 int security_inode_init_security(struct inode
*inode
, struct inode
*dir
,
815 const struct qstr
*qstr
,
816 const initxattrs initxattrs
, void *fs_data
)
818 struct xattr new_xattrs
[MAX_LSM_EVM_XATTR
+ 1];
819 struct xattr
*lsm_xattr
, *evm_xattr
, *xattr
;
822 if (unlikely(IS_PRIVATE(inode
)))
826 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
,
827 dir
, qstr
, NULL
, NULL
, NULL
);
828 memset(new_xattrs
, 0, sizeof(new_xattrs
));
829 lsm_xattr
= new_xattrs
;
830 ret
= call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
, qstr
,
833 &lsm_xattr
->value_len
);
837 evm_xattr
= lsm_xattr
+ 1;
838 ret
= evm_inode_init_security(inode
, lsm_xattr
, evm_xattr
);
841 ret
= initxattrs(inode
, new_xattrs
, fs_data
);
843 for (xattr
= new_xattrs
; xattr
->value
!= NULL
; xattr
++)
845 return (ret
== -EOPNOTSUPP
) ? 0 : ret
;
847 EXPORT_SYMBOL(security_inode_init_security
);
849 int security_old_inode_init_security(struct inode
*inode
, struct inode
*dir
,
850 const struct qstr
*qstr
, const char **name
,
851 void **value
, size_t *len
)
853 if (unlikely(IS_PRIVATE(inode
)))
855 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
,
856 qstr
, name
, value
, len
);
858 EXPORT_SYMBOL(security_old_inode_init_security
);
860 #ifdef CONFIG_SECURITY_PATH
861 int security_path_mknod(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
,
864 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
866 return call_int_hook(path_mknod
, 0, dir
, dentry
, mode
, dev
);
868 EXPORT_SYMBOL(security_path_mknod
);
870 int security_path_mkdir(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
)
872 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
874 return call_int_hook(path_mkdir
, 0, dir
, dentry
, mode
);
876 EXPORT_SYMBOL(security_path_mkdir
);
878 int security_path_rmdir(const struct path
*dir
, struct dentry
*dentry
)
880 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
882 return call_int_hook(path_rmdir
, 0, dir
, dentry
);
884 EXPORT_SYMBOL_GPL(security_path_rmdir
);
886 int security_path_unlink(const struct path
*dir
, struct dentry
*dentry
)
888 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
890 return call_int_hook(path_unlink
, 0, dir
, dentry
);
892 EXPORT_SYMBOL(security_path_unlink
);
894 int security_path_symlink(const struct path
*dir
, struct dentry
*dentry
,
895 const char *old_name
)
897 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
899 return call_int_hook(path_symlink
, 0, dir
, dentry
, old_name
);
901 EXPORT_SYMBOL_GPL(security_path_symlink
);
903 int security_path_link(struct dentry
*old_dentry
, const struct path
*new_dir
,
904 struct dentry
*new_dentry
)
906 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
908 return call_int_hook(path_link
, 0, old_dentry
, new_dir
, new_dentry
);
910 EXPORT_SYMBOL_GPL(security_path_link
);
912 int security_path_rename(const struct path
*old_dir
, struct dentry
*old_dentry
,
913 const struct path
*new_dir
, struct dentry
*new_dentry
,
916 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
917 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
920 if (flags
& RENAME_EXCHANGE
) {
921 int err
= call_int_hook(path_rename
, 0, new_dir
, new_dentry
,
922 old_dir
, old_dentry
);
927 return call_int_hook(path_rename
, 0, old_dir
, old_dentry
, new_dir
,
930 EXPORT_SYMBOL(security_path_rename
);
932 int security_path_truncate(const struct path
*path
)
934 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
936 return call_int_hook(path_truncate
, 0, path
);
938 EXPORT_SYMBOL_GPL(security_path_truncate
);
940 int security_path_chmod(const struct path
*path
, umode_t mode
)
942 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
944 return call_int_hook(path_chmod
, 0, path
, mode
);
946 EXPORT_SYMBOL_GPL(security_path_chmod
);
948 int security_path_chown(const struct path
*path
, kuid_t uid
, kgid_t gid
)
950 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
952 return call_int_hook(path_chown
, 0, path
, uid
, gid
);
954 EXPORT_SYMBOL_GPL(security_path_chown
);
956 int security_path_chroot(const struct path
*path
)
958 return call_int_hook(path_chroot
, 0, path
);
962 int security_inode_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
964 if (unlikely(IS_PRIVATE(dir
)))
966 return call_int_hook(inode_create
, 0, dir
, dentry
, mode
);
968 EXPORT_SYMBOL_GPL(security_inode_create
);
970 int security_inode_link(struct dentry
*old_dentry
, struct inode
*dir
,
971 struct dentry
*new_dentry
)
973 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
975 return call_int_hook(inode_link
, 0, old_dentry
, dir
, new_dentry
);
978 int security_inode_unlink(struct inode
*dir
, struct dentry
*dentry
)
980 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
982 return call_int_hook(inode_unlink
, 0, dir
, dentry
);
985 int security_inode_symlink(struct inode
*dir
, struct dentry
*dentry
,
986 const char *old_name
)
988 if (unlikely(IS_PRIVATE(dir
)))
990 return call_int_hook(inode_symlink
, 0, dir
, dentry
, old_name
);
993 int security_inode_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
995 if (unlikely(IS_PRIVATE(dir
)))
997 return call_int_hook(inode_mkdir
, 0, dir
, dentry
, mode
);
999 EXPORT_SYMBOL_GPL(security_inode_mkdir
);
1001 int security_inode_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1003 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1005 return call_int_hook(inode_rmdir
, 0, dir
, dentry
);
1008 int security_inode_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
, dev_t dev
)
1010 if (unlikely(IS_PRIVATE(dir
)))
1012 return call_int_hook(inode_mknod
, 0, dir
, dentry
, mode
, dev
);
1015 int security_inode_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1016 struct inode
*new_dir
, struct dentry
*new_dentry
,
1019 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1020 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1023 if (flags
& RENAME_EXCHANGE
) {
1024 int err
= call_int_hook(inode_rename
, 0, new_dir
, new_dentry
,
1025 old_dir
, old_dentry
);
1030 return call_int_hook(inode_rename
, 0, old_dir
, old_dentry
,
1031 new_dir
, new_dentry
);
1034 int security_inode_readlink(struct dentry
*dentry
)
1036 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1038 return call_int_hook(inode_readlink
, 0, dentry
);
1040 EXPORT_SYMBOL_GPL(security_inode_readlink
);
1042 int security_inode_follow_link(struct dentry
*dentry
, struct inode
*inode
,
1045 if (unlikely(IS_PRIVATE(inode
)))
1047 return call_int_hook(inode_follow_link
, 0, dentry
, inode
, rcu
);
1050 int security_inode_permission(struct inode
*inode
, int mask
)
1052 if (unlikely(IS_PRIVATE(inode
)))
1054 return call_int_hook(inode_permission
, 0, inode
, mask
);
1056 EXPORT_SYMBOL_GPL(security_inode_permission
);
1058 int security_inode_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1062 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1064 ret
= call_int_hook(inode_setattr
, 0, dentry
, attr
);
1067 return evm_inode_setattr(dentry
, attr
);
1069 EXPORT_SYMBOL_GPL(security_inode_setattr
);
1071 int security_inode_getattr(const struct path
*path
)
1073 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1075 return call_int_hook(inode_getattr
, 0, path
);
1078 int security_inode_setxattr(struct dentry
*dentry
, const char *name
,
1079 const void *value
, size_t size
, int flags
)
1083 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1086 * SELinux and Smack integrate the cap call,
1087 * so assume that all LSMs supplying this call do so.
1089 ret
= call_int_hook(inode_setxattr
, 1, dentry
, name
, value
, size
,
1093 ret
= cap_inode_setxattr(dentry
, name
, value
, size
, flags
);
1096 ret
= ima_inode_setxattr(dentry
, name
, value
, size
);
1099 return evm_inode_setxattr(dentry
, name
, value
, size
);
1102 void security_inode_post_setxattr(struct dentry
*dentry
, const char *name
,
1103 const void *value
, size_t size
, int flags
)
1105 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1107 call_void_hook(inode_post_setxattr
, dentry
, name
, value
, size
, flags
);
1108 evm_inode_post_setxattr(dentry
, name
, value
, size
);
1111 int security_inode_getxattr(struct dentry
*dentry
, const char *name
)
1113 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1115 return call_int_hook(inode_getxattr
, 0, dentry
, name
);
1118 int security_inode_listxattr(struct dentry
*dentry
)
1120 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1122 return call_int_hook(inode_listxattr
, 0, dentry
);
1125 int security_inode_removexattr(struct dentry
*dentry
, const char *name
)
1129 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1132 * SELinux and Smack integrate the cap call,
1133 * so assume that all LSMs supplying this call do so.
1135 ret
= call_int_hook(inode_removexattr
, 1, dentry
, name
);
1137 ret
= cap_inode_removexattr(dentry
, name
);
1140 ret
= ima_inode_removexattr(dentry
, name
);
1143 return evm_inode_removexattr(dentry
, name
);
1146 int security_inode_need_killpriv(struct dentry
*dentry
)
1148 return call_int_hook(inode_need_killpriv
, 0, dentry
);
1151 int security_inode_killpriv(struct dentry
*dentry
)
1153 return call_int_hook(inode_killpriv
, 0, dentry
);
1156 int security_inode_getsecurity(struct inode
*inode
, const char *name
, void **buffer
, bool alloc
)
1158 struct security_hook_list
*hp
;
1161 if (unlikely(IS_PRIVATE(inode
)))
1164 * Only one module will provide an attribute with a given name.
1166 list_for_each_entry(hp
, &security_hook_heads
.inode_getsecurity
, list
) {
1167 rc
= hp
->hook
.inode_getsecurity(inode
, name
, buffer
, alloc
);
1168 if (rc
!= -EOPNOTSUPP
)
1174 int security_inode_setsecurity(struct inode
*inode
, const char *name
, const void *value
, size_t size
, int flags
)
1176 struct security_hook_list
*hp
;
1179 if (unlikely(IS_PRIVATE(inode
)))
1182 * Only one module will provide an attribute with a given name.
1184 list_for_each_entry(hp
, &security_hook_heads
.inode_setsecurity
, list
) {
1185 rc
= hp
->hook
.inode_setsecurity(inode
, name
, value
, size
,
1187 if (rc
!= -EOPNOTSUPP
)
1193 int security_inode_listsecurity(struct inode
*inode
, char *buffer
, size_t buffer_size
)
1195 if (unlikely(IS_PRIVATE(inode
)))
1197 return call_int_hook(inode_listsecurity
, 0, inode
, buffer
, buffer_size
);
1199 EXPORT_SYMBOL(security_inode_listsecurity
);
1201 void security_inode_getsecid(struct inode
*inode
, u32
*secid
)
1203 call_void_hook(inode_getsecid
, inode
, secid
);
1206 int security_inode_copy_up(struct dentry
*src
, struct cred
**new)
1208 return call_int_hook(inode_copy_up
, 0, src
, new);
1210 EXPORT_SYMBOL(security_inode_copy_up
);
1212 int security_inode_copy_up_xattr(const char *name
)
1214 return call_int_hook(inode_copy_up_xattr
, -EOPNOTSUPP
, name
);
1216 EXPORT_SYMBOL(security_inode_copy_up_xattr
);
1218 int security_file_permission(struct file
*file
, int mask
)
1222 ret
= call_int_hook(file_permission
, 0, file
, mask
);
1226 return fsnotify_perm(file
, mask
);
1228 EXPORT_SYMBOL_GPL(security_file_permission
);
1230 int security_file_alloc(struct file
*file
)
1232 int rc
= lsm_file_alloc(file
);
1236 return call_int_hook(file_alloc_security
, 0, file
);
1239 void security_file_free(struct file
*file
)
1241 call_void_hook(file_free_security
, file
);
1243 kfree(file
->f_security
);
1244 file
->f_security
= NULL
;
1247 int security_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1249 return call_int_hook(file_ioctl
, 0, file
, cmd
, arg
);
1252 static inline unsigned long mmap_prot(struct file
*file
, unsigned long prot
)
1255 * Does we have PROT_READ and does the application expect
1256 * it to imply PROT_EXEC? If not, nothing to talk about...
1258 if ((prot
& (PROT_READ
| PROT_EXEC
)) != PROT_READ
)
1260 if (!(current
->personality
& READ_IMPLIES_EXEC
))
1263 * if that's an anonymous mapping, let it.
1266 return prot
| PROT_EXEC
;
1268 * ditto if it's not on noexec mount, except that on !MMU we need
1269 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
1271 if (!path_noexec(&file
->f_path
)) {
1273 if (file
->f_op
->mmap_capabilities
) {
1274 unsigned caps
= file
->f_op
->mmap_capabilities(file
);
1275 if (!(caps
& NOMMU_MAP_EXEC
))
1279 return prot
| PROT_EXEC
;
1281 /* anything on noexec mount won't get PROT_EXEC */
1285 int security_mmap_file(struct file
*file
, unsigned long prot
,
1286 unsigned long flags
)
1289 ret
= call_int_hook(mmap_file
, 0, file
, prot
,
1290 mmap_prot(file
, prot
), flags
);
1293 return ima_file_mmap(file
, prot
);
1295 EXPORT_SYMBOL_GPL(security_mmap_file
);
1297 int security_mmap_addr(unsigned long addr
)
1299 return call_int_hook(mmap_addr
, 0, addr
);
1302 int security_file_mprotect(struct vm_area_struct
*vma
, unsigned long reqprot
,
1305 return call_int_hook(file_mprotect
, 0, vma
, reqprot
, prot
);
1308 int security_file_lock(struct file
*file
, unsigned int cmd
)
1310 return call_int_hook(file_lock
, 0, file
, cmd
);
1313 int security_file_fcntl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1315 return call_int_hook(file_fcntl
, 0, file
, cmd
, arg
);
1318 void security_file_set_fowner(struct file
*file
)
1320 call_void_hook(file_set_fowner
, file
);
1323 int security_file_send_sigiotask(struct task_struct
*tsk
,
1324 struct fown_struct
*fown
, int sig
)
1326 return call_int_hook(file_send_sigiotask
, 0, tsk
, fown
, sig
);
1329 int security_file_receive(struct file
*file
)
1331 return call_int_hook(file_receive
, 0, file
);
1334 int security_file_open(struct file
*file
, const struct cred
*cred
)
1338 ret
= call_int_hook(file_open
, 0, file
, cred
);
1342 return fsnotify_perm(file
, MAY_OPEN
);
1345 int security_task_create(unsigned long clone_flags
)
1347 return call_int_hook(task_create
, 0, clone_flags
);
1350 int security_task_alloc(struct task_struct
*task
, unsigned long clone_flags
)
1352 return call_int_hook(task_alloc
, 0, task
, clone_flags
);
1355 void security_task_free(struct task_struct
*task
)
1357 call_void_hook(task_free
, task
);
1359 kfree(task
->security
);
1360 task
->security
= NULL
;
1363 int security_cred_alloc_blank(struct cred
*cred
, gfp_t gfp
)
1365 int rc
= lsm_cred_alloc(cred
, gfp
);
1370 return call_int_hook(cred_alloc_blank
, 0, cred
, gfp
);
1373 void security_cred_free(struct cred
*cred
)
1375 call_void_hook(cred_free
, cred
);
1377 kfree(cred
->security
);
1378 cred
->security
= NULL
;
1381 int security_prepare_creds(struct cred
*new, const struct cred
*old
, gfp_t gfp
)
1383 int rc
= lsm_cred_alloc(new, gfp
);
1388 return call_int_hook(cred_prepare
, 0, new, old
, gfp
);
1391 void security_transfer_creds(struct cred
*new, const struct cred
*old
)
1393 call_void_hook(cred_transfer
, new, old
);
1396 int security_kernel_act_as(struct cred
*new, u32 secid
)
1398 return call_int_hook(kernel_act_as
, 0, new, secid
);
1401 int security_kernel_create_files_as(struct cred
*new, struct inode
*inode
)
1403 return call_int_hook(kernel_create_files_as
, 0, new, inode
);
1406 int security_kernel_module_request(char *kmod_name
)
1408 return call_int_hook(kernel_module_request
, 0, kmod_name
);
1411 int security_kernel_read_file(struct file
*file
, enum kernel_read_file_id id
)
1415 ret
= call_int_hook(kernel_read_file
, 0, file
, id
);
1418 return ima_read_file(file
, id
);
1420 EXPORT_SYMBOL_GPL(security_kernel_read_file
);
1422 int security_kernel_post_read_file(struct file
*file
, char *buf
, loff_t size
,
1423 enum kernel_read_file_id id
)
1427 ret
= call_int_hook(kernel_post_read_file
, 0, file
, buf
, size
, id
);
1430 return ima_post_read_file(file
, buf
, size
, id
);
1432 EXPORT_SYMBOL_GPL(security_kernel_post_read_file
);
1434 int security_task_fix_setuid(struct cred
*new, const struct cred
*old
,
1437 return call_int_hook(task_fix_setuid
, 0, new, old
, flags
);
1440 int security_task_setpgid(struct task_struct
*p
, pid_t pgid
)
1442 return call_int_hook(task_setpgid
, 0, p
, pgid
);
1445 int security_task_getpgid(struct task_struct
*p
)
1447 return call_int_hook(task_getpgid
, 0, p
);
1450 int security_task_getsid(struct task_struct
*p
)
1452 return call_int_hook(task_getsid
, 0, p
);
1455 void security_task_getsecid(struct task_struct
*p
, u32
*secid
)
1458 call_void_hook(task_getsecid
, p
, secid
);
1460 EXPORT_SYMBOL(security_task_getsecid
);
1462 int security_task_setnice(struct task_struct
*p
, int nice
)
1464 return call_int_hook(task_setnice
, 0, p
, nice
);
1467 int security_task_setioprio(struct task_struct
*p
, int ioprio
)
1469 return call_int_hook(task_setioprio
, 0, p
, ioprio
);
1472 int security_task_getioprio(struct task_struct
*p
)
1474 return call_int_hook(task_getioprio
, 0, p
);
1477 int security_task_prlimit(const struct cred
*cred
, const struct cred
*tcred
,
1480 return call_int_hook(task_prlimit
, 0, cred
, tcred
, flags
);
1483 int security_task_setrlimit(struct task_struct
*p
, unsigned int resource
,
1484 struct rlimit
*new_rlim
)
1486 return call_int_hook(task_setrlimit
, 0, p
, resource
, new_rlim
);
1489 int security_task_setscheduler(struct task_struct
*p
)
1491 return call_int_hook(task_setscheduler
, 0, p
);
1494 int security_task_getscheduler(struct task_struct
*p
)
1496 return call_int_hook(task_getscheduler
, 0, p
);
1499 int security_task_movememory(struct task_struct
*p
)
1501 return call_int_hook(task_movememory
, 0, p
);
1504 int security_task_kill(struct task_struct
*p
, struct siginfo
*info
,
1507 return call_int_hook(task_kill
, 0, p
, info
, sig
, secid
);
1510 int security_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1511 unsigned long arg4
, unsigned long arg5
)
1515 struct security_hook_list
*hp
;
1517 list_for_each_entry(hp
, &security_hook_heads
.task_prctl
, list
) {
1518 thisrc
= hp
->hook
.task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1519 if (thisrc
!= -ENOSYS
) {
1528 void security_task_to_inode(struct task_struct
*p
, struct inode
*inode
)
1530 call_void_hook(task_to_inode
, p
, inode
);
1533 int security_ipc_permission(struct kern_ipc_perm
*ipcp
, short flag
)
1535 return call_int_hook(ipc_permission
, 0, ipcp
, flag
);
1538 void security_ipc_getsecid(struct kern_ipc_perm
*ipcp
, u32
*secid
)
1541 call_void_hook(ipc_getsecid
, ipcp
, secid
);
1544 int security_msg_msg_alloc(struct msg_msg
*msg
)
1546 int rc
= lsm_msg_msg_alloc(msg
);
1550 return call_int_hook(msg_msg_alloc_security
, 0, msg
);
1553 void security_msg_msg_free(struct msg_msg
*msg
)
1555 call_void_hook(msg_msg_free_security
, msg
);
1556 kfree(msg
->security
);
1557 msg
->security
= NULL
;
1560 int security_msg_queue_alloc(struct msg_queue
*msq
)
1562 int rc
= lsm_ipc_alloc(&msq
->q_perm
);
1566 return call_int_hook(msg_queue_alloc_security
, 0, msq
);
1569 void security_msg_queue_free(struct msg_queue
*msq
)
1571 struct kern_ipc_perm
*kip
= &msq
->q_perm
;
1573 call_void_hook(msg_queue_free_security
, msq
);
1574 kfree(kip
->security
);
1575 kip
->security
= NULL
;
1578 int security_msg_queue_associate(struct msg_queue
*msq
, int msqflg
)
1580 return call_int_hook(msg_queue_associate
, 0, msq
, msqflg
);
1583 int security_msg_queue_msgctl(struct msg_queue
*msq
, int cmd
)
1585 return call_int_hook(msg_queue_msgctl
, 0, msq
, cmd
);
1588 int security_msg_queue_msgsnd(struct msg_queue
*msq
,
1589 struct msg_msg
*msg
, int msqflg
)
1591 return call_int_hook(msg_queue_msgsnd
, 0, msq
, msg
, msqflg
);
1594 int security_msg_queue_msgrcv(struct msg_queue
*msq
, struct msg_msg
*msg
,
1595 struct task_struct
*target
, long type
, int mode
)
1597 return call_int_hook(msg_queue_msgrcv
, 0, msq
, msg
, target
, type
, mode
);
1600 int security_shm_alloc(struct shmid_kernel
*shp
)
1602 int rc
= lsm_ipc_alloc(&shp
->shm_perm
);
1606 return call_int_hook(shm_alloc_security
, 0, shp
);
1609 void security_shm_free(struct shmid_kernel
*shp
)
1611 struct kern_ipc_perm
*kip
= &shp
->shm_perm
;
1613 call_void_hook(shm_free_security
, shp
);
1614 kfree(kip
->security
);
1615 kip
->security
= NULL
;
1618 int security_shm_associate(struct shmid_kernel
*shp
, int shmflg
)
1620 return call_int_hook(shm_associate
, 0, shp
, shmflg
);
1623 int security_shm_shmctl(struct shmid_kernel
*shp
, int cmd
)
1625 return call_int_hook(shm_shmctl
, 0, shp
, cmd
);
1628 int security_shm_shmat(struct shmid_kernel
*shp
, char __user
*shmaddr
, int shmflg
)
1630 return call_int_hook(shm_shmat
, 0, shp
, shmaddr
, shmflg
);
1633 int security_sem_alloc(struct sem_array
*sma
)
1635 int rc
= lsm_ipc_alloc(&sma
->sem_perm
);
1639 return call_int_hook(sem_alloc_security
, 0, sma
);
1642 void security_sem_free(struct sem_array
*sma
)
1644 struct kern_ipc_perm
*kip
= &sma
->sem_perm
;
1646 call_void_hook(sem_free_security
, sma
);
1647 kfree(kip
->security
);
1648 kip
->security
= NULL
;
1651 int security_sem_associate(struct sem_array
*sma
, int semflg
)
1653 return call_int_hook(sem_associate
, 0, sma
, semflg
);
1656 int security_sem_semctl(struct sem_array
*sma
, int cmd
)
1658 return call_int_hook(sem_semctl
, 0, sma
, cmd
);
1661 int security_sem_semop(struct sem_array
*sma
, struct sembuf
*sops
,
1662 unsigned nsops
, int alter
)
1664 return call_int_hook(sem_semop
, 0, sma
, sops
, nsops
, alter
);
1667 void security_d_instantiate(struct dentry
*dentry
, struct inode
*inode
)
1669 if (unlikely(inode
&& IS_PRIVATE(inode
)))
1671 call_void_hook(d_instantiate
, dentry
, inode
);
1673 EXPORT_SYMBOL(security_d_instantiate
);
1675 int security_getprocattr(struct task_struct
*p
, const char *lsm
, char *name
,
1678 struct security_hook_list
*hp
;
1681 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1682 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1684 rc
= hp
->hook
.getprocattr(p
, name
, value
);
1691 int security_setprocattr(const char *lsm
, const char *name
, void *value
,
1694 struct security_hook_list
*hp
;
1697 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
, list
) {
1698 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1700 rc
= hp
->hook
.setprocattr(name
, value
, size
);
1707 int security_netlink_send(struct sock
*sk
, struct sk_buff
*skb
)
1709 return call_int_hook(netlink_send
, 0, sk
, skb
);
1712 int security_ismaclabel(const char *name
)
1714 return call_int_hook(ismaclabel
, 0, name
);
1716 EXPORT_SYMBOL(security_ismaclabel
);
1718 int security_secid_to_secctx(u32 secid
, char **secdata
, u32
*seclen
)
1720 return call_int_hook(secid_to_secctx
, -EOPNOTSUPP
, secid
, secdata
,
1723 EXPORT_SYMBOL(security_secid_to_secctx
);
1725 int security_secctx_to_secid(const char *secdata
, u32 seclen
, u32
*secid
)
1728 return call_int_hook(secctx_to_secid
, 0, secdata
, seclen
, secid
);
1730 EXPORT_SYMBOL(security_secctx_to_secid
);
1732 void security_release_secctx(char *secdata
, u32 seclen
)
1734 call_void_hook(release_secctx
, secdata
, seclen
);
1736 EXPORT_SYMBOL(security_release_secctx
);
1738 void security_inode_invalidate_secctx(struct inode
*inode
)
1740 call_void_hook(inode_invalidate_secctx
, inode
);
1742 EXPORT_SYMBOL(security_inode_invalidate_secctx
);
1744 int security_inode_notifysecctx(struct inode
*inode
, void *ctx
, u32 ctxlen
)
1746 return call_int_hook(inode_notifysecctx
, 0, inode
, ctx
, ctxlen
);
1748 EXPORT_SYMBOL(security_inode_notifysecctx
);
1750 int security_inode_setsecctx(struct dentry
*dentry
, void *ctx
, u32 ctxlen
)
1752 return call_int_hook(inode_setsecctx
, 0, dentry
, ctx
, ctxlen
);
1754 EXPORT_SYMBOL(security_inode_setsecctx
);
1756 int security_inode_getsecctx(struct inode
*inode
, void **ctx
, u32
*ctxlen
)
1758 return call_int_hook(inode_getsecctx
, -EOPNOTSUPP
, inode
, ctx
, ctxlen
);
1760 EXPORT_SYMBOL(security_inode_getsecctx
);
1762 #ifdef CONFIG_SECURITY_NETWORK
1764 int security_unix_stream_connect(struct sock
*sock
, struct sock
*other
, struct sock
*newsk
)
1766 return call_int_hook(unix_stream_connect
, 0, sock
, other
, newsk
);
1768 EXPORT_SYMBOL(security_unix_stream_connect
);
1770 int security_unix_may_send(struct socket
*sock
, struct socket
*other
)
1772 return call_int_hook(unix_may_send
, 0, sock
, other
);
1774 EXPORT_SYMBOL(security_unix_may_send
);
1776 int security_socket_create(int family
, int type
, int protocol
, int kern
)
1778 return call_int_hook(socket_create
, 0, family
, type
, protocol
, kern
);
1781 int security_socket_post_create(struct socket
*sock
, int family
,
1782 int type
, int protocol
, int kern
)
1784 return call_int_hook(socket_post_create
, 0, sock
, family
, type
,
1788 int security_socket_bind(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
1790 return call_int_hook(socket_bind
, 0, sock
, address
, addrlen
);
1793 int security_socket_connect(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
1795 return call_int_hook(socket_connect
, 0, sock
, address
, addrlen
);
1798 int security_socket_listen(struct socket
*sock
, int backlog
)
1800 return call_int_hook(socket_listen
, 0, sock
, backlog
);
1803 int security_socket_accept(struct socket
*sock
, struct socket
*newsock
)
1805 return call_int_hook(socket_accept
, 0, sock
, newsock
);
1808 int security_socket_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
)
1810 return call_int_hook(socket_sendmsg
, 0, sock
, msg
, size
);
1813 int security_socket_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
1814 int size
, int flags
)
1816 return call_int_hook(socket_recvmsg
, 0, sock
, msg
, size
, flags
);
1819 int security_socket_getsockname(struct socket
*sock
)
1821 return call_int_hook(socket_getsockname
, 0, sock
);
1824 int security_socket_getpeername(struct socket
*sock
)
1826 return call_int_hook(socket_getpeername
, 0, sock
);
1829 int security_socket_getsockopt(struct socket
*sock
, int level
, int optname
)
1831 return call_int_hook(socket_getsockopt
, 0, sock
, level
, optname
);
1834 int security_socket_setsockopt(struct socket
*sock
, int level
, int optname
)
1836 return call_int_hook(socket_setsockopt
, 0, sock
, level
, optname
);
1839 int security_socket_shutdown(struct socket
*sock
, int how
)
1841 return call_int_hook(socket_shutdown
, 0, sock
, how
);
1844 int security_sock_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
1846 return call_int_hook(socket_sock_rcv_skb
, 0, sk
, skb
);
1848 EXPORT_SYMBOL(security_sock_rcv_skb
);
1850 int security_socket_getpeersec_stream(struct socket
*sock
, char __user
*optval
,
1851 int __user
*optlen
, unsigned len
)
1853 return call_int_hook(socket_getpeersec_stream
, -ENOPROTOOPT
, sock
,
1854 optval
, optlen
, len
);
1857 int security_socket_getpeersec_dgram(struct socket
*sock
, struct sk_buff
*skb
, u32
*secid
)
1859 return call_int_hook(socket_getpeersec_dgram
, -ENOPROTOOPT
, sock
,
1862 EXPORT_SYMBOL(security_socket_getpeersec_dgram
);
1864 int security_sk_alloc(struct sock
*sk
, int family
, gfp_t priority
)
1866 int rc
= lsm_sock_alloc(sk
, priority
);
1870 return call_int_hook(sk_alloc_security
, 0, sk
, family
, priority
);
1873 void security_sk_free(struct sock
*sk
)
1875 call_void_hook(sk_free_security
, sk
);
1876 kfree(sk
->sk_security
);
1877 sk
->sk_security
= NULL
;
1880 void security_sk_clone(const struct sock
*sk
, struct sock
*newsk
)
1882 call_void_hook(sk_clone_security
, sk
, newsk
);
1884 EXPORT_SYMBOL(security_sk_clone
);
1886 void security_sk_classify_flow(struct sock
*sk
, struct flowi
*fl
)
1888 call_void_hook(sk_getsecid
, sk
, &fl
->flowi_secid
);
1890 EXPORT_SYMBOL(security_sk_classify_flow
);
1892 void security_req_classify_flow(const struct request_sock
*req
, struct flowi
*fl
)
1894 call_void_hook(req_classify_flow
, req
, fl
);
1896 EXPORT_SYMBOL(security_req_classify_flow
);
1898 void security_sock_graft(struct sock
*sk
, struct socket
*parent
)
1900 call_void_hook(sock_graft
, sk
, parent
);
1902 EXPORT_SYMBOL(security_sock_graft
);
1904 int security_inet_conn_request(struct sock
*sk
,
1905 struct sk_buff
*skb
, struct request_sock
*req
)
1907 return call_int_hook(inet_conn_request
, 0, sk
, skb
, req
);
1909 EXPORT_SYMBOL(security_inet_conn_request
);
1911 void security_inet_csk_clone(struct sock
*newsk
,
1912 const struct request_sock
*req
)
1914 call_void_hook(inet_csk_clone
, newsk
, req
);
1917 void security_inet_conn_established(struct sock
*sk
,
1918 struct sk_buff
*skb
)
1920 call_void_hook(inet_conn_established
, sk
, skb
);
1923 int security_secmark_relabel_packet(u32 secid
)
1925 return call_int_hook(secmark_relabel_packet
, 0, secid
);
1927 EXPORT_SYMBOL(security_secmark_relabel_packet
);
1929 void security_secmark_refcount_inc(void)
1931 call_void_hook(secmark_refcount_inc
);
1933 EXPORT_SYMBOL(security_secmark_refcount_inc
);
1935 void security_secmark_refcount_dec(void)
1937 call_void_hook(secmark_refcount_dec
);
1939 EXPORT_SYMBOL(security_secmark_refcount_dec
);
1941 int security_tun_dev_alloc_security(void **security
)
1943 return call_int_hook(tun_dev_alloc_security
, 0, security
);
1945 EXPORT_SYMBOL(security_tun_dev_alloc_security
);
1947 void security_tun_dev_free_security(void *security
)
1949 call_void_hook(tun_dev_free_security
, security
);
1951 EXPORT_SYMBOL(security_tun_dev_free_security
);
1953 int security_tun_dev_create(void)
1955 return call_int_hook(tun_dev_create
, 0);
1957 EXPORT_SYMBOL(security_tun_dev_create
);
1959 int security_tun_dev_attach_queue(void *security
)
1961 return call_int_hook(tun_dev_attach_queue
, 0, security
);
1963 EXPORT_SYMBOL(security_tun_dev_attach_queue
);
1965 int security_tun_dev_attach(struct sock
*sk
, void *security
)
1967 return call_int_hook(tun_dev_attach
, 0, sk
, security
);
1969 EXPORT_SYMBOL(security_tun_dev_attach
);
1971 int security_tun_dev_open(void *security
)
1973 return call_int_hook(tun_dev_open
, 0, security
);
1975 EXPORT_SYMBOL(security_tun_dev_open
);
1977 #endif /* CONFIG_SECURITY_NETWORK */
1979 #ifdef CONFIG_SECURITY_INFINIBAND
1981 int security_ib_pkey_access(void *sec
, u64 subnet_prefix
, u16 pkey
)
1983 return call_int_hook(ib_pkey_access
, 0, sec
, subnet_prefix
, pkey
);
1985 EXPORT_SYMBOL(security_ib_pkey_access
);
1987 int security_ib_endport_manage_subnet(void *sec
, const char *dev_name
, u8 port_num
)
1989 return call_int_hook(ib_endport_manage_subnet
, 0, sec
, dev_name
, port_num
);
1991 EXPORT_SYMBOL(security_ib_endport_manage_subnet
);
1993 int security_ib_alloc_security(void **sec
)
1995 return call_int_hook(ib_alloc_security
, 0, sec
);
1997 EXPORT_SYMBOL(security_ib_alloc_security
);
1999 void security_ib_free_security(void *sec
)
2001 call_void_hook(ib_free_security
, sec
);
2003 EXPORT_SYMBOL(security_ib_free_security
);
2004 #endif /* CONFIG_SECURITY_INFINIBAND */
2006 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2008 int security_xfrm_policy_alloc(struct xfrm_sec_ctx
**ctxp
,
2009 struct xfrm_user_sec_ctx
*sec_ctx
,
2012 return call_int_hook(xfrm_policy_alloc_security
, 0, ctxp
, sec_ctx
, gfp
);
2014 EXPORT_SYMBOL(security_xfrm_policy_alloc
);
2016 int security_xfrm_policy_clone(struct xfrm_sec_ctx
*old_ctx
,
2017 struct xfrm_sec_ctx
**new_ctxp
)
2019 return call_int_hook(xfrm_policy_clone_security
, 0, old_ctx
, new_ctxp
);
2022 void security_xfrm_policy_free(struct xfrm_sec_ctx
*ctx
)
2024 call_void_hook(xfrm_policy_free_security
, ctx
);
2026 EXPORT_SYMBOL(security_xfrm_policy_free
);
2028 int security_xfrm_policy_delete(struct xfrm_sec_ctx
*ctx
)
2030 return call_int_hook(xfrm_policy_delete_security
, 0, ctx
);
2033 int security_xfrm_state_alloc(struct xfrm_state
*x
,
2034 struct xfrm_user_sec_ctx
*sec_ctx
)
2036 return call_int_hook(xfrm_state_alloc
, 0, x
, sec_ctx
);
2038 EXPORT_SYMBOL(security_xfrm_state_alloc
);
2040 int security_xfrm_state_alloc_acquire(struct xfrm_state
*x
,
2041 struct xfrm_sec_ctx
*polsec
, u32 secid
)
2043 return call_int_hook(xfrm_state_alloc_acquire
, 0, x
, polsec
, secid
);
2046 int security_xfrm_state_delete(struct xfrm_state
*x
)
2048 return call_int_hook(xfrm_state_delete_security
, 0, x
);
2050 EXPORT_SYMBOL(security_xfrm_state_delete
);
2052 void security_xfrm_state_free(struct xfrm_state
*x
)
2054 call_void_hook(xfrm_state_free_security
, x
);
2057 int security_xfrm_policy_lookup(struct xfrm_sec_ctx
*ctx
, u32 fl_secid
, u8 dir
)
2059 return call_int_hook(xfrm_policy_lookup
, 0, ctx
, fl_secid
, dir
);
2062 int security_xfrm_state_pol_flow_match(struct xfrm_state
*x
,
2063 struct xfrm_policy
*xp
,
2064 const struct flowi
*fl
)
2066 struct security_hook_list
*hp
;
2070 * Since this function is expected to return 0 or 1, the judgment
2071 * becomes difficult if multiple LSMs supply this call. Fortunately,
2072 * we can use the first LSM's judgment because currently only SELinux
2073 * supplies this call.
2075 * For speed optimization, we explicitly break the loop rather than
2078 list_for_each_entry(hp
, &security_hook_heads
.xfrm_state_pol_flow_match
,
2080 rc
= hp
->hook
.xfrm_state_pol_flow_match(x
, xp
, fl
);
2086 int security_xfrm_decode_session(struct sk_buff
*skb
, u32
*secid
)
2088 return call_int_hook(xfrm_decode_session
, 0, skb
, secid
, 1);
2091 void security_skb_classify_flow(struct sk_buff
*skb
, struct flowi
*fl
)
2093 int rc
= call_int_hook(xfrm_decode_session
, 0, skb
, &fl
->flowi_secid
,
2098 EXPORT_SYMBOL(security_skb_classify_flow
);
2100 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
2104 int security_key_alloc(struct key
*key
, const struct cred
*cred
,
2105 unsigned long flags
)
2107 int rc
= lsm_key_alloc(key
);
2111 return call_int_hook(key_alloc
, 0, key
, cred
, flags
);
2114 void security_key_free(struct key
*key
)
2116 call_void_hook(key_free
, key
);
2117 kfree(key
->security
);
2118 key
->security
= NULL
;
2121 int security_key_permission(key_ref_t key_ref
,
2122 const struct cred
*cred
, unsigned perm
)
2124 return call_int_hook(key_permission
, 0, key_ref
, cred
, perm
);
2127 int security_key_getsecurity(struct key
*key
, char **_buffer
)
2130 return call_int_hook(key_getsecurity
, 0, key
, _buffer
);
2133 #endif /* CONFIG_KEYS */
2137 int security_audit_rule_init(u32 field
, u32 op
, char *rulestr
, void **lsmrule
)
2139 return call_int_hook(audit_rule_init
, 0, field
, op
, rulestr
, lsmrule
);
2142 int security_audit_rule_known(struct audit_krule
*krule
)
2144 return call_int_hook(audit_rule_known
, 0, krule
);
2147 void security_audit_rule_free(void *lsmrule
)
2149 call_void_hook(audit_rule_free
, lsmrule
);
2152 int security_audit_rule_match(u32 secid
, u32 field
, u32 op
, void *lsmrule
,
2153 struct audit_context
*actx
)
2155 return call_int_hook(audit_rule_match
, 0, secid
, field
, op
, lsmrule
,
2158 #endif /* CONFIG_AUDIT */