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