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