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