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