]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - security/security.c
Yama: Check for pid death before checking ancestry
[mirror_ubuntu-bionic-kernel.git] / security / security.c
CommitLineData
1da177e4
LT
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>
d291f1a6 7 * Copyright (C) 2016 Mellanox Technologies
1da177e4
LT
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
afdb09c7 15#include <linux/bpf.h>
c59ede7b 16#include <linux/capability.h>
d47be3df 17#include <linux/dcache.h>
1da177e4
LT
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
3c4ed7bd 21#include <linux/lsm_hooks.h>
f381c272 22#include <linux/integrity.h>
6c21a7fb 23#include <linux/ima.h>
3e1be52d 24#include <linux/evm.h>
40401530 25#include <linux/fsnotify.h>
8b3ec681
AV
26#include <linux/mman.h>
27#include <linux/mount.h>
28#include <linux/personality.h>
75331a59 29#include <linux/backing-dev.h>
3bb857e4 30#include <linux/string.h>
7a90fc39 31#include <linux/msg.h>
a69a0684 32#include <linux/prctl.h>
40401530 33#include <net/flow.h>
7a90fc39 34#include <net/sock.h>
1da177e4 35
823eb1cc 36#define MAX_LSM_EVM_XATTR 2
1da177e4 37
b1d9e6b0
CS
38/* Maximum number of letters for an LSM name string */
39#define SECURITY_NAME_MAX 10
f9047a0c 40#define SECURITY_CHOSEN_NAMES_MAX (SECURITY_NAME_MAX * LSM_MAX_MAJOR)
54f4b36b 41#define MODULE_STACK "(stacking)"
b1d9e6b0 42
3dfc9b02 43struct security_hook_heads security_hook_heads __lsm_ro_after_init;
8f408ab6
DJ
44static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
45
ab9b110b 46static struct kmem_cache *lsm_file_cache;
7a90fc39 47static struct kmem_cache *lsm_inode_cache;
ab9b110b 48
d69dece5 49char *lsm_names;
a69a0684
JJ
50
51/*
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.
55 */
56static struct lsm_blob_sizes blob_sizes = {
57#ifdef CONFIG_SECURITY_STACKING
469fbb39 58 .lbs_task = SECURITY_NAME_MAX + 6,
a69a0684
JJ
59#endif
60};
f1efc8c4 61
076c54c5 62/* Boot-time LSM user choice */
f9047a0c 63static __initdata char chosen_lsms[SECURITY_CHOSEN_NAMES_MAX + 1] =
54f4b36b
CS
64#ifdef CONFIG_SECURITY_STACKING
65 MODULE_STACK;
66#else
6e65f92f 67 CONFIG_DEFAULT_SECURITY;
54f4b36b 68#endif
adf8a6ee
JJ
69static __initdata char chosen_display_lsm[SECURITY_NAME_MAX + 1]
70#ifdef CONFIG_SECURITY_STACKING
71 = CONFIG_SECURITY_DEFAULT_DISPLAY_NAME
72#endif
73;
6a3b4b47 74static char default_display_lsm[SECURITY_NAME_MAX + 1];
1da177e4 75
1da177e4
LT
76static void __init do_security_initcalls(void)
77{
78 initcall_t *call;
79 call = __security_initcall_start;
80 while (call < __security_initcall_end) {
81 (*call) ();
82 call++;
83 }
84}
85
86/**
87 * security_init - initializes the security framework
88 *
89 * This should be called early in the kernel initialization sequence.
90 */
91int __init security_init(void)
92{
3dfc9b02
TH
93 int i;
94 struct list_head *list = (struct list_head *) &security_hook_heads;
95
96 for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct list_head);
97 i++)
98 INIT_LIST_HEAD(&list[i]);
b1d9e6b0 99 pr_info("Security Framework initialized\n");
1da177e4 100
b1d9e6b0 101 /*
730daa16 102 * Load minor LSMs, with the capability module always first.
b1d9e6b0
CS
103 */
104 capability_add_hooks();
b1d9e6b0 105 yama_add_hooks();
9b091556 106 loadpin_add_hooks();
730daa16 107
b1d9e6b0 108 /*
f1efc8c4
CS
109 * The first call to a module specific init function
110 * updates the blob size requirements.
111 */
112 do_security_initcalls();
113
ab9b110b
CS
114 /*
115 * Create any kmem_caches needed for blobs
116 */
117 if (blob_sizes.lbs_file)
118 lsm_file_cache = kmem_cache_create("lsm_file_cache",
119 blob_sizes.lbs_file, 0,
120 SLAB_PANIC, NULL);
7a90fc39
CS
121 if (blob_sizes.lbs_inode)
122 lsm_inode_cache = kmem_cache_create("lsm_inode_cache",
123 blob_sizes.lbs_inode, 0,
124 SLAB_PANIC, NULL);
f1efc8c4
CS
125 /*
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.
b1d9e6b0 129 */
1da177e4
LT
130 do_security_initcalls();
131
f1efc8c4
CS
132#ifdef CONFIG_SECURITY_LSM_DEBUG
133 pr_info("LSM: cred blob size = %d\n", blob_sizes.lbs_cred);
ab9b110b 134 pr_info("LSM: file blob size = %d\n", blob_sizes.lbs_file);
7a90fc39
CS
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);
137#ifdef CONFIG_KEYS
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);
7f79f508 143 pr_info("LSM: task blob size = %d\n", blob_sizes.lbs_task);
7a90fc39 144#endif /* CONFIG_SECURITY_LSM_DEBUG */
f1efc8c4 145
1da177e4
LT
146 return 0;
147}
148
076c54c5
AD
149/* Save user chosen LSM */
150static int __init choose_lsm(char *str)
151{
f9047a0c
JJ
152 strncpy(chosen_lsms, str, SECURITY_CHOSEN_NAMES_MAX);
153 pr_info("LSM: command line set '%s' security module(s).\n",
154 chosen_lsms);
076c54c5
AD
155 return 1;
156}
157__setup("security=", choose_lsm);
158
6a3b4b47
JJ
159static int __init choose_display_lsm(char *str)
160{
161 strncpy(chosen_display_lsm, str, SECURITY_NAME_MAX);
162 pr_info("LSM: command line set default display lsm %s'\n",
163 chosen_display_lsm);
164 return 1;
165}
166__setup("security.display=", choose_display_lsm);
167
3bb857e4
MS
168static bool match_last_lsm(const char *list, const char *lsm)
169{
170 const char *last;
171
172 if (WARN_ON(!list || !lsm))
173 return false;
174 last = strrchr(list, ',');
175 if (last)
176 /* Pass the comma, strcmp() will check for '\0' */
177 last++;
178 else
179 last = list;
180 return !strcmp(last, lsm);
181}
182
d69dece5
CS
183static int lsm_append(char *new, char **result)
184{
185 char *cp;
186
187 if (*result == NULL) {
188 *result = kstrdup(new, GFP_KERNEL);
cf5fe980
EB
189 if (*result == NULL)
190 return -ENOMEM;
d69dece5 191 } else {
3bb857e4
MS
192 /* Check if it is the last registered name */
193 if (match_last_lsm(*result, new))
194 return 0;
d69dece5
CS
195 cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
196 if (cp == NULL)
197 return -ENOMEM;
198 kfree(*result);
199 *result = cp;
200 }
201 return 0;
202}
203
076c54c5
AD
204/**
205 * security_module_enable - Load given security module on boot ?
b1d9e6b0 206 * @module: the name of the module
54f4b36b 207 * @stacked: indicates that the module wants to be stacked
076c54c5
AD
208 *
209 * Each LSM must pass this method before registering its own operations
210 * to avoid security registration races. This method may also be used
7cea51be 211 * to check if your LSM is currently loaded during kernel initialization.
076c54c5 212 *
0e056eb5
MCC
213 * Returns:
214 *
215 * true if:
216 *
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.
220 *
076c54c5
AD
221 * Otherwise, return false.
222 */
f9047a0c
JJ
223#ifdef CONFIG_SECURITY_STACKING
224static bool __init cmp_lsms(const char *lsm)
225{
226 const char *str = chosen_lsms;
227 const char *split;
228 int len = strlen(lsm);
229
230 if (len > SECURITY_NAME_MAX) {
231 pr_info("LSM: security module name '%s' exceeds limit\n", lsm);
232 return false;
233 }
234 for (split = strchr(str, ','); split; split = strchr(str, ',')) {
235 if ((len == split - str) && !strncmp(lsm, str, split - str))
236 return true;
237 str = split + 1;
238 }
239 if ((len == strlen(str)) && !strncmp(lsm, str, strlen(str)))
240 return true;
241 return false;
242}
243#endif
244
54f4b36b 245bool __init security_module_enable(const char *lsm, const bool stacked)
076c54c5 246{
54f4b36b
CS
247#ifdef CONFIG_SECURITY_STACKING
248 /*
249 * Module defined on the command line security=XXXX
250 */
6a3b4b47
JJ
251 if (strcmp(chosen_lsms, MODULE_STACK)) {
252 if (cmp_lsms(lsm)) {
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);
259 }
260 return true;
261 }
262 return false;
263 }
54f4b36b
CS
264 /*
265 * Module configured as stacked.
266 */
6a3b4b47
JJ
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);
272 }
273
54f4b36b
CS
274 return stacked;
275#else
6a3b4b47
JJ
276 if (strcmp(lsm, chosen_lsms) == 0) {
277 strcpy(default_display_lsm, lsm);
54f4b36b 278 return true;
6a3b4b47 279 }
54f4b36b
CS
280 return false;
281#endif
076c54c5
AD
282}
283
d0c8f0ad
JJ
284/*
285 * Keep the order of major modules for mapping secids.
286 */
287static int lsm_next_major;
288
d69dece5
CS
289/**
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
294 *
295 * Each LSM has to register its hooks with the infrastructure.
296 */
297void __init security_add_hooks(struct security_hook_list *hooks, int count,
298 char *lsm)
299{
300 int i;
d0c8f0ad
JJ
301 int lsm_index = lsm_next_major++;
302
303#ifdef CONFIG_SECURITY_LSM_DEBUG
304 pr_info("LSM: Security module %s gets index %d\n", lsm, lsm_index);
305#endif
d69dece5
CS
306 for (i = 0; i < count; i++) {
307 hooks[i].lsm = lsm;
d0c8f0ad 308 hooks[i].lsm_index = lsm_index;
d69dece5
CS
309 list_add_tail_rcu(&hooks[i].list, hooks[i].head);
310 }
311 if (lsm_append(lsm, &lsm_names) < 0)
312 panic("%s - Cannot get early memory.\n", __func__);
313}
314
8f408ab6
DJ
315int call_lsm_notifier(enum lsm_event event, void *data)
316{
317 return atomic_notifier_call_chain(&lsm_notifier_chain, event, data);
318}
319EXPORT_SYMBOL(call_lsm_notifier);
320
321int register_lsm_notifier(struct notifier_block *nb)
322{
323 return atomic_notifier_chain_register(&lsm_notifier_chain, nb);
324}
325EXPORT_SYMBOL(register_lsm_notifier);
326
327int unregister_lsm_notifier(struct notifier_block *nb)
328{
329 return atomic_notifier_chain_unregister(&lsm_notifier_chain, nb);
330}
331EXPORT_SYMBOL(unregister_lsm_notifier);
332
f1efc8c4
CS
333/**
334 * lsm_cred_alloc - allocate a composite cred blob
335 * @cred: the cred that needs a blob
336 * @gfp: allocation type
337 *
338 * Allocate the cred blob for all the modules
339 *
340 * Returns 0, or -ENOMEM if memory can't be allocated.
341 */
342int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
343{
344 if (blob_sizes.lbs_cred == 0) {
345 cred->security = NULL;
346 return 0;
347 }
348
349 cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
350 if (cred->security == NULL)
351 return -ENOMEM;
352 return 0;
353}
354
355/**
356 * lsm_early_cred - during initialization allocate a composite cred blob
357 * @cred: the cred that needs a blob
358 *
359 * Allocate the cred blob for all the modules if it's not already there
360 */
361void lsm_early_cred(struct cred *cred)
362{
363 int rc;
364
365 if (cred == NULL)
366 panic("%s: NULL cred.\n", __func__);
367 if (cred->security != NULL)
368 return;
369 rc = lsm_cred_alloc(cred, GFP_KERNEL);
370 if (rc)
371 panic("%s: Early cred alloc failed.\n", __func__);
372}
373
374static void __init lsm_set_size(int *need, int *lbs)
375{
376 int offset;
377
378 if (*need > 0) {
379 offset = *lbs;
380 *lbs += *need;
381 *need = offset;
382 }
383}
384
385/**
386 * security_add_blobs - Report blob sizes
387 * @needed: the size of blobs needed by the module
388 *
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.
394 */
395void __init security_add_blobs(struct lsm_blob_sizes *needed)
396{
397 lsm_set_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
ab9b110b 398 lsm_set_size(&needed->lbs_file, &blob_sizes.lbs_file);
7a90fc39
CS
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);
7f79f508 404 lsm_set_size(&needed->lbs_task, &blob_sizes.lbs_task);
7a90fc39
CS
405 /*
406 * The inode blob gets an rcu_head in addition to
407 * what the modules might need.
408 */
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);
ab9b110b
CS
412}
413
414/**
415 * lsm_file_alloc - allocate a composite file blob
416 * @file: the file that needs a blob
417 *
418 * Allocate the file blob for all the modules
419 *
420 * Returns 0, or -ENOMEM if memory can't be allocated.
421 */
422int lsm_file_alloc(struct file *file)
423{
424 if (!lsm_file_cache) {
425 file->f_security = NULL;
426 return 0;
427 }
428
429 file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL);
430 if (file->f_security == NULL)
431 return -ENOMEM;
432 return 0;
f1efc8c4
CS
433}
434
a69a0684
JJ
435#ifdef CONFIG_SECURITY_STACKING
436static inline char *lsm_of_task(struct task_struct *task)
437{
438#ifdef CONFIG_SECURITY_LSM_DEBUG
439 if (task->security == NULL)
440 pr_info("%s: task has no lsm name.\n", __func__);
441#endif
442 return task->security;
443}
444#endif
445
7f79f508
CS
446/**
447 * lsm_task_alloc - allocate a composite task blob
448 * @task: the task that needs a blob
449 *
450 * Allocate the task blob for all the modules
451 *
452 * Returns 0, or -ENOMEM if memory can't be allocated.
453 */
454int lsm_task_alloc(struct task_struct *task)
455{
456 if (blob_sizes.lbs_task == 0) {
457 task->security = NULL;
458 return 0;
459 }
460
461 task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL);
462 if (task->security == NULL)
463 return -ENOMEM;
76afa12e
JJ
464
465 /* inherit current display lsm */
466#ifdef CONFIG_SECURITY_STACKING
467 if (current->security)
468 strcpy(task->security, lsm_of_task(current));
6a3b4b47
JJ
469 else
470 strcpy(task->security, default_display_lsm);
76afa12e 471#endif
7f79f508
CS
472 return 0;
473}
474
7a90fc39
CS
475/**
476 * lsm_inode_alloc - allocate a composite inode blob
477 * @inode: the inode that needs a blob
478 *
479 * Allocate the inode blob for all the modules
480 *
481 * Returns 0, or -ENOMEM if memory can't be allocated.
482 */
483int lsm_inode_alloc(struct inode *inode)
484{
485 if (!lsm_inode_cache) {
486 inode->i_security = NULL;
487 return 0;
488 }
489
490 inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_KERNEL);
491 if (inode->i_security == NULL)
492 return -ENOMEM;
493 return 0;
494}
495
496/**
497 * lsm_early_inode - during initialization allocate a composite inode blob
498 * @inode: the inode that needs a blob
499 *
500 * Allocate the inode blob for all the modules if it's not already there
501 */
502void lsm_early_inode(struct inode *inode)
503{
504 int rc;
505
506 if (inode == NULL)
507 panic("%s: NULL inode.\n", __func__);
508 if (inode->i_security != NULL)
509 return;
510 rc = lsm_inode_alloc(inode);
511 if (rc)
512 panic("%s: Early inode alloc failed.\n", __func__);
513}
514
515/**
516 * lsm_ipc_alloc - allocate a composite ipc blob
517 * @kip: the ipc that needs a blob
518 *
519 * Allocate the ipc blob for all the modules
520 *
521 * Returns 0, or -ENOMEM if memory can't be allocated.
522 */
523int lsm_ipc_alloc(struct kern_ipc_perm *kip)
524{
525 if (blob_sizes.lbs_ipc == 0) {
526 kip->security = NULL;
527 return 0;
528 }
529
530 kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL);
531 if (kip->security == NULL)
532 return -ENOMEM;
533 return 0;
534}
535
536#ifdef CONFIG_KEYS
537/**
538 * lsm_key_alloc - allocate a composite key blob
539 * @key: the key that needs a blob
540 *
541 * Allocate the key blob for all the modules
542 *
543 * Returns 0, or -ENOMEM if memory can't be allocated.
544 */
545int lsm_key_alloc(struct key *key)
546{
547 if (blob_sizes.lbs_key == 0) {
548 key->security = NULL;
549 return 0;
550 }
551
552 key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL);
553 if (key->security == NULL)
554 return -ENOMEM;
555 return 0;
556}
557#endif /* CONFIG_KEYS */
558
559/**
560 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
561 * @mp: the msg_msg that needs a blob
562 *
563 * Allocate the ipc blob for all the modules
564 *
565 * Returns 0, or -ENOMEM if memory can't be allocated.
566 */
567int lsm_msg_msg_alloc(struct msg_msg *mp)
568{
569 if (blob_sizes.lbs_msg_msg == 0) {
570 mp->security = NULL;
571 return 0;
572 }
573
574 mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL);
575 if (mp->security == NULL)
576 return -ENOMEM;
577 return 0;
578}
579
580/**
581 * lsm_sock_alloc - allocate a composite sock blob
582 * @sock: the sock that needs a blob
583 * @priority: allocation mode
584 *
585 * Allocate the sock blob for all the modules
586 *
587 * Returns 0, or -ENOMEM if memory can't be allocated.
588 */
589int lsm_sock_alloc(struct sock *sock, gfp_t priority)
590{
591 if (blob_sizes.lbs_sock == 0) {
592 sock->sk_security = NULL;
593 return 0;
594 }
595
596 sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority);
597 if (sock->sk_security == NULL)
598 return -ENOMEM;
599 return 0;
600}
601
602/**
603 * lsm_superblock_alloc - allocate a composite superblock blob
604 * @sb: the superblock that needs a blob
605 *
606 * Allocate the superblock blob for all the modules
607 *
608 * Returns 0, or -ENOMEM if memory can't be allocated.
609 */
610int lsm_superblock_alloc(struct super_block *sb)
611{
612 if (blob_sizes.lbs_superblock == 0) {
613 sb->s_security = NULL;
614 return 0;
615 }
616
617 sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL);
618 if (sb->s_security == NULL)
619 return -ENOMEM;
620 return 0;
621}
622
f25fce3e 623/*
b1d9e6b0 624 * Hook list operation macros.
1da177e4 625 *
f25fce3e
CS
626 * call_void_hook:
627 * This is a hook that does not return a value.
1da177e4 628 *
f25fce3e
CS
629 * call_int_hook:
630 * This is a hook that returns a value.
1da177e4 631 */
1da177e4 632
b1d9e6b0
CS
633#define call_void_hook(FUNC, ...) \
634 do { \
635 struct security_hook_list *P; \
636 \
637 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
638 P->hook.FUNC(__VA_ARGS__); \
639 } while (0)
640
641#define call_int_hook(FUNC, IRC, ...) ({ \
642 int RC = IRC; \
643 do { \
644 struct security_hook_list *P; \
645 \
646 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
647 RC = P->hook.FUNC(__VA_ARGS__); \
648 if (RC != 0) \
649 break; \
650 } \
651 } while (0); \
652 RC; \
653})
1da177e4 654
20510f2f
JM
655/* Security operations */
656
79af7307
SS
657int security_binder_set_context_mgr(struct task_struct *mgr)
658{
f25fce3e 659 return call_int_hook(binder_set_context_mgr, 0, mgr);
79af7307
SS
660}
661
662int security_binder_transaction(struct task_struct *from,
663 struct task_struct *to)
664{
f25fce3e 665 return call_int_hook(binder_transaction, 0, from, to);
79af7307
SS
666}
667
668int security_binder_transfer_binder(struct task_struct *from,
669 struct task_struct *to)
670{
f25fce3e 671 return call_int_hook(binder_transfer_binder, 0, from, to);
79af7307
SS
672}
673
674int security_binder_transfer_file(struct task_struct *from,
675 struct task_struct *to, struct file *file)
676{
f25fce3e 677 return call_int_hook(binder_transfer_file, 0, from, to, file);
79af7307
SS
678}
679
9e48858f 680int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
20510f2f 681{
f25fce3e 682 return call_int_hook(ptrace_access_check, 0, child, mode);
5cd9c58f
DH
683}
684
685int security_ptrace_traceme(struct task_struct *parent)
686{
f25fce3e 687 return call_int_hook(ptrace_traceme, 0, parent);
20510f2f
JM
688}
689
690int security_capget(struct task_struct *target,
691 kernel_cap_t *effective,
692 kernel_cap_t *inheritable,
693 kernel_cap_t *permitted)
694{
f25fce3e
CS
695 return call_int_hook(capget, 0, target,
696 effective, inheritable, permitted);
20510f2f
JM
697}
698
d84f4f99
DH
699int 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)
20510f2f 703{
f25fce3e
CS
704 return call_int_hook(capset, 0, new, old,
705 effective, inheritable, permitted);
20510f2f
JM
706}
707
b7e724d3 708int security_capable(const struct cred *cred, struct user_namespace *ns,
3486740a 709 int cap)
20510f2f 710{
f25fce3e 711 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
06112163
EP
712}
713
c7eba4a9
EP
714int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
715 int cap)
06112163 716{
f25fce3e 717 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
20510f2f
JM
718}
719
20510f2f
JM
720int security_quotactl(int cmds, int type, int id, struct super_block *sb)
721{
f25fce3e 722 return call_int_hook(quotactl, 0, cmds, type, id, sb);
20510f2f
JM
723}
724
725int security_quota_on(struct dentry *dentry)
726{
f25fce3e 727 return call_int_hook(quota_on, 0, dentry);
20510f2f
JM
728}
729
12b3052c 730int security_syslog(int type)
20510f2f 731{
f25fce3e 732 return call_int_hook(syslog, 0, type);
20510f2f
JM
733}
734
457db29b 735int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
20510f2f 736{
f25fce3e 737 return call_int_hook(settime, 0, ts, tz);
20510f2f
JM
738}
739
20510f2f
JM
740int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
741{
b1d9e6b0
CS
742 struct security_hook_list *hp;
743 int cap_sys_admin = 1;
744 int rc;
745
746 /*
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.
752 */
753 list_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
754 rc = hp->hook.vm_enough_memory(mm, pages);
755 if (rc <= 0) {
756 cap_sys_admin = 0;
757 break;
758 }
759 }
760 return __vm_enough_memory(mm, pages, cap_sys_admin);
20510f2f
JM
761}
762
a6f76f23 763int security_bprm_set_creds(struct linux_binprm *bprm)
20510f2f 764{
f25fce3e 765 return call_int_hook(bprm_set_creds, 0, bprm);
20510f2f
JM
766}
767
a6f76f23 768int security_bprm_check(struct linux_binprm *bprm)
20510f2f 769{
6c21a7fb
MZ
770 int ret;
771
f25fce3e 772 ret = call_int_hook(bprm_check_security, 0, bprm);
6c21a7fb
MZ
773 if (ret)
774 return ret;
775 return ima_bprm_check(bprm);
20510f2f
JM
776}
777
a6f76f23 778void security_bprm_committing_creds(struct linux_binprm *bprm)
20510f2f 779{
f25fce3e 780 call_void_hook(bprm_committing_creds, bprm);
20510f2f
JM
781}
782
a6f76f23 783void security_bprm_committed_creds(struct linux_binprm *bprm)
20510f2f 784{
f25fce3e 785 call_void_hook(bprm_committed_creds, bprm);
20510f2f
JM
786}
787
20510f2f
JM
788int security_sb_alloc(struct super_block *sb)
789{
7a90fc39
CS
790 int rc = lsm_superblock_alloc(sb);
791
792 if (unlikely(rc))
793 return rc;
794 rc = call_int_hook(sb_alloc_security, 0, sb);
795 if (unlikely(rc))
796 security_sb_free(sb);
797 return rc;
20510f2f
JM
798}
799
800void security_sb_free(struct super_block *sb)
801{
f25fce3e 802 call_void_hook(sb_free_security, sb);
7a90fc39
CS
803 kfree(sb->s_security);
804 sb->s_security = NULL;
20510f2f
JM
805}
806
e0007529 807int security_sb_copy_data(char *orig, char *copy)
20510f2f 808{
f25fce3e 809 return call_int_hook(sb_copy_data, 0, orig, copy);
20510f2f 810}
e0007529 811EXPORT_SYMBOL(security_sb_copy_data);
20510f2f 812
ff36fe2c
EP
813int security_sb_remount(struct super_block *sb, void *data)
814{
f25fce3e 815 return call_int_hook(sb_remount, 0, sb, data);
ff36fe2c
EP
816}
817
12204e24 818int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
20510f2f 819{
f25fce3e 820 return call_int_hook(sb_kern_mount, 0, sb, flags, data);
20510f2f
JM
821}
822
2069f457
EP
823int security_sb_show_options(struct seq_file *m, struct super_block *sb)
824{
f25fce3e 825 return call_int_hook(sb_show_options, 0, m, sb);
2069f457
EP
826}
827
20510f2f
JM
828int security_sb_statfs(struct dentry *dentry)
829{
f25fce3e 830 return call_int_hook(sb_statfs, 0, dentry);
20510f2f
JM
831}
832
8a04c43b 833int security_sb_mount(const char *dev_name, const struct path *path,
808d4e3c 834 const char *type, unsigned long flags, void *data)
20510f2f 835{
f25fce3e 836 return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
20510f2f
JM
837}
838
20510f2f
JM
839int security_sb_umount(struct vfsmount *mnt, int flags)
840{
f25fce3e 841 return call_int_hook(sb_umount, 0, mnt, flags);
20510f2f
JM
842}
843
3b73b68c 844int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
20510f2f 845{
f25fce3e 846 return call_int_hook(sb_pivotroot, 0, old_path, new_path);
20510f2f
JM
847}
848
c9180a57 849int security_sb_set_mnt_opts(struct super_block *sb,
649f6e77
DQ
850 struct security_mnt_opts *opts,
851 unsigned long kern_flags,
852 unsigned long *set_kern_flags)
c9180a57 853{
b1d9e6b0
CS
854 return call_int_hook(sb_set_mnt_opts,
855 opts->num_mnt_opts ? -EOPNOTSUPP : 0, sb,
856 opts, kern_flags, set_kern_flags);
c9180a57 857}
e0007529 858EXPORT_SYMBOL(security_sb_set_mnt_opts);
c9180a57 859
094f7b69 860int security_sb_clone_mnt_opts(const struct super_block *oldsb,
0b4d3452
SM
861 struct super_block *newsb,
862 unsigned long kern_flags,
863 unsigned long *set_kern_flags)
c9180a57 864{
0b4d3452
SM
865 return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
866 kern_flags, set_kern_flags);
c9180a57 867}
e0007529
EP
868EXPORT_SYMBOL(security_sb_clone_mnt_opts);
869
870int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
871{
f25fce3e 872 return call_int_hook(sb_parse_opts_str, 0, options, opts);
e0007529
EP
873}
874EXPORT_SYMBOL(security_sb_parse_opts_str);
c9180a57 875
20510f2f
JM
876int security_inode_alloc(struct inode *inode)
877{
7a90fc39
CS
878 int rc = lsm_inode_alloc(inode);
879
880 if (unlikely(rc))
881 return rc;
882 rc = call_int_hook(inode_alloc_security, 0, inode);
883 if (unlikely(rc))
884 security_inode_free(inode);
885 return rc;
886}
887
888static void inode_free_by_rcu(struct rcu_head *head)
889{
890 /*
891 * The rcu head is at the start of the inode blob
892 */
893 kmem_cache_free(lsm_inode_cache, head);
20510f2f
JM
894}
895
896void security_inode_free(struct inode *inode)
897{
f381c272 898 integrity_inode_free(inode);
f25fce3e 899 call_void_hook(inode_free_security, inode);
7a90fc39
CS
900 /*
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.
908 */
909 if (inode->i_security)
910 call_rcu((struct rcu_head *)inode->i_security,
911 inode_free_by_rcu);
20510f2f
JM
912}
913
d47be3df 914int security_dentry_init_security(struct dentry *dentry, int mode,
4f3ccd76 915 const struct qstr *name, void **ctx,
d47be3df
DQ
916 u32 *ctxlen)
917{
b1d9e6b0
CS
918 return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
919 name, ctx, ctxlen);
d47be3df
DQ
920}
921EXPORT_SYMBOL(security_dentry_init_security);
922
2602625b
VG
923int security_dentry_create_files_as(struct dentry *dentry, int mode,
924 struct qstr *name,
925 const struct cred *old, struct cred *new)
926{
927 return call_int_hook(dentry_create_files_as, 0, dentry, mode,
928 name, old, new);
929}
930EXPORT_SYMBOL(security_dentry_create_files_as);
931
20510f2f 932int security_inode_init_security(struct inode *inode, struct inode *dir,
9d8f13ba
MZ
933 const struct qstr *qstr,
934 const initxattrs initxattrs, void *fs_data)
20510f2f 935{
823eb1cc
MZ
936 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
937 struct xattr *lsm_xattr, *evm_xattr, *xattr;
9d8f13ba
MZ
938 int ret;
939
20510f2f 940 if (unlikely(IS_PRIVATE(inode)))
fb88c2b6 941 return 0;
9d8f13ba 942
9d8f13ba 943 if (!initxattrs)
e308fd3b
JB
944 return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
945 dir, qstr, NULL, NULL, NULL);
9548906b 946 memset(new_xattrs, 0, sizeof(new_xattrs));
9d8f13ba 947 lsm_xattr = new_xattrs;
b1d9e6b0 948 ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
9d8f13ba
MZ
949 &lsm_xattr->name,
950 &lsm_xattr->value,
951 &lsm_xattr->value_len);
952 if (ret)
953 goto out;
823eb1cc
MZ
954
955 evm_xattr = lsm_xattr + 1;
956 ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
957 if (ret)
958 goto out;
9d8f13ba
MZ
959 ret = initxattrs(inode, new_xattrs, fs_data);
960out:
9548906b 961 for (xattr = new_xattrs; xattr->value != NULL; xattr++)
823eb1cc 962 kfree(xattr->value);
9d8f13ba
MZ
963 return (ret == -EOPNOTSUPP) ? 0 : ret;
964}
965EXPORT_SYMBOL(security_inode_init_security);
966
967int security_old_inode_init_security(struct inode *inode, struct inode *dir,
9548906b 968 const struct qstr *qstr, const char **name,
9d8f13ba 969 void **value, size_t *len)
20510f2f
JM
970{
971 if (unlikely(IS_PRIVATE(inode)))
30e05324 972 return -EOPNOTSUPP;
e308fd3b
JB
973 return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
974 qstr, name, value, len);
20510f2f 975}
9d8f13ba 976EXPORT_SYMBOL(security_old_inode_init_security);
20510f2f 977
be6d3e56 978#ifdef CONFIG_SECURITY_PATH
d3607752 979int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
be6d3e56
KT
980 unsigned int dev)
981{
c6f493d6 982 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
be6d3e56 983 return 0;
f25fce3e 984 return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
be6d3e56
KT
985}
986EXPORT_SYMBOL(security_path_mknod);
987
d3607752 988int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
be6d3e56 989{
c6f493d6 990 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
be6d3e56 991 return 0;
f25fce3e 992 return call_int_hook(path_mkdir, 0, dir, dentry, mode);
be6d3e56 993}
82140443 994EXPORT_SYMBOL(security_path_mkdir);
be6d3e56 995
989f74e0 996int security_path_rmdir(const struct path *dir, struct dentry *dentry)
be6d3e56 997{
c6f493d6 998 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
be6d3e56 999 return 0;
f25fce3e 1000 return call_int_hook(path_rmdir, 0, dir, dentry);
be6d3e56 1001}
c088e31d 1002EXPORT_SYMBOL_GPL(security_path_rmdir);
be6d3e56 1003
989f74e0 1004int security_path_unlink(const struct path *dir, struct dentry *dentry)
be6d3e56 1005{
c6f493d6 1006 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
be6d3e56 1007 return 0;
f25fce3e 1008 return call_int_hook(path_unlink, 0, dir, dentry);
be6d3e56 1009}
82140443 1010EXPORT_SYMBOL(security_path_unlink);
be6d3e56 1011
d3607752 1012int security_path_symlink(const struct path *dir, struct dentry *dentry,
be6d3e56
KT
1013 const char *old_name)
1014{
c6f493d6 1015 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
be6d3e56 1016 return 0;
f25fce3e 1017 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
be6d3e56 1018}
c088e31d 1019EXPORT_SYMBOL_GPL(security_path_symlink);
be6d3e56 1020
3ccee46a 1021int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
be6d3e56
KT
1022 struct dentry *new_dentry)
1023{
c6f493d6 1024 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
be6d3e56 1025 return 0;
f25fce3e 1026 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
be6d3e56 1027}
c088e31d 1028EXPORT_SYMBOL_GPL(security_path_link);
be6d3e56 1029
3ccee46a
AV
1030int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1031 const struct path *new_dir, struct dentry *new_dentry,
0b3974eb 1032 unsigned int flags)
be6d3e56 1033{
c6f493d6
DH
1034 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
1035 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
be6d3e56 1036 return 0;
da1ce067
MS
1037
1038 if (flags & RENAME_EXCHANGE) {
f25fce3e
CS
1039 int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
1040 old_dir, old_dentry);
da1ce067
MS
1041 if (err)
1042 return err;
1043 }
1044
f25fce3e
CS
1045 return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
1046 new_dentry);
be6d3e56 1047}
82140443 1048EXPORT_SYMBOL(security_path_rename);
be6d3e56 1049
81f4c506 1050int security_path_truncate(const struct path *path)
be6d3e56 1051{
c6f493d6 1052 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
be6d3e56 1053 return 0;
f25fce3e 1054 return call_int_hook(path_truncate, 0, path);
be6d3e56 1055}
c088e31d 1056EXPORT_SYMBOL_GPL(security_path_truncate);
89eda068 1057
be01f9f2 1058int security_path_chmod(const struct path *path, umode_t mode)
89eda068 1059{
c6f493d6 1060 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
89eda068 1061 return 0;
f25fce3e 1062 return call_int_hook(path_chmod, 0, path, mode);
89eda068 1063}
c088e31d 1064EXPORT_SYMBOL_GPL(security_path_chmod);
89eda068 1065
7fd25dac 1066int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
89eda068 1067{
c6f493d6 1068 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
89eda068 1069 return 0;
f25fce3e 1070 return call_int_hook(path_chown, 0, path, uid, gid);
89eda068 1071}
c088e31d 1072EXPORT_SYMBOL_GPL(security_path_chown);
8b8efb44 1073
77b286c0 1074int security_path_chroot(const struct path *path)
8b8efb44 1075{
f25fce3e 1076 return call_int_hook(path_chroot, 0, path);
8b8efb44 1077}
be6d3e56
KT
1078#endif
1079
4acdaf27 1080int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
20510f2f
JM
1081{
1082 if (unlikely(IS_PRIVATE(dir)))
1083 return 0;
f25fce3e 1084 return call_int_hook(inode_create, 0, dir, dentry, mode);
20510f2f 1085}
800a9647 1086EXPORT_SYMBOL_GPL(security_inode_create);
20510f2f
JM
1087
1088int security_inode_link(struct dentry *old_dentry, struct inode *dir,
1089 struct dentry *new_dentry)
1090{
c6f493d6 1091 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
20510f2f 1092 return 0;
f25fce3e 1093 return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
20510f2f
JM
1094}
1095
1096int security_inode_unlink(struct inode *dir, struct dentry *dentry)
1097{
c6f493d6 1098 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1099 return 0;
f25fce3e 1100 return call_int_hook(inode_unlink, 0, dir, dentry);
20510f2f
JM
1101}
1102
1103int security_inode_symlink(struct inode *dir, struct dentry *dentry,
1104 const char *old_name)
1105{
1106 if (unlikely(IS_PRIVATE(dir)))
1107 return 0;
f25fce3e 1108 return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
20510f2f
JM
1109}
1110
18bb1db3 1111int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20510f2f
JM
1112{
1113 if (unlikely(IS_PRIVATE(dir)))
1114 return 0;
f25fce3e 1115 return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
20510f2f 1116}
800a9647 1117EXPORT_SYMBOL_GPL(security_inode_mkdir);
20510f2f
JM
1118
1119int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
1120{
c6f493d6 1121 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1122 return 0;
f25fce3e 1123 return call_int_hook(inode_rmdir, 0, dir, dentry);
20510f2f
JM
1124}
1125
1a67aafb 1126int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
20510f2f
JM
1127{
1128 if (unlikely(IS_PRIVATE(dir)))
1129 return 0;
f25fce3e 1130 return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
20510f2f
JM
1131}
1132
1133int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
0b3974eb
MS
1134 struct inode *new_dir, struct dentry *new_dentry,
1135 unsigned int flags)
20510f2f 1136{
c6f493d6
DH
1137 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
1138 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
20510f2f 1139 return 0;
da1ce067
MS
1140
1141 if (flags & RENAME_EXCHANGE) {
f25fce3e 1142 int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
da1ce067
MS
1143 old_dir, old_dentry);
1144 if (err)
1145 return err;
1146 }
1147
f25fce3e 1148 return call_int_hook(inode_rename, 0, old_dir, old_dentry,
20510f2f
JM
1149 new_dir, new_dentry);
1150}
1151
1152int security_inode_readlink(struct dentry *dentry)
1153{
c6f493d6 1154 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1155 return 0;
f25fce3e 1156 return call_int_hook(inode_readlink, 0, dentry);
20510f2f 1157}
c088e31d 1158EXPORT_SYMBOL_GPL(security_inode_readlink);
20510f2f 1159
bda0be7a
N
1160int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1161 bool rcu)
20510f2f 1162{
bda0be7a 1163 if (unlikely(IS_PRIVATE(inode)))
20510f2f 1164 return 0;
e22619a2 1165 return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
20510f2f
JM
1166}
1167
b77b0646 1168int security_inode_permission(struct inode *inode, int mask)
20510f2f
JM
1169{
1170 if (unlikely(IS_PRIVATE(inode)))
1171 return 0;
f25fce3e 1172 return call_int_hook(inode_permission, 0, inode, mask);
20510f2f 1173}
c088e31d 1174EXPORT_SYMBOL_GPL(security_inode_permission);
20510f2f
JM
1175
1176int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1177{
817b54aa
MZ
1178 int ret;
1179
c6f493d6 1180 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1181 return 0;
f25fce3e 1182 ret = call_int_hook(inode_setattr, 0, dentry, attr);
817b54aa
MZ
1183 if (ret)
1184 return ret;
1185 return evm_inode_setattr(dentry, attr);
20510f2f 1186}
b1da47e2 1187EXPORT_SYMBOL_GPL(security_inode_setattr);
20510f2f 1188
3f7036a0 1189int security_inode_getattr(const struct path *path)
20510f2f 1190{
c6f493d6 1191 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
20510f2f 1192 return 0;
f25fce3e 1193 return call_int_hook(inode_getattr, 0, path);
20510f2f
JM
1194}
1195
8f0cfa52
DH
1196int security_inode_setxattr(struct dentry *dentry, const char *name,
1197 const void *value, size_t size, int flags)
20510f2f 1198{
3e1be52d
MZ
1199 int ret;
1200
c6f493d6 1201 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1202 return 0;
b1d9e6b0
CS
1203 /*
1204 * SELinux and Smack integrate the cap call,
1205 * so assume that all LSMs supplying this call do so.
1206 */
1207 ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
f25fce3e 1208 flags);
b1d9e6b0
CS
1209
1210 if (ret == 1)
1211 ret = cap_inode_setxattr(dentry, name, value, size, flags);
42c63330
MZ
1212 if (ret)
1213 return ret;
1214 ret = ima_inode_setxattr(dentry, name, value, size);
3e1be52d
MZ
1215 if (ret)
1216 return ret;
1217 return evm_inode_setxattr(dentry, name, value, size);
20510f2f
JM
1218}
1219
8f0cfa52
DH
1220void security_inode_post_setxattr(struct dentry *dentry, const char *name,
1221 const void *value, size_t size, int flags)
20510f2f 1222{
c6f493d6 1223 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1224 return;
f25fce3e 1225 call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
3e1be52d 1226 evm_inode_post_setxattr(dentry, name, value, size);
20510f2f
JM
1227}
1228
8f0cfa52 1229int security_inode_getxattr(struct dentry *dentry, const char *name)
20510f2f 1230{
c6f493d6 1231 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1232 return 0;
f25fce3e 1233 return call_int_hook(inode_getxattr, 0, dentry, name);
20510f2f
JM
1234}
1235
1236int security_inode_listxattr(struct dentry *dentry)
1237{
c6f493d6 1238 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1239 return 0;
f25fce3e 1240 return call_int_hook(inode_listxattr, 0, dentry);
20510f2f
JM
1241}
1242
8f0cfa52 1243int security_inode_removexattr(struct dentry *dentry, const char *name)
20510f2f 1244{
3e1be52d
MZ
1245 int ret;
1246
c6f493d6 1247 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
20510f2f 1248 return 0;
b1d9e6b0
CS
1249 /*
1250 * SELinux and Smack integrate the cap call,
1251 * so assume that all LSMs supplying this call do so.
1252 */
1253 ret = call_int_hook(inode_removexattr, 1, dentry, name);
1254 if (ret == 1)
1255 ret = cap_inode_removexattr(dentry, name);
42c63330
MZ
1256 if (ret)
1257 return ret;
1258 ret = ima_inode_removexattr(dentry, name);
3e1be52d
MZ
1259 if (ret)
1260 return ret;
1261 return evm_inode_removexattr(dentry, name);
20510f2f
JM
1262}
1263
b5376771
SH
1264int security_inode_need_killpriv(struct dentry *dentry)
1265{
f25fce3e 1266 return call_int_hook(inode_need_killpriv, 0, dentry);
b5376771
SH
1267}
1268
1269int security_inode_killpriv(struct dentry *dentry)
1270{
f25fce3e 1271 return call_int_hook(inode_killpriv, 0, dentry);
b5376771
SH
1272}
1273
ea861dfd 1274int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
20510f2f 1275{
2885c1e3
CS
1276 struct security_hook_list *hp;
1277 int rc;
1278
20510f2f 1279 if (unlikely(IS_PRIVATE(inode)))
8d952504 1280 return -EOPNOTSUPP;
2885c1e3
CS
1281 /*
1282 * Only one module will provide an attribute with a given name.
1283 */
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)
1287 return rc;
1288 }
1289 return -EOPNOTSUPP;
20510f2f
JM
1290}
1291
1292int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
1293{
2885c1e3
CS
1294 struct security_hook_list *hp;
1295 int rc;
1296
20510f2f 1297 if (unlikely(IS_PRIVATE(inode)))
8d952504 1298 return -EOPNOTSUPP;
2885c1e3
CS
1299 /*
1300 * Only one module will provide an attribute with a given name.
1301 */
1302 list_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
1303 rc = hp->hook.inode_setsecurity(inode, name, value, size,
1304 flags);
1305 if (rc != -EOPNOTSUPP)
1306 return rc;
1307 }
1308 return -EOPNOTSUPP;
20510f2f
JM
1309}
1310
1311int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
1312{
1313 if (unlikely(IS_PRIVATE(inode)))
1314 return 0;
f25fce3e 1315 return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
20510f2f 1316}
c9bccef6 1317EXPORT_SYMBOL(security_inode_listsecurity);
20510f2f 1318
d6335d77 1319void security_inode_getsecid(struct inode *inode, u32 *secid)
8a076191 1320{
f25fce3e 1321 call_void_hook(inode_getsecid, inode, secid);
8a076191
AD
1322}
1323
d8ad8b49
VG
1324int security_inode_copy_up(struct dentry *src, struct cred **new)
1325{
1326 return call_int_hook(inode_copy_up, 0, src, new);
1327}
1328EXPORT_SYMBOL(security_inode_copy_up);
1329
121ab822
VG
1330int security_inode_copy_up_xattr(const char *name)
1331{
1332 return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name);
1333}
1334EXPORT_SYMBOL(security_inode_copy_up_xattr);
1335
20510f2f
JM
1336int security_file_permission(struct file *file, int mask)
1337{
c4ec54b4
EP
1338 int ret;
1339
f25fce3e 1340 ret = call_int_hook(file_permission, 0, file, mask);
c4ec54b4
EP
1341 if (ret)
1342 return ret;
1343
1344 return fsnotify_perm(file, mask);
20510f2f 1345}
c088e31d 1346EXPORT_SYMBOL_GPL(security_file_permission);
20510f2f
JM
1347
1348int security_file_alloc(struct file *file)
1349{
ab9b110b
CS
1350 int rc = lsm_file_alloc(file);
1351
7a90fc39 1352 if (unlikely(rc))
ab9b110b
CS
1353 return rc;
1354 rc = call_int_hook(file_alloc_security, 0, file);
1355 if (unlikely(rc))
1356 security_file_free(file);
1357 return rc;
20510f2f
JM
1358}
1359
1360void security_file_free(struct file *file)
1361{
ab9b110b
CS
1362 void *blob;
1363
1364 if (!lsm_file_cache)
1365 return;
1366
f25fce3e 1367 call_void_hook(file_free_security, file);
ab9b110b
CS
1368
1369 blob = file->f_security;
1370 file->f_security = NULL;
1371 kmem_cache_free(lsm_file_cache, blob);
20510f2f
JM
1372}
1373
1374int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1375{
f25fce3e 1376 return call_int_hook(file_ioctl, 0, file, cmd, arg);
20510f2f
JM
1377}
1378
98de59bf 1379static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
20510f2f 1380{
8b3ec681 1381 /*
98de59bf
AV
1382 * Does we have PROT_READ and does the application expect
1383 * it to imply PROT_EXEC? If not, nothing to talk about...
8b3ec681 1384 */
98de59bf
AV
1385 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
1386 return prot;
8b3ec681 1387 if (!(current->personality & READ_IMPLIES_EXEC))
98de59bf
AV
1388 return prot;
1389 /*
1390 * if that's an anonymous mapping, let it.
1391 */
1392 if (!file)
1393 return prot | PROT_EXEC;
1394 /*
1395 * ditto if it's not on noexec mount, except that on !MMU we need
b4caecd4 1396 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
98de59bf 1397 */
90f8572b 1398 if (!path_noexec(&file->f_path)) {
8b3ec681 1399#ifndef CONFIG_MMU
b4caecd4
CH
1400 if (file->f_op->mmap_capabilities) {
1401 unsigned caps = file->f_op->mmap_capabilities(file);
1402 if (!(caps & NOMMU_MAP_EXEC))
1403 return prot;
1404 }
8b3ec681 1405#endif
98de59bf 1406 return prot | PROT_EXEC;
8b3ec681 1407 }
98de59bf
AV
1408 /* anything on noexec mount won't get PROT_EXEC */
1409 return prot;
1410}
1411
1412int security_mmap_file(struct file *file, unsigned long prot,
1413 unsigned long flags)
1414{
1415 int ret;
f25fce3e 1416 ret = call_int_hook(mmap_file, 0, file, prot,
98de59bf 1417 mmap_prot(file, prot), flags);
6c21a7fb
MZ
1418 if (ret)
1419 return ret;
1420 return ima_file_mmap(file, prot);
20510f2f 1421}
c088e31d 1422EXPORT_SYMBOL_GPL(security_mmap_file);
20510f2f 1423
e5467859
AV
1424int security_mmap_addr(unsigned long addr)
1425{
f25fce3e 1426 return call_int_hook(mmap_addr, 0, addr);
e5467859
AV
1427}
1428
20510f2f
JM
1429int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
1430 unsigned long prot)
1431{
f25fce3e 1432 return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
20510f2f
JM
1433}
1434
1435int security_file_lock(struct file *file, unsigned int cmd)
1436{
f25fce3e 1437 return call_int_hook(file_lock, 0, file, cmd);
20510f2f
JM
1438}
1439
1440int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1441{
f25fce3e 1442 return call_int_hook(file_fcntl, 0, file, cmd, arg);
20510f2f
JM
1443}
1444
e0b93edd 1445void security_file_set_fowner(struct file *file)
20510f2f 1446{
f25fce3e 1447 call_void_hook(file_set_fowner, file);
20510f2f
JM
1448}
1449
1450int security_file_send_sigiotask(struct task_struct *tsk,
1451 struct fown_struct *fown, int sig)
1452{
f25fce3e 1453 return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
20510f2f
JM
1454}
1455
1456int security_file_receive(struct file *file)
1457{
f25fce3e 1458 return call_int_hook(file_receive, 0, file);
20510f2f
JM
1459}
1460
83d49856 1461int security_file_open(struct file *file, const struct cred *cred)
20510f2f 1462{
c4ec54b4
EP
1463 int ret;
1464
f25fce3e 1465 ret = call_int_hook(file_open, 0, file, cred);
c4ec54b4
EP
1466 if (ret)
1467 return ret;
1468
1469 return fsnotify_perm(file, MAY_OPEN);
20510f2f
JM
1470}
1471
e4e55b47
TH
1472int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
1473{
7f79f508
CS
1474 int rc = lsm_task_alloc(task);
1475
7a90fc39 1476 if (unlikely(rc))
7f79f508
CS
1477 return rc;
1478 rc = call_int_hook(task_alloc, 0, task, clone_flags);
1479 if (unlikely(rc))
1480 security_task_free(task);
1481 return rc;
e4e55b47
TH
1482}
1483
1a2a4d06
KC
1484void security_task_free(struct task_struct *task)
1485{
f25fce3e 1486 call_void_hook(task_free, task);
7f79f508
CS
1487
1488 kfree(task->security);
1489 task->security = NULL;
1a2a4d06
KC
1490}
1491
ee18d64c
DH
1492int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1493{
f1efc8c4
CS
1494 int rc = lsm_cred_alloc(cred, gfp);
1495
7a90fc39 1496 if (unlikely(rc))
f1efc8c4
CS
1497 return rc;
1498
1499 rc = call_int_hook(cred_alloc_blank, 0, cred, gfp);
ab9b110b 1500 if (unlikely(rc))
f1efc8c4
CS
1501 security_cred_free(cred);
1502 return rc;
ee18d64c
DH
1503}
1504
d84f4f99 1505void security_cred_free(struct cred *cred)
20510f2f 1506{
f25fce3e 1507 call_void_hook(cred_free, cred);
f1efc8c4
CS
1508
1509 kfree(cred->security);
1510 cred->security = NULL;
20510f2f
JM
1511}
1512
d84f4f99 1513int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
20510f2f 1514{
f1efc8c4
CS
1515 int rc = lsm_cred_alloc(new, gfp);
1516
7a90fc39 1517 if (unlikely(rc))
f1efc8c4
CS
1518 return rc;
1519
1520 rc = call_int_hook(cred_prepare, 0, new, old, gfp);
ab9b110b 1521 if (unlikely(rc))
f1efc8c4
CS
1522 security_cred_free(new);
1523 return rc;
d84f4f99
DH
1524}
1525
ee18d64c
DH
1526void security_transfer_creds(struct cred *new, const struct cred *old)
1527{
f25fce3e 1528 call_void_hook(cred_transfer, new, old);
ee18d64c
DH
1529}
1530
3a3b7ce9
DH
1531int security_kernel_act_as(struct cred *new, u32 secid)
1532{
f25fce3e 1533 return call_int_hook(kernel_act_as, 0, new, secid);
3a3b7ce9
DH
1534}
1535
1536int security_kernel_create_files_as(struct cred *new, struct inode *inode)
1537{
f25fce3e 1538 return call_int_hook(kernel_create_files_as, 0, new, inode);
3a3b7ce9
DH
1539}
1540
dd8dbf2e 1541int security_kernel_module_request(char *kmod_name)
9188499c 1542{
f25fce3e 1543 return call_int_hook(kernel_module_request, 0, kmod_name);
9188499c
EP
1544}
1545
39eeb4fb
MZ
1546int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
1547{
1548 int ret;
1549
1550 ret = call_int_hook(kernel_read_file, 0, file, id);
1551 if (ret)
1552 return ret;
1553 return ima_read_file(file, id);
1554}
1555EXPORT_SYMBOL_GPL(security_kernel_read_file);
1556
bc8ca5b9
MZ
1557int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
1558 enum kernel_read_file_id id)
b44a7dfc 1559{
cf222217
MZ
1560 int ret;
1561
1562 ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
1563 if (ret)
1564 return ret;
1565 return ima_post_read_file(file, buf, size, id);
b44a7dfc
MZ
1566}
1567EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
1568
d84f4f99
DH
1569int security_task_fix_setuid(struct cred *new, const struct cred *old,
1570 int flags)
20510f2f 1571{
f25fce3e 1572 return call_int_hook(task_fix_setuid, 0, new, old, flags);
20510f2f
JM
1573}
1574
20510f2f
JM
1575int security_task_setpgid(struct task_struct *p, pid_t pgid)
1576{
f25fce3e 1577 return call_int_hook(task_setpgid, 0, p, pgid);
20510f2f
JM
1578}
1579
1580int security_task_getpgid(struct task_struct *p)
1581{
f25fce3e 1582 return call_int_hook(task_getpgid, 0, p);
20510f2f
JM
1583}
1584
1585int security_task_getsid(struct task_struct *p)
1586{
f25fce3e 1587 return call_int_hook(task_getsid, 0, p);
20510f2f
JM
1588}
1589
1590void security_task_getsecid(struct task_struct *p, u32 *secid)
1591{
b1d9e6b0 1592 *secid = 0;
f25fce3e 1593 call_void_hook(task_getsecid, p, secid);
20510f2f
JM
1594}
1595EXPORT_SYMBOL(security_task_getsecid);
1596
20510f2f
JM
1597int security_task_setnice(struct task_struct *p, int nice)
1598{
f25fce3e 1599 return call_int_hook(task_setnice, 0, p, nice);
20510f2f
JM
1600}
1601
1602int security_task_setioprio(struct task_struct *p, int ioprio)
1603{
f25fce3e 1604 return call_int_hook(task_setioprio, 0, p, ioprio);
20510f2f
JM
1605}
1606
1607int security_task_getioprio(struct task_struct *p)
1608{
f25fce3e 1609 return call_int_hook(task_getioprio, 0, p);
20510f2f
JM
1610}
1611
791ec491
SS
1612int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
1613 unsigned int flags)
1614{
1615 return call_int_hook(task_prlimit, 0, cred, tcred, flags);
1616}
1617
8fd00b4d
JS
1618int security_task_setrlimit(struct task_struct *p, unsigned int resource,
1619 struct rlimit *new_rlim)
20510f2f 1620{
f25fce3e 1621 return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
20510f2f
JM
1622}
1623
b0ae1981 1624int security_task_setscheduler(struct task_struct *p)
20510f2f 1625{
f25fce3e 1626 return call_int_hook(task_setscheduler, 0, p);
20510f2f
JM
1627}
1628
1629int security_task_getscheduler(struct task_struct *p)
1630{
f25fce3e 1631 return call_int_hook(task_getscheduler, 0, p);
20510f2f
JM
1632}
1633
1634int security_task_movememory(struct task_struct *p)
1635{
f25fce3e 1636 return call_int_hook(task_movememory, 0, p);
20510f2f
JM
1637}
1638
1639int security_task_kill(struct task_struct *p, struct siginfo *info,
1640 int sig, u32 secid)
1641{
f25fce3e 1642 return call_int_hook(task_kill, 0, p, info, sig, secid);
20510f2f
JM
1643}
1644
a69a0684
JJ
1645#ifdef CONFIG_SECURITY_STACKING
1646static char *nolsm = "-default";
1647#define NOLSMLEN 9
1648
c9353421
JJ
1649static bool is_registered_lsm(const char *str, size_t size)
1650{
1651 struct security_hook_list *hp;
1652
1653 list_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
1654 if (size == strlen(hp->lsm) && !strncmp(str, hp->lsm, size))
1655 return true;
1656 }
1657
1658 return false;
1659}
1660
1661static bool set_lsm_of_current(const char *str, size_t size)
1662{
1663 char *lsm = lsm_of_task(current);
1664
1665 if (is_registered_lsm(str, size)) {
1666 strncpy(lsm, str, size);
1667 lsm[size] = '\0';
1668 } else if (size == NOLSMLEN && !strncmp(str, nolsm, size)) {
1669 lsm[0] = '\0';
1670 } else {
1671 return false;
1672 }
1673 return true;
1674}
1675
a69a0684
JJ
1676static int lsm_task_prctl(int option, unsigned long arg2, unsigned long arg3,
1677 unsigned long arg4, unsigned long arg5)
1678{
1679 char *lsm = lsm_of_task(current);
1680 char buffer[SECURITY_NAME_MAX + 1];
1681 __user char *optval = (__user char *)arg2;
1682 __user int *optlen = (__user int *)arg3;
1683 int dlen;
1684 int len;
1685
1686 switch (option) {
1687 case PR_GET_DISPLAY_LSM:
1688 len = arg4;
1689 if (lsm[0] == '\0') {
1690 lsm = nolsm;
1691 dlen = NOLSMLEN;
1692 } else
1693 dlen = strlen(lsm) + 1;
1694 if (dlen > len)
1695 return -ERANGE;
1696 if (copy_to_user(optval, lsm, dlen))
1697 return -EFAULT;
1698 if (put_user(dlen, optlen))
1699 return -EFAULT;
1700 break;
1701 case PR_SET_DISPLAY_LSM:
1702 len = arg3;
1703 if (len > SECURITY_NAME_MAX)
1704 return -EINVAL;
1705 if (copy_from_user(buffer, optval, len))
1706 return -EFAULT;
1707 buffer[len] = '\0';
b3da8757 1708 /* verify the requested LSM is registered */
c9353421 1709 if (!set_lsm_of_current(buffer, len))
b3da8757 1710 return -ENOENT;
a69a0684
JJ
1711 break;
1712 default:
1713 return -ENOSYS;
1714 }
1715 return 0;
1716}
1717#endif
1718
20510f2f 1719int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
d84f4f99 1720 unsigned long arg4, unsigned long arg5)
20510f2f 1721{
b1d9e6b0
CS
1722 int thisrc;
1723 int rc = -ENOSYS;
1724 struct security_hook_list *hp;
1725
a69a0684
JJ
1726#ifdef CONFIG_SECURITY_STACKING
1727 rc = lsm_task_prctl(option, arg2, arg3, arg4, arg5);
1728 if (rc != -ENOSYS)
1729 return rc;
1730#endif
1731
b1d9e6b0
CS
1732 list_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
1733 thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5);
1734 if (thisrc != -ENOSYS) {
1735 rc = thisrc;
1736 if (thisrc != 0)
1737 break;
1738 }
1739 }
1740 return rc;
20510f2f
JM
1741}
1742
1743void security_task_to_inode(struct task_struct *p, struct inode *inode)
1744{
f25fce3e 1745 call_void_hook(task_to_inode, p, inode);
20510f2f
JM
1746}
1747
1748int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
1749{
f25fce3e 1750 return call_int_hook(ipc_permission, 0, ipcp, flag);
20510f2f
JM
1751}
1752
8a076191
AD
1753void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
1754{
b1d9e6b0 1755 *secid = 0;
f25fce3e 1756 call_void_hook(ipc_getsecid, ipcp, secid);
8a076191
AD
1757}
1758
20510f2f
JM
1759int security_msg_msg_alloc(struct msg_msg *msg)
1760{
7a90fc39
CS
1761 int rc = lsm_msg_msg_alloc(msg);
1762
1763 if (unlikely(rc))
1764 return rc;
1765 rc = call_int_hook(msg_msg_alloc_security, 0, msg);
1766 if (unlikely(rc))
1767 security_msg_msg_free(msg);
1768 return rc;
20510f2f
JM
1769}
1770
1771void security_msg_msg_free(struct msg_msg *msg)
1772{
f25fce3e 1773 call_void_hook(msg_msg_free_security, msg);
7a90fc39
CS
1774 kfree(msg->security);
1775 msg->security = NULL;
20510f2f
JM
1776}
1777
1778int security_msg_queue_alloc(struct msg_queue *msq)
1779{
7a90fc39
CS
1780 int rc = lsm_ipc_alloc(&msq->q_perm);
1781
1782 if (unlikely(rc))
1783 return rc;
1784 rc = call_int_hook(msg_queue_alloc_security, 0, msq);
1785 if (unlikely(rc))
1786 security_msg_queue_free(msq);
1787 return rc;
20510f2f
JM
1788}
1789
1790void security_msg_queue_free(struct msg_queue *msq)
1791{
7a90fc39
CS
1792 struct kern_ipc_perm *kip = &msq->q_perm;
1793
f25fce3e 1794 call_void_hook(msg_queue_free_security, msq);
7a90fc39
CS
1795 kfree(kip->security);
1796 kip->security = NULL;
20510f2f
JM
1797}
1798
1799int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
1800{
f25fce3e 1801 return call_int_hook(msg_queue_associate, 0, msq, msqflg);
20510f2f
JM
1802}
1803
1804int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1805{
f25fce3e 1806 return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
20510f2f
JM
1807}
1808
1809int security_msg_queue_msgsnd(struct msg_queue *msq,
1810 struct msg_msg *msg, int msqflg)
1811{
f25fce3e 1812 return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
20510f2f
JM
1813}
1814
1815int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1816 struct task_struct *target, long type, int mode)
1817{
f25fce3e 1818 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
20510f2f
JM
1819}
1820
1821int security_shm_alloc(struct shmid_kernel *shp)
1822{
7a90fc39
CS
1823 int rc = lsm_ipc_alloc(&shp->shm_perm);
1824
1825 if (unlikely(rc))
1826 return rc;
1827 rc = call_int_hook(shm_alloc_security, 0, shp);
1828 if (unlikely(rc))
1829 security_shm_free(shp);
1830 return rc;
20510f2f
JM
1831}
1832
1833void security_shm_free(struct shmid_kernel *shp)
1834{
7a90fc39
CS
1835 struct kern_ipc_perm *kip = &shp->shm_perm;
1836
f25fce3e 1837 call_void_hook(shm_free_security, shp);
7a90fc39
CS
1838 kfree(kip->security);
1839 kip->security = NULL;
20510f2f
JM
1840}
1841
1842int security_shm_associate(struct shmid_kernel *shp, int shmflg)
1843{
f25fce3e 1844 return call_int_hook(shm_associate, 0, shp, shmflg);
20510f2f
JM
1845}
1846
1847int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1848{
f25fce3e 1849 return call_int_hook(shm_shmctl, 0, shp, cmd);
20510f2f
JM
1850}
1851
1852int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
1853{
f25fce3e 1854 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
20510f2f
JM
1855}
1856
1857int security_sem_alloc(struct sem_array *sma)
1858{
7a90fc39
CS
1859 int rc = lsm_ipc_alloc(&sma->sem_perm);
1860
1861 if (unlikely(rc))
1862 return rc;
1863 rc = call_int_hook(sem_alloc_security, 0, sma);
1864 if (unlikely(rc))
1865 security_sem_free(sma);
1866 return rc;
20510f2f
JM
1867}
1868
1869void security_sem_free(struct sem_array *sma)
1870{
7a90fc39
CS
1871 struct kern_ipc_perm *kip = &sma->sem_perm;
1872
f25fce3e 1873 call_void_hook(sem_free_security, sma);
7a90fc39
CS
1874 kfree(kip->security);
1875 kip->security = NULL;
20510f2f
JM
1876}
1877
1878int security_sem_associate(struct sem_array *sma, int semflg)
1879{
f25fce3e 1880 return call_int_hook(sem_associate, 0, sma, semflg);
20510f2f
JM
1881}
1882
1883int security_sem_semctl(struct sem_array *sma, int cmd)
1884{
f25fce3e 1885 return call_int_hook(sem_semctl, 0, sma, cmd);
20510f2f
JM
1886}
1887
1888int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
1889 unsigned nsops, int alter)
1890{
f25fce3e 1891 return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
20510f2f
JM
1892}
1893
1894void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1895{
1896 if (unlikely(inode && IS_PRIVATE(inode)))
1897 return;
f25fce3e 1898 call_void_hook(d_instantiate, dentry, inode);
20510f2f
JM
1899}
1900EXPORT_SYMBOL(security_d_instantiate);
1901
dcd148a1
CS
1902int security_getprocattr(struct task_struct *p, const char *lsm, char *name,
1903 char **value)
20510f2f 1904{
a69a0684
JJ
1905#ifdef CONFIG_SECURITY_STACKING
1906 char *speclsm = lsm_of_task(p);
1907#endif
dcd148a1 1908 struct security_hook_list *hp;
c9353421
JJ
1909 int rc;
1910
5a1d919f 1911 if (strcmp(name, "display_lsm") == 0) {
c9353421
JJ
1912 *value = kstrdup(current->security, GFP_KERNEL);
1913 if (*value == NULL)
1914 return -ENOMEM;
1915 return strlen(*value);
1916 }
dcd148a1
CS
1917
1918 list_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
1919 if (lsm != NULL && strcmp(lsm, hp->lsm))
1920 continue;
a69a0684
JJ
1921#ifdef CONFIG_SECURITY_STACKING
1922 if (!lsm && speclsm && speclsm[0] && strcmp(speclsm, hp->lsm))
1923 continue;
1924#endif
1925 rc = hp->hook.getprocattr(p, name, value);
1926 if (rc != -ENOSYS)
1927 return rc;
dcd148a1
CS
1928 }
1929 return -EINVAL;
20510f2f
JM
1930}
1931
dcd148a1
CS
1932int security_setprocattr(const char *lsm, const char *name, void *value,
1933 size_t size)
20510f2f 1934{
a69a0684
JJ
1935#ifdef CONFIG_SECURITY_STACKING
1936 char *speclsm = lsm_of_task(current);
a69a0684
JJ
1937#else
1938 char *tvalue;
1939#endif
dcd148a1 1940 struct security_hook_list *hp;
a69a0684 1941 int rc;
a69a0684 1942
36788bfe
CIK
1943 if (!size)
1944 return -EINVAL;
1945
5a1d919f 1946 if (strcmp(name, "display_lsm") == 0) {
c9353421
JJ
1947#ifdef CONFIG_SECURITY_STACKING
1948 if (set_lsm_of_current(value, size))
1949 return size;
1950#endif
1951 return -EINVAL;
a69a0684 1952 }
dcd148a1
CS
1953
1954 list_for_each_entry(hp, &security_hook_heads.setprocattr, list) {
a69a0684
JJ
1955#ifdef CONFIG_SECURITY_STACKING
1956 if (!lsm && speclsm && speclsm[0] && strcmp(speclsm, hp->lsm))
dcd148a1 1957 continue;
a69a0684
JJ
1958#endif
1959 rc = hp->hook.setprocattr(name, value, size);
1960 if (rc)
1961 return rc;
dcd148a1
CS
1962 }
1963 return -EINVAL;
20510f2f
JM
1964}
1965
1966int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1967{
f25fce3e 1968 return call_int_hook(netlink_send, 0, sk, skb);
20510f2f 1969}
20510f2f 1970
746df9b5
DQ
1971int security_ismaclabel(const char *name)
1972{
f25fce3e 1973 return call_int_hook(ismaclabel, 0, name);
746df9b5
DQ
1974}
1975EXPORT_SYMBOL(security_ismaclabel);
1976
20510f2f
JM
1977int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1978{
b1d9e6b0
CS
1979 return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
1980 seclen);
20510f2f
JM
1981}
1982EXPORT_SYMBOL(security_secid_to_secctx);
1983
7bf570dc 1984int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
63cb3449 1985{
b1d9e6b0 1986 *secid = 0;
f25fce3e 1987 return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
63cb3449
DH
1988}
1989EXPORT_SYMBOL(security_secctx_to_secid);
1990
20510f2f
JM
1991void security_release_secctx(char *secdata, u32 seclen)
1992{
a69a0684
JJ
1993#ifdef CONFIG_SECURITY_STACKING
1994 char *speclsm = lsm_of_task(current);
1995#endif
1996 struct security_hook_list *hp;
1997
1998 list_for_each_entry(hp, &security_hook_heads.release_secctx, list) {
1999#ifdef CONFIG_SECURITY_STACKING
2000 if (speclsm[0] && strcmp(hp->lsm, speclsm))
2001 continue;
2002#endif
2003 hp->hook.release_secctx(secdata, seclen);
2004 break;
2005 }
20510f2f
JM
2006}
2007EXPORT_SYMBOL(security_release_secctx);
2008
6f3be9f5
AG
2009void security_inode_invalidate_secctx(struct inode *inode)
2010{
2011 call_void_hook(inode_invalidate_secctx, inode);
2012}
2013EXPORT_SYMBOL(security_inode_invalidate_secctx);
2014
1ee65e37
DQ
2015int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
2016{
f25fce3e 2017 return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
1ee65e37
DQ
2018}
2019EXPORT_SYMBOL(security_inode_notifysecctx);
2020
2021int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
2022{
f25fce3e 2023 return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
1ee65e37
DQ
2024}
2025EXPORT_SYMBOL(security_inode_setsecctx);
2026
2027int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
2028{
b1d9e6b0 2029 return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
1ee65e37
DQ
2030}
2031EXPORT_SYMBOL(security_inode_getsecctx);
2032
20510f2f
JM
2033#ifdef CONFIG_SECURITY_NETWORK
2034
3610cda5 2035int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
20510f2f 2036{
f25fce3e 2037 return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
20510f2f
JM
2038}
2039EXPORT_SYMBOL(security_unix_stream_connect);
2040
2041int security_unix_may_send(struct socket *sock, struct socket *other)
2042{
f25fce3e 2043 return call_int_hook(unix_may_send, 0, sock, other);
20510f2f
JM
2044}
2045EXPORT_SYMBOL(security_unix_may_send);
2046
2047int security_socket_create(int family, int type, int protocol, int kern)
2048{
f25fce3e 2049 return call_int_hook(socket_create, 0, family, type, protocol, kern);
20510f2f
JM
2050}
2051
2052int security_socket_post_create(struct socket *sock, int family,
2053 int type, int protocol, int kern)
2054{
f25fce3e 2055 return call_int_hook(socket_post_create, 0, sock, family, type,
20510f2f
JM
2056 protocol, kern);
2057}
2058
2059int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
2060{
f25fce3e 2061 return call_int_hook(socket_bind, 0, sock, address, addrlen);
20510f2f
JM
2062}
2063
2064int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
2065{
f25fce3e 2066 return call_int_hook(socket_connect, 0, sock, address, addrlen);
20510f2f
JM
2067}
2068
2069int security_socket_listen(struct socket *sock, int backlog)
2070{
f25fce3e 2071 return call_int_hook(socket_listen, 0, sock, backlog);
20510f2f
JM
2072}
2073
2074int security_socket_accept(struct socket *sock, struct socket *newsock)
2075{
f25fce3e 2076 return call_int_hook(socket_accept, 0, sock, newsock);
20510f2f
JM
2077}
2078
20510f2f
JM
2079int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
2080{
f25fce3e 2081 return call_int_hook(socket_sendmsg, 0, sock, msg, size);
20510f2f
JM
2082}
2083
2084int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
2085 int size, int flags)
2086{
f25fce3e 2087 return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
20510f2f
JM
2088}
2089
2090int security_socket_getsockname(struct socket *sock)
2091{
f25fce3e 2092 return call_int_hook(socket_getsockname, 0, sock);
20510f2f
JM
2093}
2094
2095int security_socket_getpeername(struct socket *sock)
2096{
f25fce3e 2097 return call_int_hook(socket_getpeername, 0, sock);
20510f2f
JM
2098}
2099
2100int security_socket_getsockopt(struct socket *sock, int level, int optname)
2101{
f25fce3e 2102 return call_int_hook(socket_getsockopt, 0, sock, level, optname);
20510f2f
JM
2103}
2104
2105int security_socket_setsockopt(struct socket *sock, int level, int optname)
2106{
f25fce3e 2107 return call_int_hook(socket_setsockopt, 0, sock, level, optname);
20510f2f
JM
2108}
2109
2110int security_socket_shutdown(struct socket *sock, int how)
2111{
f25fce3e 2112 return call_int_hook(socket_shutdown, 0, sock, how);
20510f2f
JM
2113}
2114
2115int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2116{
f25fce3e 2117 return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
20510f2f
JM
2118}
2119EXPORT_SYMBOL(security_sock_rcv_skb);
2120
2121int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
2122 int __user *optlen, unsigned len)
2123{
8e42f92b
JJ
2124#ifdef CONFIG_SECURITY_STACKING
2125 struct security_hook_list *hp;
2126 char *lsm = lsm_of_task(current);
2127
2128 list_for_each_entry(hp, &security_hook_heads.socket_getpeersec_stream,
2129 list) {
2130 if (!lsm || !lsm[0] || !strcmp(lsm, hp->lsm))
2131 return hp->hook.socket_getpeersec_stream(sock, optval,
2132 optlen, len);
2133 }
2134 return -ENOPROTOOPT;
2135#else
b1d9e6b0
CS
2136 return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
2137 optval, optlen, len);
8e42f92b 2138#endif
20510f2f
JM
2139}
2140
2141int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
2142{
e308fd3b
JB
2143 return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
2144 skb, secid);
20510f2f
JM
2145}
2146EXPORT_SYMBOL(security_socket_getpeersec_dgram);
2147
2148int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
2149{
7a90fc39
CS
2150 int rc = lsm_sock_alloc(sk, priority);
2151
2152 if (unlikely(rc))
2153 return rc;
2154 rc = call_int_hook(sk_alloc_security, 0, sk, family, priority);
2155 if (unlikely(rc))
2156 security_sk_free(sk);
2157 return rc;
20510f2f
JM
2158}
2159
2160void security_sk_free(struct sock *sk)
2161{
f25fce3e 2162 call_void_hook(sk_free_security, sk);
7a90fc39
CS
2163 kfree(sk->sk_security);
2164 sk->sk_security = NULL;
20510f2f
JM
2165}
2166
2167void security_sk_clone(const struct sock *sk, struct sock *newsk)
2168{
f25fce3e 2169 call_void_hook(sk_clone_security, sk, newsk);
20510f2f 2170}
6230c9b4 2171EXPORT_SYMBOL(security_sk_clone);
20510f2f
JM
2172
2173void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
2174{
f25fce3e 2175 call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
20510f2f
JM
2176}
2177EXPORT_SYMBOL(security_sk_classify_flow);
2178
2179void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
2180{
f25fce3e 2181 call_void_hook(req_classify_flow, req, fl);
20510f2f
JM
2182}
2183EXPORT_SYMBOL(security_req_classify_flow);
2184
2185void security_sock_graft(struct sock *sk, struct socket *parent)
2186{
f25fce3e 2187 call_void_hook(sock_graft, sk, parent);
20510f2f
JM
2188}
2189EXPORT_SYMBOL(security_sock_graft);
2190
2191int security_inet_conn_request(struct sock *sk,
2192 struct sk_buff *skb, struct request_sock *req)
2193{
f25fce3e 2194 return call_int_hook(inet_conn_request, 0, sk, skb, req);
20510f2f
JM
2195}
2196EXPORT_SYMBOL(security_inet_conn_request);
2197
2198void security_inet_csk_clone(struct sock *newsk,
2199 const struct request_sock *req)
2200{
f25fce3e 2201 call_void_hook(inet_csk_clone, newsk, req);
20510f2f
JM
2202}
2203
2204void security_inet_conn_established(struct sock *sk,
2205 struct sk_buff *skb)
2206{
f25fce3e 2207 call_void_hook(inet_conn_established, sk, skb);
20510f2f
JM
2208}
2209
2606fd1f
EP
2210int security_secmark_relabel_packet(u32 secid)
2211{
f25fce3e 2212 return call_int_hook(secmark_relabel_packet, 0, secid);
2606fd1f
EP
2213}
2214EXPORT_SYMBOL(security_secmark_relabel_packet);
2215
2216void security_secmark_refcount_inc(void)
2217{
f25fce3e 2218 call_void_hook(secmark_refcount_inc);
2606fd1f
EP
2219}
2220EXPORT_SYMBOL(security_secmark_refcount_inc);
2221
2222void security_secmark_refcount_dec(void)
2223{
f25fce3e 2224 call_void_hook(secmark_refcount_dec);
2606fd1f
EP
2225}
2226EXPORT_SYMBOL(security_secmark_refcount_dec);
2227
5dbbaf2d
PM
2228int security_tun_dev_alloc_security(void **security)
2229{
f25fce3e 2230 return call_int_hook(tun_dev_alloc_security, 0, security);
5dbbaf2d
PM
2231}
2232EXPORT_SYMBOL(security_tun_dev_alloc_security);
2233
2234void security_tun_dev_free_security(void *security)
2235{
f25fce3e 2236 call_void_hook(tun_dev_free_security, security);
5dbbaf2d
PM
2237}
2238EXPORT_SYMBOL(security_tun_dev_free_security);
2239
2b980dbd
PM
2240int security_tun_dev_create(void)
2241{
f25fce3e 2242 return call_int_hook(tun_dev_create, 0);
2b980dbd
PM
2243}
2244EXPORT_SYMBOL(security_tun_dev_create);
2245
5dbbaf2d 2246int security_tun_dev_attach_queue(void *security)
2b980dbd 2247{
f25fce3e 2248 return call_int_hook(tun_dev_attach_queue, 0, security);
2b980dbd 2249}
5dbbaf2d 2250EXPORT_SYMBOL(security_tun_dev_attach_queue);
2b980dbd 2251
5dbbaf2d 2252int security_tun_dev_attach(struct sock *sk, void *security)
2b980dbd 2253{
f25fce3e 2254 return call_int_hook(tun_dev_attach, 0, sk, security);
2b980dbd
PM
2255}
2256EXPORT_SYMBOL(security_tun_dev_attach);
2257
5dbbaf2d
PM
2258int security_tun_dev_open(void *security)
2259{
f25fce3e 2260 return call_int_hook(tun_dev_open, 0, security);
5dbbaf2d
PM
2261}
2262EXPORT_SYMBOL(security_tun_dev_open);
2263
20510f2f
JM
2264#endif /* CONFIG_SECURITY_NETWORK */
2265
d291f1a6
DJ
2266#ifdef CONFIG_SECURITY_INFINIBAND
2267
2268int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
2269{
2270 return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey);
2271}
2272EXPORT_SYMBOL(security_ib_pkey_access);
2273
47a2b338
DJ
2274int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
2275{
2276 return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num);
2277}
2278EXPORT_SYMBOL(security_ib_endport_manage_subnet);
2279
d291f1a6
DJ
2280int security_ib_alloc_security(void **sec)
2281{
2282 return call_int_hook(ib_alloc_security, 0, sec);
2283}
2284EXPORT_SYMBOL(security_ib_alloc_security);
2285
2286void security_ib_free_security(void *sec)
2287{
2288 call_void_hook(ib_free_security, sec);
2289}
2290EXPORT_SYMBOL(security_ib_free_security);
2291#endif /* CONFIG_SECURITY_INFINIBAND */
2292
20510f2f
JM
2293#ifdef CONFIG_SECURITY_NETWORK_XFRM
2294
52a4c640
NA
2295int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
2296 struct xfrm_user_sec_ctx *sec_ctx,
2297 gfp_t gfp)
20510f2f 2298{
f25fce3e 2299 return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
20510f2f
JM
2300}
2301EXPORT_SYMBOL(security_xfrm_policy_alloc);
2302
03e1ad7b
PM
2303int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
2304 struct xfrm_sec_ctx **new_ctxp)
20510f2f 2305{
f25fce3e 2306 return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
20510f2f
JM
2307}
2308
03e1ad7b 2309void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
20510f2f 2310{
f25fce3e 2311 call_void_hook(xfrm_policy_free_security, ctx);
20510f2f
JM
2312}
2313EXPORT_SYMBOL(security_xfrm_policy_free);
2314
03e1ad7b 2315int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
20510f2f 2316{
f25fce3e 2317 return call_int_hook(xfrm_policy_delete_security, 0, ctx);
20510f2f
JM
2318}
2319
2e5aa866
PM
2320int security_xfrm_state_alloc(struct xfrm_state *x,
2321 struct xfrm_user_sec_ctx *sec_ctx)
20510f2f 2322{
f25fce3e 2323 return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
20510f2f
JM
2324}
2325EXPORT_SYMBOL(security_xfrm_state_alloc);
2326
2327int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
2328 struct xfrm_sec_ctx *polsec, u32 secid)
2329{
f25fce3e 2330 return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
20510f2f
JM
2331}
2332
2333int security_xfrm_state_delete(struct xfrm_state *x)
2334{
f25fce3e 2335 return call_int_hook(xfrm_state_delete_security, 0, x);
20510f2f
JM
2336}
2337EXPORT_SYMBOL(security_xfrm_state_delete);
2338
2339void security_xfrm_state_free(struct xfrm_state *x)
2340{
f25fce3e 2341 call_void_hook(xfrm_state_free_security, x);
20510f2f
JM
2342}
2343
03e1ad7b 2344int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
20510f2f 2345{
f25fce3e 2346 return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
20510f2f
JM
2347}
2348
2349int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
e33f7704
DM
2350 struct xfrm_policy *xp,
2351 const struct flowi *fl)
20510f2f 2352{
b1d9e6b0
CS
2353 struct security_hook_list *hp;
2354 int rc = 1;
2355
2356 /*
2357 * Since this function is expected to return 0 or 1, the judgment
2358 * becomes difficult if multiple LSMs supply this call. Fortunately,
2359 * we can use the first LSM's judgment because currently only SELinux
2360 * supplies this call.
2361 *
2362 * For speed optimization, we explicitly break the loop rather than
2363 * using the macro
2364 */
2365 list_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
2366 list) {
2367 rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
2368 break;
2369 }
2370 return rc;
20510f2f
JM
2371}
2372
2373int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
2374{
f25fce3e 2375 return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
20510f2f
JM
2376}
2377
2378void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
2379{
f25fce3e
CS
2380 int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
2381 0);
20510f2f
JM
2382
2383 BUG_ON(rc);
2384}
2385EXPORT_SYMBOL(security_skb_classify_flow);
2386
2387#endif /* CONFIG_SECURITY_NETWORK_XFRM */
2388
2389#ifdef CONFIG_KEYS
2390
d84f4f99
DH
2391int security_key_alloc(struct key *key, const struct cred *cred,
2392 unsigned long flags)
20510f2f 2393{
7a90fc39
CS
2394 int rc = lsm_key_alloc(key);
2395
2396 if (unlikely(rc))
2397 return rc;
2398 rc = call_int_hook(key_alloc, 0, key, cred, flags);
2399 if (unlikely(rc))
2400 security_key_free(key);
2401 return rc;
20510f2f
JM
2402}
2403
2404void security_key_free(struct key *key)
2405{
f25fce3e 2406 call_void_hook(key_free, key);
7a90fc39
CS
2407 kfree(key->security);
2408 key->security = NULL;
20510f2f
JM
2409}
2410
2411int security_key_permission(key_ref_t key_ref,
f5895943 2412 const struct cred *cred, unsigned perm)
20510f2f 2413{
f25fce3e 2414 return call_int_hook(key_permission, 0, key_ref, cred, perm);
20510f2f
JM
2415}
2416
70a5bb72
DH
2417int security_key_getsecurity(struct key *key, char **_buffer)
2418{
b1d9e6b0 2419 *_buffer = NULL;
f25fce3e 2420 return call_int_hook(key_getsecurity, 0, key, _buffer);
70a5bb72
DH
2421}
2422
20510f2f 2423#endif /* CONFIG_KEYS */
03d37d25
AD
2424
2425#ifdef CONFIG_AUDIT
2426
2427int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
2428{
f25fce3e 2429 return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
03d37d25
AD
2430}
2431
2432int security_audit_rule_known(struct audit_krule *krule)
2433{
f25fce3e 2434 return call_int_hook(audit_rule_known, 0, krule);
03d37d25
AD
2435}
2436
2437void security_audit_rule_free(void *lsmrule)
2438{
f25fce3e 2439 call_void_hook(audit_rule_free, lsmrule);
03d37d25
AD
2440}
2441
2442int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
2443 struct audit_context *actx)
2444{
f25fce3e
CS
2445 return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
2446 actx);
03d37d25 2447}
b1d9e6b0 2448#endif /* CONFIG_AUDIT */
afdb09c7
CF
2449
2450#ifdef CONFIG_BPF_SYSCALL
2451int security_bpf(int cmd, union bpf_attr *attr, unsigned int size)
2452{
2453 return call_int_hook(bpf, 0, cmd, attr, size);
2454}
2455int security_bpf_map(struct bpf_map *map, fmode_t fmode)
2456{
2457 return call_int_hook(bpf_map, 0, map, fmode);
2458}
2459int security_bpf_prog(struct bpf_prog *prog)
2460{
2461 return call_int_hook(bpf_prog, 0, prog);
2462}
2463int security_bpf_map_alloc(struct bpf_map *map)
2464{
2465 return call_int_hook(bpf_map_alloc_security, 0, map);
2466}
2467int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
2468{
2469 return call_int_hook(bpf_prog_alloc_security, 0, aux);
2470}
2471void security_bpf_map_free(struct bpf_map *map)
2472{
2473 call_void_hook(bpf_map_free_security, map);
2474}
2475void security_bpf_prog_free(struct bpf_prog_aux *aux)
2476{
2477 call_void_hook(bpf_prog_free_security, aux);
2478}
2479#endif /* CONFIG_BPF_SYSCALL */