1 /*
2 * Security plug functions
3 *
4 * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14 #include <linux/capability.h>
15 #include <linux/dcache.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/security.h>
20 #include <linux/integrity.h>
21 #include <linux/ima.h>
22 #include <linux/evm.h>
23 #include <linux/fsnotify.h>
24 #include <linux/mman.h>
25 #include <linux/mount.h>
26 #include <linux/personality.h>
27 #include <linux/backing-dev.h>
28 #include <net/flow.h>
29
30 #define MAX_LSM_EVM_XATTR 2
31
32 /* Boot-time LSM user choice */
33 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
34 CONFIG_DEFAULT_SECURITY;
35
36 static struct security_operations *security_ops;
37 static struct security_operations default_security_ops = {
38 .name = "default",
39 };
40
verify(struct security_operations * ops)41 static inline int __init verify(struct security_operations *ops)
42 {
43 /* verify the security_operations structure exists */
44 if (!ops)
45 return -EINVAL;
46 security_fixup_ops(ops);
47 return 0;
48 }
49
do_security_initcalls(void)50 static 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 */
security_init(void)65 int __init security_init(void)
66 {
67 printk(KERN_INFO "Security Framework initialized\n");
68
69 security_fixup_ops(&default_security_ops);
70 security_ops = &default_security_ops;
71 do_security_initcalls();
72
73 return 0;
74 }
75
reset_security_ops(void)76 void reset_security_ops(void)
77 {
78 security_ops = &default_security_ops;
79 }
80
81 /* Save user chosen LSM */
choose_lsm(char * str)82 static int __init choose_lsm(char *str)
83 {
84 strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
85 return 1;
86 }
87 __setup("security=", choose_lsm);
88
89 /**
90 * security_module_enable - Load given security module on boot ?
91 * @ops: a pointer to the struct security_operations that is to be checked.
92 *
93 * Each LSM must pass this method before registering its own operations
94 * to avoid security registration races. This method may also be used
95 * to check if your LSM is currently loaded during kernel initialization.
96 *
97 * Return true if:
98 * -The passed LSM is the one chosen by user at boot time,
99 * -or the passed LSM is configured as the default and the user did not
100 * choose an alternate LSM at boot time.
101 * Otherwise, return false.
102 */
security_module_enable(struct security_operations * ops)103 int __init security_module_enable(struct security_operations *ops)
104 {
105 return !strcmp(ops->name, chosen_lsm);
106 }
107
108 /**
109 * register_security - registers a security framework with the kernel
110 * @ops: a pointer to the struct security_options that is to be registered
111 *
112 * This function allows a security module to register itself with the
113 * kernel security subsystem. Some rudimentary checking is done on the @ops
114 * value passed to this function. You'll need to check first if your LSM
115 * is allowed to register its @ops by calling security_module_enable(@ops).
116 *
117 * If there is already a security module registered with the kernel,
118 * an error will be returned. Otherwise %0 is returned on success.
119 */
register_security(struct security_operations * ops)120 int __init register_security(struct security_operations *ops)
121 {
122 if (verify(ops)) {
123 printk(KERN_DEBUG "%s could not verify "
124 "security_operations structure.\n", __func__);
125 return -EINVAL;
126 }
127
128 if (security_ops != &default_security_ops)
129 return -EAGAIN;
130
131 security_ops = ops;
132
133 return 0;
134 }
135
136 /* Security operations */
137
security_binder_set_context_mgr(struct task_struct * mgr)138 int security_binder_set_context_mgr(struct task_struct *mgr)
139 {
140 return security_ops->binder_set_context_mgr(mgr);
141 }
142
security_binder_transaction(struct task_struct * from,struct task_struct * to)143 int security_binder_transaction(struct task_struct *from, struct task_struct *to)
144 {
145 return security_ops->binder_transaction(from, to);
146 }
147
security_binder_transfer_binder(struct task_struct * from,struct task_struct * to)148 int security_binder_transfer_binder(struct task_struct *from, struct task_struct *to)
149 {
150 return security_ops->binder_transfer_binder(from, to);
151 }
152
security_binder_transfer_file(struct task_struct * from,struct task_struct * to,struct file * file)153 int security_binder_transfer_file(struct task_struct *from, struct task_struct *to, struct file *file)
154 {
155 return security_ops->binder_transfer_file(from, to, file);
156 }
157
security_ptrace_access_check(struct task_struct * child,unsigned int mode)158 int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
159 {
160 #ifdef CONFIG_SECURITY_YAMA_STACKED
161 int rc;
162 rc = yama_ptrace_access_check(child, mode);
163 if (rc)
164 return rc;
165 #endif
166 return security_ops->ptrace_access_check(child, mode);
167 }
168
security_ptrace_traceme(struct task_struct * parent)169 int security_ptrace_traceme(struct task_struct *parent)
170 {
171 #ifdef CONFIG_SECURITY_YAMA_STACKED
172 int rc;
173 rc = yama_ptrace_traceme(parent);
174 if (rc)
175 return rc;
176 #endif
177 return security_ops->ptrace_traceme(parent);
178 }
179
security_capget(struct task_struct * target,kernel_cap_t * effective,kernel_cap_t * inheritable,kernel_cap_t * permitted)180 int security_capget(struct task_struct *target,
181 kernel_cap_t *effective,
182 kernel_cap_t *inheritable,
183 kernel_cap_t *permitted)
184 {
185 return security_ops->capget(target, effective, inheritable, permitted);
186 }
187
security_capset(struct cred * new,const struct cred * old,const kernel_cap_t * effective,const kernel_cap_t * inheritable,const kernel_cap_t * permitted)188 int security_capset(struct cred *new, const struct cred *old,
189 const kernel_cap_t *effective,
190 const kernel_cap_t *inheritable,
191 const kernel_cap_t *permitted)
192 {
193 return security_ops->capset(new, old,
194 effective, inheritable, permitted);
195 }
196
security_capable(const struct cred * cred,struct user_namespace * ns,int cap)197 int security_capable(const struct cred *cred, struct user_namespace *ns,
198 int cap)
199 {
200 return security_ops->capable(cred, ns, cap, SECURITY_CAP_AUDIT);
201 }
202
security_capable_noaudit(const struct cred * cred,struct user_namespace * ns,int cap)203 int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
204 int cap)
205 {
206 return security_ops->capable(cred, ns, cap, SECURITY_CAP_NOAUDIT);
207 }
208
security_quotactl(int cmds,int type,int id,struct super_block * sb)209 int security_quotactl(int cmds, int type, int id, struct super_block *sb)
210 {
211 return security_ops->quotactl(cmds, type, id, sb);
212 }
213
security_quota_on(struct dentry * dentry)214 int security_quota_on(struct dentry *dentry)
215 {
216 return security_ops->quota_on(dentry);
217 }
218
security_syslog(int type)219 int security_syslog(int type)
220 {
221 return security_ops->syslog(type);
222 }
223
security_settime(const struct timespec * ts,const struct timezone * tz)224 int security_settime(const struct timespec *ts, const struct timezone *tz)
225 {
226 return security_ops->settime(ts, tz);
227 }
228
security_vm_enough_memory_mm(struct mm_struct * mm,long pages)229 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
230 {
231 return security_ops->vm_enough_memory(mm, pages);
232 }
233
security_bprm_set_creds(struct linux_binprm * bprm)234 int security_bprm_set_creds(struct linux_binprm *bprm)
235 {
236 return security_ops->bprm_set_creds(bprm);
237 }
238
security_bprm_check(struct linux_binprm * bprm)239 int security_bprm_check(struct linux_binprm *bprm)
240 {
241 int ret;
242
243 ret = security_ops->bprm_check_security(bprm);
244 if (ret)
245 return ret;
246 return ima_bprm_check(bprm);
247 }
248
security_bprm_committing_creds(struct linux_binprm * bprm)249 void security_bprm_committing_creds(struct linux_binprm *bprm)
250 {
251 security_ops->bprm_committing_creds(bprm);
252 }
253
security_bprm_committed_creds(struct linux_binprm * bprm)254 void security_bprm_committed_creds(struct linux_binprm *bprm)
255 {
256 security_ops->bprm_committed_creds(bprm);
257 }
258
security_bprm_secureexec(struct linux_binprm * bprm)259 int security_bprm_secureexec(struct linux_binprm *bprm)
260 {
261 return security_ops->bprm_secureexec(bprm);
262 }
263
security_sb_alloc(struct super_block * sb)264 int security_sb_alloc(struct super_block *sb)
265 {
266 return security_ops->sb_alloc_security(sb);
267 }
268
security_sb_free(struct super_block * sb)269 void security_sb_free(struct super_block *sb)
270 {
271 security_ops->sb_free_security(sb);
272 }
273
security_sb_copy_data(char * orig,char * copy)274 int security_sb_copy_data(char *orig, char *copy)
275 {
276 return security_ops->sb_copy_data(orig, copy);
277 }
278 EXPORT_SYMBOL(security_sb_copy_data);
279
security_sb_remount(struct super_block * sb,void * data)280 int security_sb_remount(struct super_block *sb, void *data)
281 {
282 return security_ops->sb_remount(sb, data);
283 }
284
security_sb_kern_mount(struct super_block * sb,int flags,void * data)285 int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
286 {
287 return security_ops->sb_kern_mount(sb, flags, data);
288 }
289
security_sb_show_options(struct seq_file * m,struct super_block * sb)290 int security_sb_show_options(struct seq_file *m, struct super_block *sb)
291 {
292 return security_ops->sb_show_options(m, sb);
293 }
294
security_sb_statfs(struct dentry * dentry)295 int security_sb_statfs(struct dentry *dentry)
296 {
297 return security_ops->sb_statfs(dentry);
298 }
299
security_sb_mount(const char * dev_name,struct path * path,const char * type,unsigned long flags,void * data)300 int security_sb_mount(const char *dev_name, struct path *path,
301 const char *type, unsigned long flags, void *data)
302 {
303 return security_ops->sb_mount(dev_name, path, type, flags, data);
304 }
305
security_sb_umount(struct vfsmount * mnt,int flags)306 int security_sb_umount(struct vfsmount *mnt, int flags)
307 {
308 return security_ops->sb_umount(mnt, flags);
309 }
310
security_sb_pivotroot(struct path * old_path,struct path * new_path)311 int security_sb_pivotroot(struct path *old_path, struct path *new_path)
312 {
313 return security_ops->sb_pivotroot(old_path, new_path);
314 }
315
security_sb_set_mnt_opts(struct super_block * sb,struct security_mnt_opts * opts,unsigned long kern_flags,unsigned long * set_kern_flags)316 int security_sb_set_mnt_opts(struct super_block *sb,
317 struct security_mnt_opts *opts,
318 unsigned long kern_flags,
319 unsigned long *set_kern_flags)
320 {
321 return security_ops->sb_set_mnt_opts(sb, opts, kern_flags,
322 set_kern_flags);
323 }
324 EXPORT_SYMBOL(security_sb_set_mnt_opts);
325
security_sb_clone_mnt_opts(const struct super_block * oldsb,struct super_block * newsb)326 int security_sb_clone_mnt_opts(const struct super_block *oldsb,
327 struct super_block *newsb)
328 {
329 return security_ops->sb_clone_mnt_opts(oldsb, newsb);
330 }
331 EXPORT_SYMBOL(security_sb_clone_mnt_opts);
332
security_sb_parse_opts_str(char * options,struct security_mnt_opts * opts)333 int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
334 {
335 return security_ops->sb_parse_opts_str(options, opts);
336 }
337 EXPORT_SYMBOL(security_sb_parse_opts_str);
338
security_inode_alloc(struct inode * inode)339 int security_inode_alloc(struct inode *inode)
340 {
341 inode->i_security = NULL;
342 return security_ops->inode_alloc_security(inode);
343 }
344
security_inode_free(struct inode * inode)345 void security_inode_free(struct inode *inode)
346 {
347 integrity_inode_free(inode);
348 security_ops->inode_free_security(inode);
349 }
350
security_dentry_init_security(struct dentry * dentry,int mode,struct qstr * name,void ** ctx,u32 * ctxlen)351 int security_dentry_init_security(struct dentry *dentry, int mode,
352 struct qstr *name, void **ctx,
353 u32 *ctxlen)
354 {
355 return security_ops->dentry_init_security(dentry, mode, name,
356 ctx, ctxlen);
357 }
358 EXPORT_SYMBOL(security_dentry_init_security);
359
security_inode_init_security(struct inode * inode,struct inode * dir,const struct qstr * qstr,const initxattrs initxattrs,void * fs_data)360 int security_inode_init_security(struct inode *inode, struct inode *dir,
361 const struct qstr *qstr,
362 const initxattrs initxattrs, void *fs_data)
363 {
364 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
365 struct xattr *lsm_xattr, *evm_xattr, *xattr;
366 int ret;
367
368 if (unlikely(IS_PRIVATE(inode)))
369 return 0;
370
371 if (!initxattrs)
372 return security_ops->inode_init_security(inode, dir, qstr,
373 NULL, NULL, NULL);
374 memset(new_xattrs, 0, sizeof(new_xattrs));
375 lsm_xattr = new_xattrs;
376 ret = security_ops->inode_init_security(inode, dir, qstr,
377 &lsm_xattr->name,
378 &lsm_xattr->value,
379 &lsm_xattr->value_len);
380 if (ret)
381 goto out;
382
383 evm_xattr = lsm_xattr + 1;
384 ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
385 if (ret)
386 goto out;
387 ret = initxattrs(inode, new_xattrs, fs_data);
388 out:
389 for (xattr = new_xattrs; xattr->value != NULL; xattr++)
390 kfree(xattr->value);
391 return (ret == -EOPNOTSUPP) ? 0 : ret;
392 }
393 EXPORT_SYMBOL(security_inode_init_security);
394
security_old_inode_init_security(struct inode * inode,struct inode * dir,const struct qstr * qstr,const char ** name,void ** value,size_t * len)395 int security_old_inode_init_security(struct inode *inode, struct inode *dir,
396 const struct qstr *qstr, const char **name,
397 void **value, size_t *len)
398 {
399 if (unlikely(IS_PRIVATE(inode)))
400 return -EOPNOTSUPP;
401 return security_ops->inode_init_security(inode, dir, qstr, name, value,
402 len);
403 }
404 EXPORT_SYMBOL(security_old_inode_init_security);
405
406 #ifdef CONFIG_SECURITY_PATH
security_path_mknod(struct path * dir,struct dentry * dentry,umode_t mode,unsigned int dev)407 int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
408 unsigned int dev)
409 {
410 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
411 return 0;
412 return security_ops->path_mknod(dir, dentry, mode, dev);
413 }
414 EXPORT_SYMBOL(security_path_mknod);
415
security_path_mkdir(struct path * dir,struct dentry * dentry,umode_t mode)416 int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
417 {
418 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
419 return 0;
420 return security_ops->path_mkdir(dir, dentry, mode);
421 }
422 EXPORT_SYMBOL(security_path_mkdir);
423
security_path_rmdir(struct path * dir,struct dentry * dentry)424 int security_path_rmdir(struct path *dir, struct dentry *dentry)
425 {
426 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
427 return 0;
428 return security_ops->path_rmdir(dir, dentry);
429 }
430
security_path_unlink(struct path * dir,struct dentry * dentry)431 int security_path_unlink(struct path *dir, struct dentry *dentry)
432 {
433 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
434 return 0;
435 return security_ops->path_unlink(dir, dentry);
436 }
437 EXPORT_SYMBOL(security_path_unlink);
438
security_path_symlink(struct path * dir,struct dentry * dentry,const char * old_name)439 int security_path_symlink(struct path *dir, struct dentry *dentry,
440 const char *old_name)
441 {
442 if (unlikely(IS_PRIVATE(dir->dentry->d_inode)))
443 return 0;
444 return security_ops->path_symlink(dir, dentry, old_name);
445 }
446
security_path_link(struct dentry * old_dentry,struct path * new_dir,struct dentry * new_dentry)447 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
448 struct dentry *new_dentry)
449 {
450 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
451 return 0;
452 return security_ops->path_link(old_dentry, new_dir, new_dentry);
453 }
454
security_path_rename(struct path * old_dir,struct dentry * old_dentry,struct path * new_dir,struct dentry * new_dentry,unsigned int flags)455 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
456 struct path *new_dir, struct dentry *new_dentry,
457 unsigned int flags)
458 {
459 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
460 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
461 return 0;
462
463 if (flags & RENAME_EXCHANGE) {
464 int err = security_ops->path_rename(new_dir, new_dentry,
465 old_dir, old_dentry);
466 if (err)
467 return err;
468 }
469
470 return security_ops->path_rename(old_dir, old_dentry, new_dir,
471 new_dentry);
472 }
473 EXPORT_SYMBOL(security_path_rename);
474
security_path_truncate(struct path * path)475 int security_path_truncate(struct path *path)
476 {
477 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
478 return 0;
479 return security_ops->path_truncate(path);
480 }
481
security_path_chmod(struct path * path,umode_t mode)482 int security_path_chmod(struct path *path, umode_t mode)
483 {
484 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
485 return 0;
486 return security_ops->path_chmod(path, mode);
487 }
488
security_path_chown(struct path * path,kuid_t uid,kgid_t gid)489 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
490 {
491 if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
492 return 0;
493 return security_ops->path_chown(path, uid, gid);
494 }
495 EXPORT_SYMBOL(security_path_chown);
496
security_path_chroot(struct path * path)497 int security_path_chroot(struct path *path)
498 {
499 return security_ops->path_chroot(path);
500 }
501 #endif
502
security_inode_create(struct inode * dir,struct dentry * dentry,umode_t mode)503 int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
504 {
505 if (unlikely(IS_PRIVATE(dir)))
506 return 0;
507 return security_ops->inode_create(dir, dentry, mode);
508 }
509 EXPORT_SYMBOL_GPL(security_inode_create);
510
security_inode_link(struct dentry * old_dentry,struct inode * dir,struct dentry * new_dentry)511 int security_inode_link(struct dentry *old_dentry, struct inode *dir,
512 struct dentry *new_dentry)
513 {
514 if (unlikely(IS_PRIVATE(old_dentry->d_inode)))
515 return 0;
516 return security_ops->inode_link(old_dentry, dir, new_dentry);
517 }
518
security_inode_unlink(struct inode * dir,struct dentry * dentry)519 int security_inode_unlink(struct inode *dir, struct dentry *dentry)
520 {
521 if (unlikely(IS_PRIVATE(dentry->d_inode)))
522 return 0;
523 return security_ops->inode_unlink(dir, dentry);
524 }
525
security_inode_symlink(struct inode * dir,struct dentry * dentry,const char * old_name)526 int security_inode_symlink(struct inode *dir, struct dentry *dentry,
527 const char *old_name)
528 {
529 if (unlikely(IS_PRIVATE(dir)))
530 return 0;
531 return security_ops->inode_symlink(dir, dentry, old_name);
532 }
533
security_inode_mkdir(struct inode * dir,struct dentry * dentry,umode_t mode)534 int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
535 {
536 if (unlikely(IS_PRIVATE(dir)))
537 return 0;
538 return security_ops->inode_mkdir(dir, dentry, mode);
539 }
540 EXPORT_SYMBOL_GPL(security_inode_mkdir);
541
security_inode_rmdir(struct inode * dir,struct dentry * dentry)542 int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
543 {
544 if (unlikely(IS_PRIVATE(dentry->d_inode)))
545 return 0;
546 return security_ops->inode_rmdir(dir, dentry);
547 }
548
security_inode_mknod(struct inode * dir,struct dentry * dentry,umode_t mode,dev_t dev)549 int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
550 {
551 if (unlikely(IS_PRIVATE(dir)))
552 return 0;
553 return security_ops->inode_mknod(dir, dentry, mode, dev);
554 }
555
security_inode_rename(struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)556 int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
557 struct inode *new_dir, struct dentry *new_dentry,
558 unsigned int flags)
559 {
560 if (unlikely(IS_PRIVATE(old_dentry->d_inode) ||
561 (new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode))))
562 return 0;
563
564 if (flags & RENAME_EXCHANGE) {
565 int err = security_ops->inode_rename(new_dir, new_dentry,
566 old_dir, old_dentry);
567 if (err)
568 return err;
569 }
570
571 return security_ops->inode_rename(old_dir, old_dentry,
572 new_dir, new_dentry);
573 }
574
security_inode_readlink(struct dentry * dentry)575 int security_inode_readlink(struct dentry *dentry)
576 {
577 if (unlikely(IS_PRIVATE(dentry->d_inode)))
578 return 0;
579 return security_ops->inode_readlink(dentry);
580 }
581
security_inode_follow_link(struct dentry * dentry,struct nameidata * nd)582 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
583 {
584 if (unlikely(IS_PRIVATE(dentry->d_inode)))
585 return 0;
586 return security_ops->inode_follow_link(dentry, nd);
587 }
588
security_inode_permission(struct inode * inode,int mask)589 int security_inode_permission(struct inode *inode, int mask)
590 {
591 if (unlikely(IS_PRIVATE(inode)))
592 return 0;
593 return security_ops->inode_permission(inode, mask);
594 }
595
security_inode_setattr(struct dentry * dentry,struct iattr * attr)596 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
597 {
598 int ret;
599
600 if (unlikely(IS_PRIVATE(dentry->d_inode)))
601 return 0;
602 ret = security_ops->inode_setattr(dentry, attr);
603 if (ret)
604 return ret;
605 return evm_inode_setattr(dentry, attr);
606 }
607 EXPORT_SYMBOL_GPL(security_inode_setattr);
608
security_inode_getattr(struct vfsmount * mnt,struct dentry * dentry)609 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
610 {
611 if (unlikely(IS_PRIVATE(dentry->d_inode)))
612 return 0;
613 return security_ops->inode_getattr(mnt, dentry);
614 }
615
security_inode_setxattr(struct dentry * dentry,const char * name,const void * value,size_t size,int flags)616 int security_inode_setxattr(struct dentry *dentry, const char *name,
617 const void *value, size_t size, int flags)
618 {
619 int ret;
620
621 if (unlikely(IS_PRIVATE(dentry->d_inode)))
622 return 0;
623 ret = security_ops->inode_setxattr(dentry, name, value, size, flags);
624 if (ret)
625 return ret;
626 ret = ima_inode_setxattr(dentry, name, value, size);
627 if (ret)
628 return ret;
629 return evm_inode_setxattr(dentry, name, value, size);
630 }
631
security_inode_post_setxattr(struct dentry * dentry,const char * name,const void * value,size_t size,int flags)632 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
633 const void *value, size_t size, int flags)
634 {
635 if (unlikely(IS_PRIVATE(dentry->d_inode)))
636 return;
637 security_ops->inode_post_setxattr(dentry, name, value, size, flags);
638 evm_inode_post_setxattr(dentry, name, value, size);
639 }
640
security_inode_getxattr(struct dentry * dentry,const char * name)641 int security_inode_getxattr(struct dentry *dentry, const char *name)
642 {
643 if (unlikely(IS_PRIVATE(dentry->d_inode)))
644 return 0;
645 return security_ops->inode_getxattr(dentry, name);
646 }
647
security_inode_listxattr(struct dentry * dentry)648 int security_inode_listxattr(struct dentry *dentry)
649 {
650 if (unlikely(IS_PRIVATE(dentry->d_inode)))
651 return 0;
652 return security_ops->inode_listxattr(dentry);
653 }
654
security_inode_removexattr(struct dentry * dentry,const char * name)655 int security_inode_removexattr(struct dentry *dentry, const char *name)
656 {
657 int ret;
658
659 if (unlikely(IS_PRIVATE(dentry->d_inode)))
660 return 0;
661 ret = security_ops->inode_removexattr(dentry, name);
662 if (ret)
663 return ret;
664 ret = ima_inode_removexattr(dentry, name);
665 if (ret)
666 return ret;
667 return evm_inode_removexattr(dentry, name);
668 }
669
security_inode_need_killpriv(struct dentry * dentry)670 int security_inode_need_killpriv(struct dentry *dentry)
671 {
672 return security_ops->inode_need_killpriv(dentry);
673 }
674
security_inode_killpriv(struct dentry * dentry)675 int security_inode_killpriv(struct dentry *dentry)
676 {
677 return security_ops->inode_killpriv(dentry);
678 }
679
security_inode_getsecurity(const struct inode * inode,const char * name,void ** buffer,bool alloc)680 int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
681 {
682 if (unlikely(IS_PRIVATE(inode)))
683 return -EOPNOTSUPP;
684 return security_ops->inode_getsecurity(inode, name, buffer, alloc);
685 }
686
security_inode_setsecurity(struct inode * inode,const char * name,const void * value,size_t size,int flags)687 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
688 {
689 if (unlikely(IS_PRIVATE(inode)))
690 return -EOPNOTSUPP;
691 return security_ops->inode_setsecurity(inode, name, value, size, flags);
692 }
693
security_inode_listsecurity(struct inode * inode,char * buffer,size_t buffer_size)694 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
695 {
696 if (unlikely(IS_PRIVATE(inode)))
697 return 0;
698 return security_ops->inode_listsecurity(inode, buffer, buffer_size);
699 }
700 EXPORT_SYMBOL(security_inode_listsecurity);
701
security_inode_getsecid(const struct inode * inode,u32 * secid)702 void security_inode_getsecid(const struct inode *inode, u32 *secid)
703 {
704 security_ops->inode_getsecid(inode, secid);
705 }
706
security_file_permission(struct file * file,int mask)707 int security_file_permission(struct file *file, int mask)
708 {
709 int ret;
710
711 ret = security_ops->file_permission(file, mask);
712 if (ret)
713 return ret;
714
715 return fsnotify_perm(file, mask);
716 }
717
security_file_alloc(struct file * file)718 int security_file_alloc(struct file *file)
719 {
720 return security_ops->file_alloc_security(file);
721 }
722
security_file_free(struct file * file)723 void security_file_free(struct file *file)
724 {
725 security_ops->file_free_security(file);
726 }
727
security_file_ioctl(struct file * file,unsigned int cmd,unsigned long arg)728 int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
729 {
730 return security_ops->file_ioctl(file, cmd, arg);
731 }
732
mmap_prot(struct file * file,unsigned long prot)733 static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
734 {
735 /*
736 * Does we have PROT_READ and does the application expect
737 * it to imply PROT_EXEC? If not, nothing to talk about...
738 */
739 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
740 return prot;
741 if (!(current->personality & READ_IMPLIES_EXEC))
742 return prot;
743 /*
744 * if that's an anonymous mapping, let it.
745 */
746 if (!file)
747 return prot | PROT_EXEC;
748 /*
749 * ditto if it's not on noexec mount, except that on !MMU we need
750 * BDI_CAP_EXEC_MMAP (== VM_MAYEXEC) in this case
751 */
752 if (!(file->f_path.mnt->mnt_flags & MNT_NOEXEC)) {
753 #ifndef CONFIG_MMU
754 unsigned long caps = 0;
755 struct address_space *mapping = file->f_mapping;
756 if (mapping && mapping->backing_dev_info)
757 caps = mapping->backing_dev_info->capabilities;
758 if (!(caps & BDI_CAP_EXEC_MAP))
759 return prot;
760 #endif
761 return prot | PROT_EXEC;
762 }
763 /* anything on noexec mount won't get PROT_EXEC */
764 return prot;
765 }
766
security_mmap_file(struct file * file,unsigned long prot,unsigned long flags)767 int security_mmap_file(struct file *file, unsigned long prot,
768 unsigned long flags)
769 {
770 int ret;
771 ret = security_ops->mmap_file(file, prot,
772 mmap_prot(file, prot), flags);
773 if (ret)
774 return ret;
775 return ima_file_mmap(file, prot);
776 }
777
security_mmap_addr(unsigned long addr)778 int security_mmap_addr(unsigned long addr)
779 {
780 return security_ops->mmap_addr(addr);
781 }
782
security_file_mprotect(struct vm_area_struct * vma,unsigned long reqprot,unsigned long prot)783 int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
784 unsigned long prot)
785 {
786 return security_ops->file_mprotect(vma, reqprot, prot);
787 }
788
security_file_lock(struct file * file,unsigned int cmd)789 int security_file_lock(struct file *file, unsigned int cmd)
790 {
791 return security_ops->file_lock(file, cmd);
792 }
793
security_file_fcntl(struct file * file,unsigned int cmd,unsigned long arg)794 int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
795 {
796 return security_ops->file_fcntl(file, cmd, arg);
797 }
798
security_file_set_fowner(struct file * file)799 void security_file_set_fowner(struct file *file)
800 {
801 security_ops->file_set_fowner(file);
802 }
803
security_file_send_sigiotask(struct task_struct * tsk,struct fown_struct * fown,int sig)804 int security_file_send_sigiotask(struct task_struct *tsk,
805 struct fown_struct *fown, int sig)
806 {
807 return security_ops->file_send_sigiotask(tsk, fown, sig);
808 }
809
security_file_receive(struct file * file)810 int security_file_receive(struct file *file)
811 {
812 return security_ops->file_receive(file);
813 }
814
security_file_open(struct file * file,const struct cred * cred)815 int security_file_open(struct file *file, const struct cred *cred)
816 {
817 int ret;
818
819 ret = security_ops->file_open(file, cred);
820 if (ret)
821 return ret;
822
823 return fsnotify_perm(file, MAY_OPEN);
824 }
825
security_task_create(unsigned long clone_flags)826 int security_task_create(unsigned long clone_flags)
827 {
828 return security_ops->task_create(clone_flags);
829 }
830
security_task_free(struct task_struct * task)831 void security_task_free(struct task_struct *task)
832 {
833 #ifdef CONFIG_SECURITY_YAMA_STACKED
834 yama_task_free(task);
835 #endif
836 security_ops->task_free(task);
837 }
838
security_cred_alloc_blank(struct cred * cred,gfp_t gfp)839 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
840 {
841 return security_ops->cred_alloc_blank(cred, gfp);
842 }
843
security_cred_free(struct cred * cred)844 void security_cred_free(struct cred *cred)
845 {
846 security_ops->cred_free(cred);
847 }
848
security_prepare_creds(struct cred * new,const struct cred * old,gfp_t gfp)849 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
850 {
851 return security_ops->cred_prepare(new, old, gfp);
852 }
853
security_transfer_creds(struct cred * new,const struct cred * old)854 void security_transfer_creds(struct cred *new, const struct cred *old)
855 {
856 security_ops->cred_transfer(new, old);
857 }
858
security_kernel_act_as(struct cred * new,u32 secid)859 int security_kernel_act_as(struct cred *new, u32 secid)
860 {
861 return security_ops->kernel_act_as(new, secid);
862 }
863
security_kernel_create_files_as(struct cred * new,struct inode * inode)864 int security_kernel_create_files_as(struct cred *new, struct inode *inode)
865 {
866 return security_ops->kernel_create_files_as(new, inode);
867 }
868
security_kernel_fw_from_file(struct file * file,char * buf,size_t size)869 int security_kernel_fw_from_file(struct file *file, char *buf, size_t size)
870 {
871 int ret;
872
873 ret = security_ops->kernel_fw_from_file(file, buf, size);
874 if (ret)
875 return ret;
876 return ima_fw_from_file(file, buf, size);
877 }
878 EXPORT_SYMBOL_GPL(security_kernel_fw_from_file);
879
security_kernel_module_request(char * kmod_name)880 int security_kernel_module_request(char *kmod_name)
881 {
882 return security_ops->kernel_module_request(kmod_name);
883 }
884
security_kernel_module_from_file(struct file * file)885 int security_kernel_module_from_file(struct file *file)
886 {
887 int ret;
888
889 ret = security_ops->kernel_module_from_file(file);
890 if (ret)
891 return ret;
892 return ima_module_check(file);
893 }
894
security_task_fix_setuid(struct cred * new,const struct cred * old,int flags)895 int security_task_fix_setuid(struct cred *new, const struct cred *old,
896 int flags)
897 {
898 return security_ops->task_fix_setuid(new, old, flags);
899 }
900
security_task_setpgid(struct task_struct * p,pid_t pgid)901 int security_task_setpgid(struct task_struct *p, pid_t pgid)
902 {
903 return security_ops->task_setpgid(p, pgid);
904 }
905
security_task_getpgid(struct task_struct * p)906 int security_task_getpgid(struct task_struct *p)
907 {
908 return security_ops->task_getpgid(p);
909 }
910
security_task_getsid(struct task_struct * p)911 int security_task_getsid(struct task_struct *p)
912 {
913 return security_ops->task_getsid(p);
914 }
915
security_task_getsecid(struct task_struct * p,u32 * secid)916 void security_task_getsecid(struct task_struct *p, u32 *secid)
917 {
918 security_ops->task_getsecid(p, secid);
919 }
920 EXPORT_SYMBOL(security_task_getsecid);
921
security_task_setnice(struct task_struct * p,int nice)922 int security_task_setnice(struct task_struct *p, int nice)
923 {
924 return security_ops->task_setnice(p, nice);
925 }
926
security_task_setioprio(struct task_struct * p,int ioprio)927 int security_task_setioprio(struct task_struct *p, int ioprio)
928 {
929 return security_ops->task_setioprio(p, ioprio);
930 }
931
security_task_getioprio(struct task_struct * p)932 int security_task_getioprio(struct task_struct *p)
933 {
934 return security_ops->task_getioprio(p);
935 }
936
security_task_setrlimit(struct task_struct * p,unsigned int resource,struct rlimit * new_rlim)937 int security_task_setrlimit(struct task_struct *p, unsigned int resource,
938 struct rlimit *new_rlim)
939 {
940 return security_ops->task_setrlimit(p, resource, new_rlim);
941 }
942
security_task_setscheduler(struct task_struct * p)943 int security_task_setscheduler(struct task_struct *p)
944 {
945 return security_ops->task_setscheduler(p);
946 }
947
security_task_getscheduler(struct task_struct * p)948 int security_task_getscheduler(struct task_struct *p)
949 {
950 return security_ops->task_getscheduler(p);
951 }
952
security_task_movememory(struct task_struct * p)953 int security_task_movememory(struct task_struct *p)
954 {
955 return security_ops->task_movememory(p);
956 }
957
security_task_kill(struct task_struct * p,struct siginfo * info,int sig,u32 secid)958 int security_task_kill(struct task_struct *p, struct siginfo *info,
959 int sig, u32 secid)
960 {
961 return security_ops->task_kill(p, info, sig, secid);
962 }
963
security_task_wait(struct task_struct * p)964 int security_task_wait(struct task_struct *p)
965 {
966 return security_ops->task_wait(p);
967 }
968
security_task_prctl(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5)969 int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
970 unsigned long arg4, unsigned long arg5)
971 {
972 #ifdef CONFIG_SECURITY_YAMA_STACKED
973 int rc;
974 rc = yama_task_prctl(option, arg2, arg3, arg4, arg5);
975 if (rc != -ENOSYS)
976 return rc;
977 #endif
978 return security_ops->task_prctl(option, arg2, arg3, arg4, arg5);
979 }
980
security_task_to_inode(struct task_struct * p,struct inode * inode)981 void security_task_to_inode(struct task_struct *p, struct inode *inode)
982 {
983 security_ops->task_to_inode(p, inode);
984 }
985
security_ipc_permission(struct kern_ipc_perm * ipcp,short flag)986 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
987 {
988 return security_ops->ipc_permission(ipcp, flag);
989 }
990
security_ipc_getsecid(struct kern_ipc_perm * ipcp,u32 * secid)991 void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
992 {
993 security_ops->ipc_getsecid(ipcp, secid);
994 }
995
security_msg_msg_alloc(struct msg_msg * msg)996 int security_msg_msg_alloc(struct msg_msg *msg)
997 {
998 return security_ops->msg_msg_alloc_security(msg);
999 }
1000
security_msg_msg_free(struct msg_msg * msg)1001 void security_msg_msg_free(struct msg_msg *msg)
1002 {
1003 security_ops->msg_msg_free_security(msg);
1004 }
1005
security_msg_queue_alloc(struct msg_queue * msq)1006 int security_msg_queue_alloc(struct msg_queue *msq)
1007 {
1008 return security_ops->msg_queue_alloc_security(msq);
1009 }
1010
security_msg_queue_free(struct msg_queue * msq)1011 void security_msg_queue_free(struct msg_queue *msq)
1012 {
1013 security_ops->msg_queue_free_security(msq);
1014 }
1015
security_msg_queue_associate(struct msg_queue * msq,int msqflg)1016 int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
1017 {
1018 return security_ops->msg_queue_associate(msq, msqflg);
1019 }
1020
security_msg_queue_msgctl(struct msg_queue * msq,int cmd)1021 int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1022 {
1023 return security_ops->msg_queue_msgctl(msq, cmd);
1024 }
1025
security_msg_queue_msgsnd(struct msg_queue * msq,struct msg_msg * msg,int msqflg)1026 int security_msg_queue_msgsnd(struct msg_queue *msq,
1027 struct msg_msg *msg, int msqflg)
1028 {
1029 return security_ops->msg_queue_msgsnd(msq, msg, msqflg);
1030 }
1031
security_msg_queue_msgrcv(struct msg_queue * msq,struct msg_msg * msg,struct task_struct * target,long type,int mode)1032 int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1033 struct task_struct *target, long type, int mode)
1034 {
1035 return security_ops->msg_queue_msgrcv(msq, msg, target, type, mode);
1036 }
1037
security_shm_alloc(struct shmid_kernel * shp)1038 int security_shm_alloc(struct shmid_kernel *shp)
1039 {
1040 return security_ops->shm_alloc_security(shp);
1041 }
1042
security_shm_free(struct shmid_kernel * shp)1043 void security_shm_free(struct shmid_kernel *shp)
1044 {
1045 security_ops->shm_free_security(shp);
1046 }
1047
security_shm_associate(struct shmid_kernel * shp,int shmflg)1048 int security_shm_associate(struct shmid_kernel *shp, int shmflg)
1049 {
1050 return security_ops->shm_associate(shp, shmflg);
1051 }
1052
security_shm_shmctl(struct shmid_kernel * shp,int cmd)1053 int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1054 {
1055 return security_ops->shm_shmctl(shp, cmd);
1056 }
1057
security_shm_shmat(struct shmid_kernel * shp,char __user * shmaddr,int shmflg)1058 int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
1059 {
1060 return security_ops->shm_shmat(shp, shmaddr, shmflg);
1061 }
1062
security_sem_alloc(struct sem_array * sma)1063 int security_sem_alloc(struct sem_array *sma)
1064 {
1065 return security_ops->sem_alloc_security(sma);
1066 }
1067
security_sem_free(struct sem_array * sma)1068 void security_sem_free(struct sem_array *sma)
1069 {
1070 security_ops->sem_free_security(sma);
1071 }
1072
security_sem_associate(struct sem_array * sma,int semflg)1073 int security_sem_associate(struct sem_array *sma, int semflg)
1074 {
1075 return security_ops->sem_associate(sma, semflg);
1076 }
1077
security_sem_semctl(struct sem_array * sma,int cmd)1078 int security_sem_semctl(struct sem_array *sma, int cmd)
1079 {
1080 return security_ops->sem_semctl(sma, cmd);
1081 }
1082
security_sem_semop(struct sem_array * sma,struct sembuf * sops,unsigned nsops,int alter)1083 int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
1084 unsigned nsops, int alter)
1085 {
1086 return security_ops->sem_semop(sma, sops, nsops, alter);
1087 }
1088
security_d_instantiate(struct dentry * dentry,struct inode * inode)1089 void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1090 {
1091 if (unlikely(inode && IS_PRIVATE(inode)))
1092 return;
1093 security_ops->d_instantiate(dentry, inode);
1094 }
1095 EXPORT_SYMBOL(security_d_instantiate);
1096
security_getprocattr(struct task_struct * p,char * name,char ** value)1097 int security_getprocattr(struct task_struct *p, char *name, char **value)
1098 {
1099 return security_ops->getprocattr(p, name, value);
1100 }
1101
security_setprocattr(struct task_struct * p,char * name,void * value,size_t size)1102 int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
1103 {
1104 return security_ops->setprocattr(p, name, value, size);
1105 }
1106
security_netlink_send(struct sock * sk,struct sk_buff * skb)1107 int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1108 {
1109 return security_ops->netlink_send(sk, skb);
1110 }
1111
security_ismaclabel(const char * name)1112 int security_ismaclabel(const char *name)
1113 {
1114 return security_ops->ismaclabel(name);
1115 }
1116 EXPORT_SYMBOL(security_ismaclabel);
1117
security_secid_to_secctx(u32 secid,char ** secdata,u32 * seclen)1118 int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1119 {
1120 return security_ops->secid_to_secctx(secid, secdata, seclen);
1121 }
1122 EXPORT_SYMBOL(security_secid_to_secctx);
1123
security_secctx_to_secid(const char * secdata,u32 seclen,u32 * secid)1124 int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
1125 {
1126 return security_ops->secctx_to_secid(secdata, seclen, secid);
1127 }
1128 EXPORT_SYMBOL(security_secctx_to_secid);
1129
security_release_secctx(char * secdata,u32 seclen)1130 void security_release_secctx(char *secdata, u32 seclen)
1131 {
1132 security_ops->release_secctx(secdata, seclen);
1133 }
1134 EXPORT_SYMBOL(security_release_secctx);
1135
security_inode_notifysecctx(struct inode * inode,void * ctx,u32 ctxlen)1136 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
1137 {
1138 return security_ops->inode_notifysecctx(inode, ctx, ctxlen);
1139 }
1140 EXPORT_SYMBOL(security_inode_notifysecctx);
1141
security_inode_setsecctx(struct dentry * dentry,void * ctx,u32 ctxlen)1142 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
1143 {
1144 return security_ops->inode_setsecctx(dentry, ctx, ctxlen);
1145 }
1146 EXPORT_SYMBOL(security_inode_setsecctx);
1147
security_inode_getsecctx(struct inode * inode,void ** ctx,u32 * ctxlen)1148 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1149 {
1150 return security_ops->inode_getsecctx(inode, ctx, ctxlen);
1151 }
1152 EXPORT_SYMBOL(security_inode_getsecctx);
1153
1154 #ifdef CONFIG_SECURITY_NETWORK
1155
security_unix_stream_connect(struct sock * sock,struct sock * other,struct sock * newsk)1156 int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
1157 {
1158 return security_ops->unix_stream_connect(sock, other, newsk);
1159 }
1160 EXPORT_SYMBOL(security_unix_stream_connect);
1161
security_unix_may_send(struct socket * sock,struct socket * other)1162 int security_unix_may_send(struct socket *sock, struct socket *other)
1163 {
1164 return security_ops->unix_may_send(sock, other);
1165 }
1166 EXPORT_SYMBOL(security_unix_may_send);
1167
security_socket_create(int family,int type,int protocol,int kern)1168 int security_socket_create(int family, int type, int protocol, int kern)
1169 {
1170 return security_ops->socket_create(family, type, protocol, kern);
1171 }
1172
security_socket_post_create(struct socket * sock,int family,int type,int protocol,int kern)1173 int security_socket_post_create(struct socket *sock, int family,
1174 int type, int protocol, int kern)
1175 {
1176 return security_ops->socket_post_create(sock, family, type,
1177 protocol, kern);
1178 }
1179
security_socket_bind(struct socket * sock,struct sockaddr * address,int addrlen)1180 int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
1181 {
1182 return security_ops->socket_bind(sock, address, addrlen);
1183 }
1184
security_socket_connect(struct socket * sock,struct sockaddr * address,int addrlen)1185 int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
1186 {
1187 return security_ops->socket_connect(sock, address, addrlen);
1188 }
1189
security_socket_listen(struct socket * sock,int backlog)1190 int security_socket_listen(struct socket *sock, int backlog)
1191 {
1192 return security_ops->socket_listen(sock, backlog);
1193 }
1194
security_socket_accept(struct socket * sock,struct socket * newsock)1195 int security_socket_accept(struct socket *sock, struct socket *newsock)
1196 {
1197 return security_ops->socket_accept(sock, newsock);
1198 }
1199
security_socket_sendmsg(struct socket * sock,struct msghdr * msg,int size)1200 int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
1201 {
1202 return security_ops->socket_sendmsg(sock, msg, size);
1203 }
1204
security_socket_recvmsg(struct socket * sock,struct msghdr * msg,int size,int flags)1205 int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
1206 int size, int flags)
1207 {
1208 return security_ops->socket_recvmsg(sock, msg, size, flags);
1209 }
1210
security_socket_getsockname(struct socket * sock)1211 int security_socket_getsockname(struct socket *sock)
1212 {
1213 return security_ops->socket_getsockname(sock);
1214 }
1215
security_socket_getpeername(struct socket * sock)1216 int security_socket_getpeername(struct socket *sock)
1217 {
1218 return security_ops->socket_getpeername(sock);
1219 }
1220
security_socket_getsockopt(struct socket * sock,int level,int optname)1221 int security_socket_getsockopt(struct socket *sock, int level, int optname)
1222 {
1223 return security_ops->socket_getsockopt(sock, level, optname);
1224 }
1225
security_socket_setsockopt(struct socket * sock,int level,int optname)1226 int security_socket_setsockopt(struct socket *sock, int level, int optname)
1227 {
1228 return security_ops->socket_setsockopt(sock, level, optname);
1229 }
1230
security_socket_shutdown(struct socket * sock,int how)1231 int security_socket_shutdown(struct socket *sock, int how)
1232 {
1233 return security_ops->socket_shutdown(sock, how);
1234 }
1235
security_sock_rcv_skb(struct sock * sk,struct sk_buff * skb)1236 int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
1237 {
1238 return security_ops->socket_sock_rcv_skb(sk, skb);
1239 }
1240 EXPORT_SYMBOL(security_sock_rcv_skb);
1241
security_socket_getpeersec_stream(struct socket * sock,char __user * optval,int __user * optlen,unsigned len)1242 int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1243 int __user *optlen, unsigned len)
1244 {
1245 return security_ops->socket_getpeersec_stream(sock, optval, optlen, len);
1246 }
1247
security_socket_getpeersec_dgram(struct socket * sock,struct sk_buff * skb,u32 * secid)1248 int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
1249 {
1250 return security_ops->socket_getpeersec_dgram(sock, skb, secid);
1251 }
1252 EXPORT_SYMBOL(security_socket_getpeersec_dgram);
1253
security_sk_alloc(struct sock * sk,int family,gfp_t priority)1254 int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
1255 {
1256 return security_ops->sk_alloc_security(sk, family, priority);
1257 }
1258
security_sk_free(struct sock * sk)1259 void security_sk_free(struct sock *sk)
1260 {
1261 security_ops->sk_free_security(sk);
1262 }
1263
security_sk_clone(const struct sock * sk,struct sock * newsk)1264 void security_sk_clone(const struct sock *sk, struct sock *newsk)
1265 {
1266 security_ops->sk_clone_security(sk, newsk);
1267 }
1268 EXPORT_SYMBOL(security_sk_clone);
1269
security_sk_classify_flow(struct sock * sk,struct flowi * fl)1270 void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1271 {
1272 security_ops->sk_getsecid(sk, &fl->flowi_secid);
1273 }
1274 EXPORT_SYMBOL(security_sk_classify_flow);
1275
security_req_classify_flow(const struct request_sock * req,struct flowi * fl)1276 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1277 {
1278 security_ops->req_classify_flow(req, fl);
1279 }
1280 EXPORT_SYMBOL(security_req_classify_flow);
1281
security_sock_graft(struct sock * sk,struct socket * parent)1282 void security_sock_graft(struct sock *sk, struct socket *parent)
1283 {
1284 security_ops->sock_graft(sk, parent);
1285 }
1286 EXPORT_SYMBOL(security_sock_graft);
1287
security_inet_conn_request(struct sock * sk,struct sk_buff * skb,struct request_sock * req)1288 int security_inet_conn_request(struct sock *sk,
1289 struct sk_buff *skb, struct request_sock *req)
1290 {
1291 return security_ops->inet_conn_request(sk, skb, req);
1292 }
1293 EXPORT_SYMBOL(security_inet_conn_request);
1294
security_inet_csk_clone(struct sock * newsk,const struct request_sock * req)1295 void security_inet_csk_clone(struct sock *newsk,
1296 const struct request_sock *req)
1297 {
1298 security_ops->inet_csk_clone(newsk, req);
1299 }
1300
security_inet_conn_established(struct sock * sk,struct sk_buff * skb)1301 void security_inet_conn_established(struct sock *sk,
1302 struct sk_buff *skb)
1303 {
1304 security_ops->inet_conn_established(sk, skb);
1305 }
1306
security_secmark_relabel_packet(u32 secid)1307 int security_secmark_relabel_packet(u32 secid)
1308 {
1309 return security_ops->secmark_relabel_packet(secid);
1310 }
1311 EXPORT_SYMBOL(security_secmark_relabel_packet);
1312
security_secmark_refcount_inc(void)1313 void security_secmark_refcount_inc(void)
1314 {
1315 security_ops->secmark_refcount_inc();
1316 }
1317 EXPORT_SYMBOL(security_secmark_refcount_inc);
1318
security_secmark_refcount_dec(void)1319 void security_secmark_refcount_dec(void)
1320 {
1321 security_ops->secmark_refcount_dec();
1322 }
1323 EXPORT_SYMBOL(security_secmark_refcount_dec);
1324
security_tun_dev_alloc_security(void ** security)1325 int security_tun_dev_alloc_security(void **security)
1326 {
1327 return security_ops->tun_dev_alloc_security(security);
1328 }
1329 EXPORT_SYMBOL(security_tun_dev_alloc_security);
1330
security_tun_dev_free_security(void * security)1331 void security_tun_dev_free_security(void *security)
1332 {
1333 security_ops->tun_dev_free_security(security);
1334 }
1335 EXPORT_SYMBOL(security_tun_dev_free_security);
1336
security_tun_dev_create(void)1337 int security_tun_dev_create(void)
1338 {
1339 return security_ops->tun_dev_create();
1340 }
1341 EXPORT_SYMBOL(security_tun_dev_create);
1342
security_tun_dev_attach_queue(void * security)1343 int security_tun_dev_attach_queue(void *security)
1344 {
1345 return security_ops->tun_dev_attach_queue(security);
1346 }
1347 EXPORT_SYMBOL(security_tun_dev_attach_queue);
1348
security_tun_dev_attach(struct sock * sk,void * security)1349 int security_tun_dev_attach(struct sock *sk, void *security)
1350 {
1351 return security_ops->tun_dev_attach(sk, security);
1352 }
1353 EXPORT_SYMBOL(security_tun_dev_attach);
1354
security_tun_dev_open(void * security)1355 int security_tun_dev_open(void *security)
1356 {
1357 return security_ops->tun_dev_open(security);
1358 }
1359 EXPORT_SYMBOL(security_tun_dev_open);
1360
security_skb_owned_by(struct sk_buff * skb,struct sock * sk)1361 void security_skb_owned_by(struct sk_buff *skb, struct sock *sk)
1362 {
1363 security_ops->skb_owned_by(skb, sk);
1364 }
1365
1366 #endif /* CONFIG_SECURITY_NETWORK */
1367
1368 #ifdef CONFIG_SECURITY_NETWORK_XFRM
1369
security_xfrm_policy_alloc(struct xfrm_sec_ctx ** ctxp,struct xfrm_user_sec_ctx * sec_ctx,gfp_t gfp)1370 int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
1371 struct xfrm_user_sec_ctx *sec_ctx,
1372 gfp_t gfp)
1373 {
1374 return security_ops->xfrm_policy_alloc_security(ctxp, sec_ctx, gfp);
1375 }
1376 EXPORT_SYMBOL(security_xfrm_policy_alloc);
1377
security_xfrm_policy_clone(struct xfrm_sec_ctx * old_ctx,struct xfrm_sec_ctx ** new_ctxp)1378 int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
1379 struct xfrm_sec_ctx **new_ctxp)
1380 {
1381 return security_ops->xfrm_policy_clone_security(old_ctx, new_ctxp);
1382 }
1383
security_xfrm_policy_free(struct xfrm_sec_ctx * ctx)1384 void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
1385 {
1386 security_ops->xfrm_policy_free_security(ctx);
1387 }
1388 EXPORT_SYMBOL(security_xfrm_policy_free);
1389
security_xfrm_policy_delete(struct xfrm_sec_ctx * ctx)1390 int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
1391 {
1392 return security_ops->xfrm_policy_delete_security(ctx);
1393 }
1394
security_xfrm_state_alloc(struct xfrm_state * x,struct xfrm_user_sec_ctx * sec_ctx)1395 int security_xfrm_state_alloc(struct xfrm_state *x,
1396 struct xfrm_user_sec_ctx *sec_ctx)
1397 {
1398 return security_ops->xfrm_state_alloc(x, sec_ctx);
1399 }
1400 EXPORT_SYMBOL(security_xfrm_state_alloc);
1401
security_xfrm_state_alloc_acquire(struct xfrm_state * x,struct xfrm_sec_ctx * polsec,u32 secid)1402 int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
1403 struct xfrm_sec_ctx *polsec, u32 secid)
1404 {
1405 return security_ops->xfrm_state_alloc_acquire(x, polsec, secid);
1406 }
1407
security_xfrm_state_delete(struct xfrm_state * x)1408 int security_xfrm_state_delete(struct xfrm_state *x)
1409 {
1410 return security_ops->xfrm_state_delete_security(x);
1411 }
1412 EXPORT_SYMBOL(security_xfrm_state_delete);
1413
security_xfrm_state_free(struct xfrm_state * x)1414 void security_xfrm_state_free(struct xfrm_state *x)
1415 {
1416 security_ops->xfrm_state_free_security(x);
1417 }
1418
security_xfrm_policy_lookup(struct xfrm_sec_ctx * ctx,u32 fl_secid,u8 dir)1419 int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
1420 {
1421 return security_ops->xfrm_policy_lookup(ctx, fl_secid, dir);
1422 }
1423
security_xfrm_state_pol_flow_match(struct xfrm_state * x,struct xfrm_policy * xp,const struct flowi * fl)1424 int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
1425 struct xfrm_policy *xp,
1426 const struct flowi *fl)
1427 {
1428 return security_ops->xfrm_state_pol_flow_match(x, xp, fl);
1429 }
1430
security_xfrm_decode_session(struct sk_buff * skb,u32 * secid)1431 int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
1432 {
1433 return security_ops->xfrm_decode_session(skb, secid, 1);
1434 }
1435
security_skb_classify_flow(struct sk_buff * skb,struct flowi * fl)1436 void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
1437 {
1438 int rc = security_ops->xfrm_decode_session(skb, &fl->flowi_secid, 0);
1439
1440 BUG_ON(rc);
1441 }
1442 EXPORT_SYMBOL(security_skb_classify_flow);
1443
1444 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
1445
1446 #ifdef CONFIG_KEYS
1447
security_key_alloc(struct key * key,const struct cred * cred,unsigned long flags)1448 int security_key_alloc(struct key *key, const struct cred *cred,
1449 unsigned long flags)
1450 {
1451 return security_ops->key_alloc(key, cred, flags);
1452 }
1453
security_key_free(struct key * key)1454 void security_key_free(struct key *key)
1455 {
1456 security_ops->key_free(key);
1457 }
1458
security_key_permission(key_ref_t key_ref,const struct cred * cred,unsigned perm)1459 int security_key_permission(key_ref_t key_ref,
1460 const struct cred *cred, unsigned perm)
1461 {
1462 return security_ops->key_permission(key_ref, cred, perm);
1463 }
1464
security_key_getsecurity(struct key * key,char ** _buffer)1465 int security_key_getsecurity(struct key *key, char **_buffer)
1466 {
1467 return security_ops->key_getsecurity(key, _buffer);
1468 }
1469
1470 #endif /* CONFIG_KEYS */
1471
1472 #ifdef CONFIG_AUDIT
1473
security_audit_rule_init(u32 field,u32 op,char * rulestr,void ** lsmrule)1474 int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
1475 {
1476 return security_ops->audit_rule_init(field, op, rulestr, lsmrule);
1477 }
1478
security_audit_rule_known(struct audit_krule * krule)1479 int security_audit_rule_known(struct audit_krule *krule)
1480 {
1481 return security_ops->audit_rule_known(krule);
1482 }
1483
security_audit_rule_free(void * lsmrule)1484 void security_audit_rule_free(void *lsmrule)
1485 {
1486 security_ops->audit_rule_free(lsmrule);
1487 }
1488
security_audit_rule_match(u32 secid,u32 field,u32 op,void * lsmrule,struct audit_context * actx)1489 int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
1490 struct audit_context *actx)
1491 {
1492 return security_ops->audit_rule_match(secid, field, op, lsmrule, actx);
1493 }
1494
1495 #endif /* CONFIG_AUDIT */
1496