]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - security/security.c
UBUNTU: SAUCE: LSM stacking: LSM: Infrastructure management of the remaining blobs
[mirror_ubuntu-artful-kernel.git] / security / security.c
1 /*
2 * Security plug functions
3 *
4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7 * Copyright (C) 2016 Mellanox Technologies
8 *
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.
13 */
14
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>
31 #include <net/flow.h>
32 #include <net/sock.h>
33
34 #define MAX_LSM_EVM_XATTR 2
35
36 /* Maximum number of letters for an LSM name string */
37 #define SECURITY_NAME_MAX 10
38
39 struct security_hook_heads security_hook_heads __lsm_ro_after_init;
40 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
41
42 char *lsm_names;
43 static struct lsm_blob_sizes blob_sizes;
44
45 /* Boot-time LSM user choice */
46 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
47 CONFIG_DEFAULT_SECURITY;
48
49 static void __init do_security_initcalls(void)
50 {
51 initcall_t *call;
52 call = __security_initcall_start;
53 while (call < __security_initcall_end) {
54 (*call) ();
55 call++;
56 }
57 }
58
59 /**
60 * security_init - initializes the security framework
61 *
62 * This should be called early in the kernel initialization sequence.
63 */
64 int __init security_init(void)
65 {
66 int i;
67 struct list_head *list = (struct list_head *) &security_hook_heads;
68
69 for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct list_head);
70 i++)
71 INIT_LIST_HEAD(&list[i]);
72 pr_info("Security Framework initialized\n");
73
74 /*
75 * Load minor LSMs, with the capability module always first.
76 */
77 capability_add_hooks();
78 yama_add_hooks();
79 loadpin_add_hooks();
80
81 /*
82 * The first call to a module specific init function
83 * updates the blob size requirements.
84 */
85 do_security_initcalls();
86
87 /*
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.
91 */
92 do_security_initcalls();
93
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);
99 #ifdef CONFIG_KEYS
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 */
107
108 return 0;
109 }
110
111 /* Save user chosen LSM */
112 static int __init choose_lsm(char *str)
113 {
114 strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
115 return 1;
116 }
117 __setup("security=", choose_lsm);
118
119 static bool match_last_lsm(const char *list, const char *lsm)
120 {
121 const char *last;
122
123 if (WARN_ON(!list || !lsm))
124 return false;
125 last = strrchr(list, ',');
126 if (last)
127 /* Pass the comma, strcmp() will check for '\0' */
128 last++;
129 else
130 last = list;
131 return !strcmp(last, lsm);
132 }
133
134 static int lsm_append(char *new, char **result)
135 {
136 char *cp;
137
138 if (*result == NULL) {
139 *result = kstrdup(new, GFP_KERNEL);
140 } else {
141 /* Check if it is the last registered name */
142 if (match_last_lsm(*result, new))
143 return 0;
144 cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
145 if (cp == NULL)
146 return -ENOMEM;
147 kfree(*result);
148 *result = cp;
149 }
150 return 0;
151 }
152
153 /**
154 * security_module_enable - Load given security module on boot ?
155 * @module: the name of the module
156 *
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.
160 *
161 * Returns:
162 *
163 * true if:
164 *
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.
168 *
169 * Otherwise, return false.
170 */
171 int __init security_module_enable(const char *module)
172 {
173 return !strcmp(module, chosen_lsm);
174 }
175
176 /**
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
181 *
182 * Each LSM has to register its hooks with the infrastructure.
183 */
184 void __init security_add_hooks(struct security_hook_list *hooks, int count,
185 char *lsm)
186 {
187 int i;
188
189 for (i = 0; i < count; i++) {
190 hooks[i].lsm = lsm;
191 list_add_tail_rcu(&hooks[i].list, hooks[i].head);
192 }
193 if (lsm_append(lsm, &lsm_names) < 0)
194 panic("%s - Cannot get early memory.\n", __func__);
195 }
196
197 int call_lsm_notifier(enum lsm_event event, void *data)
198 {
199 return atomic_notifier_call_chain(&lsm_notifier_chain, event, data);
200 }
201 EXPORT_SYMBOL(call_lsm_notifier);
202
203 int register_lsm_notifier(struct notifier_block *nb)
204 {
205 return atomic_notifier_chain_register(&lsm_notifier_chain, nb);
206 }
207 EXPORT_SYMBOL(register_lsm_notifier);
208
209 int unregister_lsm_notifier(struct notifier_block *nb)
210 {
211 return atomic_notifier_chain_unregister(&lsm_notifier_chain, nb);
212 }
213 EXPORT_SYMBOL(unregister_lsm_notifier);
214
215 /**
216 * lsm_cred_alloc - allocate a composite cred blob
217 * @cred: the cred that needs a blob
218 * @gfp: allocation type
219 *
220 * Allocate the cred blob for all the modules
221 *
222 * Returns 0, or -ENOMEM if memory can't be allocated.
223 */
224 int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
225 {
226 #ifdef CONFIG_SECURITY_LSM_DEBUG
227 if (cred->security)
228 pr_info("%s: Inbound cred blob is not NULL.\n", __func__);
229 #endif
230 if (blob_sizes.lbs_cred == 0)
231 return 0;
232
233 cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
234 if (cred->security == NULL)
235 return -ENOMEM;
236 return 0;
237 }
238
239 /**
240 * lsm_early_cred - during initialization allocate a composite cred blob
241 * @cred: the cred that needs a blob
242 *
243 * Allocate the cred blob for all the modules if it's not already there
244 */
245 void lsm_early_cred(struct cred *cred)
246 {
247 int rc;
248
249 if (cred == NULL)
250 panic("%s: NULL cred.\n", __func__);
251 if (cred->security != NULL)
252 return;
253 rc = lsm_cred_alloc(cred, GFP_KERNEL);
254 if (rc)
255 panic("%s: Early cred alloc failed.\n", __func__);
256 }
257
258 static void __init lsm_set_size(int *need, int *lbs)
259 {
260 int offset;
261
262 if (*need > 0) {
263 offset = *lbs;
264 *lbs += *need;
265 *need = offset;
266 }
267 }
268
269 /**
270 * security_add_blobs - Report blob sizes
271 * @needed: the size of blobs needed by the module
272 *
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.
278 */
279 void __init security_add_blobs(struct lsm_blob_sizes *needed)
280 {
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);
289 /*
290 * The inode blob gets an rcu_head in addition to
291 * what the modules might need.
292 */
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);
296 }
297
298 /**
299 * lsm_file_alloc - allocate a composite file blob
300 * @file: the file that needs a blob
301 *
302 * Allocate the file blob for all the modules
303 *
304 * Returns 0, or -ENOMEM if memory can't be allocated.
305 */
306 int lsm_file_alloc(struct file *file)
307 {
308 #ifdef CONFIG_SECURITY_LSM_DEBUG
309 if (file->f_security)
310 pr_info("%s: Inbound file blob is not NULL.\n", __func__);
311 #endif
312 if (blob_sizes.lbs_file == 0)
313 return 0;
314
315 file->f_security = kzalloc(blob_sizes.lbs_file, GFP_KERNEL);
316 if (file->f_security == NULL)
317 return -ENOMEM;
318 return 0;
319 }
320
321 /**
322 * lsm_task_alloc - allocate a composite task blob
323 * @task: the task that needs a blob
324 *
325 * Allocate the task blob for all the modules
326 *
327 * Returns 0, or -ENOMEM if memory can't be allocated.
328 */
329 int lsm_task_alloc(struct task_struct *task)
330 {
331 #ifdef CONFIG_SECURITY_LSM_DEBUG
332 if (task->security)
333 pr_info("%s: Inbound task blob is not NULL.\n", __func__);
334 #endif
335 if (blob_sizes.lbs_task == 0)
336 return 0;
337
338 task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL);
339 if (task->security == NULL)
340 return -ENOMEM;
341 return 0;
342 }
343
344 /**
345 * lsm_inode_alloc - allocate a composite inode blob
346 * @inode: the inode that needs a blob
347 *
348 * Allocate the inode blob for all the modules
349 *
350 * Returns 0, or -ENOMEM if memory can't be allocated.
351 */
352 int lsm_inode_alloc(struct inode *inode)
353 {
354 #ifdef CONFIG_SECURITY_LSM_DEBUG
355 if (inode->i_security)
356 pr_info("%s: Inbound inode blob is not NULL.\n", __func__);
357 #endif
358 if (blob_sizes.lbs_inode == 0)
359 return 0;
360
361 inode->i_security = kzalloc(blob_sizes.lbs_inode, GFP_KERNEL);
362 if (inode->i_security == NULL)
363 return -ENOMEM;
364 return 0;
365 }
366
367 /**
368 * lsm_early_inode - during initialization allocate a composite inode blob
369 * @inode: the inode that needs a blob
370 *
371 * Allocate the inode blob for all the modules if it's not already there
372 */
373 void lsm_early_inode(struct inode *inode)
374 {
375 int rc;
376
377 if (inode == NULL)
378 panic("%s: NULL inode.\n", __func__);
379 if (inode->i_security != NULL)
380 return;
381 rc = lsm_inode_alloc(inode);
382 if (rc)
383 panic("%s: Early inode alloc failed.\n", __func__);
384 }
385
386 /**
387 * lsm_ipc_alloc - allocate a composite ipc blob
388 * @kip: the ipc that needs a blob
389 *
390 * Allocate the ipc blob for all the modules
391 *
392 * Returns 0, or -ENOMEM if memory can't be allocated.
393 */
394 int lsm_ipc_alloc(struct kern_ipc_perm *kip)
395 {
396 #ifdef CONFIG_SECURITY_LSM_DEBUG
397 if (kip->security)
398 pr_info("%s: Inbound ipc blob is not NULL.\n", __func__);
399 #endif
400 if (blob_sizes.lbs_ipc == 0)
401 return 0;
402
403 kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL);
404 if (kip->security == NULL)
405 return -ENOMEM;
406 return 0;
407 }
408
409 #ifdef CONFIG_KEYS
410 /**
411 * lsm_key_alloc - allocate a composite key blob
412 * @key: the key that needs a blob
413 *
414 * Allocate the key blob for all the modules
415 *
416 * Returns 0, or -ENOMEM if memory can't be allocated.
417 */
418 int lsm_key_alloc(struct key *key)
419 {
420 #ifdef CONFIG_SECURITY_LSM_DEBUG
421 if (key->security)
422 pr_info("%s: Inbound key blob is not NULL.\n", __func__);
423 #endif
424 if (blob_sizes.lbs_key == 0)
425 return 0;
426
427 key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL);
428 if (key->security == NULL)
429 return -ENOMEM;
430 return 0;
431 }
432 #endif /* CONFIG_KEYS */
433
434 /**
435 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
436 * @mp: the msg_msg that needs a blob
437 *
438 * Allocate the ipc blob for all the modules
439 *
440 * Returns 0, or -ENOMEM if memory can't be allocated.
441 */
442 int lsm_msg_msg_alloc(struct msg_msg *mp)
443 {
444 #ifdef CONFIG_SECURITY_LSM_DEBUG
445 if (mp->security)
446 pr_info("%s: Inbound msg_msg blob is not NULL.\n", __func__);
447 #endif
448 if (blob_sizes.lbs_msg_msg == 0)
449 return 0;
450
451 mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL);
452 if (mp->security == NULL)
453 return -ENOMEM;
454 return 0;
455 }
456
457 /**
458 * lsm_sock_alloc - allocate a composite sock blob
459 * @sock: the sock that needs a blob
460 * @priority: allocation mode
461 *
462 * Allocate the sock blob for all the modules
463 *
464 * Returns 0, or -ENOMEM if memory can't be allocated.
465 */
466 int lsm_sock_alloc(struct sock *sock, gfp_t priority)
467 {
468 #ifdef CONFIG_SECURITY_LSM_DEBUG
469 if (sock->sk_security)
470 pr_info("%s: Inbound sock blob is not NULL.\n", __func__);
471 #endif
472 if (blob_sizes.lbs_sock == 0)
473 return 0;
474
475 sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority);
476 if (sock->sk_security == NULL)
477 return -ENOMEM;
478 return 0;
479 }
480
481 /**
482 * lsm_superblock_alloc - allocate a composite superblock blob
483 * @sb: the superblock that needs a blob
484 *
485 * Allocate the superblock blob for all the modules
486 *
487 * Returns 0, or -ENOMEM if memory can't be allocated.
488 */
489 int lsm_superblock_alloc(struct super_block *sb)
490 {
491 #ifdef CONFIG_SECURITY_LSM_DEBUG
492 if (sb->s_security)
493 pr_info("%s: Inbound superblock blob is not NULL.\n", __func__);
494 #endif
495 if (blob_sizes.lbs_superblock == 0)
496 return 0;
497
498 sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL);
499 if (sb->s_security == NULL)
500 return -ENOMEM;
501 return 0;
502 }
503
504 /*
505 * Hook list operation macros.
506 *
507 * call_void_hook:
508 * This is a hook that does not return a value.
509 *
510 * call_int_hook:
511 * This is a hook that returns a value.
512 */
513
514 #define call_void_hook(FUNC, ...) \
515 do { \
516 struct security_hook_list *P; \
517 \
518 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
519 P->hook.FUNC(__VA_ARGS__); \
520 } while (0)
521
522 #define call_int_hook(FUNC, IRC, ...) ({ \
523 int RC = IRC; \
524 do { \
525 struct security_hook_list *P; \
526 \
527 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
528 RC = P->hook.FUNC(__VA_ARGS__); \
529 if (RC != 0) \
530 break; \
531 } \
532 } while (0); \
533 RC; \
534 })
535
536 /* Security operations */
537
538 int security_binder_set_context_mgr(struct task_struct *mgr)
539 {
540 return call_int_hook(binder_set_context_mgr, 0, mgr);
541 }
542
543 int security_binder_transaction(struct task_struct *from,
544 struct task_struct *to)
545 {
546 return call_int_hook(binder_transaction, 0, from, to);
547 }
548
549 int security_binder_transfer_binder(struct task_struct *from,
550 struct task_struct *to)
551 {
552 return call_int_hook(binder_transfer_binder, 0, from, to);
553 }
554
555 int security_binder_transfer_file(struct task_struct *from,
556 struct task_struct *to, struct file *file)
557 {
558 return call_int_hook(binder_transfer_file, 0, from, to, file);
559 }
560
561 int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
562 {
563 return call_int_hook(ptrace_access_check, 0, child, mode);
564 }
565
566 int security_ptrace_traceme(struct task_struct *parent)
567 {
568 return call_int_hook(ptrace_traceme, 0, parent);
569 }
570
571 int security_capget(struct task_struct *target,
572 kernel_cap_t *effective,
573 kernel_cap_t *inheritable,
574 kernel_cap_t *permitted)
575 {
576 return call_int_hook(capget, 0, target,
577 effective, inheritable, permitted);
578 }
579
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)
584 {
585 return call_int_hook(capset, 0, new, old,
586 effective, inheritable, permitted);
587 }
588
589 int security_capable(const struct cred *cred, struct user_namespace *ns,
590 int cap)
591 {
592 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
593 }
594
595 int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
596 int cap)
597 {
598 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
599 }
600
601 int security_quotactl(int cmds, int type, int id, struct super_block *sb)
602 {
603 return call_int_hook(quotactl, 0, cmds, type, id, sb);
604 }
605
606 int security_quota_on(struct dentry *dentry)
607 {
608 return call_int_hook(quota_on, 0, dentry);
609 }
610
611 int security_syslog(int type)
612 {
613 return call_int_hook(syslog, 0, type);
614 }
615
616 int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
617 {
618 return call_int_hook(settime, 0, ts, tz);
619 }
620
621 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
622 {
623 struct security_hook_list *hp;
624 int cap_sys_admin = 1;
625 int rc;
626
627 /*
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.
633 */
634 list_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
635 rc = hp->hook.vm_enough_memory(mm, pages);
636 if (rc <= 0) {
637 cap_sys_admin = 0;
638 break;
639 }
640 }
641 return __vm_enough_memory(mm, pages, cap_sys_admin);
642 }
643
644 int security_bprm_set_creds(struct linux_binprm *bprm)
645 {
646 return call_int_hook(bprm_set_creds, 0, bprm);
647 }
648
649 int security_bprm_check(struct linux_binprm *bprm)
650 {
651 int ret;
652
653 ret = call_int_hook(bprm_check_security, 0, bprm);
654 if (ret)
655 return ret;
656 return ima_bprm_check(bprm);
657 }
658
659 void security_bprm_committing_creds(struct linux_binprm *bprm)
660 {
661 call_void_hook(bprm_committing_creds, bprm);
662 }
663
664 void security_bprm_committed_creds(struct linux_binprm *bprm)
665 {
666 call_void_hook(bprm_committed_creds, bprm);
667 }
668
669 int security_bprm_secureexec(struct linux_binprm *bprm)
670 {
671 return call_int_hook(bprm_secureexec, 0, bprm);
672 }
673
674 int security_sb_alloc(struct super_block *sb)
675 {
676 int rc = lsm_superblock_alloc(sb);
677
678 if (rc)
679 return rc;
680 return call_int_hook(sb_alloc_security, 0, sb);
681 }
682
683 void security_sb_free(struct super_block *sb)
684 {
685 call_void_hook(sb_free_security, sb);
686 kfree(sb->s_security);
687 sb->s_security = NULL;
688 }
689
690 int security_sb_copy_data(char *orig, char *copy)
691 {
692 return call_int_hook(sb_copy_data, 0, orig, copy);
693 }
694 EXPORT_SYMBOL(security_sb_copy_data);
695
696 int security_sb_remount(struct super_block *sb, void *data)
697 {
698 return call_int_hook(sb_remount, 0, sb, data);
699 }
700
701 int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
702 {
703 return call_int_hook(sb_kern_mount, 0, sb, flags, data);
704 }
705
706 int security_sb_show_options(struct seq_file *m, struct super_block *sb)
707 {
708 return call_int_hook(sb_show_options, 0, m, sb);
709 }
710
711 int security_sb_statfs(struct dentry *dentry)
712 {
713 return call_int_hook(sb_statfs, 0, dentry);
714 }
715
716 int security_sb_mount(const char *dev_name, const struct path *path,
717 const char *type, unsigned long flags, void *data)
718 {
719 return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
720 }
721
722 int security_sb_umount(struct vfsmount *mnt, int flags)
723 {
724 return call_int_hook(sb_umount, 0, mnt, flags);
725 }
726
727 int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
728 {
729 return call_int_hook(sb_pivotroot, 0, old_path, new_path);
730 }
731
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)
736 {
737 return call_int_hook(sb_set_mnt_opts,
738 opts->num_mnt_opts ? -EOPNOTSUPP : 0, sb,
739 opts, kern_flags, set_kern_flags);
740 }
741 EXPORT_SYMBOL(security_sb_set_mnt_opts);
742
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)
747 {
748 return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
749 kern_flags, set_kern_flags);
750 }
751 EXPORT_SYMBOL(security_sb_clone_mnt_opts);
752
753 int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
754 {
755 return call_int_hook(sb_parse_opts_str, 0, options, opts);
756 }
757 EXPORT_SYMBOL(security_sb_parse_opts_str);
758
759 int security_inode_alloc(struct inode *inode)
760 {
761 int rc = lsm_inode_alloc(inode);
762
763 if (rc)
764 return rc;
765 return call_int_hook(inode_alloc_security, 0, inode);
766 }
767
768 static void inode_free_by_rcu(struct rcu_head *head)
769 {
770 /*
771 * The rcu head is at the start of the inode blob
772 */
773 kfree(head);
774 }
775
776 void security_inode_free(struct inode *inode)
777 {
778 integrity_inode_free(inode);
779 call_void_hook(inode_free_security, inode);
780 /*
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.
788 */
789 if (inode->i_security != NULL) {
790 call_rcu((struct rcu_head *)inode->i_security,
791 inode_free_by_rcu);
792 inode->i_security = NULL;
793 }
794 }
795
796 int security_dentry_init_security(struct dentry *dentry, int mode,
797 const struct qstr *name, void **ctx,
798 u32 *ctxlen)
799 {
800 return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
801 name, ctx, ctxlen);
802 }
803 EXPORT_SYMBOL(security_dentry_init_security);
804
805 int security_dentry_create_files_as(struct dentry *dentry, int mode,
806 struct qstr *name,
807 const struct cred *old, struct cred *new)
808 {
809 return call_int_hook(dentry_create_files_as, 0, dentry, mode,
810 name, old, new);
811 }
812 EXPORT_SYMBOL(security_dentry_create_files_as);
813
814 int security_inode_init_security(struct inode *inode, struct inode *dir,
815 const struct qstr *qstr,
816 const initxattrs initxattrs, void *fs_data)
817 {
818 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
819 struct xattr *lsm_xattr, *evm_xattr, *xattr;
820 int ret;
821
822 if (unlikely(IS_PRIVATE(inode)))
823 return 0;
824
825 if (!initxattrs)
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,
831 &lsm_xattr->name,
832 &lsm_xattr->value,
833 &lsm_xattr->value_len);
834 if (ret)
835 goto out;
836
837 evm_xattr = lsm_xattr + 1;
838 ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
839 if (ret)
840 goto out;
841 ret = initxattrs(inode, new_xattrs, fs_data);
842 out:
843 for (xattr = new_xattrs; xattr->value != NULL; xattr++)
844 kfree(xattr->value);
845 return (ret == -EOPNOTSUPP) ? 0 : ret;
846 }
847 EXPORT_SYMBOL(security_inode_init_security);
848
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)
852 {
853 if (unlikely(IS_PRIVATE(inode)))
854 return -EOPNOTSUPP;
855 return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
856 qstr, name, value, len);
857 }
858 EXPORT_SYMBOL(security_old_inode_init_security);
859
860 #ifdef CONFIG_SECURITY_PATH
861 int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
862 unsigned int dev)
863 {
864 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
865 return 0;
866 return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
867 }
868 EXPORT_SYMBOL(security_path_mknod);
869
870 int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
871 {
872 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
873 return 0;
874 return call_int_hook(path_mkdir, 0, dir, dentry, mode);
875 }
876 EXPORT_SYMBOL(security_path_mkdir);
877
878 int security_path_rmdir(const struct path *dir, struct dentry *dentry)
879 {
880 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
881 return 0;
882 return call_int_hook(path_rmdir, 0, dir, dentry);
883 }
884 EXPORT_SYMBOL_GPL(security_path_rmdir);
885
886 int security_path_unlink(const struct path *dir, struct dentry *dentry)
887 {
888 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
889 return 0;
890 return call_int_hook(path_unlink, 0, dir, dentry);
891 }
892 EXPORT_SYMBOL(security_path_unlink);
893
894 int security_path_symlink(const struct path *dir, struct dentry *dentry,
895 const char *old_name)
896 {
897 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
898 return 0;
899 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
900 }
901 EXPORT_SYMBOL_GPL(security_path_symlink);
902
903 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
904 struct dentry *new_dentry)
905 {
906 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
907 return 0;
908 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
909 }
910 EXPORT_SYMBOL_GPL(security_path_link);
911
912 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
913 const struct path *new_dir, struct dentry *new_dentry,
914 unsigned int flags)
915 {
916 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
917 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
918 return 0;
919
920 if (flags & RENAME_EXCHANGE) {
921 int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
922 old_dir, old_dentry);
923 if (err)
924 return err;
925 }
926
927 return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
928 new_dentry);
929 }
930 EXPORT_SYMBOL(security_path_rename);
931
932 int security_path_truncate(const struct path *path)
933 {
934 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
935 return 0;
936 return call_int_hook(path_truncate, 0, path);
937 }
938 EXPORT_SYMBOL_GPL(security_path_truncate);
939
940 int security_path_chmod(const struct path *path, umode_t mode)
941 {
942 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
943 return 0;
944 return call_int_hook(path_chmod, 0, path, mode);
945 }
946 EXPORT_SYMBOL_GPL(security_path_chmod);
947
948 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
949 {
950 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
951 return 0;
952 return call_int_hook(path_chown, 0, path, uid, gid);
953 }
954 EXPORT_SYMBOL_GPL(security_path_chown);
955
956 int security_path_chroot(const struct path *path)
957 {
958 return call_int_hook(path_chroot, 0, path);
959 }
960 #endif
961
962 int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
963 {
964 if (unlikely(IS_PRIVATE(dir)))
965 return 0;
966 return call_int_hook(inode_create, 0, dir, dentry, mode);
967 }
968 EXPORT_SYMBOL_GPL(security_inode_create);
969
970 int security_inode_link(struct dentry *old_dentry, struct inode *dir,
971 struct dentry *new_dentry)
972 {
973 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
974 return 0;
975 return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
976 }
977
978 int security_inode_unlink(struct inode *dir, struct dentry *dentry)
979 {
980 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
981 return 0;
982 return call_int_hook(inode_unlink, 0, dir, dentry);
983 }
984
985 int security_inode_symlink(struct inode *dir, struct dentry *dentry,
986 const char *old_name)
987 {
988 if (unlikely(IS_PRIVATE(dir)))
989 return 0;
990 return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
991 }
992
993 int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
994 {
995 if (unlikely(IS_PRIVATE(dir)))
996 return 0;
997 return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
998 }
999 EXPORT_SYMBOL_GPL(security_inode_mkdir);
1000
1001 int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
1002 {
1003 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1004 return 0;
1005 return call_int_hook(inode_rmdir, 0, dir, dentry);
1006 }
1007
1008 int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
1009 {
1010 if (unlikely(IS_PRIVATE(dir)))
1011 return 0;
1012 return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
1013 }
1014
1015 int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
1016 struct inode *new_dir, struct dentry *new_dentry,
1017 unsigned int flags)
1018 {
1019 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
1020 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
1021 return 0;
1022
1023 if (flags & RENAME_EXCHANGE) {
1024 int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
1025 old_dir, old_dentry);
1026 if (err)
1027 return err;
1028 }
1029
1030 return call_int_hook(inode_rename, 0, old_dir, old_dentry,
1031 new_dir, new_dentry);
1032 }
1033
1034 int security_inode_readlink(struct dentry *dentry)
1035 {
1036 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1037 return 0;
1038 return call_int_hook(inode_readlink, 0, dentry);
1039 }
1040 EXPORT_SYMBOL_GPL(security_inode_readlink);
1041
1042 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1043 bool rcu)
1044 {
1045 if (unlikely(IS_PRIVATE(inode)))
1046 return 0;
1047 return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
1048 }
1049
1050 int security_inode_permission(struct inode *inode, int mask)
1051 {
1052 if (unlikely(IS_PRIVATE(inode)))
1053 return 0;
1054 return call_int_hook(inode_permission, 0, inode, mask);
1055 }
1056 EXPORT_SYMBOL_GPL(security_inode_permission);
1057
1058 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1059 {
1060 int ret;
1061
1062 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1063 return 0;
1064 ret = call_int_hook(inode_setattr, 0, dentry, attr);
1065 if (ret)
1066 return ret;
1067 return evm_inode_setattr(dentry, attr);
1068 }
1069 EXPORT_SYMBOL_GPL(security_inode_setattr);
1070
1071 int security_inode_getattr(const struct path *path)
1072 {
1073 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
1074 return 0;
1075 return call_int_hook(inode_getattr, 0, path);
1076 }
1077
1078 int security_inode_setxattr(struct dentry *dentry, const char *name,
1079 const void *value, size_t size, int flags)
1080 {
1081 int ret;
1082
1083 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1084 return 0;
1085 /*
1086 * SELinux and Smack integrate the cap call,
1087 * so assume that all LSMs supplying this call do so.
1088 */
1089 ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
1090 flags);
1091
1092 if (ret == 1)
1093 ret = cap_inode_setxattr(dentry, name, value, size, flags);
1094 if (ret)
1095 return ret;
1096 ret = ima_inode_setxattr(dentry, name, value, size);
1097 if (ret)
1098 return ret;
1099 return evm_inode_setxattr(dentry, name, value, size);
1100 }
1101
1102 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
1103 const void *value, size_t size, int flags)
1104 {
1105 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1106 return;
1107 call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
1108 evm_inode_post_setxattr(dentry, name, value, size);
1109 }
1110
1111 int security_inode_getxattr(struct dentry *dentry, const char *name)
1112 {
1113 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1114 return 0;
1115 return call_int_hook(inode_getxattr, 0, dentry, name);
1116 }
1117
1118 int security_inode_listxattr(struct dentry *dentry)
1119 {
1120 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1121 return 0;
1122 return call_int_hook(inode_listxattr, 0, dentry);
1123 }
1124
1125 int security_inode_removexattr(struct dentry *dentry, const char *name)
1126 {
1127 int ret;
1128
1129 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1130 return 0;
1131 /*
1132 * SELinux and Smack integrate the cap call,
1133 * so assume that all LSMs supplying this call do so.
1134 */
1135 ret = call_int_hook(inode_removexattr, 1, dentry, name);
1136 if (ret == 1)
1137 ret = cap_inode_removexattr(dentry, name);
1138 if (ret)
1139 return ret;
1140 ret = ima_inode_removexattr(dentry, name);
1141 if (ret)
1142 return ret;
1143 return evm_inode_removexattr(dentry, name);
1144 }
1145
1146 int security_inode_need_killpriv(struct dentry *dentry)
1147 {
1148 return call_int_hook(inode_need_killpriv, 0, dentry);
1149 }
1150
1151 int security_inode_killpriv(struct dentry *dentry)
1152 {
1153 return call_int_hook(inode_killpriv, 0, dentry);
1154 }
1155
1156 int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
1157 {
1158 struct security_hook_list *hp;
1159 int rc;
1160
1161 if (unlikely(IS_PRIVATE(inode)))
1162 return -EOPNOTSUPP;
1163 /*
1164 * Only one module will provide an attribute with a given name.
1165 */
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)
1169 return rc;
1170 }
1171 return -EOPNOTSUPP;
1172 }
1173
1174 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
1175 {
1176 struct security_hook_list *hp;
1177 int rc;
1178
1179 if (unlikely(IS_PRIVATE(inode)))
1180 return -EOPNOTSUPP;
1181 /*
1182 * Only one module will provide an attribute with a given name.
1183 */
1184 list_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
1185 rc = hp->hook.inode_setsecurity(inode, name, value, size,
1186 flags);
1187 if (rc != -EOPNOTSUPP)
1188 return rc;
1189 }
1190 return -EOPNOTSUPP;
1191 }
1192
1193 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
1194 {
1195 if (unlikely(IS_PRIVATE(inode)))
1196 return 0;
1197 return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
1198 }
1199 EXPORT_SYMBOL(security_inode_listsecurity);
1200
1201 void security_inode_getsecid(struct inode *inode, u32 *secid)
1202 {
1203 call_void_hook(inode_getsecid, inode, secid);
1204 }
1205
1206 int security_inode_copy_up(struct dentry *src, struct cred **new)
1207 {
1208 return call_int_hook(inode_copy_up, 0, src, new);
1209 }
1210 EXPORT_SYMBOL(security_inode_copy_up);
1211
1212 int security_inode_copy_up_xattr(const char *name)
1213 {
1214 return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name);
1215 }
1216 EXPORT_SYMBOL(security_inode_copy_up_xattr);
1217
1218 int security_file_permission(struct file *file, int mask)
1219 {
1220 int ret;
1221
1222 ret = call_int_hook(file_permission, 0, file, mask);
1223 if (ret)
1224 return ret;
1225
1226 return fsnotify_perm(file, mask);
1227 }
1228 EXPORT_SYMBOL_GPL(security_file_permission);
1229
1230 int security_file_alloc(struct file *file)
1231 {
1232 int rc = lsm_file_alloc(file);
1233
1234 if (rc)
1235 return rc;
1236 return call_int_hook(file_alloc_security, 0, file);
1237 }
1238
1239 void security_file_free(struct file *file)
1240 {
1241 call_void_hook(file_free_security, file);
1242
1243 kfree(file->f_security);
1244 file->f_security = NULL;
1245 }
1246
1247 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1248 {
1249 return call_int_hook(file_ioctl, 0, file, cmd, arg);
1250 }
1251
1252 static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
1253 {
1254 /*
1255 * Does we have PROT_READ and does the application expect
1256 * it to imply PROT_EXEC? If not, nothing to talk about...
1257 */
1258 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
1259 return prot;
1260 if (!(current->personality & READ_IMPLIES_EXEC))
1261 return prot;
1262 /*
1263 * if that's an anonymous mapping, let it.
1264 */
1265 if (!file)
1266 return prot | PROT_EXEC;
1267 /*
1268 * ditto if it's not on noexec mount, except that on !MMU we need
1269 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
1270 */
1271 if (!path_noexec(&file->f_path)) {
1272 #ifndef CONFIG_MMU
1273 if (file->f_op->mmap_capabilities) {
1274 unsigned caps = file->f_op->mmap_capabilities(file);
1275 if (!(caps & NOMMU_MAP_EXEC))
1276 return prot;
1277 }
1278 #endif
1279 return prot | PROT_EXEC;
1280 }
1281 /* anything on noexec mount won't get PROT_EXEC */
1282 return prot;
1283 }
1284
1285 int security_mmap_file(struct file *file, unsigned long prot,
1286 unsigned long flags)
1287 {
1288 int ret;
1289 ret = call_int_hook(mmap_file, 0, file, prot,
1290 mmap_prot(file, prot), flags);
1291 if (ret)
1292 return ret;
1293 return ima_file_mmap(file, prot);
1294 }
1295 EXPORT_SYMBOL_GPL(security_mmap_file);
1296
1297 int security_mmap_addr(unsigned long addr)
1298 {
1299 return call_int_hook(mmap_addr, 0, addr);
1300 }
1301
1302 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
1303 unsigned long prot)
1304 {
1305 return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
1306 }
1307
1308 int security_file_lock(struct file *file, unsigned int cmd)
1309 {
1310 return call_int_hook(file_lock, 0, file, cmd);
1311 }
1312
1313 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1314 {
1315 return call_int_hook(file_fcntl, 0, file, cmd, arg);
1316 }
1317
1318 void security_file_set_fowner(struct file *file)
1319 {
1320 call_void_hook(file_set_fowner, file);
1321 }
1322
1323 int security_file_send_sigiotask(struct task_struct *tsk,
1324 struct fown_struct *fown, int sig)
1325 {
1326 return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
1327 }
1328
1329 int security_file_receive(struct file *file)
1330 {
1331 return call_int_hook(file_receive, 0, file);
1332 }
1333
1334 int security_file_open(struct file *file, const struct cred *cred)
1335 {
1336 int ret;
1337
1338 ret = call_int_hook(file_open, 0, file, cred);
1339 if (ret)
1340 return ret;
1341
1342 return fsnotify_perm(file, MAY_OPEN);
1343 }
1344
1345 int security_task_create(unsigned long clone_flags)
1346 {
1347 return call_int_hook(task_create, 0, clone_flags);
1348 }
1349
1350 int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
1351 {
1352 return call_int_hook(task_alloc, 0, task, clone_flags);
1353 }
1354
1355 void security_task_free(struct task_struct *task)
1356 {
1357 call_void_hook(task_free, task);
1358
1359 kfree(task->security);
1360 task->security = NULL;
1361 }
1362
1363 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1364 {
1365 int rc = lsm_cred_alloc(cred, gfp);
1366
1367 if (rc)
1368 return rc;
1369
1370 return call_int_hook(cred_alloc_blank, 0, cred, gfp);
1371 }
1372
1373 void security_cred_free(struct cred *cred)
1374 {
1375 call_void_hook(cred_free, cred);
1376
1377 kfree(cred->security);
1378 cred->security = NULL;
1379 }
1380
1381 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
1382 {
1383 int rc = lsm_cred_alloc(new, gfp);
1384
1385 if (rc)
1386 return rc;
1387
1388 return call_int_hook(cred_prepare, 0, new, old, gfp);
1389 }
1390
1391 void security_transfer_creds(struct cred *new, const struct cred *old)
1392 {
1393 call_void_hook(cred_transfer, new, old);
1394 }
1395
1396 int security_kernel_act_as(struct cred *new, u32 secid)
1397 {
1398 return call_int_hook(kernel_act_as, 0, new, secid);
1399 }
1400
1401 int security_kernel_create_files_as(struct cred *new, struct inode *inode)
1402 {
1403 return call_int_hook(kernel_create_files_as, 0, new, inode);
1404 }
1405
1406 int security_kernel_module_request(char *kmod_name)
1407 {
1408 return call_int_hook(kernel_module_request, 0, kmod_name);
1409 }
1410
1411 int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
1412 {
1413 int ret;
1414
1415 ret = call_int_hook(kernel_read_file, 0, file, id);
1416 if (ret)
1417 return ret;
1418 return ima_read_file(file, id);
1419 }
1420 EXPORT_SYMBOL_GPL(security_kernel_read_file);
1421
1422 int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
1423 enum kernel_read_file_id id)
1424 {
1425 int ret;
1426
1427 ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
1428 if (ret)
1429 return ret;
1430 return ima_post_read_file(file, buf, size, id);
1431 }
1432 EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
1433
1434 int security_task_fix_setuid(struct cred *new, const struct cred *old,
1435 int flags)
1436 {
1437 return call_int_hook(task_fix_setuid, 0, new, old, flags);
1438 }
1439
1440 int security_task_setpgid(struct task_struct *p, pid_t pgid)
1441 {
1442 return call_int_hook(task_setpgid, 0, p, pgid);
1443 }
1444
1445 int security_task_getpgid(struct task_struct *p)
1446 {
1447 return call_int_hook(task_getpgid, 0, p);
1448 }
1449
1450 int security_task_getsid(struct task_struct *p)
1451 {
1452 return call_int_hook(task_getsid, 0, p);
1453 }
1454
1455 void security_task_getsecid(struct task_struct *p, u32 *secid)
1456 {
1457 *secid = 0;
1458 call_void_hook(task_getsecid, p, secid);
1459 }
1460 EXPORT_SYMBOL(security_task_getsecid);
1461
1462 int security_task_setnice(struct task_struct *p, int nice)
1463 {
1464 return call_int_hook(task_setnice, 0, p, nice);
1465 }
1466
1467 int security_task_setioprio(struct task_struct *p, int ioprio)
1468 {
1469 return call_int_hook(task_setioprio, 0, p, ioprio);
1470 }
1471
1472 int security_task_getioprio(struct task_struct *p)
1473 {
1474 return call_int_hook(task_getioprio, 0, p);
1475 }
1476
1477 int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
1478 unsigned int flags)
1479 {
1480 return call_int_hook(task_prlimit, 0, cred, tcred, flags);
1481 }
1482
1483 int security_task_setrlimit(struct task_struct *p, unsigned int resource,
1484 struct rlimit *new_rlim)
1485 {
1486 return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
1487 }
1488
1489 int security_task_setscheduler(struct task_struct *p)
1490 {
1491 return call_int_hook(task_setscheduler, 0, p);
1492 }
1493
1494 int security_task_getscheduler(struct task_struct *p)
1495 {
1496 return call_int_hook(task_getscheduler, 0, p);
1497 }
1498
1499 int security_task_movememory(struct task_struct *p)
1500 {
1501 return call_int_hook(task_movememory, 0, p);
1502 }
1503
1504 int security_task_kill(struct task_struct *p, struct siginfo *info,
1505 int sig, u32 secid)
1506 {
1507 return call_int_hook(task_kill, 0, p, info, sig, secid);
1508 }
1509
1510 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
1511 unsigned long arg4, unsigned long arg5)
1512 {
1513 int thisrc;
1514 int rc = -ENOSYS;
1515 struct security_hook_list *hp;
1516
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) {
1520 rc = thisrc;
1521 if (thisrc != 0)
1522 break;
1523 }
1524 }
1525 return rc;
1526 }
1527
1528 void security_task_to_inode(struct task_struct *p, struct inode *inode)
1529 {
1530 call_void_hook(task_to_inode, p, inode);
1531 }
1532
1533 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
1534 {
1535 return call_int_hook(ipc_permission, 0, ipcp, flag);
1536 }
1537
1538 void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
1539 {
1540 *secid = 0;
1541 call_void_hook(ipc_getsecid, ipcp, secid);
1542 }
1543
1544 int security_msg_msg_alloc(struct msg_msg *msg)
1545 {
1546 int rc = lsm_msg_msg_alloc(msg);
1547
1548 if (rc)
1549 return rc;
1550 return call_int_hook(msg_msg_alloc_security, 0, msg);
1551 }
1552
1553 void security_msg_msg_free(struct msg_msg *msg)
1554 {
1555 call_void_hook(msg_msg_free_security, msg);
1556 kfree(msg->security);
1557 msg->security = NULL;
1558 }
1559
1560 int security_msg_queue_alloc(struct msg_queue *msq)
1561 {
1562 int rc = lsm_ipc_alloc(&msq->q_perm);
1563
1564 if (rc)
1565 return rc;
1566 return call_int_hook(msg_queue_alloc_security, 0, msq);
1567 }
1568
1569 void security_msg_queue_free(struct msg_queue *msq)
1570 {
1571 struct kern_ipc_perm *kip = &msq->q_perm;
1572
1573 call_void_hook(msg_queue_free_security, msq);
1574 kfree(kip->security);
1575 kip->security = NULL;
1576 }
1577
1578 int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
1579 {
1580 return call_int_hook(msg_queue_associate, 0, msq, msqflg);
1581 }
1582
1583 int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1584 {
1585 return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
1586 }
1587
1588 int security_msg_queue_msgsnd(struct msg_queue *msq,
1589 struct msg_msg *msg, int msqflg)
1590 {
1591 return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
1592 }
1593
1594 int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1595 struct task_struct *target, long type, int mode)
1596 {
1597 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
1598 }
1599
1600 int security_shm_alloc(struct shmid_kernel *shp)
1601 {
1602 int rc = lsm_ipc_alloc(&shp->shm_perm);
1603
1604 if (rc)
1605 return rc;
1606 return call_int_hook(shm_alloc_security, 0, shp);
1607 }
1608
1609 void security_shm_free(struct shmid_kernel *shp)
1610 {
1611 struct kern_ipc_perm *kip = &shp->shm_perm;
1612
1613 call_void_hook(shm_free_security, shp);
1614 kfree(kip->security);
1615 kip->security = NULL;
1616 }
1617
1618 int security_shm_associate(struct shmid_kernel *shp, int shmflg)
1619 {
1620 return call_int_hook(shm_associate, 0, shp, shmflg);
1621 }
1622
1623 int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1624 {
1625 return call_int_hook(shm_shmctl, 0, shp, cmd);
1626 }
1627
1628 int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
1629 {
1630 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
1631 }
1632
1633 int security_sem_alloc(struct sem_array *sma)
1634 {
1635 int rc = lsm_ipc_alloc(&sma->sem_perm);
1636
1637 if (rc)
1638 return rc;
1639 return call_int_hook(sem_alloc_security, 0, sma);
1640 }
1641
1642 void security_sem_free(struct sem_array *sma)
1643 {
1644 struct kern_ipc_perm *kip = &sma->sem_perm;
1645
1646 call_void_hook(sem_free_security, sma);
1647 kfree(kip->security);
1648 kip->security = NULL;
1649 }
1650
1651 int security_sem_associate(struct sem_array *sma, int semflg)
1652 {
1653 return call_int_hook(sem_associate, 0, sma, semflg);
1654 }
1655
1656 int security_sem_semctl(struct sem_array *sma, int cmd)
1657 {
1658 return call_int_hook(sem_semctl, 0, sma, cmd);
1659 }
1660
1661 int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
1662 unsigned nsops, int alter)
1663 {
1664 return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
1665 }
1666
1667 void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1668 {
1669 if (unlikely(inode && IS_PRIVATE(inode)))
1670 return;
1671 call_void_hook(d_instantiate, dentry, inode);
1672 }
1673 EXPORT_SYMBOL(security_d_instantiate);
1674
1675 int security_getprocattr(struct task_struct *p, const char *lsm, char *name,
1676 char **value)
1677 {
1678 struct security_hook_list *hp;
1679 int rc;
1680
1681 list_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
1682 if (lsm != NULL && strcmp(lsm, hp->lsm))
1683 continue;
1684 rc = hp->hook.getprocattr(p, name, value);
1685 if (rc != -ENOENT)
1686 return rc;
1687 }
1688 return -EINVAL;
1689 }
1690
1691 int security_setprocattr(const char *lsm, const char *name, void *value,
1692 size_t size)
1693 {
1694 struct security_hook_list *hp;
1695 int rc;
1696
1697 list_for_each_entry(hp, &security_hook_heads.setprocattr, list) {
1698 if (lsm != NULL && strcmp(lsm, hp->lsm))
1699 continue;
1700 rc = hp->hook.setprocattr(name, value, size);
1701 if (rc != -ENOENT)
1702 return rc;
1703 }
1704 return -EINVAL;
1705 }
1706
1707 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1708 {
1709 return call_int_hook(netlink_send, 0, sk, skb);
1710 }
1711
1712 int security_ismaclabel(const char *name)
1713 {
1714 return call_int_hook(ismaclabel, 0, name);
1715 }
1716 EXPORT_SYMBOL(security_ismaclabel);
1717
1718 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1719 {
1720 return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
1721 seclen);
1722 }
1723 EXPORT_SYMBOL(security_secid_to_secctx);
1724
1725 int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
1726 {
1727 *secid = 0;
1728 return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
1729 }
1730 EXPORT_SYMBOL(security_secctx_to_secid);
1731
1732 void security_release_secctx(char *secdata, u32 seclen)
1733 {
1734 call_void_hook(release_secctx, secdata, seclen);
1735 }
1736 EXPORT_SYMBOL(security_release_secctx);
1737
1738 void security_inode_invalidate_secctx(struct inode *inode)
1739 {
1740 call_void_hook(inode_invalidate_secctx, inode);
1741 }
1742 EXPORT_SYMBOL(security_inode_invalidate_secctx);
1743
1744 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
1745 {
1746 return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
1747 }
1748 EXPORT_SYMBOL(security_inode_notifysecctx);
1749
1750 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
1751 {
1752 return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
1753 }
1754 EXPORT_SYMBOL(security_inode_setsecctx);
1755
1756 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1757 {
1758 return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
1759 }
1760 EXPORT_SYMBOL(security_inode_getsecctx);
1761
1762 #ifdef CONFIG_SECURITY_NETWORK
1763
1764 int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
1765 {
1766 return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
1767 }
1768 EXPORT_SYMBOL(security_unix_stream_connect);
1769
1770 int security_unix_may_send(struct socket *sock, struct socket *other)
1771 {
1772 return call_int_hook(unix_may_send, 0, sock, other);
1773 }
1774 EXPORT_SYMBOL(security_unix_may_send);
1775
1776 int security_socket_create(int family, int type, int protocol, int kern)
1777 {
1778 return call_int_hook(socket_create, 0, family, type, protocol, kern);
1779 }
1780
1781 int security_socket_post_create(struct socket *sock, int family,
1782 int type, int protocol, int kern)
1783 {
1784 return call_int_hook(socket_post_create, 0, sock, family, type,
1785 protocol, kern);
1786 }
1787
1788 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
1789 {
1790 return call_int_hook(socket_bind, 0, sock, address, addrlen);
1791 }
1792
1793 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
1794 {
1795 return call_int_hook(socket_connect, 0, sock, address, addrlen);
1796 }
1797
1798 int security_socket_listen(struct socket *sock, int backlog)
1799 {
1800 return call_int_hook(socket_listen, 0, sock, backlog);
1801 }
1802
1803 int security_socket_accept(struct socket *sock, struct socket *newsock)
1804 {
1805 return call_int_hook(socket_accept, 0, sock, newsock);
1806 }
1807
1808 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
1809 {
1810 return call_int_hook(socket_sendmsg, 0, sock, msg, size);
1811 }
1812
1813 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
1814 int size, int flags)
1815 {
1816 return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
1817 }
1818
1819 int security_socket_getsockname(struct socket *sock)
1820 {
1821 return call_int_hook(socket_getsockname, 0, sock);
1822 }
1823
1824 int security_socket_getpeername(struct socket *sock)
1825 {
1826 return call_int_hook(socket_getpeername, 0, sock);
1827 }
1828
1829 int security_socket_getsockopt(struct socket *sock, int level, int optname)
1830 {
1831 return call_int_hook(socket_getsockopt, 0, sock, level, optname);
1832 }
1833
1834 int security_socket_setsockopt(struct socket *sock, int level, int optname)
1835 {
1836 return call_int_hook(socket_setsockopt, 0, sock, level, optname);
1837 }
1838
1839 int security_socket_shutdown(struct socket *sock, int how)
1840 {
1841 return call_int_hook(socket_shutdown, 0, sock, how);
1842 }
1843
1844 int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
1845 {
1846 return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
1847 }
1848 EXPORT_SYMBOL(security_sock_rcv_skb);
1849
1850 int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1851 int __user *optlen, unsigned len)
1852 {
1853 return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
1854 optval, optlen, len);
1855 }
1856
1857 int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
1858 {
1859 return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
1860 skb, secid);
1861 }
1862 EXPORT_SYMBOL(security_socket_getpeersec_dgram);
1863
1864 int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
1865 {
1866 int rc = lsm_sock_alloc(sk, priority);
1867
1868 if (rc)
1869 return rc;
1870 return call_int_hook(sk_alloc_security, 0, sk, family, priority);
1871 }
1872
1873 void security_sk_free(struct sock *sk)
1874 {
1875 call_void_hook(sk_free_security, sk);
1876 kfree(sk->sk_security);
1877 sk->sk_security = NULL;
1878 }
1879
1880 void security_sk_clone(const struct sock *sk, struct sock *newsk)
1881 {
1882 call_void_hook(sk_clone_security, sk, newsk);
1883 }
1884 EXPORT_SYMBOL(security_sk_clone);
1885
1886 void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1887 {
1888 call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
1889 }
1890 EXPORT_SYMBOL(security_sk_classify_flow);
1891
1892 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1893 {
1894 call_void_hook(req_classify_flow, req, fl);
1895 }
1896 EXPORT_SYMBOL(security_req_classify_flow);
1897
1898 void security_sock_graft(struct sock *sk, struct socket *parent)
1899 {
1900 call_void_hook(sock_graft, sk, parent);
1901 }
1902 EXPORT_SYMBOL(security_sock_graft);
1903
1904 int security_inet_conn_request(struct sock *sk,
1905 struct sk_buff *skb, struct request_sock *req)
1906 {
1907 return call_int_hook(inet_conn_request, 0, sk, skb, req);
1908 }
1909 EXPORT_SYMBOL(security_inet_conn_request);
1910
1911 void security_inet_csk_clone(struct sock *newsk,
1912 const struct request_sock *req)
1913 {
1914 call_void_hook(inet_csk_clone, newsk, req);
1915 }
1916
1917 void security_inet_conn_established(struct sock *sk,
1918 struct sk_buff *skb)
1919 {
1920 call_void_hook(inet_conn_established, sk, skb);
1921 }
1922
1923 int security_secmark_relabel_packet(u32 secid)
1924 {
1925 return call_int_hook(secmark_relabel_packet, 0, secid);
1926 }
1927 EXPORT_SYMBOL(security_secmark_relabel_packet);
1928
1929 void security_secmark_refcount_inc(void)
1930 {
1931 call_void_hook(secmark_refcount_inc);
1932 }
1933 EXPORT_SYMBOL(security_secmark_refcount_inc);
1934
1935 void security_secmark_refcount_dec(void)
1936 {
1937 call_void_hook(secmark_refcount_dec);
1938 }
1939 EXPORT_SYMBOL(security_secmark_refcount_dec);
1940
1941 int security_tun_dev_alloc_security(void **security)
1942 {
1943 return call_int_hook(tun_dev_alloc_security, 0, security);
1944 }
1945 EXPORT_SYMBOL(security_tun_dev_alloc_security);
1946
1947 void security_tun_dev_free_security(void *security)
1948 {
1949 call_void_hook(tun_dev_free_security, security);
1950 }
1951 EXPORT_SYMBOL(security_tun_dev_free_security);
1952
1953 int security_tun_dev_create(void)
1954 {
1955 return call_int_hook(tun_dev_create, 0);
1956 }
1957 EXPORT_SYMBOL(security_tun_dev_create);
1958
1959 int security_tun_dev_attach_queue(void *security)
1960 {
1961 return call_int_hook(tun_dev_attach_queue, 0, security);
1962 }
1963 EXPORT_SYMBOL(security_tun_dev_attach_queue);
1964
1965 int security_tun_dev_attach(struct sock *sk, void *security)
1966 {
1967 return call_int_hook(tun_dev_attach, 0, sk, security);
1968 }
1969 EXPORT_SYMBOL(security_tun_dev_attach);
1970
1971 int security_tun_dev_open(void *security)
1972 {
1973 return call_int_hook(tun_dev_open, 0, security);
1974 }
1975 EXPORT_SYMBOL(security_tun_dev_open);
1976
1977 #endif /* CONFIG_SECURITY_NETWORK */
1978
1979 #ifdef CONFIG_SECURITY_INFINIBAND
1980
1981 int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
1982 {
1983 return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey);
1984 }
1985 EXPORT_SYMBOL(security_ib_pkey_access);
1986
1987 int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
1988 {
1989 return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num);
1990 }
1991 EXPORT_SYMBOL(security_ib_endport_manage_subnet);
1992
1993 int security_ib_alloc_security(void **sec)
1994 {
1995 return call_int_hook(ib_alloc_security, 0, sec);
1996 }
1997 EXPORT_SYMBOL(security_ib_alloc_security);
1998
1999 void security_ib_free_security(void *sec)
2000 {
2001 call_void_hook(ib_free_security, sec);
2002 }
2003 EXPORT_SYMBOL(security_ib_free_security);
2004 #endif /* CONFIG_SECURITY_INFINIBAND */
2005
2006 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2007
2008 int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
2009 struct xfrm_user_sec_ctx *sec_ctx,
2010 gfp_t gfp)
2011 {
2012 return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
2013 }
2014 EXPORT_SYMBOL(security_xfrm_policy_alloc);
2015
2016 int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
2017 struct xfrm_sec_ctx **new_ctxp)
2018 {
2019 return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
2020 }
2021
2022 void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
2023 {
2024 call_void_hook(xfrm_policy_free_security, ctx);
2025 }
2026 EXPORT_SYMBOL(security_xfrm_policy_free);
2027
2028 int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
2029 {
2030 return call_int_hook(xfrm_policy_delete_security, 0, ctx);
2031 }
2032
2033 int security_xfrm_state_alloc(struct xfrm_state *x,
2034 struct xfrm_user_sec_ctx *sec_ctx)
2035 {
2036 return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
2037 }
2038 EXPORT_SYMBOL(security_xfrm_state_alloc);
2039
2040 int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
2041 struct xfrm_sec_ctx *polsec, u32 secid)
2042 {
2043 return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
2044 }
2045
2046 int security_xfrm_state_delete(struct xfrm_state *x)
2047 {
2048 return call_int_hook(xfrm_state_delete_security, 0, x);
2049 }
2050 EXPORT_SYMBOL(security_xfrm_state_delete);
2051
2052 void security_xfrm_state_free(struct xfrm_state *x)
2053 {
2054 call_void_hook(xfrm_state_free_security, x);
2055 }
2056
2057 int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
2058 {
2059 return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
2060 }
2061
2062 int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
2063 struct xfrm_policy *xp,
2064 const struct flowi *fl)
2065 {
2066 struct security_hook_list *hp;
2067 int rc = 1;
2068
2069 /*
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.
2074 *
2075 * For speed optimization, we explicitly break the loop rather than
2076 * using the macro
2077 */
2078 list_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
2079 list) {
2080 rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
2081 break;
2082 }
2083 return rc;
2084 }
2085
2086 int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
2087 {
2088 return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
2089 }
2090
2091 void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
2092 {
2093 int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
2094 0);
2095
2096 BUG_ON(rc);
2097 }
2098 EXPORT_SYMBOL(security_skb_classify_flow);
2099
2100 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
2101
2102 #ifdef CONFIG_KEYS
2103
2104 int security_key_alloc(struct key *key, const struct cred *cred,
2105 unsigned long flags)
2106 {
2107 int rc = lsm_key_alloc(key);
2108
2109 if (rc)
2110 return rc;
2111 return call_int_hook(key_alloc, 0, key, cred, flags);
2112 }
2113
2114 void security_key_free(struct key *key)
2115 {
2116 call_void_hook(key_free, key);
2117 kfree(key->security);
2118 key->security = NULL;
2119 }
2120
2121 int security_key_permission(key_ref_t key_ref,
2122 const struct cred *cred, unsigned perm)
2123 {
2124 return call_int_hook(key_permission, 0, key_ref, cred, perm);
2125 }
2126
2127 int security_key_getsecurity(struct key *key, char **_buffer)
2128 {
2129 *_buffer = NULL;
2130 return call_int_hook(key_getsecurity, 0, key, _buffer);
2131 }
2132
2133 #endif /* CONFIG_KEYS */
2134
2135 #ifdef CONFIG_AUDIT
2136
2137 int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
2138 {
2139 return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
2140 }
2141
2142 int security_audit_rule_known(struct audit_krule *krule)
2143 {
2144 return call_int_hook(audit_rule_known, 0, krule);
2145 }
2146
2147 void security_audit_rule_free(void *lsmrule)
2148 {
2149 call_void_hook(audit_rule_free, lsmrule);
2150 }
2151
2152 int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
2153 struct audit_context *actx)
2154 {
2155 return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
2156 actx);
2157 }
2158 #endif /* CONFIG_AUDIT */