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