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