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