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/bpf.h>
16 #include <linux/capability.h>
17 #include <linux/dcache.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/lsm_hooks.h>
22 #include <linux/integrity.h>
23 #include <linux/ima.h>
24 #include <linux/evm.h>
25 #include <linux/fsnotify.h>
26 #include <linux/mman.h>
27 #include <linux/mount.h>
28 #include <linux/personality.h>
29 #include <linux/backing-dev.h>
30 #include <linux/string.h>
31 #include <linux/msg.h>
32 #include <linux/prctl.h>
36 #define MAX_LSM_EVM_XATTR 2
38 /* Maximum number of letters for an LSM name string */
39 #define SECURITY_NAME_MAX 10
40 #define SECURITY_CHOSEN_NAMES_MAX (SECURITY_NAME_MAX * LSM_MAX_MAJOR)
41 #define MODULE_STACK "(stacking)"
43 struct security_hook_heads security_hook_heads __lsm_ro_after_init
;
44 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain
);
46 static struct kmem_cache
*lsm_file_cache
;
47 static struct kmem_cache
*lsm_inode_cache
;
52 * If stacking is enabled the task blob will always
53 * include an indicator of what security module data
54 * should be displayed. This is set with PR_SET_DISPLAY_LSM.
56 static struct lsm_blob_sizes blob_sizes
= {
57 #ifdef CONFIG_SECURITY_STACKING
58 .lbs_task
= SECURITY_NAME_MAX
+ 6,
62 /* Boot-time LSM user choice */
63 static __initdata
char chosen_lsms
[SECURITY_CHOSEN_NAMES_MAX
+ 1] =
64 #ifdef CONFIG_SECURITY_STACKING
67 CONFIG_DEFAULT_SECURITY
;
69 static __initdata
char chosen_display_lsm
[SECURITY_NAME_MAX
+ 1]
70 #ifdef CONFIG_SECURITY_STACKING
71 = CONFIG_SECURITY_DEFAULT_DISPLAY_NAME
74 static char default_display_lsm
[SECURITY_NAME_MAX
+ 1];
76 static void __init
do_security_initcalls(void)
79 call
= __security_initcall_start
;
80 while (call
< __security_initcall_end
) {
87 * security_init - initializes the security framework
89 * This should be called early in the kernel initialization sequence.
91 int __init
security_init(void)
94 struct list_head
*list
= (struct list_head
*) &security_hook_heads
;
96 for (i
= 0; i
< sizeof(security_hook_heads
) / sizeof(struct list_head
);
98 INIT_LIST_HEAD(&list
[i
]);
99 pr_info("Security Framework initialized\n");
102 * Load minor LSMs, with the capability module always first.
104 capability_add_hooks();
109 * The first call to a module specific init function
110 * updates the blob size requirements.
112 do_security_initcalls();
115 * Create any kmem_caches needed for blobs
117 if (blob_sizes
.lbs_file
)
118 lsm_file_cache
= kmem_cache_create("lsm_file_cache",
119 blob_sizes
.lbs_file
, 0,
121 if (blob_sizes
.lbs_inode
)
122 lsm_inode_cache
= kmem_cache_create("lsm_inode_cache",
123 blob_sizes
.lbs_inode
, 0,
126 * The second call to a module specific init function
127 * adds hooks to the hook lists and does any other early
128 * initializations required.
130 do_security_initcalls();
132 #ifdef CONFIG_SECURITY_LSM_DEBUG
133 pr_info("LSM: cred blob size = %d\n", blob_sizes
.lbs_cred
);
134 pr_info("LSM: file blob size = %d\n", blob_sizes
.lbs_file
);
135 pr_info("LSM: inode blob size = %d\n", blob_sizes
.lbs_inode
);
136 pr_info("LSM: ipc blob size = %d\n", blob_sizes
.lbs_ipc
);
138 pr_info("LSM: key blob size = %d\n", blob_sizes
.lbs_key
);
139 #endif /* CONFIG_KEYS */
140 pr_info("LSM: msg_msg blob size = %d\n", blob_sizes
.lbs_msg_msg
);
141 pr_info("LSM: sock blob size = %d\n", blob_sizes
.lbs_sock
);
142 pr_info("LSM: superblock blob size = %d\n", blob_sizes
.lbs_superblock
);
143 pr_info("LSM: task blob size = %d\n", blob_sizes
.lbs_task
);
144 #endif /* CONFIG_SECURITY_LSM_DEBUG */
149 /* Save user chosen LSM */
150 static int __init
choose_lsm(char *str
)
152 strncpy(chosen_lsms
, str
, SECURITY_CHOSEN_NAMES_MAX
);
153 pr_info("LSM: command line set '%s' security module(s).\n",
157 __setup("security=", choose_lsm
);
159 static int __init
choose_display_lsm(char *str
)
161 strncpy(chosen_display_lsm
, str
, SECURITY_NAME_MAX
);
162 pr_info("LSM: command line set default display lsm %s'\n",
166 __setup("security.display=", choose_display_lsm
);
168 static bool match_last_lsm(const char *list
, const char *lsm
)
172 if (WARN_ON(!list
|| !lsm
))
174 last
= strrchr(list
, ',');
176 /* Pass the comma, strcmp() will check for '\0' */
180 return !strcmp(last
, lsm
);
183 static int lsm_append(char *new, char **result
)
187 if (*result
== NULL
) {
188 *result
= kstrdup(new, GFP_KERNEL
);
192 /* Check if it is the last registered name */
193 if (match_last_lsm(*result
, new))
195 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *result
, new);
205 * security_module_enable - Load given security module on boot ?
206 * @module: the name of the module
207 * @stacked: indicates that the module wants to be stacked
209 * Each LSM must pass this method before registering its own operations
210 * to avoid security registration races. This method may also be used
211 * to check if your LSM is currently loaded during kernel initialization.
217 * - The passed LSM is the one chosen by user at boot time,
218 * - or the passed LSM is configured as the default and the user did not
219 * choose an alternate LSM at boot time.
221 * Otherwise, return false.
223 #ifdef CONFIG_SECURITY_STACKING
224 static bool __init
cmp_lsms(const char *lsm
)
226 const char *str
= chosen_lsms
;
228 int len
= strlen(lsm
);
230 if (len
> SECURITY_NAME_MAX
) {
231 pr_info("LSM: security module name '%s' exceeds limit\n", lsm
);
234 for (split
= strchr(str
, ','); split
; split
= strchr(str
, ',')) {
235 if ((len
== split
- str
) && !strncmp(lsm
, str
, split
- str
))
239 if ((len
== strlen(str
)) && !strncmp(lsm
, str
, strlen(str
)))
245 bool __init
security_module_enable(const char *lsm
, const bool stacked
)
247 #ifdef CONFIG_SECURITY_STACKING
249 * Module defined on the command line security=XXXX
251 if (strcmp(chosen_lsms
, MODULE_STACK
)) {
253 /* set to first LSM registered and then override */
254 if (!*default_display_lsm
)
255 strcpy(default_display_lsm
, lsm
);
256 else if (*chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
257 strcpy(default_display_lsm
, lsm
);
258 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
265 * Module configured as stacked.
267 if (stacked
&& !*default_display_lsm
)
268 strcpy(default_display_lsm
, lsm
);
269 else if (stacked
&& *chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
270 strcpy(default_display_lsm
, lsm
);
271 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
276 if (strcmp(lsm
, chosen_lsms
) == 0) {
277 strcpy(default_display_lsm
, lsm
);
285 * Keep the order of major modules for mapping secids.
287 static int lsm_next_major
;
290 * security_add_hooks - Add a modules hooks to the hook lists.
291 * @hooks: the hooks to add
292 * @count: the number of hooks to add
293 * @lsm: the name of the security module
295 * Each LSM has to register its hooks with the infrastructure.
297 void __init
security_add_hooks(struct security_hook_list
*hooks
, int count
,
301 int lsm_index
= lsm_next_major
++;
303 #ifdef CONFIG_SECURITY_LSM_DEBUG
304 pr_info("LSM: Security module %s gets index %d\n", lsm
, lsm_index
);
306 for (i
= 0; i
< count
; i
++) {
308 hooks
[i
].lsm_index
= lsm_index
;
309 list_add_tail_rcu(&hooks
[i
].list
, hooks
[i
].head
);
311 if (lsm_append(lsm
, &lsm_names
) < 0)
312 panic("%s - Cannot get early memory.\n", __func__
);
315 int call_lsm_notifier(enum lsm_event event
, void *data
)
317 return atomic_notifier_call_chain(&lsm_notifier_chain
, event
, data
);
319 EXPORT_SYMBOL(call_lsm_notifier
);
321 int register_lsm_notifier(struct notifier_block
*nb
)
323 return atomic_notifier_chain_register(&lsm_notifier_chain
, nb
);
325 EXPORT_SYMBOL(register_lsm_notifier
);
327 int unregister_lsm_notifier(struct notifier_block
*nb
)
329 return atomic_notifier_chain_unregister(&lsm_notifier_chain
, nb
);
331 EXPORT_SYMBOL(unregister_lsm_notifier
);
334 * lsm_cred_alloc - allocate a composite cred blob
335 * @cred: the cred that needs a blob
336 * @gfp: allocation type
338 * Allocate the cred blob for all the modules
340 * Returns 0, or -ENOMEM if memory can't be allocated.
342 int lsm_cred_alloc(struct cred
*cred
, gfp_t gfp
)
344 if (blob_sizes
.lbs_cred
== 0) {
345 cred
->security
= NULL
;
349 cred
->security
= kzalloc(blob_sizes
.lbs_cred
, gfp
);
350 if (cred
->security
== NULL
)
356 * lsm_early_cred - during initialization allocate a composite cred blob
357 * @cred: the cred that needs a blob
359 * Allocate the cred blob for all the modules if it's not already there
361 void lsm_early_cred(struct cred
*cred
)
366 panic("%s: NULL cred.\n", __func__
);
367 if (cred
->security
!= NULL
)
369 rc
= lsm_cred_alloc(cred
, GFP_KERNEL
);
371 panic("%s: Early cred alloc failed.\n", __func__
);
374 static void __init
lsm_set_size(int *need
, int *lbs
)
386 * security_add_blobs - Report blob sizes
387 * @needed: the size of blobs needed by the module
389 * Each LSM has to register its blobs with the infrastructure.
390 * The "needed" data tells the infrastructure how much memory
391 * the module requires for each of its blobs. On return the
392 * structure is filled with the offset that module should use
393 * from the blob pointer.
395 void __init
security_add_blobs(struct lsm_blob_sizes
*needed
)
397 lsm_set_size(&needed
->lbs_cred
, &blob_sizes
.lbs_cred
);
398 lsm_set_size(&needed
->lbs_file
, &blob_sizes
.lbs_file
);
399 lsm_set_size(&needed
->lbs_ipc
, &blob_sizes
.lbs_ipc
);
400 lsm_set_size(&needed
->lbs_key
, &blob_sizes
.lbs_key
);
401 lsm_set_size(&needed
->lbs_msg_msg
, &blob_sizes
.lbs_msg_msg
);
402 lsm_set_size(&needed
->lbs_sock
, &blob_sizes
.lbs_sock
);
403 lsm_set_size(&needed
->lbs_superblock
, &blob_sizes
.lbs_superblock
);
404 lsm_set_size(&needed
->lbs_task
, &blob_sizes
.lbs_task
);
406 * The inode blob gets an rcu_head in addition to
407 * what the modules might need.
409 if (needed
->lbs_inode
&& blob_sizes
.lbs_inode
== 0)
410 blob_sizes
.lbs_inode
= sizeof(struct rcu_head
);
411 lsm_set_size(&needed
->lbs_inode
, &blob_sizes
.lbs_inode
);
415 * lsm_file_alloc - allocate a composite file blob
416 * @file: the file that needs a blob
418 * Allocate the file blob for all the modules
420 * Returns 0, or -ENOMEM if memory can't be allocated.
422 int lsm_file_alloc(struct file
*file
)
424 if (!lsm_file_cache
) {
425 file
->f_security
= NULL
;
429 file
->f_security
= kmem_cache_zalloc(lsm_file_cache
, GFP_KERNEL
);
430 if (file
->f_security
== NULL
)
435 #ifdef CONFIG_SECURITY_STACKING
436 static inline char *lsm_of_task(struct task_struct
*task
)
438 #ifdef CONFIG_SECURITY_LSM_DEBUG
439 if (task
->security
== NULL
)
440 pr_info("%s: task has no lsm name.\n", __func__
);
442 return task
->security
;
447 * lsm_task_alloc - allocate a composite task blob
448 * @task: the task that needs a blob
450 * Allocate the task blob for all the modules
452 * Returns 0, or -ENOMEM if memory can't be allocated.
454 int lsm_task_alloc(struct task_struct
*task
)
456 if (blob_sizes
.lbs_task
== 0) {
457 task
->security
= NULL
;
461 task
->security
= kzalloc(blob_sizes
.lbs_task
, GFP_KERNEL
);
462 if (task
->security
== NULL
)
465 /* inherit current display lsm */
466 #ifdef CONFIG_SECURITY_STACKING
467 if (current
->security
)
468 strcpy(task
->security
, lsm_of_task(current
));
470 strcpy(task
->security
, default_display_lsm
);
476 * lsm_inode_alloc - allocate a composite inode blob
477 * @inode: the inode that needs a blob
479 * Allocate the inode blob for all the modules
481 * Returns 0, or -ENOMEM if memory can't be allocated.
483 int lsm_inode_alloc(struct inode
*inode
)
485 if (!lsm_inode_cache
) {
486 inode
->i_security
= NULL
;
490 inode
->i_security
= kmem_cache_zalloc(lsm_inode_cache
, GFP_KERNEL
);
491 if (inode
->i_security
== NULL
)
497 * lsm_early_inode - during initialization allocate a composite inode blob
498 * @inode: the inode that needs a blob
500 * Allocate the inode blob for all the modules if it's not already there
502 void lsm_early_inode(struct inode
*inode
)
507 panic("%s: NULL inode.\n", __func__
);
508 if (inode
->i_security
!= NULL
)
510 rc
= lsm_inode_alloc(inode
);
512 panic("%s: Early inode alloc failed.\n", __func__
);
516 * lsm_ipc_alloc - allocate a composite ipc blob
517 * @kip: the ipc that needs a blob
519 * Allocate the ipc blob for all the modules
521 * Returns 0, or -ENOMEM if memory can't be allocated.
523 int lsm_ipc_alloc(struct kern_ipc_perm
*kip
)
525 if (blob_sizes
.lbs_ipc
== 0) {
526 kip
->security
= NULL
;
530 kip
->security
= kzalloc(blob_sizes
.lbs_ipc
, GFP_KERNEL
);
531 if (kip
->security
== NULL
)
538 * lsm_key_alloc - allocate a composite key blob
539 * @key: the key that needs a blob
541 * Allocate the key blob for all the modules
543 * Returns 0, or -ENOMEM if memory can't be allocated.
545 int lsm_key_alloc(struct key
*key
)
547 if (blob_sizes
.lbs_key
== 0) {
548 key
->security
= NULL
;
552 key
->security
= kzalloc(blob_sizes
.lbs_key
, GFP_KERNEL
);
553 if (key
->security
== NULL
)
557 #endif /* CONFIG_KEYS */
560 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
561 * @mp: the msg_msg that needs a blob
563 * Allocate the ipc blob for all the modules
565 * Returns 0, or -ENOMEM if memory can't be allocated.
567 int lsm_msg_msg_alloc(struct msg_msg
*mp
)
569 if (blob_sizes
.lbs_msg_msg
== 0) {
574 mp
->security
= kzalloc(blob_sizes
.lbs_msg_msg
, GFP_KERNEL
);
575 if (mp
->security
== NULL
)
581 * lsm_sock_alloc - allocate a composite sock blob
582 * @sock: the sock that needs a blob
583 * @priority: allocation mode
585 * Allocate the sock blob for all the modules
587 * Returns 0, or -ENOMEM if memory can't be allocated.
589 int lsm_sock_alloc(struct sock
*sock
, gfp_t priority
)
591 if (blob_sizes
.lbs_sock
== 0) {
592 sock
->sk_security
= NULL
;
596 sock
->sk_security
= kzalloc(blob_sizes
.lbs_sock
, priority
);
597 if (sock
->sk_security
== NULL
)
603 * lsm_superblock_alloc - allocate a composite superblock blob
604 * @sb: the superblock that needs a blob
606 * Allocate the superblock blob for all the modules
608 * Returns 0, or -ENOMEM if memory can't be allocated.
610 int lsm_superblock_alloc(struct super_block
*sb
)
612 if (blob_sizes
.lbs_superblock
== 0) {
613 sb
->s_security
= NULL
;
617 sb
->s_security
= kzalloc(blob_sizes
.lbs_superblock
, GFP_KERNEL
);
618 if (sb
->s_security
== NULL
)
624 * Hook list operation macros.
627 * This is a hook that does not return a value.
630 * This is a hook that returns a value.
633 #define call_void_hook(FUNC, ...) \
635 struct security_hook_list *P; \
637 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
638 P->hook.FUNC(__VA_ARGS__); \
641 #define call_int_hook(FUNC, IRC, ...) ({ \
644 struct security_hook_list *P; \
646 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
647 RC = P->hook.FUNC(__VA_ARGS__); \
655 /* Security operations */
657 int security_binder_set_context_mgr(struct task_struct
*mgr
)
659 return call_int_hook(binder_set_context_mgr
, 0, mgr
);
662 int security_binder_transaction(struct task_struct
*from
,
663 struct task_struct
*to
)
665 return call_int_hook(binder_transaction
, 0, from
, to
);
668 int security_binder_transfer_binder(struct task_struct
*from
,
669 struct task_struct
*to
)
671 return call_int_hook(binder_transfer_binder
, 0, from
, to
);
674 int security_binder_transfer_file(struct task_struct
*from
,
675 struct task_struct
*to
, struct file
*file
)
677 return call_int_hook(binder_transfer_file
, 0, from
, to
, file
);
680 int security_ptrace_access_check(struct task_struct
*child
, unsigned int mode
)
682 return call_int_hook(ptrace_access_check
, 0, child
, mode
);
685 int security_ptrace_traceme(struct task_struct
*parent
)
687 return call_int_hook(ptrace_traceme
, 0, parent
);
690 int security_capget(struct task_struct
*target
,
691 kernel_cap_t
*effective
,
692 kernel_cap_t
*inheritable
,
693 kernel_cap_t
*permitted
)
695 return call_int_hook(capget
, 0, target
,
696 effective
, inheritable
, permitted
);
699 int security_capset(struct cred
*new, const struct cred
*old
,
700 const kernel_cap_t
*effective
,
701 const kernel_cap_t
*inheritable
,
702 const kernel_cap_t
*permitted
)
704 return call_int_hook(capset
, 0, new, old
,
705 effective
, inheritable
, permitted
);
708 int security_capable(const struct cred
*cred
, struct user_namespace
*ns
,
711 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_AUDIT
);
714 int security_capable_noaudit(const struct cred
*cred
, struct user_namespace
*ns
,
717 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_NOAUDIT
);
720 int security_quotactl(int cmds
, int type
, int id
, struct super_block
*sb
)
722 return call_int_hook(quotactl
, 0, cmds
, type
, id
, sb
);
725 int security_quota_on(struct dentry
*dentry
)
727 return call_int_hook(quota_on
, 0, dentry
);
730 int security_syslog(int type
)
732 return call_int_hook(syslog
, 0, type
);
735 int security_settime64(const struct timespec64
*ts
, const struct timezone
*tz
)
737 return call_int_hook(settime
, 0, ts
, tz
);
740 int security_vm_enough_memory_mm(struct mm_struct
*mm
, long pages
)
742 struct security_hook_list
*hp
;
743 int cap_sys_admin
= 1;
747 * The module will respond with a positive value if
748 * it thinks the __vm_enough_memory() call should be
749 * made with the cap_sys_admin set. If all of the modules
750 * agree that it should be set it will. If any module
751 * thinks it should not be set it won't.
753 list_for_each_entry(hp
, &security_hook_heads
.vm_enough_memory
, list
) {
754 rc
= hp
->hook
.vm_enough_memory(mm
, pages
);
760 return __vm_enough_memory(mm
, pages
, cap_sys_admin
);
763 int security_bprm_set_creds(struct linux_binprm
*bprm
)
765 return call_int_hook(bprm_set_creds
, 0, bprm
);
768 int security_bprm_check(struct linux_binprm
*bprm
)
772 ret
= call_int_hook(bprm_check_security
, 0, bprm
);
775 return ima_bprm_check(bprm
);
778 void security_bprm_committing_creds(struct linux_binprm
*bprm
)
780 call_void_hook(bprm_committing_creds
, bprm
);
783 void security_bprm_committed_creds(struct linux_binprm
*bprm
)
785 call_void_hook(bprm_committed_creds
, bprm
);
788 int security_sb_alloc(struct super_block
*sb
)
790 int rc
= lsm_superblock_alloc(sb
);
794 rc
= call_int_hook(sb_alloc_security
, 0, sb
);
796 security_sb_free(sb
);
800 void security_sb_free(struct super_block
*sb
)
802 call_void_hook(sb_free_security
, sb
);
803 kfree(sb
->s_security
);
804 sb
->s_security
= NULL
;
807 int security_sb_copy_data(char *orig
, char *copy
)
809 return call_int_hook(sb_copy_data
, 0, orig
, copy
);
811 EXPORT_SYMBOL(security_sb_copy_data
);
813 int security_sb_remount(struct super_block
*sb
, void *data
)
815 return call_int_hook(sb_remount
, 0, sb
, data
);
818 int security_sb_kern_mount(struct super_block
*sb
, int flags
, void *data
)
820 return call_int_hook(sb_kern_mount
, 0, sb
, flags
, data
);
823 int security_sb_show_options(struct seq_file
*m
, struct super_block
*sb
)
825 return call_int_hook(sb_show_options
, 0, m
, sb
);
828 int security_sb_statfs(struct dentry
*dentry
)
830 return call_int_hook(sb_statfs
, 0, dentry
);
833 int security_sb_mount(const char *dev_name
, const struct path
*path
,
834 const char *type
, unsigned long flags
, void *data
)
836 return call_int_hook(sb_mount
, 0, dev_name
, path
, type
, flags
, data
);
839 int security_sb_umount(struct vfsmount
*mnt
, int flags
)
841 return call_int_hook(sb_umount
, 0, mnt
, flags
);
844 int security_sb_pivotroot(const struct path
*old_path
, const struct path
*new_path
)
846 return call_int_hook(sb_pivotroot
, 0, old_path
, new_path
);
849 int security_sb_set_mnt_opts(struct super_block
*sb
,
850 struct security_mnt_opts
*opts
,
851 unsigned long kern_flags
,
852 unsigned long *set_kern_flags
)
854 return call_int_hook(sb_set_mnt_opts
,
855 opts
->num_mnt_opts
? -EOPNOTSUPP
: 0, sb
,
856 opts
, kern_flags
, set_kern_flags
);
858 EXPORT_SYMBOL(security_sb_set_mnt_opts
);
860 int security_sb_clone_mnt_opts(const struct super_block
*oldsb
,
861 struct super_block
*newsb
,
862 unsigned long kern_flags
,
863 unsigned long *set_kern_flags
)
865 return call_int_hook(sb_clone_mnt_opts
, 0, oldsb
, newsb
,
866 kern_flags
, set_kern_flags
);
868 EXPORT_SYMBOL(security_sb_clone_mnt_opts
);
870 int security_sb_parse_opts_str(char *options
, struct security_mnt_opts
*opts
)
872 return call_int_hook(sb_parse_opts_str
, 0, options
, opts
);
874 EXPORT_SYMBOL(security_sb_parse_opts_str
);
876 int security_inode_alloc(struct inode
*inode
)
878 int rc
= lsm_inode_alloc(inode
);
882 rc
= call_int_hook(inode_alloc_security
, 0, inode
);
884 security_inode_free(inode
);
888 static void inode_free_by_rcu(struct rcu_head
*head
)
891 * The rcu head is at the start of the inode blob
893 kmem_cache_free(lsm_inode_cache
, head
);
896 void security_inode_free(struct inode
*inode
)
898 integrity_inode_free(inode
);
899 call_void_hook(inode_free_security
, inode
);
901 * The inode may still be referenced in a path walk and
902 * a call to security_inode_permission() can be made
903 * after inode_free_security() is called. Ideally, the VFS
904 * wouldn't do this, but fixing that is a much harder
905 * job. For now, simply free the i_security via RCU, and
906 * leave the current inode->i_security pointer intact.
907 * The inode will be freed after the RCU grace period too.
909 if (inode
->i_security
)
910 call_rcu((struct rcu_head
*)inode
->i_security
,
914 int security_dentry_init_security(struct dentry
*dentry
, int mode
,
915 const struct qstr
*name
, void **ctx
,
918 return call_int_hook(dentry_init_security
, -EOPNOTSUPP
, dentry
, mode
,
921 EXPORT_SYMBOL(security_dentry_init_security
);
923 int security_dentry_create_files_as(struct dentry
*dentry
, int mode
,
925 const struct cred
*old
, struct cred
*new)
927 return call_int_hook(dentry_create_files_as
, 0, dentry
, mode
,
930 EXPORT_SYMBOL(security_dentry_create_files_as
);
932 int security_inode_init_security(struct inode
*inode
, struct inode
*dir
,
933 const struct qstr
*qstr
,
934 const initxattrs initxattrs
, void *fs_data
)
936 struct xattr new_xattrs
[MAX_LSM_EVM_XATTR
+ 1];
937 struct xattr
*lsm_xattr
, *evm_xattr
, *xattr
;
940 if (unlikely(IS_PRIVATE(inode
)))
944 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
,
945 dir
, qstr
, NULL
, NULL
, NULL
);
946 memset(new_xattrs
, 0, sizeof(new_xattrs
));
947 lsm_xattr
= new_xattrs
;
948 ret
= call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
, qstr
,
951 &lsm_xattr
->value_len
);
955 evm_xattr
= lsm_xattr
+ 1;
956 ret
= evm_inode_init_security(inode
, lsm_xattr
, evm_xattr
);
959 ret
= initxattrs(inode
, new_xattrs
, fs_data
);
961 for (xattr
= new_xattrs
; xattr
->value
!= NULL
; xattr
++)
963 return (ret
== -EOPNOTSUPP
) ? 0 : ret
;
965 EXPORT_SYMBOL(security_inode_init_security
);
967 int security_old_inode_init_security(struct inode
*inode
, struct inode
*dir
,
968 const struct qstr
*qstr
, const char **name
,
969 void **value
, size_t *len
)
971 if (unlikely(IS_PRIVATE(inode
)))
973 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
,
974 qstr
, name
, value
, len
);
976 EXPORT_SYMBOL(security_old_inode_init_security
);
978 #ifdef CONFIG_SECURITY_PATH
979 int security_path_mknod(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
,
982 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
984 return call_int_hook(path_mknod
, 0, dir
, dentry
, mode
, dev
);
986 EXPORT_SYMBOL(security_path_mknod
);
988 int security_path_mkdir(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
)
990 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
992 return call_int_hook(path_mkdir
, 0, dir
, dentry
, mode
);
994 EXPORT_SYMBOL(security_path_mkdir
);
996 int security_path_rmdir(const struct path
*dir
, struct dentry
*dentry
)
998 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1000 return call_int_hook(path_rmdir
, 0, dir
, dentry
);
1002 EXPORT_SYMBOL_GPL(security_path_rmdir
);
1004 int security_path_unlink(const struct path
*dir
, struct dentry
*dentry
)
1006 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1008 return call_int_hook(path_unlink
, 0, dir
, dentry
);
1010 EXPORT_SYMBOL(security_path_unlink
);
1012 int security_path_symlink(const struct path
*dir
, struct dentry
*dentry
,
1013 const char *old_name
)
1015 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1017 return call_int_hook(path_symlink
, 0, dir
, dentry
, old_name
);
1019 EXPORT_SYMBOL_GPL(security_path_symlink
);
1021 int security_path_link(struct dentry
*old_dentry
, const struct path
*new_dir
,
1022 struct dentry
*new_dentry
)
1024 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1026 return call_int_hook(path_link
, 0, old_dentry
, new_dir
, new_dentry
);
1028 EXPORT_SYMBOL_GPL(security_path_link
);
1030 int security_path_rename(const struct path
*old_dir
, struct dentry
*old_dentry
,
1031 const struct path
*new_dir
, struct dentry
*new_dentry
,
1034 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1035 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1038 if (flags
& RENAME_EXCHANGE
) {
1039 int err
= call_int_hook(path_rename
, 0, new_dir
, new_dentry
,
1040 old_dir
, old_dentry
);
1045 return call_int_hook(path_rename
, 0, old_dir
, old_dentry
, new_dir
,
1048 EXPORT_SYMBOL(security_path_rename
);
1050 int security_path_truncate(const struct path
*path
)
1052 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1054 return call_int_hook(path_truncate
, 0, path
);
1056 EXPORT_SYMBOL_GPL(security_path_truncate
);
1058 int security_path_chmod(const struct path
*path
, umode_t mode
)
1060 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1062 return call_int_hook(path_chmod
, 0, path
, mode
);
1064 EXPORT_SYMBOL_GPL(security_path_chmod
);
1066 int security_path_chown(const struct path
*path
, kuid_t uid
, kgid_t gid
)
1068 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1070 return call_int_hook(path_chown
, 0, path
, uid
, gid
);
1072 EXPORT_SYMBOL_GPL(security_path_chown
);
1074 int security_path_chroot(const struct path
*path
)
1076 return call_int_hook(path_chroot
, 0, path
);
1080 int security_inode_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1082 if (unlikely(IS_PRIVATE(dir
)))
1084 return call_int_hook(inode_create
, 0, dir
, dentry
, mode
);
1086 EXPORT_SYMBOL_GPL(security_inode_create
);
1088 int security_inode_link(struct dentry
*old_dentry
, struct inode
*dir
,
1089 struct dentry
*new_dentry
)
1091 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1093 return call_int_hook(inode_link
, 0, old_dentry
, dir
, new_dentry
);
1096 int security_inode_unlink(struct inode
*dir
, struct dentry
*dentry
)
1098 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1100 return call_int_hook(inode_unlink
, 0, dir
, dentry
);
1103 int security_inode_symlink(struct inode
*dir
, struct dentry
*dentry
,
1104 const char *old_name
)
1106 if (unlikely(IS_PRIVATE(dir
)))
1108 return call_int_hook(inode_symlink
, 0, dir
, dentry
, old_name
);
1111 int security_inode_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1113 if (unlikely(IS_PRIVATE(dir
)))
1115 return call_int_hook(inode_mkdir
, 0, dir
, dentry
, mode
);
1117 EXPORT_SYMBOL_GPL(security_inode_mkdir
);
1119 int security_inode_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1121 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1123 return call_int_hook(inode_rmdir
, 0, dir
, dentry
);
1126 int security_inode_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
, dev_t dev
)
1128 if (unlikely(IS_PRIVATE(dir
)))
1130 return call_int_hook(inode_mknod
, 0, dir
, dentry
, mode
, dev
);
1133 int security_inode_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1134 struct inode
*new_dir
, struct dentry
*new_dentry
,
1137 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1138 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1141 if (flags
& RENAME_EXCHANGE
) {
1142 int err
= call_int_hook(inode_rename
, 0, new_dir
, new_dentry
,
1143 old_dir
, old_dentry
);
1148 return call_int_hook(inode_rename
, 0, old_dir
, old_dentry
,
1149 new_dir
, new_dentry
);
1152 int security_inode_readlink(struct dentry
*dentry
)
1154 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1156 return call_int_hook(inode_readlink
, 0, dentry
);
1158 EXPORT_SYMBOL_GPL(security_inode_readlink
);
1160 int security_inode_follow_link(struct dentry
*dentry
, struct inode
*inode
,
1163 if (unlikely(IS_PRIVATE(inode
)))
1165 return call_int_hook(inode_follow_link
, 0, dentry
, inode
, rcu
);
1168 int security_inode_permission(struct inode
*inode
, int mask
)
1170 if (unlikely(IS_PRIVATE(inode
)))
1172 return call_int_hook(inode_permission
, 0, inode
, mask
);
1174 EXPORT_SYMBOL_GPL(security_inode_permission
);
1176 int security_inode_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1180 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1182 ret
= call_int_hook(inode_setattr
, 0, dentry
, attr
);
1185 return evm_inode_setattr(dentry
, attr
);
1187 EXPORT_SYMBOL_GPL(security_inode_setattr
);
1189 int security_inode_getattr(const struct path
*path
)
1191 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1193 return call_int_hook(inode_getattr
, 0, path
);
1196 int security_inode_setxattr(struct dentry
*dentry
, const char *name
,
1197 const void *value
, size_t size
, int flags
)
1201 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1204 * SELinux and Smack integrate the cap call,
1205 * so assume that all LSMs supplying this call do so.
1207 ret
= call_int_hook(inode_setxattr
, 1, dentry
, name
, value
, size
,
1211 ret
= cap_inode_setxattr(dentry
, name
, value
, size
, flags
);
1214 ret
= ima_inode_setxattr(dentry
, name
, value
, size
);
1217 return evm_inode_setxattr(dentry
, name
, value
, size
);
1220 void security_inode_post_setxattr(struct dentry
*dentry
, const char *name
,
1221 const void *value
, size_t size
, int flags
)
1223 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1225 call_void_hook(inode_post_setxattr
, dentry
, name
, value
, size
, flags
);
1226 evm_inode_post_setxattr(dentry
, name
, value
, size
);
1229 int security_inode_getxattr(struct dentry
*dentry
, const char *name
)
1231 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1233 return call_int_hook(inode_getxattr
, 0, dentry
, name
);
1236 int security_inode_listxattr(struct dentry
*dentry
)
1238 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1240 return call_int_hook(inode_listxattr
, 0, dentry
);
1243 int security_inode_removexattr(struct dentry
*dentry
, const char *name
)
1247 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1250 * SELinux and Smack integrate the cap call,
1251 * so assume that all LSMs supplying this call do so.
1253 ret
= call_int_hook(inode_removexattr
, 1, dentry
, name
);
1255 ret
= cap_inode_removexattr(dentry
, name
);
1258 ret
= ima_inode_removexattr(dentry
, name
);
1261 return evm_inode_removexattr(dentry
, name
);
1264 int security_inode_need_killpriv(struct dentry
*dentry
)
1266 return call_int_hook(inode_need_killpriv
, 0, dentry
);
1269 int security_inode_killpriv(struct dentry
*dentry
)
1271 return call_int_hook(inode_killpriv
, 0, dentry
);
1274 int security_inode_getsecurity(struct inode
*inode
, const char *name
, void **buffer
, bool alloc
)
1276 struct security_hook_list
*hp
;
1279 if (unlikely(IS_PRIVATE(inode
)))
1282 * Only one module will provide an attribute with a given name.
1284 list_for_each_entry(hp
, &security_hook_heads
.inode_getsecurity
, list
) {
1285 rc
= hp
->hook
.inode_getsecurity(inode
, name
, buffer
, alloc
);
1286 if (rc
!= -EOPNOTSUPP
)
1292 int security_inode_setsecurity(struct inode
*inode
, const char *name
, const void *value
, size_t size
, int flags
)
1294 struct security_hook_list
*hp
;
1297 if (unlikely(IS_PRIVATE(inode
)))
1300 * Only one module will provide an attribute with a given name.
1302 list_for_each_entry(hp
, &security_hook_heads
.inode_setsecurity
, list
) {
1303 rc
= hp
->hook
.inode_setsecurity(inode
, name
, value
, size
,
1305 if (rc
!= -EOPNOTSUPP
)
1311 int security_inode_listsecurity(struct inode
*inode
, char *buffer
, size_t buffer_size
)
1313 if (unlikely(IS_PRIVATE(inode
)))
1315 return call_int_hook(inode_listsecurity
, 0, inode
, buffer
, buffer_size
);
1317 EXPORT_SYMBOL(security_inode_listsecurity
);
1319 void security_inode_getsecid(struct inode
*inode
, u32
*secid
)
1321 call_void_hook(inode_getsecid
, inode
, secid
);
1324 int security_inode_copy_up(struct dentry
*src
, struct cred
**new)
1326 return call_int_hook(inode_copy_up
, 0, src
, new);
1328 EXPORT_SYMBOL(security_inode_copy_up
);
1330 int security_inode_copy_up_xattr(const char *name
)
1332 return call_int_hook(inode_copy_up_xattr
, -EOPNOTSUPP
, name
);
1334 EXPORT_SYMBOL(security_inode_copy_up_xattr
);
1336 int security_file_permission(struct file
*file
, int mask
)
1340 ret
= call_int_hook(file_permission
, 0, file
, mask
);
1344 return fsnotify_perm(file
, mask
);
1346 EXPORT_SYMBOL_GPL(security_file_permission
);
1348 int security_file_alloc(struct file
*file
)
1350 int rc
= lsm_file_alloc(file
);
1354 rc
= call_int_hook(file_alloc_security
, 0, file
);
1356 security_file_free(file
);
1360 void security_file_free(struct file
*file
)
1364 if (!lsm_file_cache
)
1367 call_void_hook(file_free_security
, file
);
1369 blob
= file
->f_security
;
1370 file
->f_security
= NULL
;
1371 kmem_cache_free(lsm_file_cache
, blob
);
1374 int security_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1376 return call_int_hook(file_ioctl
, 0, file
, cmd
, arg
);
1379 static inline unsigned long mmap_prot(struct file
*file
, unsigned long prot
)
1382 * Does we have PROT_READ and does the application expect
1383 * it to imply PROT_EXEC? If not, nothing to talk about...
1385 if ((prot
& (PROT_READ
| PROT_EXEC
)) != PROT_READ
)
1387 if (!(current
->personality
& READ_IMPLIES_EXEC
))
1390 * if that's an anonymous mapping, let it.
1393 return prot
| PROT_EXEC
;
1395 * ditto if it's not on noexec mount, except that on !MMU we need
1396 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
1398 if (!path_noexec(&file
->f_path
)) {
1400 if (file
->f_op
->mmap_capabilities
) {
1401 unsigned caps
= file
->f_op
->mmap_capabilities(file
);
1402 if (!(caps
& NOMMU_MAP_EXEC
))
1406 return prot
| PROT_EXEC
;
1408 /* anything on noexec mount won't get PROT_EXEC */
1412 int security_mmap_file(struct file
*file
, unsigned long prot
,
1413 unsigned long flags
)
1416 ret
= call_int_hook(mmap_file
, 0, file
, prot
,
1417 mmap_prot(file
, prot
), flags
);
1420 return ima_file_mmap(file
, prot
);
1422 EXPORT_SYMBOL_GPL(security_mmap_file
);
1424 int security_mmap_addr(unsigned long addr
)
1426 return call_int_hook(mmap_addr
, 0, addr
);
1429 int security_file_mprotect(struct vm_area_struct
*vma
, unsigned long reqprot
,
1432 return call_int_hook(file_mprotect
, 0, vma
, reqprot
, prot
);
1435 int security_file_lock(struct file
*file
, unsigned int cmd
)
1437 return call_int_hook(file_lock
, 0, file
, cmd
);
1440 int security_file_fcntl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1442 return call_int_hook(file_fcntl
, 0, file
, cmd
, arg
);
1445 void security_file_set_fowner(struct file
*file
)
1447 call_void_hook(file_set_fowner
, file
);
1450 int security_file_send_sigiotask(struct task_struct
*tsk
,
1451 struct fown_struct
*fown
, int sig
)
1453 return call_int_hook(file_send_sigiotask
, 0, tsk
, fown
, sig
);
1456 int security_file_receive(struct file
*file
)
1458 return call_int_hook(file_receive
, 0, file
);
1461 int security_file_open(struct file
*file
, const struct cred
*cred
)
1465 ret
= call_int_hook(file_open
, 0, file
, cred
);
1469 return fsnotify_perm(file
, MAY_OPEN
);
1472 int security_task_alloc(struct task_struct
*task
, unsigned long clone_flags
)
1474 int rc
= lsm_task_alloc(task
);
1478 rc
= call_int_hook(task_alloc
, 0, task
, clone_flags
);
1480 security_task_free(task
);
1484 void security_task_free(struct task_struct
*task
)
1486 call_void_hook(task_free
, task
);
1488 kfree(task
->security
);
1489 task
->security
= NULL
;
1492 int security_cred_alloc_blank(struct cred
*cred
, gfp_t gfp
)
1494 int rc
= lsm_cred_alloc(cred
, gfp
);
1499 rc
= call_int_hook(cred_alloc_blank
, 0, cred
, gfp
);
1501 security_cred_free(cred
);
1505 void security_cred_free(struct cred
*cred
)
1508 * There is a failure case in prepare_creds() that
1509 * may result in a call here with ->security being NULL.
1511 if (unlikely(cred
->security
== NULL
))
1514 call_void_hook(cred_free
, cred
);
1516 kfree(cred
->security
);
1517 cred
->security
= NULL
;
1520 int security_prepare_creds(struct cred
*new, const struct cred
*old
, gfp_t gfp
)
1522 int rc
= lsm_cred_alloc(new, gfp
);
1527 rc
= call_int_hook(cred_prepare
, 0, new, old
, gfp
);
1529 security_cred_free(new);
1533 void security_transfer_creds(struct cred
*new, const struct cred
*old
)
1535 call_void_hook(cred_transfer
, new, old
);
1538 int security_kernel_act_as(struct cred
*new, u32 secid
)
1540 return call_int_hook(kernel_act_as
, 0, new, secid
);
1543 int security_kernel_create_files_as(struct cred
*new, struct inode
*inode
)
1545 return call_int_hook(kernel_create_files_as
, 0, new, inode
);
1548 int security_kernel_module_request(char *kmod_name
)
1550 return call_int_hook(kernel_module_request
, 0, kmod_name
);
1553 int security_kernel_read_file(struct file
*file
, enum kernel_read_file_id id
)
1557 ret
= call_int_hook(kernel_read_file
, 0, file
, id
);
1560 return ima_read_file(file
, id
);
1562 EXPORT_SYMBOL_GPL(security_kernel_read_file
);
1564 int security_kernel_post_read_file(struct file
*file
, char *buf
, loff_t size
,
1565 enum kernel_read_file_id id
)
1569 ret
= call_int_hook(kernel_post_read_file
, 0, file
, buf
, size
, id
);
1572 return ima_post_read_file(file
, buf
, size
, id
);
1574 EXPORT_SYMBOL_GPL(security_kernel_post_read_file
);
1576 int security_task_fix_setuid(struct cred
*new, const struct cred
*old
,
1579 return call_int_hook(task_fix_setuid
, 0, new, old
, flags
);
1582 int security_task_setpgid(struct task_struct
*p
, pid_t pgid
)
1584 return call_int_hook(task_setpgid
, 0, p
, pgid
);
1587 int security_task_getpgid(struct task_struct
*p
)
1589 return call_int_hook(task_getpgid
, 0, p
);
1592 int security_task_getsid(struct task_struct
*p
)
1594 return call_int_hook(task_getsid
, 0, p
);
1597 void security_task_getsecid(struct task_struct
*p
, u32
*secid
)
1600 call_void_hook(task_getsecid
, p
, secid
);
1602 EXPORT_SYMBOL(security_task_getsecid
);
1604 int security_task_setnice(struct task_struct
*p
, int nice
)
1606 return call_int_hook(task_setnice
, 0, p
, nice
);
1609 int security_task_setioprio(struct task_struct
*p
, int ioprio
)
1611 return call_int_hook(task_setioprio
, 0, p
, ioprio
);
1614 int security_task_getioprio(struct task_struct
*p
)
1616 return call_int_hook(task_getioprio
, 0, p
);
1619 int security_task_prlimit(const struct cred
*cred
, const struct cred
*tcred
,
1622 return call_int_hook(task_prlimit
, 0, cred
, tcred
, flags
);
1625 int security_task_setrlimit(struct task_struct
*p
, unsigned int resource
,
1626 struct rlimit
*new_rlim
)
1628 return call_int_hook(task_setrlimit
, 0, p
, resource
, new_rlim
);
1631 int security_task_setscheduler(struct task_struct
*p
)
1633 return call_int_hook(task_setscheduler
, 0, p
);
1636 int security_task_getscheduler(struct task_struct
*p
)
1638 return call_int_hook(task_getscheduler
, 0, p
);
1641 int security_task_movememory(struct task_struct
*p
)
1643 return call_int_hook(task_movememory
, 0, p
);
1646 int security_task_kill(struct task_struct
*p
, struct siginfo
*info
,
1649 return call_int_hook(task_kill
, 0, p
, info
, sig
, secid
);
1652 #ifdef CONFIG_SECURITY_STACKING
1653 static char *nolsm
= "-default";
1656 static bool is_registered_lsm(const char *str
, size_t size
)
1658 struct security_hook_list
*hp
;
1660 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1661 if (size
== strlen(hp
->lsm
) && !strncmp(str
, hp
->lsm
, size
))
1668 static bool set_lsm_of_current(const char *str
, size_t size
)
1670 char *lsm
= lsm_of_task(current
);
1672 if (is_registered_lsm(str
, size
)) {
1673 strncpy(lsm
, str
, size
);
1675 } else if (size
== NOLSMLEN
&& !strncmp(str
, nolsm
, size
)) {
1683 static int lsm_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1684 unsigned long arg4
, unsigned long arg5
)
1686 char *lsm
= lsm_of_task(current
);
1687 char buffer
[SECURITY_NAME_MAX
+ 1];
1688 __user
char *optval
= (__user
char *)arg2
;
1689 __user
int *optlen
= (__user
int *)arg3
;
1694 case PR_GET_DISPLAY_LSM
:
1696 if (lsm
[0] == '\0') {
1700 dlen
= strlen(lsm
) + 1;
1703 if (copy_to_user(optval
, lsm
, dlen
))
1705 if (put_user(dlen
, optlen
))
1708 case PR_SET_DISPLAY_LSM
:
1710 if (len
> SECURITY_NAME_MAX
)
1712 if (copy_from_user(buffer
, optval
, len
))
1715 /* verify the requested LSM is registered */
1716 if (!set_lsm_of_current(buffer
, len
))
1726 int security_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1727 unsigned long arg4
, unsigned long arg5
)
1731 struct security_hook_list
*hp
;
1733 #ifdef CONFIG_SECURITY_STACKING
1734 rc
= lsm_task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1739 list_for_each_entry(hp
, &security_hook_heads
.task_prctl
, list
) {
1740 thisrc
= hp
->hook
.task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1741 if (thisrc
!= -ENOSYS
) {
1750 void security_task_to_inode(struct task_struct
*p
, struct inode
*inode
)
1752 call_void_hook(task_to_inode
, p
, inode
);
1755 int security_ipc_permission(struct kern_ipc_perm
*ipcp
, short flag
)
1757 return call_int_hook(ipc_permission
, 0, ipcp
, flag
);
1760 void security_ipc_getsecid(struct kern_ipc_perm
*ipcp
, u32
*secid
)
1763 call_void_hook(ipc_getsecid
, ipcp
, secid
);
1766 int security_msg_msg_alloc(struct msg_msg
*msg
)
1768 int rc
= lsm_msg_msg_alloc(msg
);
1772 rc
= call_int_hook(msg_msg_alloc_security
, 0, msg
);
1774 security_msg_msg_free(msg
);
1778 void security_msg_msg_free(struct msg_msg
*msg
)
1780 call_void_hook(msg_msg_free_security
, msg
);
1781 kfree(msg
->security
);
1782 msg
->security
= NULL
;
1785 int security_msg_queue_alloc(struct msg_queue
*msq
)
1787 int rc
= lsm_ipc_alloc(&msq
->q_perm
);
1791 rc
= call_int_hook(msg_queue_alloc_security
, 0, msq
);
1793 security_msg_queue_free(msq
);
1797 void security_msg_queue_free(struct msg_queue
*msq
)
1799 struct kern_ipc_perm
*kip
= &msq
->q_perm
;
1801 call_void_hook(msg_queue_free_security
, msq
);
1802 kfree(kip
->security
);
1803 kip
->security
= NULL
;
1806 int security_msg_queue_associate(struct msg_queue
*msq
, int msqflg
)
1808 return call_int_hook(msg_queue_associate
, 0, msq
, msqflg
);
1811 int security_msg_queue_msgctl(struct msg_queue
*msq
, int cmd
)
1813 return call_int_hook(msg_queue_msgctl
, 0, msq
, cmd
);
1816 int security_msg_queue_msgsnd(struct msg_queue
*msq
,
1817 struct msg_msg
*msg
, int msqflg
)
1819 return call_int_hook(msg_queue_msgsnd
, 0, msq
, msg
, msqflg
);
1822 int security_msg_queue_msgrcv(struct msg_queue
*msq
, struct msg_msg
*msg
,
1823 struct task_struct
*target
, long type
, int mode
)
1825 return call_int_hook(msg_queue_msgrcv
, 0, msq
, msg
, target
, type
, mode
);
1828 int security_shm_alloc(struct shmid_kernel
*shp
)
1830 int rc
= lsm_ipc_alloc(&shp
->shm_perm
);
1834 rc
= call_int_hook(shm_alloc_security
, 0, shp
);
1836 security_shm_free(shp
);
1840 void security_shm_free(struct shmid_kernel
*shp
)
1842 struct kern_ipc_perm
*kip
= &shp
->shm_perm
;
1844 call_void_hook(shm_free_security
, shp
);
1845 kfree(kip
->security
);
1846 kip
->security
= NULL
;
1849 int security_shm_associate(struct shmid_kernel
*shp
, int shmflg
)
1851 return call_int_hook(shm_associate
, 0, shp
, shmflg
);
1854 int security_shm_shmctl(struct shmid_kernel
*shp
, int cmd
)
1856 return call_int_hook(shm_shmctl
, 0, shp
, cmd
);
1859 int security_shm_shmat(struct shmid_kernel
*shp
, char __user
*shmaddr
, int shmflg
)
1861 return call_int_hook(shm_shmat
, 0, shp
, shmaddr
, shmflg
);
1864 int security_sem_alloc(struct sem_array
*sma
)
1866 int rc
= lsm_ipc_alloc(&sma
->sem_perm
);
1870 rc
= call_int_hook(sem_alloc_security
, 0, sma
);
1872 security_sem_free(sma
);
1876 void security_sem_free(struct sem_array
*sma
)
1878 struct kern_ipc_perm
*kip
= &sma
->sem_perm
;
1880 call_void_hook(sem_free_security
, sma
);
1881 kfree(kip
->security
);
1882 kip
->security
= NULL
;
1885 int security_sem_associate(struct sem_array
*sma
, int semflg
)
1887 return call_int_hook(sem_associate
, 0, sma
, semflg
);
1890 int security_sem_semctl(struct sem_array
*sma
, int cmd
)
1892 return call_int_hook(sem_semctl
, 0, sma
, cmd
);
1895 int security_sem_semop(struct sem_array
*sma
, struct sembuf
*sops
,
1896 unsigned nsops
, int alter
)
1898 return call_int_hook(sem_semop
, 0, sma
, sops
, nsops
, alter
);
1901 void security_d_instantiate(struct dentry
*dentry
, struct inode
*inode
)
1903 if (unlikely(inode
&& IS_PRIVATE(inode
)))
1905 call_void_hook(d_instantiate
, dentry
, inode
);
1907 EXPORT_SYMBOL(security_d_instantiate
);
1909 int security_getprocattr(struct task_struct
*p
, const char *lsm
, char *name
,
1912 #ifdef CONFIG_SECURITY_STACKING
1913 char *speclsm
= lsm_of_task(p
);
1915 struct security_hook_list
*hp
;
1918 if (strcmp(name
, "display_lsm") == 0) {
1919 *value
= kstrdup(current
->security
, GFP_KERNEL
);
1922 return strlen(*value
);
1925 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1926 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1928 #ifdef CONFIG_SECURITY_STACKING
1929 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
1932 rc
= hp
->hook
.getprocattr(p
, name
, value
);
1939 int security_setprocattr(const char *lsm
, const char *name
, void *value
,
1942 #ifdef CONFIG_SECURITY_STACKING
1943 char *speclsm
= lsm_of_task(current
);
1947 struct security_hook_list
*hp
;
1953 if (strcmp(name
, "display_lsm") == 0) {
1954 #ifdef CONFIG_SECURITY_STACKING
1955 if (set_lsm_of_current(value
, size
))
1961 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
, list
) {
1962 #ifdef CONFIG_SECURITY_STACKING
1963 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
1966 rc
= hp
->hook
.setprocattr(name
, value
, size
);
1973 int security_netlink_send(struct sock
*sk
, struct sk_buff
*skb
)
1975 return call_int_hook(netlink_send
, 0, sk
, skb
);
1978 int security_ismaclabel(const char *name
)
1980 return call_int_hook(ismaclabel
, 0, name
);
1982 EXPORT_SYMBOL(security_ismaclabel
);
1984 int security_secid_to_secctx(u32 secid
, char **secdata
, u32
*seclen
)
1986 return call_int_hook(secid_to_secctx
, -EOPNOTSUPP
, secid
, secdata
,
1989 EXPORT_SYMBOL(security_secid_to_secctx
);
1991 int security_secctx_to_secid(const char *secdata
, u32 seclen
, u32
*secid
)
1994 return call_int_hook(secctx_to_secid
, 0, secdata
, seclen
, secid
);
1996 EXPORT_SYMBOL(security_secctx_to_secid
);
1998 void security_release_secctx(char *secdata
, u32 seclen
)
2000 #ifdef CONFIG_SECURITY_STACKING
2001 char *speclsm
= lsm_of_task(current
);
2003 struct security_hook_list
*hp
;
2005 list_for_each_entry(hp
, &security_hook_heads
.release_secctx
, list
) {
2006 #ifdef CONFIG_SECURITY_STACKING
2007 if (speclsm
[0] && strcmp(hp
->lsm
, speclsm
))
2010 hp
->hook
.release_secctx(secdata
, seclen
);
2014 EXPORT_SYMBOL(security_release_secctx
);
2016 void security_inode_invalidate_secctx(struct inode
*inode
)
2018 call_void_hook(inode_invalidate_secctx
, inode
);
2020 EXPORT_SYMBOL(security_inode_invalidate_secctx
);
2022 int security_inode_notifysecctx(struct inode
*inode
, void *ctx
, u32 ctxlen
)
2024 return call_int_hook(inode_notifysecctx
, 0, inode
, ctx
, ctxlen
);
2026 EXPORT_SYMBOL(security_inode_notifysecctx
);
2028 int security_inode_setsecctx(struct dentry
*dentry
, void *ctx
, u32 ctxlen
)
2030 return call_int_hook(inode_setsecctx
, 0, dentry
, ctx
, ctxlen
);
2032 EXPORT_SYMBOL(security_inode_setsecctx
);
2034 int security_inode_getsecctx(struct inode
*inode
, void **ctx
, u32
*ctxlen
)
2036 return call_int_hook(inode_getsecctx
, -EOPNOTSUPP
, inode
, ctx
, ctxlen
);
2038 EXPORT_SYMBOL(security_inode_getsecctx
);
2040 #ifdef CONFIG_SECURITY_NETWORK
2042 int security_unix_stream_connect(struct sock
*sock
, struct sock
*other
, struct sock
*newsk
)
2044 return call_int_hook(unix_stream_connect
, 0, sock
, other
, newsk
);
2046 EXPORT_SYMBOL(security_unix_stream_connect
);
2048 int security_unix_may_send(struct socket
*sock
, struct socket
*other
)
2050 return call_int_hook(unix_may_send
, 0, sock
, other
);
2052 EXPORT_SYMBOL(security_unix_may_send
);
2054 int security_socket_create(int family
, int type
, int protocol
, int kern
)
2056 return call_int_hook(socket_create
, 0, family
, type
, protocol
, kern
);
2059 int security_socket_post_create(struct socket
*sock
, int family
,
2060 int type
, int protocol
, int kern
)
2062 return call_int_hook(socket_post_create
, 0, sock
, family
, type
,
2066 int security_socket_bind(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2068 return call_int_hook(socket_bind
, 0, sock
, address
, addrlen
);
2071 int security_socket_connect(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2073 return call_int_hook(socket_connect
, 0, sock
, address
, addrlen
);
2076 int security_socket_listen(struct socket
*sock
, int backlog
)
2078 return call_int_hook(socket_listen
, 0, sock
, backlog
);
2081 int security_socket_accept(struct socket
*sock
, struct socket
*newsock
)
2083 return call_int_hook(socket_accept
, 0, sock
, newsock
);
2086 int security_socket_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
)
2088 return call_int_hook(socket_sendmsg
, 0, sock
, msg
, size
);
2091 int security_socket_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
2092 int size
, int flags
)
2094 return call_int_hook(socket_recvmsg
, 0, sock
, msg
, size
, flags
);
2097 int security_socket_getsockname(struct socket
*sock
)
2099 return call_int_hook(socket_getsockname
, 0, sock
);
2102 int security_socket_getpeername(struct socket
*sock
)
2104 return call_int_hook(socket_getpeername
, 0, sock
);
2107 int security_socket_getsockopt(struct socket
*sock
, int level
, int optname
)
2109 return call_int_hook(socket_getsockopt
, 0, sock
, level
, optname
);
2112 int security_socket_setsockopt(struct socket
*sock
, int level
, int optname
)
2114 return call_int_hook(socket_setsockopt
, 0, sock
, level
, optname
);
2117 int security_socket_shutdown(struct socket
*sock
, int how
)
2119 return call_int_hook(socket_shutdown
, 0, sock
, how
);
2122 int security_sock_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
2124 return call_int_hook(socket_sock_rcv_skb
, 0, sk
, skb
);
2126 EXPORT_SYMBOL(security_sock_rcv_skb
);
2128 int security_socket_getpeersec_stream(struct socket
*sock
, char __user
*optval
,
2129 int __user
*optlen
, unsigned len
)
2131 #ifdef CONFIG_SECURITY_STACKING
2132 struct security_hook_list
*hp
;
2133 char *lsm
= lsm_of_task(current
);
2135 list_for_each_entry(hp
, &security_hook_heads
.socket_getpeersec_stream
,
2137 if (!lsm
|| !lsm
[0] || !strcmp(lsm
, hp
->lsm
))
2138 return hp
->hook
.socket_getpeersec_stream(sock
, optval
,
2141 return -ENOPROTOOPT
;
2143 return call_int_hook(socket_getpeersec_stream
, -ENOPROTOOPT
, sock
,
2144 optval
, optlen
, len
);
2148 int security_socket_getpeersec_dgram(struct socket
*sock
, struct sk_buff
*skb
, u32
*secid
)
2150 return call_int_hook(socket_getpeersec_dgram
, -ENOPROTOOPT
, sock
,
2153 EXPORT_SYMBOL(security_socket_getpeersec_dgram
);
2155 int security_sk_alloc(struct sock
*sk
, int family
, gfp_t priority
)
2157 int rc
= lsm_sock_alloc(sk
, priority
);
2161 rc
= call_int_hook(sk_alloc_security
, 0, sk
, family
, priority
);
2163 security_sk_free(sk
);
2167 void security_sk_free(struct sock
*sk
)
2169 call_void_hook(sk_free_security
, sk
);
2170 kfree(sk
->sk_security
);
2171 sk
->sk_security
= NULL
;
2174 void security_sk_clone(const struct sock
*sk
, struct sock
*newsk
)
2176 call_void_hook(sk_clone_security
, sk
, newsk
);
2178 EXPORT_SYMBOL(security_sk_clone
);
2180 void security_sk_classify_flow(struct sock
*sk
, struct flowi
*fl
)
2182 call_void_hook(sk_getsecid
, sk
, &fl
->flowi_secid
);
2184 EXPORT_SYMBOL(security_sk_classify_flow
);
2186 void security_req_classify_flow(const struct request_sock
*req
, struct flowi
*fl
)
2188 call_void_hook(req_classify_flow
, req
, fl
);
2190 EXPORT_SYMBOL(security_req_classify_flow
);
2192 void security_sock_graft(struct sock
*sk
, struct socket
*parent
)
2194 call_void_hook(sock_graft
, sk
, parent
);
2196 EXPORT_SYMBOL(security_sock_graft
);
2198 int security_inet_conn_request(struct sock
*sk
,
2199 struct sk_buff
*skb
, struct request_sock
*req
)
2201 return call_int_hook(inet_conn_request
, 0, sk
, skb
, req
);
2203 EXPORT_SYMBOL(security_inet_conn_request
);
2205 void security_inet_csk_clone(struct sock
*newsk
,
2206 const struct request_sock
*req
)
2208 call_void_hook(inet_csk_clone
, newsk
, req
);
2211 void security_inet_conn_established(struct sock
*sk
,
2212 struct sk_buff
*skb
)
2214 call_void_hook(inet_conn_established
, sk
, skb
);
2217 int security_secmark_relabel_packet(u32 secid
)
2219 return call_int_hook(secmark_relabel_packet
, 0, secid
);
2221 EXPORT_SYMBOL(security_secmark_relabel_packet
);
2223 void security_secmark_refcount_inc(void)
2225 call_void_hook(secmark_refcount_inc
);
2227 EXPORT_SYMBOL(security_secmark_refcount_inc
);
2229 void security_secmark_refcount_dec(void)
2231 call_void_hook(secmark_refcount_dec
);
2233 EXPORT_SYMBOL(security_secmark_refcount_dec
);
2235 int security_tun_dev_alloc_security(void **security
)
2237 return call_int_hook(tun_dev_alloc_security
, 0, security
);
2239 EXPORT_SYMBOL(security_tun_dev_alloc_security
);
2241 void security_tun_dev_free_security(void *security
)
2243 call_void_hook(tun_dev_free_security
, security
);
2245 EXPORT_SYMBOL(security_tun_dev_free_security
);
2247 int security_tun_dev_create(void)
2249 return call_int_hook(tun_dev_create
, 0);
2251 EXPORT_SYMBOL(security_tun_dev_create
);
2253 int security_tun_dev_attach_queue(void *security
)
2255 return call_int_hook(tun_dev_attach_queue
, 0, security
);
2257 EXPORT_SYMBOL(security_tun_dev_attach_queue
);
2259 int security_tun_dev_attach(struct sock
*sk
, void *security
)
2261 return call_int_hook(tun_dev_attach
, 0, sk
, security
);
2263 EXPORT_SYMBOL(security_tun_dev_attach
);
2265 int security_tun_dev_open(void *security
)
2267 return call_int_hook(tun_dev_open
, 0, security
);
2269 EXPORT_SYMBOL(security_tun_dev_open
);
2271 #endif /* CONFIG_SECURITY_NETWORK */
2273 #ifdef CONFIG_SECURITY_INFINIBAND
2275 int security_ib_pkey_access(void *sec
, u64 subnet_prefix
, u16 pkey
)
2277 return call_int_hook(ib_pkey_access
, 0, sec
, subnet_prefix
, pkey
);
2279 EXPORT_SYMBOL(security_ib_pkey_access
);
2281 int security_ib_endport_manage_subnet(void *sec
, const char *dev_name
, u8 port_num
)
2283 return call_int_hook(ib_endport_manage_subnet
, 0, sec
, dev_name
, port_num
);
2285 EXPORT_SYMBOL(security_ib_endport_manage_subnet
);
2287 int security_ib_alloc_security(void **sec
)
2289 return call_int_hook(ib_alloc_security
, 0, sec
);
2291 EXPORT_SYMBOL(security_ib_alloc_security
);
2293 void security_ib_free_security(void *sec
)
2295 call_void_hook(ib_free_security
, sec
);
2297 EXPORT_SYMBOL(security_ib_free_security
);
2298 #endif /* CONFIG_SECURITY_INFINIBAND */
2300 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2302 int security_xfrm_policy_alloc(struct xfrm_sec_ctx
**ctxp
,
2303 struct xfrm_user_sec_ctx
*sec_ctx
,
2306 return call_int_hook(xfrm_policy_alloc_security
, 0, ctxp
, sec_ctx
, gfp
);
2308 EXPORT_SYMBOL(security_xfrm_policy_alloc
);
2310 int security_xfrm_policy_clone(struct xfrm_sec_ctx
*old_ctx
,
2311 struct xfrm_sec_ctx
**new_ctxp
)
2313 return call_int_hook(xfrm_policy_clone_security
, 0, old_ctx
, new_ctxp
);
2316 void security_xfrm_policy_free(struct xfrm_sec_ctx
*ctx
)
2318 call_void_hook(xfrm_policy_free_security
, ctx
);
2320 EXPORT_SYMBOL(security_xfrm_policy_free
);
2322 int security_xfrm_policy_delete(struct xfrm_sec_ctx
*ctx
)
2324 return call_int_hook(xfrm_policy_delete_security
, 0, ctx
);
2327 int security_xfrm_state_alloc(struct xfrm_state
*x
,
2328 struct xfrm_user_sec_ctx
*sec_ctx
)
2330 return call_int_hook(xfrm_state_alloc
, 0, x
, sec_ctx
);
2332 EXPORT_SYMBOL(security_xfrm_state_alloc
);
2334 int security_xfrm_state_alloc_acquire(struct xfrm_state
*x
,
2335 struct xfrm_sec_ctx
*polsec
, u32 secid
)
2337 return call_int_hook(xfrm_state_alloc_acquire
, 0, x
, polsec
, secid
);
2340 int security_xfrm_state_delete(struct xfrm_state
*x
)
2342 return call_int_hook(xfrm_state_delete_security
, 0, x
);
2344 EXPORT_SYMBOL(security_xfrm_state_delete
);
2346 void security_xfrm_state_free(struct xfrm_state
*x
)
2348 call_void_hook(xfrm_state_free_security
, x
);
2351 int security_xfrm_policy_lookup(struct xfrm_sec_ctx
*ctx
, u32 fl_secid
, u8 dir
)
2353 return call_int_hook(xfrm_policy_lookup
, 0, ctx
, fl_secid
, dir
);
2356 int security_xfrm_state_pol_flow_match(struct xfrm_state
*x
,
2357 struct xfrm_policy
*xp
,
2358 const struct flowi
*fl
)
2360 struct security_hook_list
*hp
;
2364 * Since this function is expected to return 0 or 1, the judgment
2365 * becomes difficult if multiple LSMs supply this call. Fortunately,
2366 * we can use the first LSM's judgment because currently only SELinux
2367 * supplies this call.
2369 * For speed optimization, we explicitly break the loop rather than
2372 list_for_each_entry(hp
, &security_hook_heads
.xfrm_state_pol_flow_match
,
2374 rc
= hp
->hook
.xfrm_state_pol_flow_match(x
, xp
, fl
);
2380 int security_xfrm_decode_session(struct sk_buff
*skb
, u32
*secid
)
2382 return call_int_hook(xfrm_decode_session
, 0, skb
, secid
, 1);
2385 void security_skb_classify_flow(struct sk_buff
*skb
, struct flowi
*fl
)
2387 int rc
= call_int_hook(xfrm_decode_session
, 0, skb
, &fl
->flowi_secid
,
2392 EXPORT_SYMBOL(security_skb_classify_flow
);
2394 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
2398 int security_key_alloc(struct key
*key
, const struct cred
*cred
,
2399 unsigned long flags
)
2401 int rc
= lsm_key_alloc(key
);
2405 rc
= call_int_hook(key_alloc
, 0, key
, cred
, flags
);
2407 security_key_free(key
);
2411 void security_key_free(struct key
*key
)
2413 call_void_hook(key_free
, key
);
2414 kfree(key
->security
);
2415 key
->security
= NULL
;
2418 int security_key_permission(key_ref_t key_ref
,
2419 const struct cred
*cred
, unsigned perm
)
2421 return call_int_hook(key_permission
, 0, key_ref
, cred
, perm
);
2424 int security_key_getsecurity(struct key
*key
, char **_buffer
)
2427 return call_int_hook(key_getsecurity
, 0, key
, _buffer
);
2430 #endif /* CONFIG_KEYS */
2434 int security_audit_rule_init(u32 field
, u32 op
, char *rulestr
, void **lsmrule
)
2436 return call_int_hook(audit_rule_init
, 0, field
, op
, rulestr
, lsmrule
);
2439 int security_audit_rule_known(struct audit_krule
*krule
)
2441 return call_int_hook(audit_rule_known
, 0, krule
);
2444 void security_audit_rule_free(void *lsmrule
)
2446 call_void_hook(audit_rule_free
, lsmrule
);
2449 int security_audit_rule_match(u32 secid
, u32 field
, u32 op
, void *lsmrule
,
2450 struct audit_context
*actx
)
2452 return call_int_hook(audit_rule_match
, 0, secid
, field
, op
, lsmrule
,
2455 #endif /* CONFIG_AUDIT */
2457 #ifdef CONFIG_BPF_SYSCALL
2458 int security_bpf(int cmd
, union bpf_attr
*attr
, unsigned int size
)
2460 return call_int_hook(bpf
, 0, cmd
, attr
, size
);
2462 int security_bpf_map(struct bpf_map
*map
, fmode_t fmode
)
2464 return call_int_hook(bpf_map
, 0, map
, fmode
);
2466 int security_bpf_prog(struct bpf_prog
*prog
)
2468 return call_int_hook(bpf_prog
, 0, prog
);
2470 int security_bpf_map_alloc(struct bpf_map
*map
)
2472 return call_int_hook(bpf_map_alloc_security
, 0, map
);
2474 int security_bpf_prog_alloc(struct bpf_prog_aux
*aux
)
2476 return call_int_hook(bpf_prog_alloc_security
, 0, aux
);
2478 void security_bpf_map_free(struct bpf_map
*map
)
2480 call_void_hook(bpf_map_free_security
, map
);
2482 void security_bpf_prog_free(struct bpf_prog_aux
*aux
)
2484 call_void_hook(bpf_prog_free_security
, aux
);
2486 #endif /* CONFIG_BPF_SYSCALL */