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