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