blob: 02dc72006afa5986f777a5cadac334859fcaace5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Randy.Dunlapc59ede72006-01-11 12:17:46 -080014#include <linux/capability.h>
David Quigleyd47be3d2013-05-22 12:50:34 -040015#include <linux/dcache.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -070019#include <linux/lsm_hooks.h>
Mimi Zoharf381c272011-03-09 14:13:22 -050020#include <linux/integrity.h>
Mimi Zohar6c21a7f2009-10-22 17:30:13 -040021#include <linux/ima.h>
Mimi Zohar3e1be522011-03-09 14:38:26 -050022#include <linux/evm.h>
Al Viro40401532012-02-13 03:58:52 +000023#include <linux/fsnotify.h>
Al Viro8b3ec682012-05-30 17:11:23 -040024#include <linux/mman.h>
25#include <linux/mount.h>
26#include <linux/personality.h>
Paul Mundt75331a52012-07-02 14:34:11 +090027#include <linux/backing-dev.h>
Al Viro40401532012-02-13 03:58:52 +000028#include <net/flow.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Mimi Zohar823eb1c2011-06-15 21:19:10 -040030#define MAX_LSM_EVM_XATTR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +020032/* Boot-time LSM user choice */
John Johansen6e65f922009-11-05 17:03:20 -080033static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
34 CONFIG_DEFAULT_SECURITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
wzt.wzt@gmail.com189b3b12010-02-23 23:15:28 +080036static struct security_operations *security_ops;
37static struct security_operations default_security_ops = {
38 .name = "default",
39};
Eric Parisa5ecbcb2008-01-31 15:11:22 -050040
Tetsuo Handac80901f2010-05-14 12:01:26 +090041static inline int __init verify(struct security_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 /* verify the security_operations structure exists */
44 if (!ops)
45 return -EINVAL;
46 security_fixup_ops(ops);
47 return 0;
48}
49
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{
James Morris20510f22007-10-16 23:31:32 -070067 printk(KERN_INFO "Security Framework initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Miklos Szeredi5915eb52008-07-03 20:56:05 +020069 security_fixup_ops(&default_security_ops);
70 security_ops = &default_security_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 do_security_initcalls();
72
73 return 0;
74}
75
wzt.wzt@gmail.com189b3b12010-02-23 23:15:28 +080076void reset_security_ops(void)
77{
78 security_ops = &default_security_ops;
79}
80
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +020081/* Save user chosen LSM */
82static 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
James Morris7cea51b2008-03-07 12:23:49 +110095 * to check if your LSM is currently loaded during kernel initialization.
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +020096 *
97 * Return true if:
98 * -The passed LSM is the one chosen by user at boot time,
John Johansen6e65f922009-11-05 17:03:20 -080099 * -or the passed LSM is configured as the default and the user did not
Tetsuo Handa065d78a2010-08-28 14:58:44 +0900100 * choose an alternate LSM at boot time.
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200101 * Otherwise, return false.
102 */
103int __init security_module_enable(struct security_operations *ops)
104{
Tetsuo Handa065d78a2010-08-28 14:58:44 +0900105 return !strcmp(ops->name, chosen_lsm);
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200106}
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/**
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 *
Randy Dunlap3f23d812008-08-17 21:44:22 -0700112 * This function allows a security module to register itself with the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 * kernel security subsystem. Some rudimentary checking is done on the @ops
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200114 * 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).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 *
117 * If there is already a security module registered with the kernel,
Randy Dunlap3f23d812008-08-17 21:44:22 -0700118 * an error will be returned. Otherwise %0 is returned on success.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 */
wzt.wzt@gmail.comc1e992b2010-02-26 22:49:55 +0800120int __init register_security(struct security_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 if (verify(ops)) {
123 printk(KERN_DEBUG "%s could not verify "
Harvey Harrisondd6f9532008-03-06 10:03:59 +1100124 "security_operations structure.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return -EINVAL;
126 }
127
Miklos Szeredi5915eb52008-07-03 20:56:05 +0200128 if (security_ops != &default_security_ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return -EAGAIN;
130
131 security_ops = ops;
132
133 return 0;
134}
135
Casey Schauflerf25fce32015-05-02 15:11:29 -0700136/*
137 * Hook operation macros.
138 *
139 * call_void_hook:
140 * This is a hook that does not return a value.
141 *
142 * call_int_hook:
143 * This is a hook that returns a value.
144 */
145
146#define call_void_hook(FUNC, ...) security_ops->FUNC(__VA_ARGS__)
147#define call_int_hook(FUNC, IRC, ...) security_ops->FUNC(__VA_ARGS__)
148
James Morris20510f22007-10-16 23:31:32 -0700149/* Security operations */
150
Stephen Smalley79af7302015-01-21 10:54:10 -0500151int security_binder_set_context_mgr(struct task_struct *mgr)
152{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700153 return call_int_hook(binder_set_context_mgr, 0, mgr);
Stephen Smalley79af7302015-01-21 10:54:10 -0500154}
155
156int security_binder_transaction(struct task_struct *from,
157 struct task_struct *to)
158{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700159 return call_int_hook(binder_transaction, 0, from, to);
Stephen Smalley79af7302015-01-21 10:54:10 -0500160}
161
162int security_binder_transfer_binder(struct task_struct *from,
163 struct task_struct *to)
164{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700165 return call_int_hook(binder_transfer_binder, 0, from, to);
Stephen Smalley79af7302015-01-21 10:54:10 -0500166}
167
168int security_binder_transfer_file(struct task_struct *from,
169 struct task_struct *to, struct file *file)
170{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700171 return call_int_hook(binder_transfer_file, 0, from, to, file);
Stephen Smalley79af7302015-01-21 10:54:10 -0500172}
173
Ingo Molnar9e488582009-05-07 19:26:19 +1000174int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
James Morris20510f22007-10-16 23:31:32 -0700175{
Kees Cookc6993e42012-09-04 13:32:13 -0700176#ifdef CONFIG_SECURITY_YAMA_STACKED
177 int rc;
178 rc = yama_ptrace_access_check(child, mode);
179 if (rc)
180 return rc;
181#endif
Casey Schauflerf25fce32015-05-02 15:11:29 -0700182 return call_int_hook(ptrace_access_check, 0, child, mode);
David Howells5cd9c582008-08-14 11:37:28 +0100183}
184
185int security_ptrace_traceme(struct task_struct *parent)
186{
Kees Cookc6993e42012-09-04 13:32:13 -0700187#ifdef CONFIG_SECURITY_YAMA_STACKED
188 int rc;
189 rc = yama_ptrace_traceme(parent);
190 if (rc)
191 return rc;
192#endif
Casey Schauflerf25fce32015-05-02 15:11:29 -0700193 return call_int_hook(ptrace_traceme, 0, parent);
James Morris20510f22007-10-16 23:31:32 -0700194}
195
196int security_capget(struct task_struct *target,
197 kernel_cap_t *effective,
198 kernel_cap_t *inheritable,
199 kernel_cap_t *permitted)
200{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700201 return call_int_hook(capget, 0, target,
202 effective, inheritable, permitted);
James Morris20510f22007-10-16 23:31:32 -0700203}
204
David Howellsd84f4f92008-11-14 10:39:23 +1100205int security_capset(struct cred *new, const struct cred *old,
206 const kernel_cap_t *effective,
207 const kernel_cap_t *inheritable,
208 const kernel_cap_t *permitted)
James Morris20510f22007-10-16 23:31:32 -0700209{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700210 return call_int_hook(capset, 0, new, old,
211 effective, inheritable, permitted);
James Morris20510f22007-10-16 23:31:32 -0700212}
213
Eric Parisb7e724d2012-01-03 12:25:15 -0500214int security_capable(const struct cred *cred, struct user_namespace *ns,
Serge E. Hallyn34867402011-03-23 16:43:17 -0700215 int cap)
James Morris20510f22007-10-16 23:31:32 -0700216{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700217 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
Eric Paris06112162008-11-11 22:02:50 +1100218}
219
Eric Parisc7eba4a2012-01-03 12:25:15 -0500220int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
221 int cap)
Eric Paris06112162008-11-11 22:02:50 +1100222{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700223 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
James Morris20510f22007-10-16 23:31:32 -0700224}
225
James Morris20510f22007-10-16 23:31:32 -0700226int security_quotactl(int cmds, int type, int id, struct super_block *sb)
227{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700228 return call_int_hook(quotactl, 0, cmds, type, id, sb);
James Morris20510f22007-10-16 23:31:32 -0700229}
230
231int security_quota_on(struct dentry *dentry)
232{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700233 return call_int_hook(quota_on, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700234}
235
Eric Paris12b30522010-11-15 18:36:29 -0500236int security_syslog(int type)
James Morris20510f22007-10-16 23:31:32 -0700237{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700238 return call_int_hook(syslog, 0, type);
James Morris20510f22007-10-16 23:31:32 -0700239}
240
Richard Cochran1e6d7672011-02-01 13:50:58 +0000241int security_settime(const struct timespec *ts, const struct timezone *tz)
James Morris20510f22007-10-16 23:31:32 -0700242{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700243 return call_int_hook(settime, 0, ts, tz);
James Morris20510f22007-10-16 23:31:32 -0700244}
245
James Morris20510f22007-10-16 23:31:32 -0700246int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
247{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700248 return call_int_hook(vm_enough_memory, 0, mm, pages);
James Morris20510f22007-10-16 23:31:32 -0700249}
250
David Howellsa6f76f22008-11-14 10:39:24 +1100251int security_bprm_set_creds(struct linux_binprm *bprm)
James Morris20510f22007-10-16 23:31:32 -0700252{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700253 return call_int_hook(bprm_set_creds, 0, bprm);
James Morris20510f22007-10-16 23:31:32 -0700254}
255
256int security_bprm_check(struct linux_binprm *bprm)
257{
Mimi Zohar6c21a7f2009-10-22 17:30:13 -0400258 int ret;
259
Casey Schauflerf25fce32015-05-02 15:11:29 -0700260 ret = call_int_hook(bprm_check_security, 0, bprm);
Mimi Zohar6c21a7f2009-10-22 17:30:13 -0400261 if (ret)
262 return ret;
263 return ima_bprm_check(bprm);
James Morris20510f22007-10-16 23:31:32 -0700264}
265
David Howellsa6f76f22008-11-14 10:39:24 +1100266void security_bprm_committing_creds(struct linux_binprm *bprm)
267{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700268 call_void_hook(bprm_committing_creds, bprm);
David Howellsa6f76f22008-11-14 10:39:24 +1100269}
270
271void security_bprm_committed_creds(struct linux_binprm *bprm)
272{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700273 call_void_hook(bprm_committed_creds, bprm);
David Howellsa6f76f22008-11-14 10:39:24 +1100274}
275
James Morris20510f22007-10-16 23:31:32 -0700276int security_bprm_secureexec(struct linux_binprm *bprm)
277{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700278 return call_int_hook(bprm_secureexec, 0, bprm);
James Morris20510f22007-10-16 23:31:32 -0700279}
280
281int security_sb_alloc(struct super_block *sb)
282{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700283 return call_int_hook(sb_alloc_security, 0, sb);
James Morris20510f22007-10-16 23:31:32 -0700284}
285
286void security_sb_free(struct super_block *sb)
287{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700288 call_void_hook(sb_free_security, sb);
James Morris20510f22007-10-16 23:31:32 -0700289}
290
Eric Parise0007522008-03-05 10:31:54 -0500291int security_sb_copy_data(char *orig, char *copy)
James Morris20510f22007-10-16 23:31:32 -0700292{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700293 return call_int_hook(sb_copy_data, 0, orig, copy);
James Morris20510f22007-10-16 23:31:32 -0700294}
Eric Parise0007522008-03-05 10:31:54 -0500295EXPORT_SYMBOL(security_sb_copy_data);
James Morris20510f22007-10-16 23:31:32 -0700296
Eric Parisff36fe22011-03-03 16:09:14 -0500297int security_sb_remount(struct super_block *sb, void *data)
298{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700299 return call_int_hook(sb_remount, 0, sb, data);
Eric Parisff36fe22011-03-03 16:09:14 -0500300}
301
James Morris12204e22008-12-19 10:44:42 +1100302int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
James Morris20510f22007-10-16 23:31:32 -0700303{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700304 return call_int_hook(sb_kern_mount, 0, sb, flags, data);
James Morris20510f22007-10-16 23:31:32 -0700305}
306
Eric Paris2069f452008-07-04 09:47:13 +1000307int security_sb_show_options(struct seq_file *m, struct super_block *sb)
308{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700309 return call_int_hook(sb_show_options, 0, m, sb);
Eric Paris2069f452008-07-04 09:47:13 +1000310}
311
James Morris20510f22007-10-16 23:31:32 -0700312int security_sb_statfs(struct dentry *dentry)
313{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700314 return call_int_hook(sb_statfs, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700315}
316
Al Viro808d4e32012-10-11 11:42:01 -0400317int security_sb_mount(const char *dev_name, struct path *path,
318 const char *type, unsigned long flags, void *data)
James Morris20510f22007-10-16 23:31:32 -0700319{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700320 return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
James Morris20510f22007-10-16 23:31:32 -0700321}
322
James Morris20510f22007-10-16 23:31:32 -0700323int security_sb_umount(struct vfsmount *mnt, int flags)
324{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700325 return call_int_hook(sb_umount, 0, mnt, flags);
James Morris20510f22007-10-16 23:31:32 -0700326}
327
Al Virob5266eb2008-03-22 17:48:24 -0400328int security_sb_pivotroot(struct path *old_path, struct path *new_path)
James Morris20510f22007-10-16 23:31:32 -0700329{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700330 return call_int_hook(sb_pivotroot, 0, old_path, new_path);
James Morris20510f22007-10-16 23:31:32 -0700331}
332
Eric Parisc9180a52007-11-30 13:00:35 -0500333int security_sb_set_mnt_opts(struct super_block *sb,
David Quigley649f6e72013-05-22 12:50:36 -0400334 struct security_mnt_opts *opts,
335 unsigned long kern_flags,
336 unsigned long *set_kern_flags)
Eric Parisc9180a52007-11-30 13:00:35 -0500337{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700338 return call_int_hook(sb_set_mnt_opts, 0, sb, opts, kern_flags,
David Quigley649f6e72013-05-22 12:50:36 -0400339 set_kern_flags);
Eric Parisc9180a52007-11-30 13:00:35 -0500340}
Eric Parise0007522008-03-05 10:31:54 -0500341EXPORT_SYMBOL(security_sb_set_mnt_opts);
Eric Parisc9180a52007-11-30 13:00:35 -0500342
Jeff Layton094f7b62013-04-01 08:14:24 -0400343int security_sb_clone_mnt_opts(const struct super_block *oldsb,
Eric Parisc9180a52007-11-30 13:00:35 -0500344 struct super_block *newsb)
345{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700346 return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb);
Eric Parisc9180a52007-11-30 13:00:35 -0500347}
Eric Parise0007522008-03-05 10:31:54 -0500348EXPORT_SYMBOL(security_sb_clone_mnt_opts);
349
350int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
351{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700352 return call_int_hook(sb_parse_opts_str, 0, options, opts);
Eric Parise0007522008-03-05 10:31:54 -0500353}
354EXPORT_SYMBOL(security_sb_parse_opts_str);
Eric Parisc9180a52007-11-30 13:00:35 -0500355
James Morris20510f22007-10-16 23:31:32 -0700356int security_inode_alloc(struct inode *inode)
357{
358 inode->i_security = NULL;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700359 return call_int_hook(inode_alloc_security, 0, inode);
James Morris20510f22007-10-16 23:31:32 -0700360}
361
362void security_inode_free(struct inode *inode)
363{
Mimi Zoharf381c272011-03-09 14:13:22 -0500364 integrity_inode_free(inode);
Casey Schauflerf25fce32015-05-02 15:11:29 -0700365 call_void_hook(inode_free_security, inode);
James Morris20510f22007-10-16 23:31:32 -0700366}
367
David Quigleyd47be3d2013-05-22 12:50:34 -0400368int security_dentry_init_security(struct dentry *dentry, int mode,
369 struct qstr *name, void **ctx,
370 u32 *ctxlen)
371{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700372 return call_int_hook(dentry_init_security, 0, dentry, mode, name,
David Quigleyd47be3d2013-05-22 12:50:34 -0400373 ctx, ctxlen);
374}
375EXPORT_SYMBOL(security_dentry_init_security);
376
James Morris20510f22007-10-16 23:31:32 -0700377int security_inode_init_security(struct inode *inode, struct inode *dir,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400378 const struct qstr *qstr,
379 const initxattrs initxattrs, void *fs_data)
380{
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400381 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
382 struct xattr *lsm_xattr, *evm_xattr, *xattr;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400383 int ret;
384
385 if (unlikely(IS_PRIVATE(inode)))
Mimi Zoharfb88c2b2011-08-15 10:13:18 -0400386 return 0;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400387
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400388 if (!initxattrs)
Casey Schauflerf25fce32015-05-02 15:11:29 -0700389 return call_int_hook(inode_init_security, 0, inode, dir, qstr,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400390 NULL, NULL, NULL);
Tetsuo Handa95489062013-07-25 05:44:02 +0900391 memset(new_xattrs, 0, sizeof(new_xattrs));
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400392 lsm_xattr = new_xattrs;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700393 ret = call_int_hook(inode_init_security, 0, inode, dir, qstr,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400394 &lsm_xattr->name,
395 &lsm_xattr->value,
396 &lsm_xattr->value_len);
397 if (ret)
398 goto out;
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400399
400 evm_xattr = lsm_xattr + 1;
401 ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
402 if (ret)
403 goto out;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400404 ret = initxattrs(inode, new_xattrs, fs_data);
405out:
Tetsuo Handa95489062013-07-25 05:44:02 +0900406 for (xattr = new_xattrs; xattr->value != NULL; xattr++)
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400407 kfree(xattr->value);
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400408 return (ret == -EOPNOTSUPP) ? 0 : ret;
409}
410EXPORT_SYMBOL(security_inode_init_security);
411
412int security_old_inode_init_security(struct inode *inode, struct inode *dir,
Tetsuo Handa95489062013-07-25 05:44:02 +0900413 const struct qstr *qstr, const char **name,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400414 void **value, size_t *len)
James Morris20510f22007-10-16 23:31:32 -0700415{
416 if (unlikely(IS_PRIVATE(inode)))
Jan Kara30e05322012-01-03 13:14:29 +0100417 return -EOPNOTSUPP;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700418 return call_int_hook(inode_init_security, 0, inode, dir, qstr,
419 name, value, len);
James Morris20510f22007-10-16 23:31:32 -0700420}
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400421EXPORT_SYMBOL(security_old_inode_init_security);
James Morris20510f22007-10-16 23:31:32 -0700422
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900423#ifdef CONFIG_SECURITY_PATH
Al Viro04fc66e2011-11-21 14:58:38 -0500424int security_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900425 unsigned int dev)
426{
David Howellsc6f493d2015-03-17 22:26:22 +0000427 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900428 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700429 return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900430}
431EXPORT_SYMBOL(security_path_mknod);
432
Al Viro4572bef2011-11-21 14:56:21 -0500433int security_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900434{
David Howellsc6f493d2015-03-17 22:26:22 +0000435 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900436 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700437 return call_int_hook(path_mkdir, 0, dir, dentry, mode);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900438}
David Howells82140442010-12-24 14:48:35 +0000439EXPORT_SYMBOL(security_path_mkdir);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900440
Tetsuo Handa5d0901a2009-11-26 15:24:49 +0900441int security_path_rmdir(struct path *dir, struct dentry *dentry)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900442{
David Howellsc6f493d2015-03-17 22:26:22 +0000443 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900444 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700445 return call_int_hook(path_rmdir, 0, dir, dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900446}
447
Tetsuo Handa5d0901a2009-11-26 15:24:49 +0900448int security_path_unlink(struct path *dir, struct dentry *dentry)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900449{
David Howellsc6f493d2015-03-17 22:26:22 +0000450 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900451 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700452 return call_int_hook(path_unlink, 0, dir, dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900453}
David Howells82140442010-12-24 14:48:35 +0000454EXPORT_SYMBOL(security_path_unlink);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900455
Tetsuo Handa5d0901a2009-11-26 15:24:49 +0900456int security_path_symlink(struct path *dir, struct dentry *dentry,
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900457 const char *old_name)
458{
David Howellsc6f493d2015-03-17 22:26:22 +0000459 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900460 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700461 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900462}
463
464int security_path_link(struct dentry *old_dentry, struct path *new_dir,
465 struct dentry *new_dentry)
466{
David Howellsc6f493d2015-03-17 22:26:22 +0000467 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900468 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700469 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900470}
471
472int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
Miklos Szeredi0b3974e2014-04-01 17:08:43 +0200473 struct path *new_dir, struct dentry *new_dentry,
474 unsigned int flags)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900475{
David Howellsc6f493d2015-03-17 22:26:22 +0000476 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
477 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900478 return 0;
Miklos Szeredida1ce062014-04-01 17:08:43 +0200479
480 if (flags & RENAME_EXCHANGE) {
Casey Schauflerf25fce32015-05-02 15:11:29 -0700481 int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
482 old_dir, old_dentry);
Miklos Szeredida1ce062014-04-01 17:08:43 +0200483 if (err)
484 return err;
485 }
486
Casey Schauflerf25fce32015-05-02 15:11:29 -0700487 return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
488 new_dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900489}
David Howells82140442010-12-24 14:48:35 +0000490EXPORT_SYMBOL(security_path_rename);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900491
Tetsuo Handaea0d3ab2010-06-02 13:24:43 +0900492int security_path_truncate(struct path *path)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900493{
David Howellsc6f493d2015-03-17 22:26:22 +0000494 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900495 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700496 return call_int_hook(path_truncate, 0, path);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900497}
Tetsuo Handa89eda062009-10-04 21:49:47 +0900498
Al Virocdcf1162011-12-08 10:51:53 -0500499int security_path_chmod(struct path *path, umode_t mode)
Tetsuo Handa89eda062009-10-04 21:49:47 +0900500{
David Howellsc6f493d2015-03-17 22:26:22 +0000501 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Tetsuo Handa89eda062009-10-04 21:49:47 +0900502 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700503 return call_int_hook(path_chmod, 0, path, mode);
Tetsuo Handa89eda062009-10-04 21:49:47 +0900504}
505
Eric W. Biedermand2b31ca2012-06-01 16:14:19 -0600506int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
Tetsuo Handa89eda062009-10-04 21:49:47 +0900507{
David Howellsc6f493d2015-03-17 22:26:22 +0000508 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Tetsuo Handa89eda062009-10-04 21:49:47 +0900509 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700510 return call_int_hook(path_chown, 0, path, uid, gid);
Tetsuo Handa89eda062009-10-04 21:49:47 +0900511}
Tetsuo Handa8b8efb42009-10-04 21:49:48 +0900512
513int security_path_chroot(struct path *path)
514{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700515 return call_int_hook(path_chroot, 0, path);
Tetsuo Handa8b8efb42009-10-04 21:49:48 +0900516}
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900517#endif
518
Al Viro4acdaf22011-07-26 01:42:34 -0400519int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
James Morris20510f22007-10-16 23:31:32 -0700520{
521 if (unlikely(IS_PRIVATE(dir)))
522 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700523 return call_int_hook(inode_create, 0, dir, dentry, mode);
James Morris20510f22007-10-16 23:31:32 -0700524}
David Howells800a9642009-04-03 16:42:40 +0100525EXPORT_SYMBOL_GPL(security_inode_create);
James Morris20510f22007-10-16 23:31:32 -0700526
527int security_inode_link(struct dentry *old_dentry, struct inode *dir,
528 struct dentry *new_dentry)
529{
David Howellsc6f493d2015-03-17 22:26:22 +0000530 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
James Morris20510f22007-10-16 23:31:32 -0700531 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700532 return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
James Morris20510f22007-10-16 23:31:32 -0700533}
534
535int security_inode_unlink(struct inode *dir, struct dentry *dentry)
536{
David Howellsc6f493d2015-03-17 22:26:22 +0000537 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700538 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700539 return call_int_hook(inode_unlink, 0, dir, dentry);
James Morris20510f22007-10-16 23:31:32 -0700540}
541
542int security_inode_symlink(struct inode *dir, struct dentry *dentry,
543 const char *old_name)
544{
545 if (unlikely(IS_PRIVATE(dir)))
546 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700547 return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
James Morris20510f22007-10-16 23:31:32 -0700548}
549
Al Viro18bb1db2011-07-26 01:41:39 -0400550int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
James Morris20510f22007-10-16 23:31:32 -0700551{
552 if (unlikely(IS_PRIVATE(dir)))
553 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700554 return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
James Morris20510f22007-10-16 23:31:32 -0700555}
David Howells800a9642009-04-03 16:42:40 +0100556EXPORT_SYMBOL_GPL(security_inode_mkdir);
James Morris20510f22007-10-16 23:31:32 -0700557
558int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
559{
David Howellsc6f493d2015-03-17 22:26:22 +0000560 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700561 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700562 return call_int_hook(inode_rmdir, 0, dir, dentry);
James Morris20510f22007-10-16 23:31:32 -0700563}
564
Al Viro1a67aaf2011-07-26 01:52:52 -0400565int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
James Morris20510f22007-10-16 23:31:32 -0700566{
567 if (unlikely(IS_PRIVATE(dir)))
568 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700569 return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
James Morris20510f22007-10-16 23:31:32 -0700570}
571
572int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredi0b3974e2014-04-01 17:08:43 +0200573 struct inode *new_dir, struct dentry *new_dentry,
574 unsigned int flags)
James Morris20510f22007-10-16 23:31:32 -0700575{
David Howellsc6f493d2015-03-17 22:26:22 +0000576 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
577 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
James Morris20510f22007-10-16 23:31:32 -0700578 return 0;
Miklos Szeredida1ce062014-04-01 17:08:43 +0200579
580 if (flags & RENAME_EXCHANGE) {
Casey Schauflerf25fce32015-05-02 15:11:29 -0700581 int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
Miklos Szeredida1ce062014-04-01 17:08:43 +0200582 old_dir, old_dentry);
583 if (err)
584 return err;
585 }
586
Casey Schauflerf25fce32015-05-02 15:11:29 -0700587 return call_int_hook(inode_rename, 0, old_dir, old_dentry,
James Morris20510f22007-10-16 23:31:32 -0700588 new_dir, new_dentry);
589}
590
591int security_inode_readlink(struct dentry *dentry)
592{
David Howellsc6f493d2015-03-17 22:26:22 +0000593 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700594 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700595 return call_int_hook(inode_readlink, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700596}
597
598int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
599{
David Howellsc6f493d2015-03-17 22:26:22 +0000600 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700601 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700602 return call_int_hook(inode_follow_link, 0, dentry, nd);
James Morris20510f22007-10-16 23:31:32 -0700603}
604
Al Virob77b0642008-07-17 09:37:02 -0400605int security_inode_permission(struct inode *inode, int mask)
James Morris20510f22007-10-16 23:31:32 -0700606{
607 if (unlikely(IS_PRIVATE(inode)))
608 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700609 return call_int_hook(inode_permission, 0, inode, mask);
James Morris20510f22007-10-16 23:31:32 -0700610}
611
612int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
613{
Mimi Zohar817b54a2011-05-13 12:53:38 -0400614 int ret;
615
David Howellsc6f493d2015-03-17 22:26:22 +0000616 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700617 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700618 ret = call_int_hook(inode_setattr, 0, dentry, attr);
Mimi Zohar817b54a2011-05-13 12:53:38 -0400619 if (ret)
620 return ret;
621 return evm_inode_setattr(dentry, attr);
James Morris20510f22007-10-16 23:31:32 -0700622}
Miklos Szeredib1da47e2008-07-01 15:01:28 +0200623EXPORT_SYMBOL_GPL(security_inode_setattr);
James Morris20510f22007-10-16 23:31:32 -0700624
Al Viro3f7036a2015-03-08 19:28:30 -0400625int security_inode_getattr(const struct path *path)
James Morris20510f22007-10-16 23:31:32 -0700626{
David Howellsc6f493d2015-03-17 22:26:22 +0000627 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
James Morris20510f22007-10-16 23:31:32 -0700628 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700629 return call_int_hook(inode_getattr, 0, path);
James Morris20510f22007-10-16 23:31:32 -0700630}
631
David Howells8f0cfa52008-04-29 00:59:41 -0700632int security_inode_setxattr(struct dentry *dentry, const char *name,
633 const void *value, size_t size, int flags)
James Morris20510f22007-10-16 23:31:32 -0700634{
Mimi Zohar3e1be522011-03-09 14:38:26 -0500635 int ret;
636
David Howellsc6f493d2015-03-17 22:26:22 +0000637 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700638 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700639 ret = call_int_hook(inode_setxattr, 0, dentry, name, value, size,
640 flags);
Mimi Zohar3e1be522011-03-09 14:38:26 -0500641 if (ret)
642 return ret;
Mimi Zohar42c63332011-03-10 18:54:15 -0500643 ret = ima_inode_setxattr(dentry, name, value, size);
644 if (ret)
645 return ret;
Mimi Zohar3e1be522011-03-09 14:38:26 -0500646 return evm_inode_setxattr(dentry, name, value, size);
James Morris20510f22007-10-16 23:31:32 -0700647}
648
David Howells8f0cfa52008-04-29 00:59:41 -0700649void security_inode_post_setxattr(struct dentry *dentry, const char *name,
650 const void *value, size_t size, int flags)
James Morris20510f22007-10-16 23:31:32 -0700651{
David Howellsc6f493d2015-03-17 22:26:22 +0000652 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700653 return;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700654 call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
Mimi Zohar3e1be522011-03-09 14:38:26 -0500655 evm_inode_post_setxattr(dentry, name, value, size);
James Morris20510f22007-10-16 23:31:32 -0700656}
657
David Howells8f0cfa52008-04-29 00:59:41 -0700658int security_inode_getxattr(struct dentry *dentry, const char *name)
James Morris20510f22007-10-16 23:31:32 -0700659{
David Howellsc6f493d2015-03-17 22:26:22 +0000660 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700661 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700662 return call_int_hook(inode_getxattr, 0, dentry, name);
James Morris20510f22007-10-16 23:31:32 -0700663}
664
665int security_inode_listxattr(struct dentry *dentry)
666{
David Howellsc6f493d2015-03-17 22:26:22 +0000667 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700668 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700669 return call_int_hook(inode_listxattr, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700670}
671
David Howells8f0cfa52008-04-29 00:59:41 -0700672int security_inode_removexattr(struct dentry *dentry, const char *name)
James Morris20510f22007-10-16 23:31:32 -0700673{
Mimi Zohar3e1be522011-03-09 14:38:26 -0500674 int ret;
675
David Howellsc6f493d2015-03-17 22:26:22 +0000676 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700677 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700678 ret = call_int_hook(inode_removexattr, 0, dentry, name);
Mimi Zohar3e1be522011-03-09 14:38:26 -0500679 if (ret)
680 return ret;
Mimi Zohar42c63332011-03-10 18:54:15 -0500681 ret = ima_inode_removexattr(dentry, name);
682 if (ret)
683 return ret;
Mimi Zohar3e1be522011-03-09 14:38:26 -0500684 return evm_inode_removexattr(dentry, name);
James Morris20510f22007-10-16 23:31:32 -0700685}
686
Serge E. Hallynb5376772007-10-16 23:31:36 -0700687int security_inode_need_killpriv(struct dentry *dentry)
688{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700689 return call_int_hook(inode_need_killpriv, 0, dentry);
Serge E. Hallynb5376772007-10-16 23:31:36 -0700690}
691
692int security_inode_killpriv(struct dentry *dentry)
693{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700694 return call_int_hook(inode_killpriv, 0, dentry);
Serge E. Hallynb5376772007-10-16 23:31:36 -0700695}
696
David P. Quigley42492592008-02-04 22:29:39 -0800697int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
James Morris20510f22007-10-16 23:31:32 -0700698{
699 if (unlikely(IS_PRIVATE(inode)))
James Morris8d952502010-01-14 09:33:28 +1100700 return -EOPNOTSUPP;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700701 return call_int_hook(inode_getsecurity, 0, inode, name, buffer, alloc);
James Morris20510f22007-10-16 23:31:32 -0700702}
703
704int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
705{
706 if (unlikely(IS_PRIVATE(inode)))
James Morris8d952502010-01-14 09:33:28 +1100707 return -EOPNOTSUPP;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700708 return call_int_hook(inode_setsecurity, 0, inode, name, value, size,
709 flags);
James Morris20510f22007-10-16 23:31:32 -0700710}
711
712int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
713{
714 if (unlikely(IS_PRIVATE(inode)))
715 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700716 return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
James Morris20510f22007-10-16 23:31:32 -0700717}
David Quigleyc9bccef2013-05-22 12:50:45 -0400718EXPORT_SYMBOL(security_inode_listsecurity);
James Morris20510f22007-10-16 23:31:32 -0700719
Ahmed S. Darwish8a076192008-03-01 21:51:09 +0200720void security_inode_getsecid(const struct inode *inode, u32 *secid)
721{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700722 call_void_hook(inode_getsecid, inode, secid);
Ahmed S. Darwish8a076192008-03-01 21:51:09 +0200723}
724
James Morris20510f22007-10-16 23:31:32 -0700725int security_file_permission(struct file *file, int mask)
726{
Eric Parisc4ec54b2009-12-17 21:24:34 -0500727 int ret;
728
Casey Schauflerf25fce32015-05-02 15:11:29 -0700729 ret = call_int_hook(file_permission, 0, file, mask);
Eric Parisc4ec54b2009-12-17 21:24:34 -0500730 if (ret)
731 return ret;
732
733 return fsnotify_perm(file, mask);
James Morris20510f22007-10-16 23:31:32 -0700734}
735
736int security_file_alloc(struct file *file)
737{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700738 return call_int_hook(file_alloc_security, 0, file);
James Morris20510f22007-10-16 23:31:32 -0700739}
740
741void security_file_free(struct file *file)
742{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700743 call_void_hook(file_free_security, file);
James Morris20510f22007-10-16 23:31:32 -0700744}
745
746int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
747{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700748 return call_int_hook(file_ioctl, 0, file, cmd, arg);
James Morris20510f22007-10-16 23:31:32 -0700749}
750
Al Viro98de59b2012-05-30 19:58:30 -0400751static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
James Morris20510f22007-10-16 23:31:32 -0700752{
Al Viro8b3ec682012-05-30 17:11:23 -0400753 /*
Al Viro98de59b2012-05-30 19:58:30 -0400754 * Does we have PROT_READ and does the application expect
755 * it to imply PROT_EXEC? If not, nothing to talk about...
Al Viro8b3ec682012-05-30 17:11:23 -0400756 */
Al Viro98de59b2012-05-30 19:58:30 -0400757 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
758 return prot;
Al Viro8b3ec682012-05-30 17:11:23 -0400759 if (!(current->personality & READ_IMPLIES_EXEC))
Al Viro98de59b2012-05-30 19:58:30 -0400760 return prot;
761 /*
762 * if that's an anonymous mapping, let it.
763 */
764 if (!file)
765 return prot | PROT_EXEC;
766 /*
767 * ditto if it's not on noexec mount, except that on !MMU we need
Christoph Hellwigb4caecd2015-01-14 10:42:32 +0100768 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
Al Viro98de59b2012-05-30 19:58:30 -0400769 */
770 if (!(file->f_path.mnt->mnt_flags & MNT_NOEXEC)) {
Al Viro8b3ec682012-05-30 17:11:23 -0400771#ifndef CONFIG_MMU
Christoph Hellwigb4caecd2015-01-14 10:42:32 +0100772 if (file->f_op->mmap_capabilities) {
773 unsigned caps = file->f_op->mmap_capabilities(file);
774 if (!(caps & NOMMU_MAP_EXEC))
775 return prot;
776 }
Al Viro8b3ec682012-05-30 17:11:23 -0400777#endif
Al Viro98de59b2012-05-30 19:58:30 -0400778 return prot | PROT_EXEC;
Al Viro8b3ec682012-05-30 17:11:23 -0400779 }
Al Viro98de59b2012-05-30 19:58:30 -0400780 /* anything on noexec mount won't get PROT_EXEC */
781 return prot;
782}
783
784int security_mmap_file(struct file *file, unsigned long prot,
785 unsigned long flags)
786{
787 int ret;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700788 ret = call_int_hook(mmap_file, 0, file, prot,
Al Viro98de59b2012-05-30 19:58:30 -0400789 mmap_prot(file, prot), flags);
Mimi Zohar6c21a7f2009-10-22 17:30:13 -0400790 if (ret)
791 return ret;
792 return ima_file_mmap(file, prot);
James Morris20510f22007-10-16 23:31:32 -0700793}
794
Al Viroe5467852012-05-30 13:30:51 -0400795int security_mmap_addr(unsigned long addr)
796{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700797 return call_int_hook(mmap_addr, 0, addr);
Al Viroe5467852012-05-30 13:30:51 -0400798}
799
James Morris20510f22007-10-16 23:31:32 -0700800int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
801 unsigned long prot)
802{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700803 return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
James Morris20510f22007-10-16 23:31:32 -0700804}
805
806int security_file_lock(struct file *file, unsigned int cmd)
807{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700808 return call_int_hook(file_lock, 0, file, cmd);
James Morris20510f22007-10-16 23:31:32 -0700809}
810
811int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
812{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700813 return call_int_hook(file_fcntl, 0, file, cmd, arg);
James Morris20510f22007-10-16 23:31:32 -0700814}
815
Jeff Laytone0b93ed2014-08-22 11:27:32 -0400816void security_file_set_fowner(struct file *file)
James Morris20510f22007-10-16 23:31:32 -0700817{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700818 call_void_hook(file_set_fowner, file);
James Morris20510f22007-10-16 23:31:32 -0700819}
820
821int security_file_send_sigiotask(struct task_struct *tsk,
822 struct fown_struct *fown, int sig)
823{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700824 return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
James Morris20510f22007-10-16 23:31:32 -0700825}
826
827int security_file_receive(struct file *file)
828{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700829 return call_int_hook(file_receive, 0, file);
James Morris20510f22007-10-16 23:31:32 -0700830}
831
Eric Paris83d49852012-04-04 13:45:40 -0400832int security_file_open(struct file *file, const struct cred *cred)
James Morris20510f22007-10-16 23:31:32 -0700833{
Eric Parisc4ec54b2009-12-17 21:24:34 -0500834 int ret;
835
Casey Schauflerf25fce32015-05-02 15:11:29 -0700836 ret = call_int_hook(file_open, 0, file, cred);
Eric Parisc4ec54b2009-12-17 21:24:34 -0500837 if (ret)
838 return ret;
839
840 return fsnotify_perm(file, MAY_OPEN);
James Morris20510f22007-10-16 23:31:32 -0700841}
842
843int security_task_create(unsigned long clone_flags)
844{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700845 return call_int_hook(task_create, 0, clone_flags);
James Morris20510f22007-10-16 23:31:32 -0700846}
847
Kees Cook1a2a4d02011-12-21 12:17:03 -0800848void security_task_free(struct task_struct *task)
849{
Kees Cookc6993e42012-09-04 13:32:13 -0700850#ifdef CONFIG_SECURITY_YAMA_STACKED
851 yama_task_free(task);
852#endif
Casey Schauflerf25fce32015-05-02 15:11:29 -0700853 call_void_hook(task_free, task);
Kees Cook1a2a4d02011-12-21 12:17:03 -0800854}
855
David Howellsee18d642009-09-02 09:14:21 +0100856int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
857{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700858 return call_int_hook(cred_alloc_blank, 0, cred, gfp);
David Howellsee18d642009-09-02 09:14:21 +0100859}
860
David Howellsf1752ee2008-11-14 10:39:17 +1100861void security_cred_free(struct cred *cred)
James Morris20510f22007-10-16 23:31:32 -0700862{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700863 call_void_hook(cred_free, cred);
James Morris20510f22007-10-16 23:31:32 -0700864}
865
David Howellsd84f4f92008-11-14 10:39:23 +1100866int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
867{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700868 return call_int_hook(cred_prepare, 0, new, old, gfp);
David Howellsd84f4f92008-11-14 10:39:23 +1100869}
870
David Howellsee18d642009-09-02 09:14:21 +0100871void security_transfer_creds(struct cred *new, const struct cred *old)
872{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700873 call_void_hook(cred_transfer, new, old);
David Howellsee18d642009-09-02 09:14:21 +0100874}
875
David Howells3a3b7ce2008-11-14 10:39:28 +1100876int security_kernel_act_as(struct cred *new, u32 secid)
877{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700878 return call_int_hook(kernel_act_as, 0, new, secid);
David Howells3a3b7ce2008-11-14 10:39:28 +1100879}
880
881int security_kernel_create_files_as(struct cred *new, struct inode *inode)
882{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700883 return call_int_hook(kernel_create_files_as, 0, new, inode);
David Howells3a3b7ce2008-11-14 10:39:28 +1100884}
885
Kees Cook13752fe2014-02-25 10:28:04 -0800886int security_kernel_fw_from_file(struct file *file, char *buf, size_t size)
887{
Mimi Zohar5a9196d2014-07-22 10:39:48 -0400888 int ret;
889
Casey Schauflerf25fce32015-05-02 15:11:29 -0700890 ret = call_int_hook(kernel_fw_from_file, 0, file, buf, size);
Mimi Zohar5a9196d2014-07-22 10:39:48 -0400891 if (ret)
892 return ret;
893 return ima_fw_from_file(file, buf, size);
Kees Cook13752fe2014-02-25 10:28:04 -0800894}
895EXPORT_SYMBOL_GPL(security_kernel_fw_from_file);
896
Eric Parisdd8dbf22009-11-03 16:35:32 +1100897int security_kernel_module_request(char *kmod_name)
Eric Paris91884992009-08-13 09:44:57 -0400898{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700899 return call_int_hook(kernel_module_request, 0, kmod_name);
Eric Paris91884992009-08-13 09:44:57 -0400900}
901
Kees Cook2e72d512012-10-16 07:32:07 +1030902int security_kernel_module_from_file(struct file *file)
903{
Mimi Zoharfdf90722012-10-16 12:40:08 +1030904 int ret;
905
Casey Schauflerf25fce32015-05-02 15:11:29 -0700906 ret = call_int_hook(kernel_module_from_file, 0, file);
Mimi Zoharfdf90722012-10-16 12:40:08 +1030907 if (ret)
908 return ret;
909 return ima_module_check(file);
Kees Cook2e72d512012-10-16 07:32:07 +1030910}
911
David Howellsd84f4f92008-11-14 10:39:23 +1100912int security_task_fix_setuid(struct cred *new, const struct cred *old,
913 int flags)
James Morris20510f22007-10-16 23:31:32 -0700914{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700915 return call_int_hook(task_fix_setuid, 0, new, old, flags);
James Morris20510f22007-10-16 23:31:32 -0700916}
917
James Morris20510f22007-10-16 23:31:32 -0700918int security_task_setpgid(struct task_struct *p, pid_t pgid)
919{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700920 return call_int_hook(task_setpgid, 0, p, pgid);
James Morris20510f22007-10-16 23:31:32 -0700921}
922
923int security_task_getpgid(struct task_struct *p)
924{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700925 return call_int_hook(task_getpgid, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700926}
927
928int security_task_getsid(struct task_struct *p)
929{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700930 return call_int_hook(task_getsid, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700931}
932
933void security_task_getsecid(struct task_struct *p, u32 *secid)
934{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700935 call_void_hook(task_getsecid, p, secid);
James Morris20510f22007-10-16 23:31:32 -0700936}
937EXPORT_SYMBOL(security_task_getsecid);
938
James Morris20510f22007-10-16 23:31:32 -0700939int security_task_setnice(struct task_struct *p, int nice)
940{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700941 return call_int_hook(task_setnice, 0, p, nice);
James Morris20510f22007-10-16 23:31:32 -0700942}
943
944int security_task_setioprio(struct task_struct *p, int ioprio)
945{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700946 return call_int_hook(task_setioprio, 0, p, ioprio);
James Morris20510f22007-10-16 23:31:32 -0700947}
948
949int security_task_getioprio(struct task_struct *p)
950{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700951 return call_int_hook(task_getioprio, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700952}
953
Jiri Slaby8fd00b42009-08-26 18:41:16 +0200954int security_task_setrlimit(struct task_struct *p, unsigned int resource,
955 struct rlimit *new_rlim)
James Morris20510f22007-10-16 23:31:32 -0700956{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700957 return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
James Morris20510f22007-10-16 23:31:32 -0700958}
959
KOSAKI Motohirob0ae1982010-10-15 04:21:18 +0900960int security_task_setscheduler(struct task_struct *p)
James Morris20510f22007-10-16 23:31:32 -0700961{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700962 return call_int_hook(task_setscheduler, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700963}
964
965int security_task_getscheduler(struct task_struct *p)
966{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700967 return call_int_hook(task_getscheduler, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700968}
969
970int security_task_movememory(struct task_struct *p)
971{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700972 return call_int_hook(task_movememory, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700973}
974
975int security_task_kill(struct task_struct *p, struct siginfo *info,
976 int sig, u32 secid)
977{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700978 return call_int_hook(task_kill, 0, p, info, sig, secid);
James Morris20510f22007-10-16 23:31:32 -0700979}
980
981int security_task_wait(struct task_struct *p)
982{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700983 return call_int_hook(task_wait, 0, p);
James Morris20510f22007-10-16 23:31:32 -0700984}
985
986int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
David Howellsd84f4f92008-11-14 10:39:23 +1100987 unsigned long arg4, unsigned long arg5)
James Morris20510f22007-10-16 23:31:32 -0700988{
Kees Cookc6993e42012-09-04 13:32:13 -0700989#ifdef CONFIG_SECURITY_YAMA_STACKED
990 int rc;
991 rc = yama_task_prctl(option, arg2, arg3, arg4, arg5);
992 if (rc != -ENOSYS)
993 return rc;
994#endif
Casey Schauflerf25fce32015-05-02 15:11:29 -0700995 return call_int_hook(task_prctl, 0, option, arg2, arg3, arg4, arg5);
James Morris20510f22007-10-16 23:31:32 -0700996}
997
998void security_task_to_inode(struct task_struct *p, struct inode *inode)
999{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001000 call_void_hook(task_to_inode, p, inode);
James Morris20510f22007-10-16 23:31:32 -07001001}
1002
1003int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
1004{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001005 return call_int_hook(ipc_permission, 0, ipcp, flag);
James Morris20510f22007-10-16 23:31:32 -07001006}
1007
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001008void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
1009{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001010 call_void_hook(ipc_getsecid, ipcp, secid);
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001011}
1012
James Morris20510f22007-10-16 23:31:32 -07001013int security_msg_msg_alloc(struct msg_msg *msg)
1014{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001015 return call_int_hook(msg_msg_alloc_security, 0, msg);
James Morris20510f22007-10-16 23:31:32 -07001016}
1017
1018void security_msg_msg_free(struct msg_msg *msg)
1019{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001020 call_void_hook(msg_msg_free_security, msg);
James Morris20510f22007-10-16 23:31:32 -07001021}
1022
1023int security_msg_queue_alloc(struct msg_queue *msq)
1024{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001025 return call_int_hook(msg_queue_alloc_security, 0, msq);
James Morris20510f22007-10-16 23:31:32 -07001026}
1027
1028void security_msg_queue_free(struct msg_queue *msq)
1029{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001030 call_void_hook(msg_queue_free_security, msq);
James Morris20510f22007-10-16 23:31:32 -07001031}
1032
1033int security_msg_queue_associate(struct msg_queue *msq, int msqflg)
1034{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001035 return call_int_hook(msg_queue_associate, 0, msq, msqflg);
James Morris20510f22007-10-16 23:31:32 -07001036}
1037
1038int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1039{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001040 return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
James Morris20510f22007-10-16 23:31:32 -07001041}
1042
1043int security_msg_queue_msgsnd(struct msg_queue *msq,
1044 struct msg_msg *msg, int msqflg)
1045{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001046 return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
James Morris20510f22007-10-16 23:31:32 -07001047}
1048
1049int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1050 struct task_struct *target, long type, int mode)
1051{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001052 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
James Morris20510f22007-10-16 23:31:32 -07001053}
1054
1055int security_shm_alloc(struct shmid_kernel *shp)
1056{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001057 return call_int_hook(shm_alloc_security, 0, shp);
James Morris20510f22007-10-16 23:31:32 -07001058}
1059
1060void security_shm_free(struct shmid_kernel *shp)
1061{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001062 call_void_hook(shm_free_security, shp);
James Morris20510f22007-10-16 23:31:32 -07001063}
1064
1065int security_shm_associate(struct shmid_kernel *shp, int shmflg)
1066{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001067 return call_int_hook(shm_associate, 0, shp, shmflg);
James Morris20510f22007-10-16 23:31:32 -07001068}
1069
1070int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
1071{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001072 return call_int_hook(shm_shmctl, 0, shp, cmd);
James Morris20510f22007-10-16 23:31:32 -07001073}
1074
1075int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg)
1076{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001077 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
James Morris20510f22007-10-16 23:31:32 -07001078}
1079
1080int security_sem_alloc(struct sem_array *sma)
1081{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001082 return call_int_hook(sem_alloc_security, 0, sma);
James Morris20510f22007-10-16 23:31:32 -07001083}
1084
1085void security_sem_free(struct sem_array *sma)
1086{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001087 call_void_hook(sem_free_security, sma);
James Morris20510f22007-10-16 23:31:32 -07001088}
1089
1090int security_sem_associate(struct sem_array *sma, int semflg)
1091{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001092 return call_int_hook(sem_associate, 0, sma, semflg);
James Morris20510f22007-10-16 23:31:32 -07001093}
1094
1095int security_sem_semctl(struct sem_array *sma, int cmd)
1096{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001097 return call_int_hook(sem_semctl, 0, sma, cmd);
James Morris20510f22007-10-16 23:31:32 -07001098}
1099
1100int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
1101 unsigned nsops, int alter)
1102{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001103 return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
James Morris20510f22007-10-16 23:31:32 -07001104}
1105
1106void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1107{
1108 if (unlikely(inode && IS_PRIVATE(inode)))
1109 return;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001110 call_void_hook(d_instantiate, dentry, inode);
James Morris20510f22007-10-16 23:31:32 -07001111}
1112EXPORT_SYMBOL(security_d_instantiate);
1113
1114int security_getprocattr(struct task_struct *p, char *name, char **value)
1115{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001116 return call_int_hook(getprocattr, 0, p, name, value);
James Morris20510f22007-10-16 23:31:32 -07001117}
1118
1119int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
1120{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001121 return call_int_hook(setprocattr, 0, p, name, value, size);
James Morris20510f22007-10-16 23:31:32 -07001122}
1123
1124int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1125{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001126 return call_int_hook(netlink_send, 0, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001127}
James Morris20510f22007-10-16 23:31:32 -07001128
David Quigley746df9b2013-05-22 12:50:35 -04001129int security_ismaclabel(const char *name)
1130{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001131 return call_int_hook(ismaclabel, 0, name);
David Quigley746df9b2013-05-22 12:50:35 -04001132}
1133EXPORT_SYMBOL(security_ismaclabel);
1134
James Morris20510f22007-10-16 23:31:32 -07001135int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1136{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001137 return call_int_hook(secid_to_secctx, 0, secid, secdata, seclen);
James Morris20510f22007-10-16 23:31:32 -07001138}
1139EXPORT_SYMBOL(security_secid_to_secctx);
1140
David Howells7bf570d2008-04-29 20:52:51 +01001141int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
David Howells63cb3442008-01-15 23:47:35 +00001142{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001143 return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
David Howells63cb3442008-01-15 23:47:35 +00001144}
1145EXPORT_SYMBOL(security_secctx_to_secid);
1146
James Morris20510f22007-10-16 23:31:32 -07001147void security_release_secctx(char *secdata, u32 seclen)
1148{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001149 call_void_hook(release_secctx, secdata, seclen);
James Morris20510f22007-10-16 23:31:32 -07001150}
1151EXPORT_SYMBOL(security_release_secctx);
1152
David P. Quigley1ee65e32009-09-03 14:25:57 -04001153int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
1154{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001155 return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001156}
1157EXPORT_SYMBOL(security_inode_notifysecctx);
1158
1159int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
1160{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001161 return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001162}
1163EXPORT_SYMBOL(security_inode_setsecctx);
1164
1165int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1166{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001167 return call_int_hook(inode_getsecctx, 0, inode, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001168}
1169EXPORT_SYMBOL(security_inode_getsecctx);
1170
James Morris20510f22007-10-16 23:31:32 -07001171#ifdef CONFIG_SECURITY_NETWORK
1172
David S. Miller3610cda2011-01-05 15:38:53 -08001173int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
James Morris20510f22007-10-16 23:31:32 -07001174{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001175 return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
James Morris20510f22007-10-16 23:31:32 -07001176}
1177EXPORT_SYMBOL(security_unix_stream_connect);
1178
1179int security_unix_may_send(struct socket *sock, struct socket *other)
1180{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001181 return call_int_hook(unix_may_send, 0, sock, other);
James Morris20510f22007-10-16 23:31:32 -07001182}
1183EXPORT_SYMBOL(security_unix_may_send);
1184
1185int security_socket_create(int family, int type, int protocol, int kern)
1186{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001187 return call_int_hook(socket_create, 0, family, type, protocol, kern);
James Morris20510f22007-10-16 23:31:32 -07001188}
1189
1190int security_socket_post_create(struct socket *sock, int family,
1191 int type, int protocol, int kern)
1192{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001193 return call_int_hook(socket_post_create, 0, sock, family, type,
James Morris20510f22007-10-16 23:31:32 -07001194 protocol, kern);
1195}
1196
1197int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
1198{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001199 return call_int_hook(socket_bind, 0, sock, address, addrlen);
James Morris20510f22007-10-16 23:31:32 -07001200}
1201
1202int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
1203{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001204 return call_int_hook(socket_connect, 0, sock, address, addrlen);
James Morris20510f22007-10-16 23:31:32 -07001205}
1206
1207int security_socket_listen(struct socket *sock, int backlog)
1208{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001209 return call_int_hook(socket_listen, 0, sock, backlog);
James Morris20510f22007-10-16 23:31:32 -07001210}
1211
1212int security_socket_accept(struct socket *sock, struct socket *newsock)
1213{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001214 return call_int_hook(socket_accept, 0, sock, newsock);
James Morris20510f22007-10-16 23:31:32 -07001215}
1216
James Morris20510f22007-10-16 23:31:32 -07001217int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
1218{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001219 return call_int_hook(socket_sendmsg, 0, sock, msg, size);
James Morris20510f22007-10-16 23:31:32 -07001220}
1221
1222int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
1223 int size, int flags)
1224{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001225 return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
James Morris20510f22007-10-16 23:31:32 -07001226}
1227
1228int security_socket_getsockname(struct socket *sock)
1229{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001230 return call_int_hook(socket_getsockname, 0, sock);
James Morris20510f22007-10-16 23:31:32 -07001231}
1232
1233int security_socket_getpeername(struct socket *sock)
1234{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001235 return call_int_hook(socket_getpeername, 0, sock);
James Morris20510f22007-10-16 23:31:32 -07001236}
1237
1238int security_socket_getsockopt(struct socket *sock, int level, int optname)
1239{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001240 return call_int_hook(socket_getsockopt, 0, sock, level, optname);
James Morris20510f22007-10-16 23:31:32 -07001241}
1242
1243int security_socket_setsockopt(struct socket *sock, int level, int optname)
1244{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001245 return call_int_hook(socket_setsockopt, 0, sock, level, optname);
James Morris20510f22007-10-16 23:31:32 -07001246}
1247
1248int security_socket_shutdown(struct socket *sock, int how)
1249{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001250 return call_int_hook(socket_shutdown, 0, sock, how);
James Morris20510f22007-10-16 23:31:32 -07001251}
1252
1253int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
1254{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001255 return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001256}
1257EXPORT_SYMBOL(security_sock_rcv_skb);
1258
1259int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1260 int __user *optlen, unsigned len)
1261{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001262 return call_int_hook(socket_getpeersec_stream, 0, sock, optval,
1263 optlen, len);
James Morris20510f22007-10-16 23:31:32 -07001264}
1265
1266int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
1267{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001268 return call_int_hook(socket_getpeersec_dgram, 0, sock, skb, secid);
James Morris20510f22007-10-16 23:31:32 -07001269}
1270EXPORT_SYMBOL(security_socket_getpeersec_dgram);
1271
1272int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
1273{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001274 return call_int_hook(sk_alloc_security, 0, sk, family, priority);
James Morris20510f22007-10-16 23:31:32 -07001275}
1276
1277void security_sk_free(struct sock *sk)
1278{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001279 call_void_hook(sk_free_security, sk);
James Morris20510f22007-10-16 23:31:32 -07001280}
1281
1282void security_sk_clone(const struct sock *sk, struct sock *newsk)
1283{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001284 call_void_hook(sk_clone_security, sk, newsk);
James Morris20510f22007-10-16 23:31:32 -07001285}
Paul Moore6230c9b2011-10-07 09:40:59 +00001286EXPORT_SYMBOL(security_sk_clone);
James Morris20510f22007-10-16 23:31:32 -07001287
1288void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1289{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001290 call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
James Morris20510f22007-10-16 23:31:32 -07001291}
1292EXPORT_SYMBOL(security_sk_classify_flow);
1293
1294void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1295{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001296 call_void_hook(req_classify_flow, req, fl);
James Morris20510f22007-10-16 23:31:32 -07001297}
1298EXPORT_SYMBOL(security_req_classify_flow);
1299
1300void security_sock_graft(struct sock *sk, struct socket *parent)
1301{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001302 call_void_hook(sock_graft, sk, parent);
James Morris20510f22007-10-16 23:31:32 -07001303}
1304EXPORT_SYMBOL(security_sock_graft);
1305
1306int security_inet_conn_request(struct sock *sk,
1307 struct sk_buff *skb, struct request_sock *req)
1308{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001309 return call_int_hook(inet_conn_request, 0, sk, skb, req);
James Morris20510f22007-10-16 23:31:32 -07001310}
1311EXPORT_SYMBOL(security_inet_conn_request);
1312
1313void security_inet_csk_clone(struct sock *newsk,
1314 const struct request_sock *req)
1315{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001316 call_void_hook(inet_csk_clone, newsk, req);
James Morris20510f22007-10-16 23:31:32 -07001317}
1318
1319void security_inet_conn_established(struct sock *sk,
1320 struct sk_buff *skb)
1321{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001322 call_void_hook(inet_conn_established, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001323}
1324
Eric Paris2606fd12010-10-13 16:24:41 -04001325int security_secmark_relabel_packet(u32 secid)
1326{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001327 return call_int_hook(secmark_relabel_packet, 0, secid);
Eric Paris2606fd12010-10-13 16:24:41 -04001328}
1329EXPORT_SYMBOL(security_secmark_relabel_packet);
1330
1331void security_secmark_refcount_inc(void)
1332{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001333 call_void_hook(secmark_refcount_inc);
Eric Paris2606fd12010-10-13 16:24:41 -04001334}
1335EXPORT_SYMBOL(security_secmark_refcount_inc);
1336
1337void security_secmark_refcount_dec(void)
1338{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001339 call_void_hook(secmark_refcount_dec);
Eric Paris2606fd12010-10-13 16:24:41 -04001340}
1341EXPORT_SYMBOL(security_secmark_refcount_dec);
1342
Paul Moore5dbbaf22013-01-14 07:12:19 +00001343int security_tun_dev_alloc_security(void **security)
1344{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001345 return call_int_hook(tun_dev_alloc_security, 0, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001346}
1347EXPORT_SYMBOL(security_tun_dev_alloc_security);
1348
1349void security_tun_dev_free_security(void *security)
1350{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001351 call_void_hook(tun_dev_free_security, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001352}
1353EXPORT_SYMBOL(security_tun_dev_free_security);
1354
Paul Moore2b980db2009-08-28 18:12:43 -04001355int security_tun_dev_create(void)
1356{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001357 return call_int_hook(tun_dev_create, 0);
Paul Moore2b980db2009-08-28 18:12:43 -04001358}
1359EXPORT_SYMBOL(security_tun_dev_create);
1360
Paul Moore5dbbaf22013-01-14 07:12:19 +00001361int security_tun_dev_attach_queue(void *security)
Paul Moore2b980db2009-08-28 18:12:43 -04001362{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001363 return call_int_hook(tun_dev_attach_queue, 0, security);
Paul Moore2b980db2009-08-28 18:12:43 -04001364}
Paul Moore5dbbaf22013-01-14 07:12:19 +00001365EXPORT_SYMBOL(security_tun_dev_attach_queue);
Paul Moore2b980db2009-08-28 18:12:43 -04001366
Paul Moore5dbbaf22013-01-14 07:12:19 +00001367int security_tun_dev_attach(struct sock *sk, void *security)
Paul Moore2b980db2009-08-28 18:12:43 -04001368{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001369 return call_int_hook(tun_dev_attach, 0, sk, security);
Paul Moore2b980db2009-08-28 18:12:43 -04001370}
1371EXPORT_SYMBOL(security_tun_dev_attach);
1372
Paul Moore5dbbaf22013-01-14 07:12:19 +00001373int security_tun_dev_open(void *security)
1374{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001375 return call_int_hook(tun_dev_open, 0, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001376}
1377EXPORT_SYMBOL(security_tun_dev_open);
1378
James Morris20510f22007-10-16 23:31:32 -07001379#endif /* CONFIG_SECURITY_NETWORK */
1380
1381#ifdef CONFIG_SECURITY_NETWORK_XFRM
1382
Nikolay Aleksandrov52a4c642014-03-07 12:44:19 +01001383int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
1384 struct xfrm_user_sec_ctx *sec_ctx,
1385 gfp_t gfp)
James Morris20510f22007-10-16 23:31:32 -07001386{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001387 return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
James Morris20510f22007-10-16 23:31:32 -07001388}
1389EXPORT_SYMBOL(security_xfrm_policy_alloc);
1390
Paul Moore03e1ad72008-04-12 19:07:52 -07001391int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
1392 struct xfrm_sec_ctx **new_ctxp)
James Morris20510f22007-10-16 23:31:32 -07001393{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001394 return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
James Morris20510f22007-10-16 23:31:32 -07001395}
1396
Paul Moore03e1ad72008-04-12 19:07:52 -07001397void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
James Morris20510f22007-10-16 23:31:32 -07001398{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001399 call_void_hook(xfrm_policy_free_security, ctx);
James Morris20510f22007-10-16 23:31:32 -07001400}
1401EXPORT_SYMBOL(security_xfrm_policy_free);
1402
Paul Moore03e1ad72008-04-12 19:07:52 -07001403int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
James Morris20510f22007-10-16 23:31:32 -07001404{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001405 return call_int_hook(xfrm_policy_delete_security, 0, ctx);
James Morris20510f22007-10-16 23:31:32 -07001406}
1407
Paul Moore2e5aa862013-07-23 17:38:38 -04001408int security_xfrm_state_alloc(struct xfrm_state *x,
1409 struct xfrm_user_sec_ctx *sec_ctx)
James Morris20510f22007-10-16 23:31:32 -07001410{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001411 return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
James Morris20510f22007-10-16 23:31:32 -07001412}
1413EXPORT_SYMBOL(security_xfrm_state_alloc);
1414
1415int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
1416 struct xfrm_sec_ctx *polsec, u32 secid)
1417{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001418 return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
James Morris20510f22007-10-16 23:31:32 -07001419}
1420
1421int security_xfrm_state_delete(struct xfrm_state *x)
1422{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001423 return call_int_hook(xfrm_state_delete_security, 0, x);
James Morris20510f22007-10-16 23:31:32 -07001424}
1425EXPORT_SYMBOL(security_xfrm_state_delete);
1426
1427void security_xfrm_state_free(struct xfrm_state *x)
1428{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001429 call_void_hook(xfrm_state_free_security, x);
James Morris20510f22007-10-16 23:31:32 -07001430}
1431
Paul Moore03e1ad72008-04-12 19:07:52 -07001432int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
James Morris20510f22007-10-16 23:31:32 -07001433{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001434 return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
James Morris20510f22007-10-16 23:31:32 -07001435}
1436
1437int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
David S. Millere33f7702011-02-22 18:13:15 -08001438 struct xfrm_policy *xp,
1439 const struct flowi *fl)
James Morris20510f22007-10-16 23:31:32 -07001440{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001441 return call_int_hook(xfrm_state_pol_flow_match, 0, x, xp, fl);
James Morris20510f22007-10-16 23:31:32 -07001442}
1443
1444int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
1445{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001446 return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
James Morris20510f22007-10-16 23:31:32 -07001447}
1448
1449void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
1450{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001451 int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
1452 0);
James Morris20510f22007-10-16 23:31:32 -07001453
1454 BUG_ON(rc);
1455}
1456EXPORT_SYMBOL(security_skb_classify_flow);
1457
1458#endif /* CONFIG_SECURITY_NETWORK_XFRM */
1459
1460#ifdef CONFIG_KEYS
1461
David Howellsd84f4f92008-11-14 10:39:23 +11001462int security_key_alloc(struct key *key, const struct cred *cred,
1463 unsigned long flags)
James Morris20510f22007-10-16 23:31:32 -07001464{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001465 return call_int_hook(key_alloc, 0, key, cred, flags);
James Morris20510f22007-10-16 23:31:32 -07001466}
1467
1468void security_key_free(struct key *key)
1469{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001470 call_void_hook(key_free, key);
James Morris20510f22007-10-16 23:31:32 -07001471}
1472
1473int security_key_permission(key_ref_t key_ref,
David Howellsf5895942014-03-14 17:44:49 +00001474 const struct cred *cred, unsigned perm)
James Morris20510f22007-10-16 23:31:32 -07001475{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001476 return call_int_hook(key_permission, 0, key_ref, cred, perm);
James Morris20510f22007-10-16 23:31:32 -07001477}
1478
David Howells70a5bb72008-04-29 01:01:26 -07001479int security_key_getsecurity(struct key *key, char **_buffer)
1480{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001481 return call_int_hook(key_getsecurity, 0, key, _buffer);
David Howells70a5bb72008-04-29 01:01:26 -07001482}
1483
James Morris20510f22007-10-16 23:31:32 -07001484#endif /* CONFIG_KEYS */
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02001485
1486#ifdef CONFIG_AUDIT
1487
1488int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
1489{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001490 return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02001491}
1492
1493int security_audit_rule_known(struct audit_krule *krule)
1494{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001495 return call_int_hook(audit_rule_known, 0, krule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02001496}
1497
1498void security_audit_rule_free(void *lsmrule)
1499{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001500 call_void_hook(audit_rule_free, lsmrule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02001501}
1502
1503int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
1504 struct audit_context *actx)
1505{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001506 return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
1507 actx);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02001508}
1509
1510#endif /* CONFIG_AUDIT */