Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * Security plug functions | |
4 | * | |
5 | * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> | |
6 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> | |
7 | * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> | |
d291f1a6 | 8 | * Copyright (C) 2016 Mellanox Technologies |
1661372c | 9 | * Copyright (C) 2023 Microsoft Corporation <paul@paul-moore.com> |
1da177e4 LT |
10 | */ |
11 | ||
9b8c7c14 KC |
12 | #define pr_fmt(fmt) "LSM: " fmt |
13 | ||
afdb09c7 | 14 | #include <linux/bpf.h> |
c59ede7b | 15 | #include <linux/capability.h> |
d47be3df | 16 | #include <linux/dcache.h> |
876979c9 | 17 | #include <linux/export.h> |
1da177e4 LT |
18 | #include <linux/init.h> |
19 | #include <linux/kernel.h> | |
b89999d0 | 20 | #include <linux/kernel_read_file.h> |
3c4ed7bd | 21 | #include <linux/lsm_hooks.h> |
f381c272 | 22 | #include <linux/integrity.h> |
6c21a7fb | 23 | #include <linux/ima.h> |
3e1be52d | 24 | #include <linux/evm.h> |
40401530 | 25 | #include <linux/fsnotify.h> |
8b3ec681 AV |
26 | #include <linux/mman.h> |
27 | #include <linux/mount.h> | |
28 | #include <linux/personality.h> | |
75331a59 | 29 | #include <linux/backing-dev.h> |
3bb857e4 | 30 | #include <linux/string.h> |
ecd5f82e | 31 | #include <linux/msg.h> |
40401530 | 32 | #include <net/flow.h> |
1da177e4 | 33 | |
823eb1cc | 34 | #define MAX_LSM_EVM_XATTR 2 |
1da177e4 | 35 | |
2d4d5119 KC |
36 | /* How many LSMs were built into the kernel? */ |
37 | #define LSM_COUNT (__end_lsm_info - __start_lsm_info) | |
38 | ||
59438b46 SS |
39 | /* |
40 | * These are descriptions of the reasons that can be passed to the | |
41 | * security_locked_down() LSM hook. Placing this array here allows | |
42 | * all security modules to use the same descriptions for auditing | |
43 | * purposes. | |
44 | */ | |
45 | const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { | |
46 | [LOCKDOWN_NONE] = "none", | |
47 | [LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading", | |
48 | [LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port", | |
49 | [LOCKDOWN_EFI_TEST] = "/dev/efi_test access", | |
50 | [LOCKDOWN_KEXEC] = "kexec of unsigned images", | |
51 | [LOCKDOWN_HIBERNATION] = "hibernation", | |
52 | [LOCKDOWN_PCI_ACCESS] = "direct PCI access", | |
53 | [LOCKDOWN_IOPORT] = "raw io port access", | |
54 | [LOCKDOWN_MSR] = "raw MSR access", | |
55 | [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", | |
99df7a28 | 56 | [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", |
59438b46 SS |
57 | [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", |
58 | [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", | |
59 | [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", | |
60 | [LOCKDOWN_MMIOTRACE] = "unsafe mmio", | |
61 | [LOCKDOWN_DEBUGFS] = "debugfs access", | |
62 | [LOCKDOWN_XMON_WR] = "xmon write access", | |
51e1bb9e | 63 | [LOCKDOWN_BPF_WRITE_USER] = "use of bpf to write user RAM", |
eadb2f47 | 64 | [LOCKDOWN_DBG_WRITE_KERNEL] = "use of kgdb/kdb to write kernel RAM", |
b8f3e488 | 65 | [LOCKDOWN_RTAS_ERROR_INJECTION] = "RTAS error injection", |
59438b46 SS |
66 | [LOCKDOWN_INTEGRITY_MAX] = "integrity", |
67 | [LOCKDOWN_KCORE] = "/proc/kcore access", | |
68 | [LOCKDOWN_KPROBES] = "use of kprobes", | |
71330842 | 69 | [LOCKDOWN_BPF_READ_KERNEL] = "use of bpf to read kernel RAM", |
eadb2f47 | 70 | [LOCKDOWN_DBG_READ_KERNEL] = "use of kgdb/kdb to read kernel RAM", |
59438b46 SS |
71 | [LOCKDOWN_PERF] = "unsafe use of perf", |
72 | [LOCKDOWN_TRACEFS] = "use of tracefs", | |
73 | [LOCKDOWN_XMON_RW] = "xmon read and write access", | |
c7a5899e | 74 | [LOCKDOWN_XFRM_SECRET] = "xfrm SA secret", |
59438b46 SS |
75 | [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", |
76 | }; | |
77 | ||
3dfc9b02 | 78 | struct security_hook_heads security_hook_heads __lsm_ro_after_init; |
42df744c | 79 | static BLOCKING_NOTIFIER_HEAD(blocking_lsm_notifier_chain); |
8f408ab6 | 80 | |
33bf60ca | 81 | static struct kmem_cache *lsm_file_cache; |
afb1cbe3 | 82 | static struct kmem_cache *lsm_inode_cache; |
33bf60ca | 83 | |
d69dece5 | 84 | char *lsm_names; |
bbd3662a CS |
85 | static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init; |
86 | ||
076c54c5 | 87 | /* Boot-time LSM user choice */ |
79f7865d | 88 | static __initdata const char *chosen_lsm_order; |
5ef4e419 | 89 | static __initdata const char *chosen_major_lsm; |
1da177e4 | 90 | |
13e735c0 KC |
91 | static __initconst const char * const builtin_lsm_order = CONFIG_LSM; |
92 | ||
2d4d5119 KC |
93 | /* Ordered list of LSMs to initialize. */ |
94 | static __initdata struct lsm_info **ordered_lsms; | |
14bd99c8 | 95 | static __initdata struct lsm_info *exclusive; |
2d4d5119 | 96 | |
9b8c7c14 KC |
97 | static __initdata bool debug; |
98 | #define init_debug(...) \ | |
99 | do { \ | |
100 | if (debug) \ | |
101 | pr_info(__VA_ARGS__); \ | |
102 | } while (0) | |
103 | ||
f4941d75 KC |
104 | static bool __init is_enabled(struct lsm_info *lsm) |
105 | { | |
a8027fb0 KC |
106 | if (!lsm->enabled) |
107 | return false; | |
f4941d75 | 108 | |
a8027fb0 | 109 | return *lsm->enabled; |
f4941d75 KC |
110 | } |
111 | ||
112 | /* Mark an LSM's enabled flag. */ | |
113 | static int lsm_enabled_true __initdata = 1; | |
114 | static int lsm_enabled_false __initdata = 0; | |
115 | static void __init set_enabled(struct lsm_info *lsm, bool enabled) | |
116 | { | |
117 | /* | |
118 | * When an LSM hasn't configured an enable variable, we can use | |
119 | * a hard-coded location for storing the default enabled state. | |
120 | */ | |
121 | if (!lsm->enabled) { | |
122 | if (enabled) | |
123 | lsm->enabled = &lsm_enabled_true; | |
124 | else | |
125 | lsm->enabled = &lsm_enabled_false; | |
126 | } else if (lsm->enabled == &lsm_enabled_true) { | |
127 | if (!enabled) | |
128 | lsm->enabled = &lsm_enabled_false; | |
129 | } else if (lsm->enabled == &lsm_enabled_false) { | |
130 | if (enabled) | |
131 | lsm->enabled = &lsm_enabled_true; | |
132 | } else { | |
133 | *lsm->enabled = enabled; | |
134 | } | |
135 | } | |
136 | ||
2d4d5119 KC |
137 | /* Is an LSM already listed in the ordered LSMs list? */ |
138 | static bool __init exists_ordered_lsm(struct lsm_info *lsm) | |
139 | { | |
140 | struct lsm_info **check; | |
141 | ||
142 | for (check = ordered_lsms; *check; check++) | |
143 | if (*check == lsm) | |
144 | return true; | |
145 | ||
146 | return false; | |
147 | } | |
148 | ||
149 | /* Append an LSM to the list of ordered LSMs to initialize. */ | |
150 | static int last_lsm __initdata; | |
151 | static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) | |
152 | { | |
153 | /* Ignore duplicate selections. */ | |
154 | if (exists_ordered_lsm(lsm)) | |
155 | return; | |
156 | ||
157 | if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from)) | |
158 | return; | |
159 | ||
a8027fb0 KC |
160 | /* Enable this LSM, if it is not already set. */ |
161 | if (!lsm->enabled) | |
162 | lsm->enabled = &lsm_enabled_true; | |
2d4d5119 | 163 | ordered_lsms[last_lsm++] = lsm; |
a8027fb0 | 164 | |
86ef3c73 KC |
165 | init_debug("%s ordered: %s (%s)\n", from, lsm->name, |
166 | is_enabled(lsm) ? "enabled" : "disabled"); | |
2d4d5119 KC |
167 | } |
168 | ||
f4941d75 KC |
169 | /* Is an LSM allowed to be initialized? */ |
170 | static bool __init lsm_allowed(struct lsm_info *lsm) | |
171 | { | |
172 | /* Skip if the LSM is disabled. */ | |
173 | if (!is_enabled(lsm)) | |
174 | return false; | |
175 | ||
14bd99c8 KC |
176 | /* Not allowed if another exclusive LSM already initialized. */ |
177 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) { | |
178 | init_debug("exclusive disabled: %s\n", lsm->name); | |
179 | return false; | |
180 | } | |
181 | ||
f4941d75 KC |
182 | return true; |
183 | } | |
184 | ||
bbd3662a CS |
185 | static void __init lsm_set_blob_size(int *need, int *lbs) |
186 | { | |
187 | int offset; | |
188 | ||
b9f5ce27 GN |
189 | if (*need <= 0) |
190 | return; | |
191 | ||
192 | offset = ALIGN(*lbs, sizeof(void *)); | |
193 | *lbs = offset + *need; | |
194 | *need = offset; | |
bbd3662a CS |
195 | } |
196 | ||
197 | static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) | |
198 | { | |
199 | if (!needed) | |
200 | return; | |
201 | ||
202 | lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred); | |
33bf60ca | 203 | lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file); |
afb1cbe3 CS |
204 | /* |
205 | * The inode blob gets an rcu_head in addition to | |
206 | * what the modules might need. | |
207 | */ | |
208 | if (needed->lbs_inode && blob_sizes.lbs_inode == 0) | |
209 | blob_sizes.lbs_inode = sizeof(struct rcu_head); | |
210 | lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); | |
ecd5f82e CS |
211 | lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); |
212 | lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); | |
1aea7808 | 213 | lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock); |
f4ad8f2c | 214 | lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task); |
bbd3662a CS |
215 | } |
216 | ||
d8e9bbd4 KC |
217 | /* Prepare LSM for initialization. */ |
218 | static void __init prepare_lsm(struct lsm_info *lsm) | |
f4941d75 KC |
219 | { |
220 | int enabled = lsm_allowed(lsm); | |
221 | ||
222 | /* Record enablement (to handle any following exclusive LSMs). */ | |
223 | set_enabled(lsm, enabled); | |
224 | ||
d8e9bbd4 | 225 | /* If enabled, do pre-initialization work. */ |
f4941d75 | 226 | if (enabled) { |
14bd99c8 KC |
227 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { |
228 | exclusive = lsm; | |
86ef3c73 | 229 | init_debug("exclusive chosen: %s\n", lsm->name); |
14bd99c8 | 230 | } |
bbd3662a CS |
231 | |
232 | lsm_set_blob_sizes(lsm->blobs); | |
d8e9bbd4 KC |
233 | } |
234 | } | |
235 | ||
236 | /* Initialize a given LSM, if it is enabled. */ | |
237 | static void __init initialize_lsm(struct lsm_info *lsm) | |
238 | { | |
239 | if (is_enabled(lsm)) { | |
240 | int ret; | |
14bd99c8 | 241 | |
f4941d75 KC |
242 | init_debug("initializing %s\n", lsm->name); |
243 | ret = lsm->init(); | |
244 | WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret); | |
245 | } | |
246 | } | |
247 | ||
13e735c0 | 248 | /* Populate ordered LSMs list from comma-separated LSM name list. */ |
2d4d5119 | 249 | static void __init ordered_lsm_parse(const char *order, const char *origin) |
657d910b KC |
250 | { |
251 | struct lsm_info *lsm; | |
13e735c0 KC |
252 | char *sep, *name, *next; |
253 | ||
e2bc445b KC |
254 | /* LSM_ORDER_FIRST is always first. */ |
255 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
256 | if (lsm->order == LSM_ORDER_FIRST) | |
86ef3c73 | 257 | append_ordered_lsm(lsm, " first"); |
e2bc445b KC |
258 | } |
259 | ||
7e611486 | 260 | /* Process "security=", if given. */ |
7e611486 KC |
261 | if (chosen_major_lsm) { |
262 | struct lsm_info *major; | |
263 | ||
264 | /* | |
265 | * To match the original "security=" behavior, this | |
266 | * explicitly does NOT fallback to another Legacy Major | |
267 | * if the selected one was separately disabled: disable | |
268 | * all non-matching Legacy Major LSMs. | |
269 | */ | |
270 | for (major = __start_lsm_info; major < __end_lsm_info; | |
271 | major++) { | |
272 | if ((major->flags & LSM_FLAG_LEGACY_MAJOR) && | |
273 | strcmp(major->name, chosen_major_lsm) != 0) { | |
274 | set_enabled(major, false); | |
86ef3c73 | 275 | init_debug("security=%s disabled: %s (only one legacy major LSM)\n", |
7e611486 KC |
276 | chosen_major_lsm, major->name); |
277 | } | |
278 | } | |
279 | } | |
5ef4e419 | 280 | |
13e735c0 KC |
281 | sep = kstrdup(order, GFP_KERNEL); |
282 | next = sep; | |
283 | /* Walk the list, looking for matching LSMs. */ | |
284 | while ((name = strsep(&next, ",")) != NULL) { | |
285 | bool found = false; | |
286 | ||
287 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
e2bc445b KC |
288 | if (lsm->order == LSM_ORDER_MUTABLE && |
289 | strcmp(lsm->name, name) == 0) { | |
13e735c0 KC |
290 | append_ordered_lsm(lsm, origin); |
291 | found = true; | |
292 | } | |
293 | } | |
294 | ||
295 | if (!found) | |
86ef3c73 KC |
296 | init_debug("%s ignored: %s (not built into kernel)\n", |
297 | origin, name); | |
657d910b | 298 | } |
c91d8106 CS |
299 | |
300 | /* Process "security=", if given. */ | |
301 | if (chosen_major_lsm) { | |
302 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
303 | if (exists_ordered_lsm(lsm)) | |
304 | continue; | |
305 | if (strcmp(lsm->name, chosen_major_lsm) == 0) | |
306 | append_ordered_lsm(lsm, "security="); | |
307 | } | |
308 | } | |
309 | ||
310 | /* Disable all LSMs not in the ordered list. */ | |
311 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
312 | if (exists_ordered_lsm(lsm)) | |
313 | continue; | |
314 | set_enabled(lsm, false); | |
86ef3c73 KC |
315 | init_debug("%s skipped: %s (not in requested order)\n", |
316 | origin, lsm->name); | |
c91d8106 CS |
317 | } |
318 | ||
13e735c0 | 319 | kfree(sep); |
657d910b KC |
320 | } |
321 | ||
1cfb2a51 TH |
322 | static void __init lsm_early_cred(struct cred *cred); |
323 | static void __init lsm_early_task(struct task_struct *task); | |
324 | ||
e6b1db98 MG |
325 | static int lsm_append(const char *new, char **result); |
326 | ||
86ef3c73 KC |
327 | static void __init report_lsm_order(void) |
328 | { | |
329 | struct lsm_info **lsm, *early; | |
330 | int first = 0; | |
331 | ||
332 | pr_info("initializing lsm="); | |
333 | ||
334 | /* Report each enabled LSM name, comma separated. */ | |
335 | for (early = __start_early_lsm_info; early < __end_early_lsm_info; early++) | |
336 | if (is_enabled(early)) | |
337 | pr_cont("%s%s", first++ == 0 ? "" : ",", early->name); | |
338 | for (lsm = ordered_lsms; *lsm; lsm++) | |
339 | if (is_enabled(*lsm)) | |
340 | pr_cont("%s%s", first++ == 0 ? "" : ",", (*lsm)->name); | |
341 | ||
342 | pr_cont("\n"); | |
343 | } | |
344 | ||
2d4d5119 KC |
345 | static void __init ordered_lsm_init(void) |
346 | { | |
347 | struct lsm_info **lsm; | |
348 | ||
349 | ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), | |
350 | GFP_KERNEL); | |
351 | ||
89a9684e KC |
352 | if (chosen_lsm_order) { |
353 | if (chosen_major_lsm) { | |
86ef3c73 KC |
354 | pr_warn("security=%s is ignored because it is superseded by lsm=%s\n", |
355 | chosen_major_lsm, chosen_lsm_order); | |
89a9684e KC |
356 | chosen_major_lsm = NULL; |
357 | } | |
79f7865d | 358 | ordered_lsm_parse(chosen_lsm_order, "cmdline"); |
89a9684e | 359 | } else |
79f7865d | 360 | ordered_lsm_parse(builtin_lsm_order, "builtin"); |
2d4d5119 KC |
361 | |
362 | for (lsm = ordered_lsms; *lsm; lsm++) | |
d8e9bbd4 KC |
363 | prepare_lsm(*lsm); |
364 | ||
86ef3c73 KC |
365 | report_lsm_order(); |
366 | ||
1aea7808 CS |
367 | init_debug("cred blob size = %d\n", blob_sizes.lbs_cred); |
368 | init_debug("file blob size = %d\n", blob_sizes.lbs_file); | |
369 | init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); | |
370 | init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); | |
371 | init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); | |
372 | init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock); | |
373 | init_debug("task blob size = %d\n", blob_sizes.lbs_task); | |
33bf60ca CS |
374 | |
375 | /* | |
376 | * Create any kmem_caches needed for blobs | |
377 | */ | |
378 | if (blob_sizes.lbs_file) | |
379 | lsm_file_cache = kmem_cache_create("lsm_file_cache", | |
380 | blob_sizes.lbs_file, 0, | |
381 | SLAB_PANIC, NULL); | |
afb1cbe3 CS |
382 | if (blob_sizes.lbs_inode) |
383 | lsm_inode_cache = kmem_cache_create("lsm_inode_cache", | |
384 | blob_sizes.lbs_inode, 0, | |
385 | SLAB_PANIC, NULL); | |
bbd3662a | 386 | |
1cfb2a51 TH |
387 | lsm_early_cred((struct cred *) current->cred); |
388 | lsm_early_task(current); | |
d8e9bbd4 KC |
389 | for (lsm = ordered_lsms; *lsm; lsm++) |
390 | initialize_lsm(*lsm); | |
2d4d5119 KC |
391 | |
392 | kfree(ordered_lsms); | |
393 | } | |
394 | ||
e6b1db98 MG |
395 | int __init early_security_init(void) |
396 | { | |
e6b1db98 MG |
397 | struct lsm_info *lsm; |
398 | ||
75c1182e BW |
399 | #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ |
400 | INIT_HLIST_HEAD(&security_hook_heads.NAME); | |
401 | #include "linux/lsm_hook_defs.h" | |
402 | #undef LSM_HOOK | |
e6b1db98 MG |
403 | |
404 | for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) { | |
405 | if (!lsm->enabled) | |
406 | lsm->enabled = &lsm_enabled_true; | |
407 | prepare_lsm(lsm); | |
408 | initialize_lsm(lsm); | |
409 | } | |
410 | ||
411 | return 0; | |
412 | } | |
413 | ||
1da177e4 LT |
414 | /** |
415 | * security_init - initializes the security framework | |
416 | * | |
417 | * This should be called early in the kernel initialization sequence. | |
418 | */ | |
419 | int __init security_init(void) | |
420 | { | |
e6b1db98 | 421 | struct lsm_info *lsm; |
3dfc9b02 | 422 | |
86ef3c73 KC |
423 | init_debug("legacy security=%s\n", chosen_major_lsm ?: " *unspecified*"); |
424 | init_debug(" CONFIG_LSM=%s\n", builtin_lsm_order); | |
425 | init_debug("boot arg lsm=%s\n", chosen_lsm_order ?: " *unspecified*"); | |
98d29170 | 426 | |
e6b1db98 MG |
427 | /* |
428 | * Append the names of the early LSM modules now that kmalloc() is | |
429 | * available | |
430 | */ | |
431 | for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) { | |
86ef3c73 KC |
432 | init_debug(" early started: %s (%s)\n", lsm->name, |
433 | is_enabled(lsm) ? "enabled" : "disabled"); | |
e6b1db98 MG |
434 | if (lsm->enabled) |
435 | lsm_append(lsm->name, &lsm_names); | |
436 | } | |
1da177e4 | 437 | |
657d910b KC |
438 | /* Load LSMs in specified order. */ |
439 | ordered_lsm_init(); | |
440 | ||
1da177e4 LT |
441 | return 0; |
442 | } | |
443 | ||
076c54c5 | 444 | /* Save user chosen LSM */ |
5ef4e419 | 445 | static int __init choose_major_lsm(char *str) |
076c54c5 | 446 | { |
5ef4e419 | 447 | chosen_major_lsm = str; |
076c54c5 AD |
448 | return 1; |
449 | } | |
5ef4e419 | 450 | __setup("security=", choose_major_lsm); |
076c54c5 | 451 | |
79f7865d KC |
452 | /* Explicitly choose LSM initialization order. */ |
453 | static int __init choose_lsm_order(char *str) | |
454 | { | |
455 | chosen_lsm_order = str; | |
456 | return 1; | |
457 | } | |
458 | __setup("lsm=", choose_lsm_order); | |
459 | ||
9b8c7c14 KC |
460 | /* Enable LSM order debugging. */ |
461 | static int __init enable_debug(char *str) | |
462 | { | |
463 | debug = true; | |
464 | return 1; | |
465 | } | |
466 | __setup("lsm.debug", enable_debug); | |
467 | ||
3bb857e4 MS |
468 | static bool match_last_lsm(const char *list, const char *lsm) |
469 | { | |
470 | const char *last; | |
471 | ||
472 | if (WARN_ON(!list || !lsm)) | |
473 | return false; | |
474 | last = strrchr(list, ','); | |
475 | if (last) | |
476 | /* Pass the comma, strcmp() will check for '\0' */ | |
477 | last++; | |
478 | else | |
479 | last = list; | |
480 | return !strcmp(last, lsm); | |
481 | } | |
482 | ||
e6b1db98 | 483 | static int lsm_append(const char *new, char **result) |
d69dece5 CS |
484 | { |
485 | char *cp; | |
486 | ||
487 | if (*result == NULL) { | |
488 | *result = kstrdup(new, GFP_KERNEL); | |
87ea5843 EB |
489 | if (*result == NULL) |
490 | return -ENOMEM; | |
d69dece5 | 491 | } else { |
3bb857e4 MS |
492 | /* Check if it is the last registered name */ |
493 | if (match_last_lsm(*result, new)) | |
494 | return 0; | |
d69dece5 CS |
495 | cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new); |
496 | if (cp == NULL) | |
497 | return -ENOMEM; | |
498 | kfree(*result); | |
499 | *result = cp; | |
500 | } | |
501 | return 0; | |
502 | } | |
503 | ||
d69dece5 CS |
504 | /** |
505 | * security_add_hooks - Add a modules hooks to the hook lists. | |
506 | * @hooks: the hooks to add | |
507 | * @count: the number of hooks to add | |
508 | * @lsm: the name of the security module | |
509 | * | |
510 | * Each LSM has to register its hooks with the infrastructure. | |
511 | */ | |
512 | void __init security_add_hooks(struct security_hook_list *hooks, int count, | |
1af0e4a0 | 513 | const char *lsm) |
d69dece5 CS |
514 | { |
515 | int i; | |
516 | ||
517 | for (i = 0; i < count; i++) { | |
518 | hooks[i].lsm = lsm; | |
df0ce173 | 519 | hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); |
d69dece5 | 520 | } |
e6b1db98 MG |
521 | |
522 | /* | |
523 | * Don't try to append during early_security_init(), we'll come back | |
524 | * and fix this up afterwards. | |
525 | */ | |
526 | if (slab_is_available()) { | |
527 | if (lsm_append(lsm, &lsm_names) < 0) | |
528 | panic("%s - Cannot get early memory.\n", __func__); | |
529 | } | |
d69dece5 CS |
530 | } |
531 | ||
42df744c | 532 | int call_blocking_lsm_notifier(enum lsm_event event, void *data) |
8f408ab6 | 533 | { |
42df744c JK |
534 | return blocking_notifier_call_chain(&blocking_lsm_notifier_chain, |
535 | event, data); | |
8f408ab6 | 536 | } |
42df744c | 537 | EXPORT_SYMBOL(call_blocking_lsm_notifier); |
8f408ab6 | 538 | |
42df744c | 539 | int register_blocking_lsm_notifier(struct notifier_block *nb) |
8f408ab6 | 540 | { |
42df744c JK |
541 | return blocking_notifier_chain_register(&blocking_lsm_notifier_chain, |
542 | nb); | |
8f408ab6 | 543 | } |
42df744c | 544 | EXPORT_SYMBOL(register_blocking_lsm_notifier); |
8f408ab6 | 545 | |
42df744c | 546 | int unregister_blocking_lsm_notifier(struct notifier_block *nb) |
8f408ab6 | 547 | { |
42df744c JK |
548 | return blocking_notifier_chain_unregister(&blocking_lsm_notifier_chain, |
549 | nb); | |
8f408ab6 | 550 | } |
42df744c | 551 | EXPORT_SYMBOL(unregister_blocking_lsm_notifier); |
8f408ab6 | 552 | |
bbd3662a CS |
553 | /** |
554 | * lsm_cred_alloc - allocate a composite cred blob | |
555 | * @cred: the cred that needs a blob | |
556 | * @gfp: allocation type | |
557 | * | |
558 | * Allocate the cred blob for all the modules | |
559 | * | |
560 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
561 | */ | |
562 | static int lsm_cred_alloc(struct cred *cred, gfp_t gfp) | |
563 | { | |
564 | if (blob_sizes.lbs_cred == 0) { | |
565 | cred->security = NULL; | |
566 | return 0; | |
567 | } | |
568 | ||
569 | cred->security = kzalloc(blob_sizes.lbs_cred, gfp); | |
570 | if (cred->security == NULL) | |
571 | return -ENOMEM; | |
572 | return 0; | |
573 | } | |
574 | ||
575 | /** | |
576 | * lsm_early_cred - during initialization allocate a composite cred blob | |
577 | * @cred: the cred that needs a blob | |
578 | * | |
1cfb2a51 | 579 | * Allocate the cred blob for all the modules |
bbd3662a | 580 | */ |
1cfb2a51 | 581 | static void __init lsm_early_cred(struct cred *cred) |
bbd3662a | 582 | { |
1cfb2a51 | 583 | int rc = lsm_cred_alloc(cred, GFP_KERNEL); |
bbd3662a | 584 | |
bbd3662a CS |
585 | if (rc) |
586 | panic("%s: Early cred alloc failed.\n", __func__); | |
587 | } | |
588 | ||
33bf60ca CS |
589 | /** |
590 | * lsm_file_alloc - allocate a composite file blob | |
591 | * @file: the file that needs a blob | |
592 | * | |
593 | * Allocate the file blob for all the modules | |
594 | * | |
595 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
596 | */ | |
597 | static int lsm_file_alloc(struct file *file) | |
598 | { | |
599 | if (!lsm_file_cache) { | |
600 | file->f_security = NULL; | |
601 | return 0; | |
602 | } | |
603 | ||
604 | file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL); | |
605 | if (file->f_security == NULL) | |
606 | return -ENOMEM; | |
607 | return 0; | |
608 | } | |
609 | ||
afb1cbe3 CS |
610 | /** |
611 | * lsm_inode_alloc - allocate a composite inode blob | |
612 | * @inode: the inode that needs a blob | |
613 | * | |
614 | * Allocate the inode blob for all the modules | |
615 | * | |
616 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
617 | */ | |
618 | int lsm_inode_alloc(struct inode *inode) | |
619 | { | |
620 | if (!lsm_inode_cache) { | |
621 | inode->i_security = NULL; | |
622 | return 0; | |
623 | } | |
624 | ||
625 | inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS); | |
626 | if (inode->i_security == NULL) | |
627 | return -ENOMEM; | |
628 | return 0; | |
629 | } | |
630 | ||
f4ad8f2c CS |
631 | /** |
632 | * lsm_task_alloc - allocate a composite task blob | |
633 | * @task: the task that needs a blob | |
634 | * | |
635 | * Allocate the task blob for all the modules | |
636 | * | |
637 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
638 | */ | |
3e8c7367 | 639 | static int lsm_task_alloc(struct task_struct *task) |
f4ad8f2c CS |
640 | { |
641 | if (blob_sizes.lbs_task == 0) { | |
642 | task->security = NULL; | |
643 | return 0; | |
644 | } | |
645 | ||
646 | task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL); | |
647 | if (task->security == NULL) | |
648 | return -ENOMEM; | |
649 | return 0; | |
650 | } | |
651 | ||
ecd5f82e CS |
652 | /** |
653 | * lsm_ipc_alloc - allocate a composite ipc blob | |
654 | * @kip: the ipc that needs a blob | |
655 | * | |
656 | * Allocate the ipc blob for all the modules | |
657 | * | |
658 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
659 | */ | |
3e8c7367 | 660 | static int lsm_ipc_alloc(struct kern_ipc_perm *kip) |
ecd5f82e CS |
661 | { |
662 | if (blob_sizes.lbs_ipc == 0) { | |
663 | kip->security = NULL; | |
664 | return 0; | |
665 | } | |
666 | ||
667 | kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL); | |
668 | if (kip->security == NULL) | |
669 | return -ENOMEM; | |
670 | return 0; | |
671 | } | |
672 | ||
673 | /** | |
674 | * lsm_msg_msg_alloc - allocate a composite msg_msg blob | |
675 | * @mp: the msg_msg that needs a blob | |
676 | * | |
677 | * Allocate the ipc blob for all the modules | |
678 | * | |
679 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
680 | */ | |
3e8c7367 | 681 | static int lsm_msg_msg_alloc(struct msg_msg *mp) |
ecd5f82e CS |
682 | { |
683 | if (blob_sizes.lbs_msg_msg == 0) { | |
684 | mp->security = NULL; | |
685 | return 0; | |
686 | } | |
687 | ||
688 | mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL); | |
689 | if (mp->security == NULL) | |
690 | return -ENOMEM; | |
691 | return 0; | |
692 | } | |
693 | ||
f4ad8f2c CS |
694 | /** |
695 | * lsm_early_task - during initialization allocate a composite task blob | |
696 | * @task: the task that needs a blob | |
697 | * | |
1cfb2a51 | 698 | * Allocate the task blob for all the modules |
f4ad8f2c | 699 | */ |
1cfb2a51 | 700 | static void __init lsm_early_task(struct task_struct *task) |
f4ad8f2c | 701 | { |
1cfb2a51 | 702 | int rc = lsm_task_alloc(task); |
f4ad8f2c | 703 | |
f4ad8f2c CS |
704 | if (rc) |
705 | panic("%s: Early task alloc failed.\n", __func__); | |
706 | } | |
707 | ||
1aea7808 CS |
708 | /** |
709 | * lsm_superblock_alloc - allocate a composite superblock blob | |
710 | * @sb: the superblock that needs a blob | |
711 | * | |
712 | * Allocate the superblock blob for all the modules | |
713 | * | |
714 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
715 | */ | |
716 | static int lsm_superblock_alloc(struct super_block *sb) | |
717 | { | |
718 | if (blob_sizes.lbs_superblock == 0) { | |
719 | sb->s_security = NULL; | |
720 | return 0; | |
721 | } | |
722 | ||
723 | sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL); | |
724 | if (sb->s_security == NULL) | |
725 | return -ENOMEM; | |
726 | return 0; | |
727 | } | |
728 | ||
98e828a0 KS |
729 | /* |
730 | * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and | |
731 | * can be accessed with: | |
732 | * | |
733 | * LSM_RET_DEFAULT(<hook_name>) | |
734 | * | |
735 | * The macros below define static constants for the default value of each | |
736 | * LSM hook. | |
737 | */ | |
738 | #define LSM_RET_DEFAULT(NAME) (NAME##_default) | |
739 | #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME) | |
740 | #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \ | |
86dd9fd5 | 741 | static const int __maybe_unused LSM_RET_DEFAULT(NAME) = (DEFAULT); |
98e828a0 KS |
742 | #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ |
743 | DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME) | |
744 | ||
745 | #include <linux/lsm_hook_defs.h> | |
746 | #undef LSM_HOOK | |
747 | ||
f25fce3e | 748 | /* |
b1d9e6b0 | 749 | * Hook list operation macros. |
1da177e4 | 750 | * |
f25fce3e CS |
751 | * call_void_hook: |
752 | * This is a hook that does not return a value. | |
1da177e4 | 753 | * |
f25fce3e CS |
754 | * call_int_hook: |
755 | * This is a hook that returns a value. | |
1da177e4 | 756 | */ |
1da177e4 | 757 | |
b1d9e6b0 CS |
758 | #define call_void_hook(FUNC, ...) \ |
759 | do { \ | |
760 | struct security_hook_list *P; \ | |
761 | \ | |
df0ce173 | 762 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \ |
b1d9e6b0 CS |
763 | P->hook.FUNC(__VA_ARGS__); \ |
764 | } while (0) | |
765 | ||
766 | #define call_int_hook(FUNC, IRC, ...) ({ \ | |
767 | int RC = IRC; \ | |
768 | do { \ | |
769 | struct security_hook_list *P; \ | |
770 | \ | |
df0ce173 | 771 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ |
b1d9e6b0 CS |
772 | RC = P->hook.FUNC(__VA_ARGS__); \ |
773 | if (RC != 0) \ | |
774 | break; \ | |
775 | } \ | |
776 | } while (0); \ | |
777 | RC; \ | |
778 | }) | |
1da177e4 | 779 | |
20510f2f JM |
780 | /* Security operations */ |
781 | ||
52f88693 | 782 | int security_binder_set_context_mgr(const struct cred *mgr) |
79af7307 | 783 | { |
f25fce3e | 784 | return call_int_hook(binder_set_context_mgr, 0, mgr); |
79af7307 SS |
785 | } |
786 | ||
52f88693 TK |
787 | int security_binder_transaction(const struct cred *from, |
788 | const struct cred *to) | |
79af7307 | 789 | { |
f25fce3e | 790 | return call_int_hook(binder_transaction, 0, from, to); |
79af7307 SS |
791 | } |
792 | ||
52f88693 TK |
793 | int security_binder_transfer_binder(const struct cred *from, |
794 | const struct cred *to) | |
79af7307 | 795 | { |
f25fce3e | 796 | return call_int_hook(binder_transfer_binder, 0, from, to); |
79af7307 SS |
797 | } |
798 | ||
52f88693 TK |
799 | int security_binder_transfer_file(const struct cred *from, |
800 | const struct cred *to, struct file *file) | |
79af7307 | 801 | { |
f25fce3e | 802 | return call_int_hook(binder_transfer_file, 0, from, to, file); |
79af7307 SS |
803 | } |
804 | ||
9e48858f | 805 | int security_ptrace_access_check(struct task_struct *child, unsigned int mode) |
20510f2f | 806 | { |
f25fce3e | 807 | return call_int_hook(ptrace_access_check, 0, child, mode); |
5cd9c58f DH |
808 | } |
809 | ||
810 | int security_ptrace_traceme(struct task_struct *parent) | |
811 | { | |
f25fce3e | 812 | return call_int_hook(ptrace_traceme, 0, parent); |
20510f2f JM |
813 | } |
814 | ||
815 | int security_capget(struct task_struct *target, | |
816 | kernel_cap_t *effective, | |
817 | kernel_cap_t *inheritable, | |
818 | kernel_cap_t *permitted) | |
819 | { | |
f25fce3e CS |
820 | return call_int_hook(capget, 0, target, |
821 | effective, inheritable, permitted); | |
20510f2f JM |
822 | } |
823 | ||
d84f4f99 DH |
824 | int security_capset(struct cred *new, const struct cred *old, |
825 | const kernel_cap_t *effective, | |
826 | const kernel_cap_t *inheritable, | |
827 | const kernel_cap_t *permitted) | |
20510f2f | 828 | { |
f25fce3e CS |
829 | return call_int_hook(capset, 0, new, old, |
830 | effective, inheritable, permitted); | |
20510f2f JM |
831 | } |
832 | ||
c1a85a00 MM |
833 | int security_capable(const struct cred *cred, |
834 | struct user_namespace *ns, | |
835 | int cap, | |
836 | unsigned int opts) | |
20510f2f | 837 | { |
c1a85a00 | 838 | return call_int_hook(capable, 0, cred, ns, cap, opts); |
20510f2f JM |
839 | } |
840 | ||
20510f2f JM |
841 | int security_quotactl(int cmds, int type, int id, struct super_block *sb) |
842 | { | |
f25fce3e | 843 | return call_int_hook(quotactl, 0, cmds, type, id, sb); |
20510f2f JM |
844 | } |
845 | ||
846 | int security_quota_on(struct dentry *dentry) | |
847 | { | |
f25fce3e | 848 | return call_int_hook(quota_on, 0, dentry); |
20510f2f JM |
849 | } |
850 | ||
12b3052c | 851 | int security_syslog(int type) |
20510f2f | 852 | { |
f25fce3e | 853 | return call_int_hook(syslog, 0, type); |
20510f2f JM |
854 | } |
855 | ||
457db29b | 856 | int security_settime64(const struct timespec64 *ts, const struct timezone *tz) |
20510f2f | 857 | { |
f25fce3e | 858 | return call_int_hook(settime, 0, ts, tz); |
20510f2f JM |
859 | } |
860 | ||
20510f2f JM |
861 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) |
862 | { | |
b1d9e6b0 CS |
863 | struct security_hook_list *hp; |
864 | int cap_sys_admin = 1; | |
865 | int rc; | |
866 | ||
867 | /* | |
868 | * The module will respond with a positive value if | |
869 | * it thinks the __vm_enough_memory() call should be | |
870 | * made with the cap_sys_admin set. If all of the modules | |
871 | * agree that it should be set it will. If any module | |
872 | * thinks it should not be set it won't. | |
873 | */ | |
df0ce173 | 874 | hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) { |
b1d9e6b0 CS |
875 | rc = hp->hook.vm_enough_memory(mm, pages); |
876 | if (rc <= 0) { | |
877 | cap_sys_admin = 0; | |
878 | break; | |
879 | } | |
880 | } | |
881 | return __vm_enough_memory(mm, pages, cap_sys_admin); | |
20510f2f JM |
882 | } |
883 | ||
1661372c PM |
884 | /** |
885 | * security_bprm_creds_for_exec() - Prepare the credentials for exec() | |
886 | * @bprm: binary program information | |
887 | * | |
888 | * If the setup in prepare_exec_creds did not setup @bprm->cred->security | |
889 | * properly for executing @bprm->file, update the LSM's portion of | |
890 | * @bprm->cred->security to be what commit_creds needs to install for the new | |
891 | * program. This hook may also optionally check permissions (e.g. for | |
892 | * transitions between security domains). The hook must set @bprm->secureexec | |
893 | * to 1 if AT_SECURE should be set to request libc enable secure mode. @bprm | |
894 | * contains the linux_binprm structure. | |
895 | * | |
896 | * Return: Returns 0 if the hook is successful and permission is granted. | |
897 | */ | |
b8bff599 | 898 | int security_bprm_creds_for_exec(struct linux_binprm *bprm) |
20510f2f | 899 | { |
b8bff599 EB |
900 | return call_int_hook(bprm_creds_for_exec, 0, bprm); |
901 | } | |
902 | ||
1661372c PM |
903 | /** |
904 | * security_bprm_creds_from_file() - Update linux_binprm creds based on file | |
905 | * @bprm: binary program information | |
906 | * @file: associated file | |
907 | * | |
908 | * If @file is setpcap, suid, sgid or otherwise marked to change privilege upon | |
909 | * exec, update @bprm->cred to reflect that change. This is called after | |
910 | * finding the binary that will be executed without an interpreter. This | |
911 | * ensures that the credentials will not be derived from a script that the | |
912 | * binary will need to reopen, which when reopend may end up being a completely | |
913 | * different file. This hook may also optionally check permissions (e.g. for | |
914 | * transitions between security domains). The hook must set @bprm->secureexec | |
915 | * to 1 if AT_SECURE should be set to request libc enable secure mode. The | |
916 | * hook must add to @bprm->per_clear any personality flags that should be | |
917 | * cleared from current->personality. @bprm contains the linux_binprm | |
918 | * structure. | |
919 | * | |
920 | * Return: Returns 0 if the hook is successful and permission is granted. | |
921 | */ | |
56305aa9 | 922 | int security_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file) |
20510f2f | 923 | { |
56305aa9 | 924 | return call_int_hook(bprm_creds_from_file, 0, bprm, file); |
20510f2f JM |
925 | } |
926 | ||
1661372c PM |
927 | /** |
928 | * security_bprm_check() - Mediate binary handler search | |
929 | * @bprm: binary program information | |
930 | * | |
931 | * This hook mediates the point when a search for a binary handler will begin. | |
932 | * It allows a check against the @bprm->cred->security value which was set in | |
933 | * the preceding creds_for_exec call. The argv list and envp list are reliably | |
934 | * available in @bprm. This hook may be called multiple times during a single | |
935 | * execve. @bprm contains the linux_binprm structure. | |
936 | * | |
937 | * Return: Returns 0 if the hook is successful and permission is granted. | |
938 | */ | |
a6f76f23 | 939 | int security_bprm_check(struct linux_binprm *bprm) |
20510f2f | 940 | { |
6c21a7fb MZ |
941 | int ret; |
942 | ||
f25fce3e | 943 | ret = call_int_hook(bprm_check_security, 0, bprm); |
6c21a7fb MZ |
944 | if (ret) |
945 | return ret; | |
946 | return ima_bprm_check(bprm); | |
20510f2f JM |
947 | } |
948 | ||
1661372c PM |
949 | /** |
950 | * security_bprm_committing_creds() - Install creds for a process during exec() | |
951 | * @bprm: binary program information | |
952 | * | |
953 | * Prepare to install the new security attributes of a process being | |
954 | * transformed by an execve operation, based on the old credentials pointed to | |
955 | * by @current->cred and the information set in @bprm->cred by the | |
956 | * bprm_creds_for_exec hook. @bprm points to the linux_binprm structure. This | |
957 | * hook is a good place to perform state changes on the process such as closing | |
958 | * open file descriptors to which access will no longer be granted when the | |
959 | * attributes are changed. This is called immediately before commit_creds(). | |
960 | */ | |
a6f76f23 | 961 | void security_bprm_committing_creds(struct linux_binprm *bprm) |
20510f2f | 962 | { |
f25fce3e | 963 | call_void_hook(bprm_committing_creds, bprm); |
20510f2f JM |
964 | } |
965 | ||
1661372c PM |
966 | /** |
967 | * security_bprm_committed_creds() - Tidy up after cred install during exec() | |
968 | * @bprm: binary program information | |
969 | * | |
970 | * Tidy up after the installation of the new security attributes of a process | |
971 | * being transformed by an execve operation. The new credentials have, by this | |
972 | * point, been set to @current->cred. @bprm points to the linux_binprm | |
973 | * structure. This hook is a good place to perform state changes on the | |
974 | * process such as clearing out non-inheritable signal state. This is called | |
975 | * immediately after commit_creds(). | |
976 | */ | |
a6f76f23 | 977 | void security_bprm_committed_creds(struct linux_binprm *bprm) |
20510f2f | 978 | { |
f25fce3e | 979 | call_void_hook(bprm_committed_creds, bprm); |
20510f2f JM |
980 | } |
981 | ||
36819f18 PM |
982 | /** |
983 | * security_fs_context_dup() - Duplicate a fs_context LSM blob | |
984 | * @fc: destination filesystem context | |
985 | * @src_fc: source filesystem context | |
986 | * | |
987 | * Allocate and attach a security structure to sc->security. This pointer is | |
988 | * initialised to NULL by the caller. @fc indicates the new filesystem context. | |
989 | * @src_fc indicates the original filesystem context. | |
990 | * | |
991 | * Return: Returns 0 on success or a negative error code on failure. | |
992 | */ | |
0b52075e AV |
993 | int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) |
994 | { | |
995 | return call_int_hook(fs_context_dup, 0, fc, src_fc); | |
996 | } | |
997 | ||
36819f18 PM |
998 | /** |
999 | * security_fs_context_parse_param() - Configure a filesystem context | |
1000 | * @fc: filesystem context | |
1001 | * @param: filesystem parameter | |
1002 | * | |
1003 | * Userspace provided a parameter to configure a superblock. The LSM can | |
1004 | * consume the parameter or return it to the caller for use elsewhere. | |
1005 | * | |
1006 | * Return: If the parameter is used by the LSM it should return 0, if it is | |
1007 | * returned to the caller -ENOPARAM is returned, otherwise a negative | |
1008 | * error code is returned. | |
1009 | */ | |
ecff3057 CS |
1010 | int security_fs_context_parse_param(struct fs_context *fc, |
1011 | struct fs_parameter *param) | |
da2441fd | 1012 | { |
ecff3057 CS |
1013 | struct security_hook_list *hp; |
1014 | int trc; | |
1015 | int rc = -ENOPARAM; | |
1016 | ||
1017 | hlist_for_each_entry(hp, &security_hook_heads.fs_context_parse_param, | |
1018 | list) { | |
1019 | trc = hp->hook.fs_context_parse_param(fc, param); | |
1020 | if (trc == 0) | |
1021 | rc = 0; | |
1022 | else if (trc != -ENOPARAM) | |
1023 | return trc; | |
1024 | } | |
1025 | return rc; | |
da2441fd DH |
1026 | } |
1027 | ||
08526a90 PM |
1028 | /** |
1029 | * security_sb_alloc() - Allocate a super_block LSM blob | |
1030 | * @sb: filesystem superblock | |
1031 | * | |
1032 | * Allocate and attach a security structure to the sb->s_security field. The | |
1033 | * s_security field is initialized to NULL when the structure is allocated. | |
1034 | * @sb contains the super_block structure to be modified. | |
1035 | * | |
1036 | * Return: Returns 0 if operation was successful. | |
1037 | */ | |
20510f2f JM |
1038 | int security_sb_alloc(struct super_block *sb) |
1039 | { | |
1aea7808 CS |
1040 | int rc = lsm_superblock_alloc(sb); |
1041 | ||
1042 | if (unlikely(rc)) | |
1043 | return rc; | |
1044 | rc = call_int_hook(sb_alloc_security, 0, sb); | |
1045 | if (unlikely(rc)) | |
1046 | security_sb_free(sb); | |
1047 | return rc; | |
20510f2f JM |
1048 | } |
1049 | ||
08526a90 PM |
1050 | /** |
1051 | * security_sb_delete() - Release super_block LSM associated objects | |
1052 | * @sb: filesystem superblock | |
1053 | * | |
1054 | * Release objects tied to a superblock (e.g. inodes). @sb contains the | |
1055 | * super_block structure being released. | |
1056 | */ | |
83e804f0 MS |
1057 | void security_sb_delete(struct super_block *sb) |
1058 | { | |
1059 | call_void_hook(sb_delete, sb); | |
20510f2f JM |
1060 | } |
1061 | ||
08526a90 PM |
1062 | /** |
1063 | * security_sb_free() - Free a super_block LSM blob | |
1064 | * @sb: filesystem superblock | |
1065 | * | |
1066 | * Deallocate and clear the sb->s_security field. @sb contains the super_block | |
1067 | * structure to be modified. | |
1068 | */ | |
20510f2f JM |
1069 | void security_sb_free(struct super_block *sb) |
1070 | { | |
f25fce3e | 1071 | call_void_hook(sb_free_security, sb); |
1aea7808 CS |
1072 | kfree(sb->s_security); |
1073 | sb->s_security = NULL; | |
20510f2f JM |
1074 | } |
1075 | ||
08526a90 PM |
1076 | /** |
1077 | * security_free_mnt_opts() - Free memory associated with mount options | |
1078 | * @mnt_ops: LSM processed mount options | |
1079 | * | |
1080 | * Free memory associated with @mnt_ops. | |
1081 | */ | |
204cc0cc | 1082 | void security_free_mnt_opts(void **mnt_opts) |
20510f2f | 1083 | { |
204cc0cc AV |
1084 | if (!*mnt_opts) |
1085 | return; | |
1086 | call_void_hook(sb_free_mnt_opts, *mnt_opts); | |
1087 | *mnt_opts = NULL; | |
20510f2f | 1088 | } |
204cc0cc | 1089 | EXPORT_SYMBOL(security_free_mnt_opts); |
20510f2f | 1090 | |
08526a90 PM |
1091 | /** |
1092 | * security_sb_eat_lsm_opts() - Consume LSM mount options | |
1093 | * @options: mount options | |
1094 | * @mnt_ops: LSM processed mount options | |
1095 | * | |
1096 | * Eat (scan @options) and save them in @mnt_opts. | |
1097 | * | |
1098 | * Return: Returns 0 on success, negative values on failure. | |
1099 | */ | |
204cc0cc | 1100 | int security_sb_eat_lsm_opts(char *options, void **mnt_opts) |
ff36fe2c | 1101 | { |
204cc0cc | 1102 | return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts); |
ff36fe2c | 1103 | } |
f5c0c26d | 1104 | EXPORT_SYMBOL(security_sb_eat_lsm_opts); |
ff36fe2c | 1105 | |
08526a90 PM |
1106 | /** |
1107 | * security_sb_mnt_opts_compat() - Check if new mount options are allowed | |
1108 | * @sb: filesystem superblock | |
1109 | * @mnt_opts: new mount options | |
1110 | * | |
1111 | * Determine if the new mount options in @mnt_opts are allowed given the | |
1112 | * existing mounted filesystem at @sb. @sb superblock being compared. | |
1113 | * | |
1114 | * Return: Returns 0 if options are compatible. | |
1115 | */ | |
69c4a42d OK |
1116 | int security_sb_mnt_opts_compat(struct super_block *sb, |
1117 | void *mnt_opts) | |
1118 | { | |
1119 | return call_int_hook(sb_mnt_opts_compat, 0, sb, mnt_opts); | |
1120 | } | |
1121 | EXPORT_SYMBOL(security_sb_mnt_opts_compat); | |
1122 | ||
08526a90 PM |
1123 | /** |
1124 | * security_sb_remount() - Verify no incompatible mount changes during remount | |
1125 | * @sb: filesystem superblock | |
1126 | * @mnt_opts: (re)mount options | |
1127 | * | |
1128 | * Extracts security system specific mount options and verifies no changes are | |
1129 | * being made to those options. | |
1130 | * | |
1131 | * Return: Returns 0 if permission is granted. | |
1132 | */ | |
c039bc3c | 1133 | int security_sb_remount(struct super_block *sb, |
204cc0cc | 1134 | void *mnt_opts) |
20510f2f | 1135 | { |
204cc0cc | 1136 | return call_int_hook(sb_remount, 0, sb, mnt_opts); |
ff36fe2c | 1137 | } |
a65001e8 | 1138 | EXPORT_SYMBOL(security_sb_remount); |
ff36fe2c | 1139 | |
08526a90 PM |
1140 | /** |
1141 | * security_sb_kern_mount() - Check if a kernel mount is allowed | |
1142 | * @sb: filesystem superblock | |
1143 | * | |
1144 | * Mount this @sb if allowed by permissions. | |
1145 | * | |
1146 | * Return: Returns 0 if permission is granted. | |
1147 | */ | |
a10d7c22 | 1148 | int security_sb_kern_mount(struct super_block *sb) |
20510f2f | 1149 | { |
a10d7c22 | 1150 | return call_int_hook(sb_kern_mount, 0, sb); |
20510f2f JM |
1151 | } |
1152 | ||
08526a90 PM |
1153 | /** |
1154 | * security_sb_show_options() - Output the mount options for a superblock | |
1155 | * @m: output file | |
1156 | * @sb: filesystem superblock | |
1157 | * | |
1158 | * Show (print on @m) mount options for this @sb. | |
1159 | * | |
1160 | * Return: Returns 0 on success, negative values on failure. | |
1161 | */ | |
2069f457 EP |
1162 | int security_sb_show_options(struct seq_file *m, struct super_block *sb) |
1163 | { | |
f25fce3e | 1164 | return call_int_hook(sb_show_options, 0, m, sb); |
2069f457 EP |
1165 | } |
1166 | ||
08526a90 PM |
1167 | /** |
1168 | * security_sb_statfs() - Check if accessing fs stats is allowed | |
1169 | * @dentry: superblock handle | |
1170 | * | |
1171 | * Check permission before obtaining filesystem statistics for the @mnt | |
1172 | * mountpoint. @dentry is a handle on the superblock for the filesystem. | |
1173 | * | |
1174 | * Return: Returns 0 if permission is granted. | |
1175 | */ | |
20510f2f JM |
1176 | int security_sb_statfs(struct dentry *dentry) |
1177 | { | |
f25fce3e | 1178 | return call_int_hook(sb_statfs, 0, dentry); |
20510f2f JM |
1179 | } |
1180 | ||
08526a90 PM |
1181 | /** |
1182 | * security_sb_mount() - Check permission for mounting a filesystem | |
1183 | * @dev_name: filesystem backing device | |
1184 | * @path: mount point | |
1185 | * @type: filesystem type | |
1186 | * @flags: mount flags | |
1187 | * @data: filesystem specific data | |
1188 | * | |
1189 | * Check permission before an object specified by @dev_name is mounted on the | |
1190 | * mount point named by @nd. For an ordinary mount, @dev_name identifies a | |
1191 | * device if the file system type requires a device. For a remount | |
1192 | * (@flags & MS_REMOUNT), @dev_name is irrelevant. For a loopback/bind mount | |
1193 | * (@flags & MS_BIND), @dev_name identifies the pathname of the object being | |
1194 | * mounted. | |
1195 | * | |
1196 | * Return: Returns 0 if permission is granted. | |
1197 | */ | |
8a04c43b | 1198 | int security_sb_mount(const char *dev_name, const struct path *path, |
808d4e3c | 1199 | const char *type, unsigned long flags, void *data) |
20510f2f | 1200 | { |
f25fce3e | 1201 | return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data); |
20510f2f JM |
1202 | } |
1203 | ||
08526a90 PM |
1204 | /** |
1205 | * security_sb_umount() - Check permission for unmounting a filesystem | |
1206 | * @mnt: mounted filesystem | |
1207 | * @flags: unmount flags | |
1208 | * | |
1209 | * Check permission before the @mnt file system is unmounted. | |
1210 | * | |
1211 | * Return: Returns 0 if permission is granted. | |
1212 | */ | |
20510f2f JM |
1213 | int security_sb_umount(struct vfsmount *mnt, int flags) |
1214 | { | |
f25fce3e | 1215 | return call_int_hook(sb_umount, 0, mnt, flags); |
20510f2f JM |
1216 | } |
1217 | ||
08526a90 PM |
1218 | /** |
1219 | * security_sb_pivotroot() - Check permissions for pivoting the rootfs | |
1220 | * @old_path: new location for current rootfs | |
1221 | * @new_path: location of the new rootfs | |
1222 | * | |
1223 | * Check permission before pivoting the root filesystem. | |
1224 | * | |
1225 | * Return: Returns 0 if permission is granted. | |
1226 | */ | |
3b73b68c | 1227 | int security_sb_pivotroot(const struct path *old_path, const struct path *new_path) |
20510f2f | 1228 | { |
f25fce3e | 1229 | return call_int_hook(sb_pivotroot, 0, old_path, new_path); |
20510f2f JM |
1230 | } |
1231 | ||
08526a90 PM |
1232 | /** |
1233 | * security_sb_set_mnt_opts() - Set the mount options for a filesystem | |
1234 | * @sb: filesystem superblock | |
1235 | * @mnt_opts: binary mount options | |
1236 | * @kern_flags: kernel flags (in) | |
1237 | * @set_kern_flags: kernel flags (out) | |
1238 | * | |
1239 | * Set the security relevant mount options used for a superblock. | |
1240 | * | |
1241 | * Return: Returns 0 on success, error on failure. | |
1242 | */ | |
c9180a57 | 1243 | int security_sb_set_mnt_opts(struct super_block *sb, |
204cc0cc | 1244 | void *mnt_opts, |
649f6e77 DQ |
1245 | unsigned long kern_flags, |
1246 | unsigned long *set_kern_flags) | |
c9180a57 | 1247 | { |
b1d9e6b0 | 1248 | return call_int_hook(sb_set_mnt_opts, |
204cc0cc AV |
1249 | mnt_opts ? -EOPNOTSUPP : 0, sb, |
1250 | mnt_opts, kern_flags, set_kern_flags); | |
c9180a57 | 1251 | } |
e0007529 | 1252 | EXPORT_SYMBOL(security_sb_set_mnt_opts); |
c9180a57 | 1253 | |
08526a90 PM |
1254 | /** |
1255 | * security_sb_clone_mnt_opts() - Duplicate superblock mount options | |
1256 | * @olddb: source superblock | |
1257 | * @newdb: destination superblock | |
1258 | * @kern_flags: kernel flags (in) | |
1259 | * @set_kern_flags: kernel flags (out) | |
1260 | * | |
1261 | * Copy all security options from a given superblock to another. | |
1262 | * | |
1263 | * Return: Returns 0 on success, error on failure. | |
1264 | */ | |
094f7b69 | 1265 | int security_sb_clone_mnt_opts(const struct super_block *oldsb, |
0b4d3452 SM |
1266 | struct super_block *newsb, |
1267 | unsigned long kern_flags, | |
1268 | unsigned long *set_kern_flags) | |
c9180a57 | 1269 | { |
0b4d3452 SM |
1270 | return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb, |
1271 | kern_flags, set_kern_flags); | |
c9180a57 | 1272 | } |
e0007529 EP |
1273 | EXPORT_SYMBOL(security_sb_clone_mnt_opts); |
1274 | ||
08526a90 PM |
1275 | /** |
1276 | * security_move_mount() - Check permissions for moving a mount | |
1277 | * @from_path: source mount point | |
1278 | * @to_path: destination mount point | |
1279 | * | |
1280 | * Check permission before a mount is moved. | |
1281 | * | |
1282 | * Return: Returns 0 if permission is granted. | |
1283 | */ | |
2db154b3 DH |
1284 | int security_move_mount(const struct path *from_path, const struct path *to_path) |
1285 | { | |
1286 | return call_int_hook(move_mount, 0, from_path, to_path); | |
1287 | } | |
1288 | ||
ac5656d8 AG |
1289 | int security_path_notify(const struct path *path, u64 mask, |
1290 | unsigned int obj_type) | |
1291 | { | |
1292 | return call_int_hook(path_notify, 0, path, mask, obj_type); | |
1293 | } | |
1294 | ||
20510f2f JM |
1295 | int security_inode_alloc(struct inode *inode) |
1296 | { | |
afb1cbe3 CS |
1297 | int rc = lsm_inode_alloc(inode); |
1298 | ||
1299 | if (unlikely(rc)) | |
1300 | return rc; | |
1301 | rc = call_int_hook(inode_alloc_security, 0, inode); | |
1302 | if (unlikely(rc)) | |
1303 | security_inode_free(inode); | |
1304 | return rc; | |
1305 | } | |
1306 | ||
1307 | static void inode_free_by_rcu(struct rcu_head *head) | |
1308 | { | |
1309 | /* | |
1310 | * The rcu head is at the start of the inode blob | |
1311 | */ | |
1312 | kmem_cache_free(lsm_inode_cache, head); | |
20510f2f JM |
1313 | } |
1314 | ||
1315 | void security_inode_free(struct inode *inode) | |
1316 | { | |
f381c272 | 1317 | integrity_inode_free(inode); |
f25fce3e | 1318 | call_void_hook(inode_free_security, inode); |
afb1cbe3 CS |
1319 | /* |
1320 | * The inode may still be referenced in a path walk and | |
1321 | * a call to security_inode_permission() can be made | |
1322 | * after inode_free_security() is called. Ideally, the VFS | |
1323 | * wouldn't do this, but fixing that is a much harder | |
1324 | * job. For now, simply free the i_security via RCU, and | |
1325 | * leave the current inode->i_security pointer intact. | |
1326 | * The inode will be freed after the RCU grace period too. | |
1327 | */ | |
1328 | if (inode->i_security) | |
1329 | call_rcu((struct rcu_head *)inode->i_security, | |
1330 | inode_free_by_rcu); | |
20510f2f JM |
1331 | } |
1332 | ||
08526a90 PM |
1333 | /** |
1334 | * security_dentry_init_security() - Perform dentry initialization | |
1335 | * @dentry: the dentry to initialize | |
1336 | * @mode: mode used to determine resource type | |
1337 | * @name: name of the last path component | |
1338 | * @xattr_name: name of the security/LSM xattr | |
1339 | * @ctx: pointer to the resulting LSM context | |
1340 | * @ctxlen: length of @ctx | |
1341 | * | |
1342 | * Compute a context for a dentry as the inode is not yet available since NFSv4 | |
1343 | * has no label backed by an EA anyway. It is important to note that | |
1344 | * @xattr_name does not need to be free'd by the caller, it is a static string. | |
1345 | * | |
1346 | * Return: Returns 0 on success, negative values on failure. | |
1347 | */ | |
d47be3df | 1348 | int security_dentry_init_security(struct dentry *dentry, int mode, |
15bf3239 VG |
1349 | const struct qstr *name, |
1350 | const char **xattr_name, void **ctx, | |
1351 | u32 *ctxlen) | |
d47be3df | 1352 | { |
7f5056b9 VG |
1353 | struct security_hook_list *hp; |
1354 | int rc; | |
1355 | ||
1356 | /* | |
1357 | * Only one module will provide a security context. | |
1358 | */ | |
1359 | hlist_for_each_entry(hp, &security_hook_heads.dentry_init_security, list) { | |
1360 | rc = hp->hook.dentry_init_security(dentry, mode, name, | |
1361 | xattr_name, ctx, ctxlen); | |
1362 | if (rc != LSM_RET_DEFAULT(dentry_init_security)) | |
1363 | return rc; | |
1364 | } | |
1365 | return LSM_RET_DEFAULT(dentry_init_security); | |
d47be3df DQ |
1366 | } |
1367 | EXPORT_SYMBOL(security_dentry_init_security); | |
1368 | ||
08526a90 PM |
1369 | /** |
1370 | * security_dentry_create_files_as() - Perform dentry initialization | |
1371 | * @dentry: the dentry to initialize | |
1372 | * @mode: mode used to determine resource type | |
1373 | * @name: name of the last path component | |
1374 | * @old: creds to use for LSM context calculations | |
1375 | * @new: creds to modify | |
1376 | * | |
1377 | * Compute a context for a dentry as the inode is not yet available and set | |
1378 | * that context in passed in creds so that new files are created using that | |
1379 | * context. Context is calculated using the passed in creds and not the creds | |
1380 | * of the caller. | |
1381 | * | |
1382 | * Return: Returns 0 on success, error on failure. | |
1383 | */ | |
2602625b VG |
1384 | int security_dentry_create_files_as(struct dentry *dentry, int mode, |
1385 | struct qstr *name, | |
1386 | const struct cred *old, struct cred *new) | |
1387 | { | |
1388 | return call_int_hook(dentry_create_files_as, 0, dentry, mode, | |
1389 | name, old, new); | |
1390 | } | |
1391 | EXPORT_SYMBOL(security_dentry_create_files_as); | |
1392 | ||
20510f2f | 1393 | int security_inode_init_security(struct inode *inode, struct inode *dir, |
9d8f13ba MZ |
1394 | const struct qstr *qstr, |
1395 | const initxattrs initxattrs, void *fs_data) | |
20510f2f | 1396 | { |
823eb1cc MZ |
1397 | struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1]; |
1398 | struct xattr *lsm_xattr, *evm_xattr, *xattr; | |
9d8f13ba MZ |
1399 | int ret; |
1400 | ||
20510f2f | 1401 | if (unlikely(IS_PRIVATE(inode))) |
fb88c2b6 | 1402 | return 0; |
9d8f13ba | 1403 | |
9d8f13ba | 1404 | if (!initxattrs) |
e308fd3b JB |
1405 | return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, |
1406 | dir, qstr, NULL, NULL, NULL); | |
9548906b | 1407 | memset(new_xattrs, 0, sizeof(new_xattrs)); |
9d8f13ba | 1408 | lsm_xattr = new_xattrs; |
b1d9e6b0 | 1409 | ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr, |
9d8f13ba MZ |
1410 | &lsm_xattr->name, |
1411 | &lsm_xattr->value, | |
1412 | &lsm_xattr->value_len); | |
1413 | if (ret) | |
1414 | goto out; | |
823eb1cc MZ |
1415 | |
1416 | evm_xattr = lsm_xattr + 1; | |
1417 | ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr); | |
1418 | if (ret) | |
1419 | goto out; | |
9d8f13ba MZ |
1420 | ret = initxattrs(inode, new_xattrs, fs_data); |
1421 | out: | |
9548906b | 1422 | for (xattr = new_xattrs; xattr->value != NULL; xattr++) |
823eb1cc | 1423 | kfree(xattr->value); |
9d8f13ba MZ |
1424 | return (ret == -EOPNOTSUPP) ? 0 : ret; |
1425 | } | |
1426 | EXPORT_SYMBOL(security_inode_init_security); | |
1427 | ||
215b674b LG |
1428 | int security_inode_init_security_anon(struct inode *inode, |
1429 | const struct qstr *name, | |
1430 | const struct inode *context_inode) | |
1431 | { | |
1432 | return call_int_hook(inode_init_security_anon, 0, inode, name, | |
1433 | context_inode); | |
1434 | } | |
1435 | ||
9d8f13ba | 1436 | int security_old_inode_init_security(struct inode *inode, struct inode *dir, |
9548906b | 1437 | const struct qstr *qstr, const char **name, |
9d8f13ba | 1438 | void **value, size_t *len) |
20510f2f JM |
1439 | { |
1440 | if (unlikely(IS_PRIVATE(inode))) | |
30e05324 | 1441 | return -EOPNOTSUPP; |
e308fd3b JB |
1442 | return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, |
1443 | qstr, name, value, len); | |
20510f2f | 1444 | } |
9d8f13ba | 1445 | EXPORT_SYMBOL(security_old_inode_init_security); |
20510f2f | 1446 | |
be6d3e56 | 1447 | #ifdef CONFIG_SECURITY_PATH |
d3607752 | 1448 | int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode, |
be6d3e56 KT |
1449 | unsigned int dev) |
1450 | { | |
c6f493d6 | 1451 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1452 | return 0; |
f25fce3e | 1453 | return call_int_hook(path_mknod, 0, dir, dentry, mode, dev); |
be6d3e56 KT |
1454 | } |
1455 | EXPORT_SYMBOL(security_path_mknod); | |
1456 | ||
d3607752 | 1457 | int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode) |
be6d3e56 | 1458 | { |
c6f493d6 | 1459 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1460 | return 0; |
f25fce3e | 1461 | return call_int_hook(path_mkdir, 0, dir, dentry, mode); |
be6d3e56 | 1462 | } |
82140443 | 1463 | EXPORT_SYMBOL(security_path_mkdir); |
be6d3e56 | 1464 | |
989f74e0 | 1465 | int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
be6d3e56 | 1466 | { |
c6f493d6 | 1467 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1468 | return 0; |
f25fce3e | 1469 | return call_int_hook(path_rmdir, 0, dir, dentry); |
be6d3e56 KT |
1470 | } |
1471 | ||
989f74e0 | 1472 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
be6d3e56 | 1473 | { |
c6f493d6 | 1474 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1475 | return 0; |
f25fce3e | 1476 | return call_int_hook(path_unlink, 0, dir, dentry); |
be6d3e56 | 1477 | } |
82140443 | 1478 | EXPORT_SYMBOL(security_path_unlink); |
be6d3e56 | 1479 | |
d3607752 | 1480 | int security_path_symlink(const struct path *dir, struct dentry *dentry, |
be6d3e56 KT |
1481 | const char *old_name) |
1482 | { | |
c6f493d6 | 1483 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1484 | return 0; |
f25fce3e | 1485 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
be6d3e56 KT |
1486 | } |
1487 | ||
3ccee46a | 1488 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
be6d3e56 KT |
1489 | struct dentry *new_dentry) |
1490 | { | |
c6f493d6 | 1491 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
be6d3e56 | 1492 | return 0; |
f25fce3e | 1493 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
be6d3e56 KT |
1494 | } |
1495 | ||
3ccee46a AV |
1496 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
1497 | const struct path *new_dir, struct dentry *new_dentry, | |
0b3974eb | 1498 | unsigned int flags) |
be6d3e56 | 1499 | { |
c6f493d6 DH |
1500 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
1501 | (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry))))) | |
be6d3e56 | 1502 | return 0; |
da1ce067 | 1503 | |
f25fce3e | 1504 | return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir, |
100f59d9 | 1505 | new_dentry, flags); |
be6d3e56 | 1506 | } |
82140443 | 1507 | EXPORT_SYMBOL(security_path_rename); |
be6d3e56 | 1508 | |
81f4c506 | 1509 | int security_path_truncate(const struct path *path) |
be6d3e56 | 1510 | { |
c6f493d6 | 1511 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
be6d3e56 | 1512 | return 0; |
f25fce3e | 1513 | return call_int_hook(path_truncate, 0, path); |
be6d3e56 | 1514 | } |
89eda068 | 1515 | |
be01f9f2 | 1516 | int security_path_chmod(const struct path *path, umode_t mode) |
89eda068 | 1517 | { |
c6f493d6 | 1518 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
89eda068 | 1519 | return 0; |
f25fce3e | 1520 | return call_int_hook(path_chmod, 0, path, mode); |
89eda068 TH |
1521 | } |
1522 | ||
7fd25dac | 1523 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
89eda068 | 1524 | { |
c6f493d6 | 1525 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
89eda068 | 1526 | return 0; |
f25fce3e | 1527 | return call_int_hook(path_chown, 0, path, uid, gid); |
89eda068 | 1528 | } |
8b8efb44 | 1529 | |
77b286c0 | 1530 | int security_path_chroot(const struct path *path) |
8b8efb44 | 1531 | { |
f25fce3e | 1532 | return call_int_hook(path_chroot, 0, path); |
8b8efb44 | 1533 | } |
be6d3e56 KT |
1534 | #endif |
1535 | ||
4acdaf27 | 1536 | int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode) |
20510f2f JM |
1537 | { |
1538 | if (unlikely(IS_PRIVATE(dir))) | |
1539 | return 0; | |
f25fce3e | 1540 | return call_int_hook(inode_create, 0, dir, dentry, mode); |
20510f2f | 1541 | } |
800a9647 | 1542 | EXPORT_SYMBOL_GPL(security_inode_create); |
20510f2f JM |
1543 | |
1544 | int security_inode_link(struct dentry *old_dentry, struct inode *dir, | |
1545 | struct dentry *new_dentry) | |
1546 | { | |
c6f493d6 | 1547 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
20510f2f | 1548 | return 0; |
f25fce3e | 1549 | return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry); |
20510f2f JM |
1550 | } |
1551 | ||
1552 | int security_inode_unlink(struct inode *dir, struct dentry *dentry) | |
1553 | { | |
c6f493d6 | 1554 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1555 | return 0; |
f25fce3e | 1556 | return call_int_hook(inode_unlink, 0, dir, dentry); |
20510f2f JM |
1557 | } |
1558 | ||
1559 | int security_inode_symlink(struct inode *dir, struct dentry *dentry, | |
1560 | const char *old_name) | |
1561 | { | |
1562 | if (unlikely(IS_PRIVATE(dir))) | |
1563 | return 0; | |
f25fce3e | 1564 | return call_int_hook(inode_symlink, 0, dir, dentry, old_name); |
20510f2f JM |
1565 | } |
1566 | ||
18bb1db3 | 1567 | int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
20510f2f JM |
1568 | { |
1569 | if (unlikely(IS_PRIVATE(dir))) | |
1570 | return 0; | |
f25fce3e | 1571 | return call_int_hook(inode_mkdir, 0, dir, dentry, mode); |
20510f2f | 1572 | } |
800a9647 | 1573 | EXPORT_SYMBOL_GPL(security_inode_mkdir); |
20510f2f JM |
1574 | |
1575 | int security_inode_rmdir(struct inode *dir, struct dentry *dentry) | |
1576 | { | |
c6f493d6 | 1577 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1578 | return 0; |
f25fce3e | 1579 | return call_int_hook(inode_rmdir, 0, dir, dentry); |
20510f2f JM |
1580 | } |
1581 | ||
1a67aafb | 1582 | int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) |
20510f2f JM |
1583 | { |
1584 | if (unlikely(IS_PRIVATE(dir))) | |
1585 | return 0; | |
f25fce3e | 1586 | return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev); |
20510f2f JM |
1587 | } |
1588 | ||
1589 | int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, | |
0b3974eb MS |
1590 | struct inode *new_dir, struct dentry *new_dentry, |
1591 | unsigned int flags) | |
20510f2f | 1592 | { |
c6f493d6 DH |
1593 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
1594 | (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry))))) | |
20510f2f | 1595 | return 0; |
da1ce067 MS |
1596 | |
1597 | if (flags & RENAME_EXCHANGE) { | |
f25fce3e | 1598 | int err = call_int_hook(inode_rename, 0, new_dir, new_dentry, |
da1ce067 MS |
1599 | old_dir, old_dentry); |
1600 | if (err) | |
1601 | return err; | |
1602 | } | |
1603 | ||
f25fce3e | 1604 | return call_int_hook(inode_rename, 0, old_dir, old_dentry, |
20510f2f JM |
1605 | new_dir, new_dentry); |
1606 | } | |
1607 | ||
1608 | int security_inode_readlink(struct dentry *dentry) | |
1609 | { | |
c6f493d6 | 1610 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1611 | return 0; |
f25fce3e | 1612 | return call_int_hook(inode_readlink, 0, dentry); |
20510f2f JM |
1613 | } |
1614 | ||
bda0be7a N |
1615 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
1616 | bool rcu) | |
20510f2f | 1617 | { |
bda0be7a | 1618 | if (unlikely(IS_PRIVATE(inode))) |
20510f2f | 1619 | return 0; |
e22619a2 | 1620 | return call_int_hook(inode_follow_link, 0, dentry, inode, rcu); |
20510f2f JM |
1621 | } |
1622 | ||
b77b0646 | 1623 | int security_inode_permission(struct inode *inode, int mask) |
20510f2f JM |
1624 | { |
1625 | if (unlikely(IS_PRIVATE(inode))) | |
1626 | return 0; | |
f25fce3e | 1627 | return call_int_hook(inode_permission, 0, inode, mask); |
20510f2f JM |
1628 | } |
1629 | ||
c1632a0f | 1630 | int security_inode_setattr(struct mnt_idmap *idmap, |
0e363cf3 | 1631 | struct dentry *dentry, struct iattr *attr) |
20510f2f | 1632 | { |
817b54aa MZ |
1633 | int ret; |
1634 | ||
c6f493d6 | 1635 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1636 | return 0; |
f25fce3e | 1637 | ret = call_int_hook(inode_setattr, 0, dentry, attr); |
817b54aa MZ |
1638 | if (ret) |
1639 | return ret; | |
c1632a0f | 1640 | return evm_inode_setattr(idmap, dentry, attr); |
20510f2f | 1641 | } |
b1da47e2 | 1642 | EXPORT_SYMBOL_GPL(security_inode_setattr); |
20510f2f | 1643 | |
3f7036a0 | 1644 | int security_inode_getattr(const struct path *path) |
20510f2f | 1645 | { |
c6f493d6 | 1646 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
20510f2f | 1647 | return 0; |
f25fce3e | 1648 | return call_int_hook(inode_getattr, 0, path); |
20510f2f JM |
1649 | } |
1650 | ||
39f60c1c | 1651 | int security_inode_setxattr(struct mnt_idmap *idmap, |
71bc356f | 1652 | struct dentry *dentry, const char *name, |
8f0cfa52 | 1653 | const void *value, size_t size, int flags) |
20510f2f | 1654 | { |
3e1be52d MZ |
1655 | int ret; |
1656 | ||
c6f493d6 | 1657 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1658 | return 0; |
b1d9e6b0 CS |
1659 | /* |
1660 | * SELinux and Smack integrate the cap call, | |
1661 | * so assume that all LSMs supplying this call do so. | |
1662 | */ | |
39f60c1c | 1663 | ret = call_int_hook(inode_setxattr, 1, idmap, dentry, name, value, |
71bc356f | 1664 | size, flags); |
b1d9e6b0 CS |
1665 | |
1666 | if (ret == 1) | |
1667 | ret = cap_inode_setxattr(dentry, name, value, size, flags); | |
42c63330 MZ |
1668 | if (ret) |
1669 | return ret; | |
1670 | ret = ima_inode_setxattr(dentry, name, value, size); | |
3e1be52d MZ |
1671 | if (ret) |
1672 | return ret; | |
39f60c1c | 1673 | return evm_inode_setxattr(idmap, dentry, name, value, size); |
20510f2f JM |
1674 | } |
1675 | ||
700b7940 | 1676 | int security_inode_set_acl(struct mnt_idmap *idmap, |
72b3897e CB |
1677 | struct dentry *dentry, const char *acl_name, |
1678 | struct posix_acl *kacl) | |
1679 | { | |
e61b135f CB |
1680 | int ret; |
1681 | ||
72b3897e CB |
1682 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
1683 | return 0; | |
700b7940 | 1684 | ret = call_int_hook(inode_set_acl, 0, idmap, dentry, acl_name, |
e61b135f CB |
1685 | kacl); |
1686 | if (ret) | |
1687 | return ret; | |
700b7940 | 1688 | ret = ima_inode_set_acl(idmap, dentry, acl_name, kacl); |
e61b135f CB |
1689 | if (ret) |
1690 | return ret; | |
700b7940 | 1691 | return evm_inode_set_acl(idmap, dentry, acl_name, kacl); |
72b3897e CB |
1692 | } |
1693 | ||
700b7940 | 1694 | int security_inode_get_acl(struct mnt_idmap *idmap, |
72b3897e CB |
1695 | struct dentry *dentry, const char *acl_name) |
1696 | { | |
1697 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) | |
1698 | return 0; | |
700b7940 | 1699 | return call_int_hook(inode_get_acl, 0, idmap, dentry, acl_name); |
72b3897e CB |
1700 | } |
1701 | ||
700b7940 | 1702 | int security_inode_remove_acl(struct mnt_idmap *idmap, |
72b3897e CB |
1703 | struct dentry *dentry, const char *acl_name) |
1704 | { | |
e61b135f CB |
1705 | int ret; |
1706 | ||
72b3897e CB |
1707 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
1708 | return 0; | |
700b7940 | 1709 | ret = call_int_hook(inode_remove_acl, 0, idmap, dentry, acl_name); |
e61b135f CB |
1710 | if (ret) |
1711 | return ret; | |
700b7940 | 1712 | ret = ima_inode_remove_acl(idmap, dentry, acl_name); |
e61b135f CB |
1713 | if (ret) |
1714 | return ret; | |
700b7940 | 1715 | return evm_inode_remove_acl(idmap, dentry, acl_name); |
72b3897e CB |
1716 | } |
1717 | ||
8f0cfa52 DH |
1718 | void security_inode_post_setxattr(struct dentry *dentry, const char *name, |
1719 | const void *value, size_t size, int flags) | |
20510f2f | 1720 | { |
c6f493d6 | 1721 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1722 | return; |
f25fce3e | 1723 | call_void_hook(inode_post_setxattr, dentry, name, value, size, flags); |
3e1be52d | 1724 | evm_inode_post_setxattr(dentry, name, value, size); |
20510f2f JM |
1725 | } |
1726 | ||
8f0cfa52 | 1727 | int security_inode_getxattr(struct dentry *dentry, const char *name) |
20510f2f | 1728 | { |
c6f493d6 | 1729 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1730 | return 0; |
f25fce3e | 1731 | return call_int_hook(inode_getxattr, 0, dentry, name); |
20510f2f JM |
1732 | } |
1733 | ||
1734 | int security_inode_listxattr(struct dentry *dentry) | |
1735 | { | |
c6f493d6 | 1736 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1737 | return 0; |
f25fce3e | 1738 | return call_int_hook(inode_listxattr, 0, dentry); |
20510f2f JM |
1739 | } |
1740 | ||
39f60c1c | 1741 | int security_inode_removexattr(struct mnt_idmap *idmap, |
71bc356f | 1742 | struct dentry *dentry, const char *name) |
20510f2f | 1743 | { |
3e1be52d MZ |
1744 | int ret; |
1745 | ||
c6f493d6 | 1746 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 1747 | return 0; |
b1d9e6b0 CS |
1748 | /* |
1749 | * SELinux and Smack integrate the cap call, | |
1750 | * so assume that all LSMs supplying this call do so. | |
1751 | */ | |
39f60c1c | 1752 | ret = call_int_hook(inode_removexattr, 1, idmap, dentry, name); |
b1d9e6b0 | 1753 | if (ret == 1) |
39f60c1c | 1754 | ret = cap_inode_removexattr(idmap, dentry, name); |
42c63330 MZ |
1755 | if (ret) |
1756 | return ret; | |
1757 | ret = ima_inode_removexattr(dentry, name); | |
3e1be52d MZ |
1758 | if (ret) |
1759 | return ret; | |
39f60c1c | 1760 | return evm_inode_removexattr(idmap, dentry, name); |
20510f2f JM |
1761 | } |
1762 | ||
b5376771 SH |
1763 | int security_inode_need_killpriv(struct dentry *dentry) |
1764 | { | |
f25fce3e | 1765 | return call_int_hook(inode_need_killpriv, 0, dentry); |
b5376771 SH |
1766 | } |
1767 | ||
39f60c1c | 1768 | int security_inode_killpriv(struct mnt_idmap *idmap, |
71bc356f | 1769 | struct dentry *dentry) |
b5376771 | 1770 | { |
39f60c1c | 1771 | return call_int_hook(inode_killpriv, 0, idmap, dentry); |
b5376771 SH |
1772 | } |
1773 | ||
4609e1f1 | 1774 | int security_inode_getsecurity(struct mnt_idmap *idmap, |
71bc356f CB |
1775 | struct inode *inode, const char *name, |
1776 | void **buffer, bool alloc) | |
20510f2f | 1777 | { |
2885c1e3 CS |
1778 | struct security_hook_list *hp; |
1779 | int rc; | |
1780 | ||
20510f2f | 1781 | if (unlikely(IS_PRIVATE(inode))) |
98e828a0 | 1782 | return LSM_RET_DEFAULT(inode_getsecurity); |
2885c1e3 CS |
1783 | /* |
1784 | * Only one module will provide an attribute with a given name. | |
1785 | */ | |
df0ce173 | 1786 | hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { |
4609e1f1 | 1787 | rc = hp->hook.inode_getsecurity(idmap, inode, name, buffer, alloc); |
98e828a0 | 1788 | if (rc != LSM_RET_DEFAULT(inode_getsecurity)) |
2885c1e3 CS |
1789 | return rc; |
1790 | } | |
98e828a0 | 1791 | return LSM_RET_DEFAULT(inode_getsecurity); |
20510f2f JM |
1792 | } |
1793 | ||
1794 | int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) | |
1795 | { | |
2885c1e3 CS |
1796 | struct security_hook_list *hp; |
1797 | int rc; | |
1798 | ||
20510f2f | 1799 | if (unlikely(IS_PRIVATE(inode))) |
98e828a0 | 1800 | return LSM_RET_DEFAULT(inode_setsecurity); |
2885c1e3 CS |
1801 | /* |
1802 | * Only one module will provide an attribute with a given name. | |
1803 | */ | |
df0ce173 | 1804 | hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) { |
2885c1e3 CS |
1805 | rc = hp->hook.inode_setsecurity(inode, name, value, size, |
1806 | flags); | |
98e828a0 | 1807 | if (rc != LSM_RET_DEFAULT(inode_setsecurity)) |
2885c1e3 CS |
1808 | return rc; |
1809 | } | |
98e828a0 | 1810 | return LSM_RET_DEFAULT(inode_setsecurity); |
20510f2f JM |
1811 | } |
1812 | ||
1813 | int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size) | |
1814 | { | |
1815 | if (unlikely(IS_PRIVATE(inode))) | |
1816 | return 0; | |
f25fce3e | 1817 | return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size); |
20510f2f | 1818 | } |
c9bccef6 | 1819 | EXPORT_SYMBOL(security_inode_listsecurity); |
20510f2f | 1820 | |
d6335d77 | 1821 | void security_inode_getsecid(struct inode *inode, u32 *secid) |
8a076191 | 1822 | { |
f25fce3e | 1823 | call_void_hook(inode_getsecid, inode, secid); |
8a076191 AD |
1824 | } |
1825 | ||
d8ad8b49 VG |
1826 | int security_inode_copy_up(struct dentry *src, struct cred **new) |
1827 | { | |
1828 | return call_int_hook(inode_copy_up, 0, src, new); | |
1829 | } | |
1830 | EXPORT_SYMBOL(security_inode_copy_up); | |
1831 | ||
121ab822 VG |
1832 | int security_inode_copy_up_xattr(const char *name) |
1833 | { | |
23e390cd KS |
1834 | struct security_hook_list *hp; |
1835 | int rc; | |
1836 | ||
1837 | /* | |
1838 | * The implementation can return 0 (accept the xattr), 1 (discard the | |
1839 | * xattr), -EOPNOTSUPP if it does not know anything about the xattr or | |
1840 | * any other error code incase of an error. | |
1841 | */ | |
1842 | hlist_for_each_entry(hp, | |
1843 | &security_hook_heads.inode_copy_up_xattr, list) { | |
1844 | rc = hp->hook.inode_copy_up_xattr(name); | |
1845 | if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr)) | |
1846 | return rc; | |
1847 | } | |
1848 | ||
1849 | return LSM_RET_DEFAULT(inode_copy_up_xattr); | |
121ab822 VG |
1850 | } |
1851 | EXPORT_SYMBOL(security_inode_copy_up_xattr); | |
1852 | ||
b230d5ab OM |
1853 | int security_kernfs_init_security(struct kernfs_node *kn_dir, |
1854 | struct kernfs_node *kn) | |
1855 | { | |
1856 | return call_int_hook(kernfs_init_security, 0, kn_dir, kn); | |
1857 | } | |
1858 | ||
20510f2f JM |
1859 | int security_file_permission(struct file *file, int mask) |
1860 | { | |
c4ec54b4 EP |
1861 | int ret; |
1862 | ||
f25fce3e | 1863 | ret = call_int_hook(file_permission, 0, file, mask); |
c4ec54b4 EP |
1864 | if (ret) |
1865 | return ret; | |
1866 | ||
1867 | return fsnotify_perm(file, mask); | |
20510f2f JM |
1868 | } |
1869 | ||
1870 | int security_file_alloc(struct file *file) | |
1871 | { | |
33bf60ca CS |
1872 | int rc = lsm_file_alloc(file); |
1873 | ||
1874 | if (rc) | |
1875 | return rc; | |
1876 | rc = call_int_hook(file_alloc_security, 0, file); | |
1877 | if (unlikely(rc)) | |
1878 | security_file_free(file); | |
1879 | return rc; | |
20510f2f JM |
1880 | } |
1881 | ||
1882 | void security_file_free(struct file *file) | |
1883 | { | |
33bf60ca CS |
1884 | void *blob; |
1885 | ||
f25fce3e | 1886 | call_void_hook(file_free_security, file); |
33bf60ca CS |
1887 | |
1888 | blob = file->f_security; | |
1889 | if (blob) { | |
1890 | file->f_security = NULL; | |
1891 | kmem_cache_free(lsm_file_cache, blob); | |
1892 | } | |
20510f2f JM |
1893 | } |
1894 | ||
1895 | int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
1896 | { | |
f25fce3e | 1897 | return call_int_hook(file_ioctl, 0, file, cmd, arg); |
20510f2f | 1898 | } |
292f902a | 1899 | EXPORT_SYMBOL_GPL(security_file_ioctl); |
20510f2f | 1900 | |
98de59bf | 1901 | static inline unsigned long mmap_prot(struct file *file, unsigned long prot) |
20510f2f | 1902 | { |
8b3ec681 | 1903 | /* |
98de59bf AV |
1904 | * Does we have PROT_READ and does the application expect |
1905 | * it to imply PROT_EXEC? If not, nothing to talk about... | |
8b3ec681 | 1906 | */ |
98de59bf AV |
1907 | if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ) |
1908 | return prot; | |
8b3ec681 | 1909 | if (!(current->personality & READ_IMPLIES_EXEC)) |
98de59bf AV |
1910 | return prot; |
1911 | /* | |
1912 | * if that's an anonymous mapping, let it. | |
1913 | */ | |
1914 | if (!file) | |
1915 | return prot | PROT_EXEC; | |
1916 | /* | |
1917 | * ditto if it's not on noexec mount, except that on !MMU we need | |
b4caecd4 | 1918 | * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case |
98de59bf | 1919 | */ |
90f8572b | 1920 | if (!path_noexec(&file->f_path)) { |
8b3ec681 | 1921 | #ifndef CONFIG_MMU |
b4caecd4 CH |
1922 | if (file->f_op->mmap_capabilities) { |
1923 | unsigned caps = file->f_op->mmap_capabilities(file); | |
1924 | if (!(caps & NOMMU_MAP_EXEC)) | |
1925 | return prot; | |
1926 | } | |
8b3ec681 | 1927 | #endif |
98de59bf | 1928 | return prot | PROT_EXEC; |
8b3ec681 | 1929 | } |
98de59bf AV |
1930 | /* anything on noexec mount won't get PROT_EXEC */ |
1931 | return prot; | |
1932 | } | |
1933 | ||
1934 | int security_mmap_file(struct file *file, unsigned long prot, | |
1935 | unsigned long flags) | |
1936 | { | |
4971c268 | 1937 | unsigned long prot_adj = mmap_prot(file, prot); |
98de59bf | 1938 | int ret; |
4971c268 RS |
1939 | |
1940 | ret = call_int_hook(mmap_file, 0, file, prot, prot_adj, flags); | |
6c21a7fb MZ |
1941 | if (ret) |
1942 | return ret; | |
4971c268 | 1943 | return ima_file_mmap(file, prot, prot_adj, flags); |
20510f2f JM |
1944 | } |
1945 | ||
e5467859 AV |
1946 | int security_mmap_addr(unsigned long addr) |
1947 | { | |
f25fce3e | 1948 | return call_int_hook(mmap_addr, 0, addr); |
e5467859 AV |
1949 | } |
1950 | ||
20510f2f JM |
1951 | int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, |
1952 | unsigned long prot) | |
1953 | { | |
8eb613c0 MZ |
1954 | int ret; |
1955 | ||
1956 | ret = call_int_hook(file_mprotect, 0, vma, reqprot, prot); | |
1957 | if (ret) | |
1958 | return ret; | |
1959 | return ima_file_mprotect(vma, prot); | |
20510f2f JM |
1960 | } |
1961 | ||
1962 | int security_file_lock(struct file *file, unsigned int cmd) | |
1963 | { | |
f25fce3e | 1964 | return call_int_hook(file_lock, 0, file, cmd); |
20510f2f JM |
1965 | } |
1966 | ||
1967 | int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |
1968 | { | |
f25fce3e | 1969 | return call_int_hook(file_fcntl, 0, file, cmd, arg); |
20510f2f JM |
1970 | } |
1971 | ||
e0b93edd | 1972 | void security_file_set_fowner(struct file *file) |
20510f2f | 1973 | { |
f25fce3e | 1974 | call_void_hook(file_set_fowner, file); |
20510f2f JM |
1975 | } |
1976 | ||
1977 | int security_file_send_sigiotask(struct task_struct *tsk, | |
1978 | struct fown_struct *fown, int sig) | |
1979 | { | |
f25fce3e | 1980 | return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig); |
20510f2f JM |
1981 | } |
1982 | ||
1983 | int security_file_receive(struct file *file) | |
1984 | { | |
f25fce3e | 1985 | return call_int_hook(file_receive, 0, file); |
20510f2f JM |
1986 | } |
1987 | ||
e3f20ae2 | 1988 | int security_file_open(struct file *file) |
20510f2f | 1989 | { |
c4ec54b4 EP |
1990 | int ret; |
1991 | ||
94817692 | 1992 | ret = call_int_hook(file_open, 0, file); |
c4ec54b4 EP |
1993 | if (ret) |
1994 | return ret; | |
1995 | ||
1996 | return fsnotify_perm(file, MAY_OPEN); | |
20510f2f JM |
1997 | } |
1998 | ||
3350607d GN |
1999 | int security_file_truncate(struct file *file) |
2000 | { | |
2001 | return call_int_hook(file_truncate, 0, file); | |
2002 | } | |
2003 | ||
e4e55b47 TH |
2004 | int security_task_alloc(struct task_struct *task, unsigned long clone_flags) |
2005 | { | |
f4ad8f2c CS |
2006 | int rc = lsm_task_alloc(task); |
2007 | ||
2008 | if (rc) | |
2009 | return rc; | |
2010 | rc = call_int_hook(task_alloc, 0, task, clone_flags); | |
2011 | if (unlikely(rc)) | |
2012 | security_task_free(task); | |
2013 | return rc; | |
e4e55b47 TH |
2014 | } |
2015 | ||
1a2a4d06 KC |
2016 | void security_task_free(struct task_struct *task) |
2017 | { | |
f25fce3e | 2018 | call_void_hook(task_free, task); |
f4ad8f2c CS |
2019 | |
2020 | kfree(task->security); | |
2021 | task->security = NULL; | |
1a2a4d06 KC |
2022 | } |
2023 | ||
ee18d64c DH |
2024 | int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) |
2025 | { | |
bbd3662a CS |
2026 | int rc = lsm_cred_alloc(cred, gfp); |
2027 | ||
2028 | if (rc) | |
2029 | return rc; | |
2030 | ||
2031 | rc = call_int_hook(cred_alloc_blank, 0, cred, gfp); | |
33bf60ca | 2032 | if (unlikely(rc)) |
bbd3662a CS |
2033 | security_cred_free(cred); |
2034 | return rc; | |
ee18d64c DH |
2035 | } |
2036 | ||
d84f4f99 | 2037 | void security_cred_free(struct cred *cred) |
20510f2f | 2038 | { |
a5795fd3 JM |
2039 | /* |
2040 | * There is a failure case in prepare_creds() that | |
2041 | * may result in a call here with ->security being NULL. | |
2042 | */ | |
2043 | if (unlikely(cred->security == NULL)) | |
2044 | return; | |
2045 | ||
f25fce3e | 2046 | call_void_hook(cred_free, cred); |
bbd3662a CS |
2047 | |
2048 | kfree(cred->security); | |
2049 | cred->security = NULL; | |
20510f2f JM |
2050 | } |
2051 | ||
d84f4f99 | 2052 | int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp) |
20510f2f | 2053 | { |
bbd3662a CS |
2054 | int rc = lsm_cred_alloc(new, gfp); |
2055 | ||
2056 | if (rc) | |
2057 | return rc; | |
2058 | ||
2059 | rc = call_int_hook(cred_prepare, 0, new, old, gfp); | |
33bf60ca | 2060 | if (unlikely(rc)) |
bbd3662a CS |
2061 | security_cred_free(new); |
2062 | return rc; | |
d84f4f99 DH |
2063 | } |
2064 | ||
ee18d64c DH |
2065 | void security_transfer_creds(struct cred *new, const struct cred *old) |
2066 | { | |
f25fce3e | 2067 | call_void_hook(cred_transfer, new, old); |
ee18d64c DH |
2068 | } |
2069 | ||
3ec30113 MG |
2070 | void security_cred_getsecid(const struct cred *c, u32 *secid) |
2071 | { | |
2072 | *secid = 0; | |
2073 | call_void_hook(cred_getsecid, c, secid); | |
2074 | } | |
2075 | EXPORT_SYMBOL(security_cred_getsecid); | |
2076 | ||
3a3b7ce9 DH |
2077 | int security_kernel_act_as(struct cred *new, u32 secid) |
2078 | { | |
f25fce3e | 2079 | return call_int_hook(kernel_act_as, 0, new, secid); |
3a3b7ce9 DH |
2080 | } |
2081 | ||
2082 | int security_kernel_create_files_as(struct cred *new, struct inode *inode) | |
2083 | { | |
f25fce3e | 2084 | return call_int_hook(kernel_create_files_as, 0, new, inode); |
3a3b7ce9 DH |
2085 | } |
2086 | ||
dd8dbf2e | 2087 | int security_kernel_module_request(char *kmod_name) |
9188499c | 2088 | { |
6eb864c1 MK |
2089 | int ret; |
2090 | ||
2091 | ret = call_int_hook(kernel_module_request, 0, kmod_name); | |
2092 | if (ret) | |
2093 | return ret; | |
2094 | return integrity_kernel_module_request(kmod_name); | |
9188499c EP |
2095 | } |
2096 | ||
2039bda1 KC |
2097 | int security_kernel_read_file(struct file *file, enum kernel_read_file_id id, |
2098 | bool contents) | |
39eeb4fb MZ |
2099 | { |
2100 | int ret; | |
2101 | ||
2039bda1 | 2102 | ret = call_int_hook(kernel_read_file, 0, file, id, contents); |
39eeb4fb MZ |
2103 | if (ret) |
2104 | return ret; | |
2039bda1 | 2105 | return ima_read_file(file, id, contents); |
39eeb4fb MZ |
2106 | } |
2107 | EXPORT_SYMBOL_GPL(security_kernel_read_file); | |
2108 | ||
bc8ca5b9 MZ |
2109 | int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, |
2110 | enum kernel_read_file_id id) | |
b44a7dfc | 2111 | { |
cf222217 MZ |
2112 | int ret; |
2113 | ||
2114 | ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id); | |
2115 | if (ret) | |
2116 | return ret; | |
2117 | return ima_post_read_file(file, buf, size, id); | |
b44a7dfc MZ |
2118 | } |
2119 | EXPORT_SYMBOL_GPL(security_kernel_post_read_file); | |
2120 | ||
b64fcae7 | 2121 | int security_kernel_load_data(enum kernel_load_data_id id, bool contents) |
377179cd | 2122 | { |
16c267aa MZ |
2123 | int ret; |
2124 | ||
b64fcae7 | 2125 | ret = call_int_hook(kernel_load_data, 0, id, contents); |
16c267aa MZ |
2126 | if (ret) |
2127 | return ret; | |
b64fcae7 | 2128 | return ima_load_data(id, contents); |
377179cd | 2129 | } |
83a68a06 | 2130 | EXPORT_SYMBOL_GPL(security_kernel_load_data); |
377179cd | 2131 | |
b64fcae7 KC |
2132 | int security_kernel_post_load_data(char *buf, loff_t size, |
2133 | enum kernel_load_data_id id, | |
2134 | char *description) | |
2135 | { | |
2136 | int ret; | |
2137 | ||
2138 | ret = call_int_hook(kernel_post_load_data, 0, buf, size, id, | |
2139 | description); | |
2140 | if (ret) | |
2141 | return ret; | |
2142 | return ima_post_load_data(buf, size, id, description); | |
2143 | } | |
2144 | EXPORT_SYMBOL_GPL(security_kernel_post_load_data); | |
2145 | ||
d84f4f99 DH |
2146 | int security_task_fix_setuid(struct cred *new, const struct cred *old, |
2147 | int flags) | |
20510f2f | 2148 | { |
f25fce3e | 2149 | return call_int_hook(task_fix_setuid, 0, new, old, flags); |
20510f2f JM |
2150 | } |
2151 | ||
39030e13 TC |
2152 | int security_task_fix_setgid(struct cred *new, const struct cred *old, |
2153 | int flags) | |
2154 | { | |
2155 | return call_int_hook(task_fix_setgid, 0, new, old, flags); | |
2156 | } | |
2157 | ||
fcfe0ac2 MM |
2158 | int security_task_fix_setgroups(struct cred *new, const struct cred *old) |
2159 | { | |
2160 | return call_int_hook(task_fix_setgroups, 0, new, old); | |
2161 | } | |
2162 | ||
20510f2f JM |
2163 | int security_task_setpgid(struct task_struct *p, pid_t pgid) |
2164 | { | |
f25fce3e | 2165 | return call_int_hook(task_setpgid, 0, p, pgid); |
20510f2f JM |
2166 | } |
2167 | ||
2168 | int security_task_getpgid(struct task_struct *p) | |
2169 | { | |
f25fce3e | 2170 | return call_int_hook(task_getpgid, 0, p); |
20510f2f JM |
2171 | } |
2172 | ||
2173 | int security_task_getsid(struct task_struct *p) | |
2174 | { | |
f25fce3e | 2175 | return call_int_hook(task_getsid, 0, p); |
20510f2f JM |
2176 | } |
2177 | ||
6326948f | 2178 | void security_current_getsecid_subj(u32 *secid) |
20510f2f | 2179 | { |
b1d9e6b0 | 2180 | *secid = 0; |
6326948f | 2181 | call_void_hook(current_getsecid_subj, secid); |
20510f2f | 2182 | } |
6326948f | 2183 | EXPORT_SYMBOL(security_current_getsecid_subj); |
4ebd7651 PM |
2184 | |
2185 | void security_task_getsecid_obj(struct task_struct *p, u32 *secid) | |
2186 | { | |
2187 | *secid = 0; | |
2188 | call_void_hook(task_getsecid_obj, p, secid); | |
2189 | } | |
2190 | EXPORT_SYMBOL(security_task_getsecid_obj); | |
20510f2f | 2191 | |
20510f2f JM |
2192 | int security_task_setnice(struct task_struct *p, int nice) |
2193 | { | |
f25fce3e | 2194 | return call_int_hook(task_setnice, 0, p, nice); |
20510f2f JM |
2195 | } |
2196 | ||
2197 | int security_task_setioprio(struct task_struct *p, int ioprio) | |
2198 | { | |
f25fce3e | 2199 | return call_int_hook(task_setioprio, 0, p, ioprio); |
20510f2f JM |
2200 | } |
2201 | ||
2202 | int security_task_getioprio(struct task_struct *p) | |
2203 | { | |
f25fce3e | 2204 | return call_int_hook(task_getioprio, 0, p); |
20510f2f JM |
2205 | } |
2206 | ||
791ec491 SS |
2207 | int security_task_prlimit(const struct cred *cred, const struct cred *tcred, |
2208 | unsigned int flags) | |
2209 | { | |
2210 | return call_int_hook(task_prlimit, 0, cred, tcred, flags); | |
2211 | } | |
2212 | ||
8fd00b4d JS |
2213 | int security_task_setrlimit(struct task_struct *p, unsigned int resource, |
2214 | struct rlimit *new_rlim) | |
20510f2f | 2215 | { |
f25fce3e | 2216 | return call_int_hook(task_setrlimit, 0, p, resource, new_rlim); |
20510f2f JM |
2217 | } |
2218 | ||
b0ae1981 | 2219 | int security_task_setscheduler(struct task_struct *p) |
20510f2f | 2220 | { |
f25fce3e | 2221 | return call_int_hook(task_setscheduler, 0, p); |
20510f2f JM |
2222 | } |
2223 | ||
2224 | int security_task_getscheduler(struct task_struct *p) | |
2225 | { | |
f25fce3e | 2226 | return call_int_hook(task_getscheduler, 0, p); |
20510f2f JM |
2227 | } |
2228 | ||
2229 | int security_task_movememory(struct task_struct *p) | |
2230 | { | |
f25fce3e | 2231 | return call_int_hook(task_movememory, 0, p); |
20510f2f JM |
2232 | } |
2233 | ||
ae7795bc | 2234 | int security_task_kill(struct task_struct *p, struct kernel_siginfo *info, |
6b4f3d01 | 2235 | int sig, const struct cred *cred) |
20510f2f | 2236 | { |
6b4f3d01 | 2237 | return call_int_hook(task_kill, 0, p, info, sig, cred); |
20510f2f JM |
2238 | } |
2239 | ||
20510f2f | 2240 | int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, |
d84f4f99 | 2241 | unsigned long arg4, unsigned long arg5) |
20510f2f | 2242 | { |
b1d9e6b0 | 2243 | int thisrc; |
98e828a0 | 2244 | int rc = LSM_RET_DEFAULT(task_prctl); |
b1d9e6b0 CS |
2245 | struct security_hook_list *hp; |
2246 | ||
df0ce173 | 2247 | hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) { |
b1d9e6b0 | 2248 | thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5); |
98e828a0 | 2249 | if (thisrc != LSM_RET_DEFAULT(task_prctl)) { |
b1d9e6b0 CS |
2250 | rc = thisrc; |
2251 | if (thisrc != 0) | |
2252 | break; | |
2253 | } | |
2254 | } | |
2255 | return rc; | |
20510f2f JM |
2256 | } |
2257 | ||
2258 | void security_task_to_inode(struct task_struct *p, struct inode *inode) | |
2259 | { | |
f25fce3e | 2260 | call_void_hook(task_to_inode, p, inode); |
20510f2f JM |
2261 | } |
2262 | ||
7cd4c5c2 FL |
2263 | int security_create_user_ns(const struct cred *cred) |
2264 | { | |
2265 | return call_int_hook(userns_create, 0, cred); | |
2266 | } | |
20510f2f JM |
2267 | |
2268 | int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) | |
2269 | { | |
f25fce3e | 2270 | return call_int_hook(ipc_permission, 0, ipcp, flag); |
20510f2f JM |
2271 | } |
2272 | ||
8a076191 AD |
2273 | void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) |
2274 | { | |
b1d9e6b0 | 2275 | *secid = 0; |
f25fce3e | 2276 | call_void_hook(ipc_getsecid, ipcp, secid); |
8a076191 AD |
2277 | } |
2278 | ||
20510f2f JM |
2279 | int security_msg_msg_alloc(struct msg_msg *msg) |
2280 | { | |
ecd5f82e CS |
2281 | int rc = lsm_msg_msg_alloc(msg); |
2282 | ||
2283 | if (unlikely(rc)) | |
2284 | return rc; | |
2285 | rc = call_int_hook(msg_msg_alloc_security, 0, msg); | |
2286 | if (unlikely(rc)) | |
2287 | security_msg_msg_free(msg); | |
2288 | return rc; | |
20510f2f JM |
2289 | } |
2290 | ||
2291 | void security_msg_msg_free(struct msg_msg *msg) | |
2292 | { | |
f25fce3e | 2293 | call_void_hook(msg_msg_free_security, msg); |
ecd5f82e CS |
2294 | kfree(msg->security); |
2295 | msg->security = NULL; | |
20510f2f JM |
2296 | } |
2297 | ||
d8c6e854 | 2298 | int security_msg_queue_alloc(struct kern_ipc_perm *msq) |
20510f2f | 2299 | { |
ecd5f82e CS |
2300 | int rc = lsm_ipc_alloc(msq); |
2301 | ||
2302 | if (unlikely(rc)) | |
2303 | return rc; | |
2304 | rc = call_int_hook(msg_queue_alloc_security, 0, msq); | |
2305 | if (unlikely(rc)) | |
2306 | security_msg_queue_free(msq); | |
2307 | return rc; | |
20510f2f JM |
2308 | } |
2309 | ||
d8c6e854 | 2310 | void security_msg_queue_free(struct kern_ipc_perm *msq) |
20510f2f | 2311 | { |
f25fce3e | 2312 | call_void_hook(msg_queue_free_security, msq); |
ecd5f82e CS |
2313 | kfree(msq->security); |
2314 | msq->security = NULL; | |
20510f2f JM |
2315 | } |
2316 | ||
d8c6e854 | 2317 | int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg) |
20510f2f | 2318 | { |
f25fce3e | 2319 | return call_int_hook(msg_queue_associate, 0, msq, msqflg); |
20510f2f JM |
2320 | } |
2321 | ||
d8c6e854 | 2322 | int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd) |
20510f2f | 2323 | { |
f25fce3e | 2324 | return call_int_hook(msg_queue_msgctl, 0, msq, cmd); |
20510f2f JM |
2325 | } |
2326 | ||
d8c6e854 | 2327 | int security_msg_queue_msgsnd(struct kern_ipc_perm *msq, |
20510f2f JM |
2328 | struct msg_msg *msg, int msqflg) |
2329 | { | |
f25fce3e | 2330 | return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg); |
20510f2f JM |
2331 | } |
2332 | ||
d8c6e854 | 2333 | int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg, |
20510f2f JM |
2334 | struct task_struct *target, long type, int mode) |
2335 | { | |
f25fce3e | 2336 | return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode); |
20510f2f JM |
2337 | } |
2338 | ||
7191adff | 2339 | int security_shm_alloc(struct kern_ipc_perm *shp) |
20510f2f | 2340 | { |
ecd5f82e CS |
2341 | int rc = lsm_ipc_alloc(shp); |
2342 | ||
2343 | if (unlikely(rc)) | |
2344 | return rc; | |
2345 | rc = call_int_hook(shm_alloc_security, 0, shp); | |
2346 | if (unlikely(rc)) | |
2347 | security_shm_free(shp); | |
2348 | return rc; | |
20510f2f JM |
2349 | } |
2350 | ||
7191adff | 2351 | void security_shm_free(struct kern_ipc_perm *shp) |
20510f2f | 2352 | { |
f25fce3e | 2353 | call_void_hook(shm_free_security, shp); |
ecd5f82e CS |
2354 | kfree(shp->security); |
2355 | shp->security = NULL; | |
20510f2f JM |
2356 | } |
2357 | ||
7191adff | 2358 | int security_shm_associate(struct kern_ipc_perm *shp, int shmflg) |
20510f2f | 2359 | { |
f25fce3e | 2360 | return call_int_hook(shm_associate, 0, shp, shmflg); |
20510f2f JM |
2361 | } |
2362 | ||
7191adff | 2363 | int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd) |
20510f2f | 2364 | { |
f25fce3e | 2365 | return call_int_hook(shm_shmctl, 0, shp, cmd); |
20510f2f JM |
2366 | } |
2367 | ||
7191adff | 2368 | int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg) |
20510f2f | 2369 | { |
f25fce3e | 2370 | return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg); |
20510f2f JM |
2371 | } |
2372 | ||
aefad959 | 2373 | int security_sem_alloc(struct kern_ipc_perm *sma) |
20510f2f | 2374 | { |
ecd5f82e CS |
2375 | int rc = lsm_ipc_alloc(sma); |
2376 | ||
2377 | if (unlikely(rc)) | |
2378 | return rc; | |
2379 | rc = call_int_hook(sem_alloc_security, 0, sma); | |
2380 | if (unlikely(rc)) | |
2381 | security_sem_free(sma); | |
2382 | return rc; | |
20510f2f JM |
2383 | } |
2384 | ||
aefad959 | 2385 | void security_sem_free(struct kern_ipc_perm *sma) |
20510f2f | 2386 | { |
f25fce3e | 2387 | call_void_hook(sem_free_security, sma); |
ecd5f82e CS |
2388 | kfree(sma->security); |
2389 | sma->security = NULL; | |
20510f2f JM |
2390 | } |
2391 | ||
aefad959 | 2392 | int security_sem_associate(struct kern_ipc_perm *sma, int semflg) |
20510f2f | 2393 | { |
f25fce3e | 2394 | return call_int_hook(sem_associate, 0, sma, semflg); |
20510f2f JM |
2395 | } |
2396 | ||
aefad959 | 2397 | int security_sem_semctl(struct kern_ipc_perm *sma, int cmd) |
20510f2f | 2398 | { |
f25fce3e | 2399 | return call_int_hook(sem_semctl, 0, sma, cmd); |
20510f2f JM |
2400 | } |
2401 | ||
aefad959 | 2402 | int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, |
20510f2f JM |
2403 | unsigned nsops, int alter) |
2404 | { | |
f25fce3e | 2405 | return call_int_hook(sem_semop, 0, sma, sops, nsops, alter); |
20510f2f JM |
2406 | } |
2407 | ||
2408 | void security_d_instantiate(struct dentry *dentry, struct inode *inode) | |
2409 | { | |
2410 | if (unlikely(inode && IS_PRIVATE(inode))) | |
2411 | return; | |
f25fce3e | 2412 | call_void_hook(d_instantiate, dentry, inode); |
20510f2f JM |
2413 | } |
2414 | EXPORT_SYMBOL(security_d_instantiate); | |
2415 | ||
c8e477c6 AV |
2416 | int security_getprocattr(struct task_struct *p, const char *lsm, |
2417 | const char *name, char **value) | |
20510f2f | 2418 | { |
6d9c939d CS |
2419 | struct security_hook_list *hp; |
2420 | ||
2421 | hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { | |
2422 | if (lsm != NULL && strcmp(lsm, hp->lsm)) | |
2423 | continue; | |
2424 | return hp->hook.getprocattr(p, name, value); | |
2425 | } | |
98e828a0 | 2426 | return LSM_RET_DEFAULT(getprocattr); |
20510f2f JM |
2427 | } |
2428 | ||
6d9c939d CS |
2429 | int security_setprocattr(const char *lsm, const char *name, void *value, |
2430 | size_t size) | |
20510f2f | 2431 | { |
6d9c939d CS |
2432 | struct security_hook_list *hp; |
2433 | ||
2434 | hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) { | |
2435 | if (lsm != NULL && strcmp(lsm, hp->lsm)) | |
2436 | continue; | |
2437 | return hp->hook.setprocattr(name, value, size); | |
2438 | } | |
98e828a0 | 2439 | return LSM_RET_DEFAULT(setprocattr); |
20510f2f JM |
2440 | } |
2441 | ||
2442 | int security_netlink_send(struct sock *sk, struct sk_buff *skb) | |
2443 | { | |
f25fce3e | 2444 | return call_int_hook(netlink_send, 0, sk, skb); |
20510f2f | 2445 | } |
20510f2f | 2446 | |
746df9b5 DQ |
2447 | int security_ismaclabel(const char *name) |
2448 | { | |
f25fce3e | 2449 | return call_int_hook(ismaclabel, 0, name); |
746df9b5 DQ |
2450 | } |
2451 | EXPORT_SYMBOL(security_ismaclabel); | |
2452 | ||
20510f2f JM |
2453 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) |
2454 | { | |
0550cfe8 KS |
2455 | struct security_hook_list *hp; |
2456 | int rc; | |
2457 | ||
2458 | /* | |
2459 | * Currently, only one LSM can implement secid_to_secctx (i.e this | |
2460 | * LSM hook is not "stackable"). | |
2461 | */ | |
2462 | hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) { | |
2463 | rc = hp->hook.secid_to_secctx(secid, secdata, seclen); | |
2464 | if (rc != LSM_RET_DEFAULT(secid_to_secctx)) | |
2465 | return rc; | |
2466 | } | |
2467 | ||
2468 | return LSM_RET_DEFAULT(secid_to_secctx); | |
20510f2f JM |
2469 | } |
2470 | EXPORT_SYMBOL(security_secid_to_secctx); | |
2471 | ||
7bf570dc | 2472 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) |
63cb3449 | 2473 | { |
b1d9e6b0 | 2474 | *secid = 0; |
f25fce3e | 2475 | return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid); |
63cb3449 DH |
2476 | } |
2477 | EXPORT_SYMBOL(security_secctx_to_secid); | |
2478 | ||
20510f2f JM |
2479 | void security_release_secctx(char *secdata, u32 seclen) |
2480 | { | |
f25fce3e | 2481 | call_void_hook(release_secctx, secdata, seclen); |
20510f2f JM |
2482 | } |
2483 | EXPORT_SYMBOL(security_release_secctx); | |
2484 | ||
6f3be9f5 AG |
2485 | void security_inode_invalidate_secctx(struct inode *inode) |
2486 | { | |
2487 | call_void_hook(inode_invalidate_secctx, inode); | |
2488 | } | |
2489 | EXPORT_SYMBOL(security_inode_invalidate_secctx); | |
2490 | ||
1ee65e37 DQ |
2491 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) |
2492 | { | |
f25fce3e | 2493 | return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); |
1ee65e37 DQ |
2494 | } |
2495 | EXPORT_SYMBOL(security_inode_notifysecctx); | |
2496 | ||
2497 | int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) | |
2498 | { | |
f25fce3e | 2499 | return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen); |
1ee65e37 DQ |
2500 | } |
2501 | EXPORT_SYMBOL(security_inode_setsecctx); | |
2502 | ||
2503 | int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) | |
2504 | { | |
b1d9e6b0 | 2505 | return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); |
1ee65e37 DQ |
2506 | } |
2507 | EXPORT_SYMBOL(security_inode_getsecctx); | |
2508 | ||
344fa64e DH |
2509 | #ifdef CONFIG_WATCH_QUEUE |
2510 | int security_post_notification(const struct cred *w_cred, | |
2511 | const struct cred *cred, | |
2512 | struct watch_notification *n) | |
2513 | { | |
2514 | return call_int_hook(post_notification, 0, w_cred, cred, n); | |
2515 | } | |
2516 | #endif /* CONFIG_WATCH_QUEUE */ | |
2517 | ||
998f5040 DH |
2518 | #ifdef CONFIG_KEY_NOTIFICATIONS |
2519 | int security_watch_key(struct key *key) | |
2520 | { | |
2521 | return call_int_hook(watch_key, 0, key); | |
2522 | } | |
2523 | #endif | |
2524 | ||
20510f2f JM |
2525 | #ifdef CONFIG_SECURITY_NETWORK |
2526 | ||
3610cda5 | 2527 | int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk) |
20510f2f | 2528 | { |
f25fce3e | 2529 | return call_int_hook(unix_stream_connect, 0, sock, other, newsk); |
20510f2f JM |
2530 | } |
2531 | EXPORT_SYMBOL(security_unix_stream_connect); | |
2532 | ||
2533 | int security_unix_may_send(struct socket *sock, struct socket *other) | |
2534 | { | |
f25fce3e | 2535 | return call_int_hook(unix_may_send, 0, sock, other); |
20510f2f JM |
2536 | } |
2537 | EXPORT_SYMBOL(security_unix_may_send); | |
2538 | ||
2539 | int security_socket_create(int family, int type, int protocol, int kern) | |
2540 | { | |
f25fce3e | 2541 | return call_int_hook(socket_create, 0, family, type, protocol, kern); |
20510f2f JM |
2542 | } |
2543 | ||
2544 | int security_socket_post_create(struct socket *sock, int family, | |
2545 | int type, int protocol, int kern) | |
2546 | { | |
f25fce3e | 2547 | return call_int_hook(socket_post_create, 0, sock, family, type, |
20510f2f JM |
2548 | protocol, kern); |
2549 | } | |
2550 | ||
aae7cfcb DH |
2551 | int security_socket_socketpair(struct socket *socka, struct socket *sockb) |
2552 | { | |
2553 | return call_int_hook(socket_socketpair, 0, socka, sockb); | |
2554 | } | |
2555 | EXPORT_SYMBOL(security_socket_socketpair); | |
2556 | ||
20510f2f JM |
2557 | int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) |
2558 | { | |
f25fce3e | 2559 | return call_int_hook(socket_bind, 0, sock, address, addrlen); |
20510f2f JM |
2560 | } |
2561 | ||
2562 | int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) | |
2563 | { | |
f25fce3e | 2564 | return call_int_hook(socket_connect, 0, sock, address, addrlen); |
20510f2f JM |
2565 | } |
2566 | ||
2567 | int security_socket_listen(struct socket *sock, int backlog) | |
2568 | { | |
f25fce3e | 2569 | return call_int_hook(socket_listen, 0, sock, backlog); |
20510f2f JM |
2570 | } |
2571 | ||
2572 | int security_socket_accept(struct socket *sock, struct socket *newsock) | |
2573 | { | |
f25fce3e | 2574 | return call_int_hook(socket_accept, 0, sock, newsock); |
20510f2f JM |
2575 | } |
2576 | ||
20510f2f JM |
2577 | int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size) |
2578 | { | |
f25fce3e | 2579 | return call_int_hook(socket_sendmsg, 0, sock, msg, size); |
20510f2f JM |
2580 | } |
2581 | ||
2582 | int security_socket_recvmsg(struct socket *sock, struct msghdr *msg, | |
2583 | int size, int flags) | |
2584 | { | |
f25fce3e | 2585 | return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags); |
20510f2f JM |
2586 | } |
2587 | ||
2588 | int security_socket_getsockname(struct socket *sock) | |
2589 | { | |
f25fce3e | 2590 | return call_int_hook(socket_getsockname, 0, sock); |
20510f2f JM |
2591 | } |
2592 | ||
2593 | int security_socket_getpeername(struct socket *sock) | |
2594 | { | |
f25fce3e | 2595 | return call_int_hook(socket_getpeername, 0, sock); |
20510f2f JM |
2596 | } |
2597 | ||
2598 | int security_socket_getsockopt(struct socket *sock, int level, int optname) | |
2599 | { | |
f25fce3e | 2600 | return call_int_hook(socket_getsockopt, 0, sock, level, optname); |
20510f2f JM |
2601 | } |
2602 | ||
2603 | int security_socket_setsockopt(struct socket *sock, int level, int optname) | |
2604 | { | |
f25fce3e | 2605 | return call_int_hook(socket_setsockopt, 0, sock, level, optname); |
20510f2f JM |
2606 | } |
2607 | ||
2608 | int security_socket_shutdown(struct socket *sock, int how) | |
2609 | { | |
f25fce3e | 2610 | return call_int_hook(socket_shutdown, 0, sock, how); |
20510f2f JM |
2611 | } |
2612 | ||
2613 | int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |
2614 | { | |
f25fce3e | 2615 | return call_int_hook(socket_sock_rcv_skb, 0, sk, skb); |
20510f2f JM |
2616 | } |
2617 | EXPORT_SYMBOL(security_sock_rcv_skb); | |
2618 | ||
b10b9c34 PM |
2619 | int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval, |
2620 | sockptr_t optlen, unsigned int len) | |
20510f2f | 2621 | { |
b1d9e6b0 | 2622 | return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock, |
b10b9c34 | 2623 | optval, optlen, len); |
20510f2f JM |
2624 | } |
2625 | ||
2626 | int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) | |
2627 | { | |
e308fd3b JB |
2628 | return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, |
2629 | skb, secid); | |
20510f2f JM |
2630 | } |
2631 | EXPORT_SYMBOL(security_socket_getpeersec_dgram); | |
2632 | ||
2633 | int security_sk_alloc(struct sock *sk, int family, gfp_t priority) | |
2634 | { | |
f25fce3e | 2635 | return call_int_hook(sk_alloc_security, 0, sk, family, priority); |
20510f2f JM |
2636 | } |
2637 | ||
2638 | void security_sk_free(struct sock *sk) | |
2639 | { | |
f25fce3e | 2640 | call_void_hook(sk_free_security, sk); |
20510f2f JM |
2641 | } |
2642 | ||
2643 | void security_sk_clone(const struct sock *sk, struct sock *newsk) | |
2644 | { | |
f25fce3e | 2645 | call_void_hook(sk_clone_security, sk, newsk); |
20510f2f | 2646 | } |
6230c9b4 | 2647 | EXPORT_SYMBOL(security_sk_clone); |
20510f2f | 2648 | |
3df98d79 | 2649 | void security_sk_classify_flow(struct sock *sk, struct flowi_common *flic) |
20510f2f | 2650 | { |
3df98d79 | 2651 | call_void_hook(sk_getsecid, sk, &flic->flowic_secid); |
20510f2f JM |
2652 | } |
2653 | EXPORT_SYMBOL(security_sk_classify_flow); | |
2654 | ||
3df98d79 PM |
2655 | void security_req_classify_flow(const struct request_sock *req, |
2656 | struct flowi_common *flic) | |
20510f2f | 2657 | { |
3df98d79 | 2658 | call_void_hook(req_classify_flow, req, flic); |
20510f2f JM |
2659 | } |
2660 | EXPORT_SYMBOL(security_req_classify_flow); | |
2661 | ||
2662 | void security_sock_graft(struct sock *sk, struct socket *parent) | |
2663 | { | |
f25fce3e | 2664 | call_void_hook(sock_graft, sk, parent); |
20510f2f JM |
2665 | } |
2666 | EXPORT_SYMBOL(security_sock_graft); | |
2667 | ||
41dd9596 | 2668 | int security_inet_conn_request(const struct sock *sk, |
20510f2f JM |
2669 | struct sk_buff *skb, struct request_sock *req) |
2670 | { | |
f25fce3e | 2671 | return call_int_hook(inet_conn_request, 0, sk, skb, req); |
20510f2f JM |
2672 | } |
2673 | EXPORT_SYMBOL(security_inet_conn_request); | |
2674 | ||
2675 | void security_inet_csk_clone(struct sock *newsk, | |
2676 | const struct request_sock *req) | |
2677 | { | |
f25fce3e | 2678 | call_void_hook(inet_csk_clone, newsk, req); |
20510f2f JM |
2679 | } |
2680 | ||
2681 | void security_inet_conn_established(struct sock *sk, | |
2682 | struct sk_buff *skb) | |
2683 | { | |
f25fce3e | 2684 | call_void_hook(inet_conn_established, sk, skb); |
20510f2f | 2685 | } |
72e89f50 | 2686 | EXPORT_SYMBOL(security_inet_conn_established); |
20510f2f | 2687 | |
2606fd1f EP |
2688 | int security_secmark_relabel_packet(u32 secid) |
2689 | { | |
f25fce3e | 2690 | return call_int_hook(secmark_relabel_packet, 0, secid); |
2606fd1f EP |
2691 | } |
2692 | EXPORT_SYMBOL(security_secmark_relabel_packet); | |
2693 | ||
2694 | void security_secmark_refcount_inc(void) | |
2695 | { | |
f25fce3e | 2696 | call_void_hook(secmark_refcount_inc); |
2606fd1f EP |
2697 | } |
2698 | EXPORT_SYMBOL(security_secmark_refcount_inc); | |
2699 | ||
2700 | void security_secmark_refcount_dec(void) | |
2701 | { | |
f25fce3e | 2702 | call_void_hook(secmark_refcount_dec); |
2606fd1f EP |
2703 | } |
2704 | EXPORT_SYMBOL(security_secmark_refcount_dec); | |
2705 | ||
5dbbaf2d PM |
2706 | int security_tun_dev_alloc_security(void **security) |
2707 | { | |
f25fce3e | 2708 | return call_int_hook(tun_dev_alloc_security, 0, security); |
5dbbaf2d PM |
2709 | } |
2710 | EXPORT_SYMBOL(security_tun_dev_alloc_security); | |
2711 | ||
2712 | void security_tun_dev_free_security(void *security) | |
2713 | { | |
f25fce3e | 2714 | call_void_hook(tun_dev_free_security, security); |
5dbbaf2d PM |
2715 | } |
2716 | EXPORT_SYMBOL(security_tun_dev_free_security); | |
2717 | ||
2b980dbd PM |
2718 | int security_tun_dev_create(void) |
2719 | { | |
f25fce3e | 2720 | return call_int_hook(tun_dev_create, 0); |
2b980dbd PM |
2721 | } |
2722 | EXPORT_SYMBOL(security_tun_dev_create); | |
2723 | ||
5dbbaf2d | 2724 | int security_tun_dev_attach_queue(void *security) |
2b980dbd | 2725 | { |
f25fce3e | 2726 | return call_int_hook(tun_dev_attach_queue, 0, security); |
2b980dbd | 2727 | } |
5dbbaf2d | 2728 | EXPORT_SYMBOL(security_tun_dev_attach_queue); |
2b980dbd | 2729 | |
5dbbaf2d | 2730 | int security_tun_dev_attach(struct sock *sk, void *security) |
2b980dbd | 2731 | { |
f25fce3e | 2732 | return call_int_hook(tun_dev_attach, 0, sk, security); |
2b980dbd PM |
2733 | } |
2734 | EXPORT_SYMBOL(security_tun_dev_attach); | |
2735 | ||
5dbbaf2d PM |
2736 | int security_tun_dev_open(void *security) |
2737 | { | |
f25fce3e | 2738 | return call_int_hook(tun_dev_open, 0, security); |
5dbbaf2d PM |
2739 | } |
2740 | EXPORT_SYMBOL(security_tun_dev_open); | |
2741 | ||
c081d53f | 2742 | int security_sctp_assoc_request(struct sctp_association *asoc, struct sk_buff *skb) |
72e89f50 | 2743 | { |
c081d53f | 2744 | return call_int_hook(sctp_assoc_request, 0, asoc, skb); |
72e89f50 RH |
2745 | } |
2746 | EXPORT_SYMBOL(security_sctp_assoc_request); | |
2747 | ||
2748 | int security_sctp_bind_connect(struct sock *sk, int optname, | |
2749 | struct sockaddr *address, int addrlen) | |
2750 | { | |
2751 | return call_int_hook(sctp_bind_connect, 0, sk, optname, | |
2752 | address, addrlen); | |
2753 | } | |
2754 | EXPORT_SYMBOL(security_sctp_bind_connect); | |
2755 | ||
c081d53f | 2756 | void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk, |
72e89f50 RH |
2757 | struct sock *newsk) |
2758 | { | |
c081d53f | 2759 | call_void_hook(sctp_sk_clone, asoc, sk, newsk); |
72e89f50 RH |
2760 | } |
2761 | EXPORT_SYMBOL(security_sctp_sk_clone); | |
2762 | ||
5e50f5d4 OM |
2763 | int security_sctp_assoc_established(struct sctp_association *asoc, |
2764 | struct sk_buff *skb) | |
2765 | { | |
2766 | return call_int_hook(sctp_assoc_established, 0, asoc, skb); | |
2767 | } | |
2768 | EXPORT_SYMBOL(security_sctp_assoc_established); | |
2769 | ||
20510f2f JM |
2770 | #endif /* CONFIG_SECURITY_NETWORK */ |
2771 | ||
d291f1a6 DJ |
2772 | #ifdef CONFIG_SECURITY_INFINIBAND |
2773 | ||
2774 | int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey) | |
2775 | { | |
2776 | return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey); | |
2777 | } | |
2778 | EXPORT_SYMBOL(security_ib_pkey_access); | |
2779 | ||
47a2b338 DJ |
2780 | int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num) |
2781 | { | |
2782 | return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num); | |
2783 | } | |
2784 | EXPORT_SYMBOL(security_ib_endport_manage_subnet); | |
2785 | ||
d291f1a6 DJ |
2786 | int security_ib_alloc_security(void **sec) |
2787 | { | |
2788 | return call_int_hook(ib_alloc_security, 0, sec); | |
2789 | } | |
2790 | EXPORT_SYMBOL(security_ib_alloc_security); | |
2791 | ||
2792 | void security_ib_free_security(void *sec) | |
2793 | { | |
2794 | call_void_hook(ib_free_security, sec); | |
2795 | } | |
2796 | EXPORT_SYMBOL(security_ib_free_security); | |
2797 | #endif /* CONFIG_SECURITY_INFINIBAND */ | |
2798 | ||
20510f2f JM |
2799 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
2800 | ||
52a4c640 NA |
2801 | int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, |
2802 | struct xfrm_user_sec_ctx *sec_ctx, | |
2803 | gfp_t gfp) | |
20510f2f | 2804 | { |
f25fce3e | 2805 | return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp); |
20510f2f JM |
2806 | } |
2807 | EXPORT_SYMBOL(security_xfrm_policy_alloc); | |
2808 | ||
03e1ad7b PM |
2809 | int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
2810 | struct xfrm_sec_ctx **new_ctxp) | |
20510f2f | 2811 | { |
f25fce3e | 2812 | return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp); |
20510f2f JM |
2813 | } |
2814 | ||
03e1ad7b | 2815 | void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) |
20510f2f | 2816 | { |
f25fce3e | 2817 | call_void_hook(xfrm_policy_free_security, ctx); |
20510f2f JM |
2818 | } |
2819 | EXPORT_SYMBOL(security_xfrm_policy_free); | |
2820 | ||
03e1ad7b | 2821 | int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) |
20510f2f | 2822 | { |
f25fce3e | 2823 | return call_int_hook(xfrm_policy_delete_security, 0, ctx); |
20510f2f JM |
2824 | } |
2825 | ||
2e5aa866 PM |
2826 | int security_xfrm_state_alloc(struct xfrm_state *x, |
2827 | struct xfrm_user_sec_ctx *sec_ctx) | |
20510f2f | 2828 | { |
f25fce3e | 2829 | return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx); |
20510f2f JM |
2830 | } |
2831 | EXPORT_SYMBOL(security_xfrm_state_alloc); | |
2832 | ||
2833 | int security_xfrm_state_alloc_acquire(struct xfrm_state *x, | |
2834 | struct xfrm_sec_ctx *polsec, u32 secid) | |
2835 | { | |
f25fce3e | 2836 | return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid); |
20510f2f JM |
2837 | } |
2838 | ||
2839 | int security_xfrm_state_delete(struct xfrm_state *x) | |
2840 | { | |
f25fce3e | 2841 | return call_int_hook(xfrm_state_delete_security, 0, x); |
20510f2f JM |
2842 | } |
2843 | EXPORT_SYMBOL(security_xfrm_state_delete); | |
2844 | ||
2845 | void security_xfrm_state_free(struct xfrm_state *x) | |
2846 | { | |
f25fce3e | 2847 | call_void_hook(xfrm_state_free_security, x); |
20510f2f JM |
2848 | } |
2849 | ||
8a922805 | 2850 | int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid) |
20510f2f | 2851 | { |
8a922805 | 2852 | return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid); |
20510f2f JM |
2853 | } |
2854 | ||
2855 | int security_xfrm_state_pol_flow_match(struct xfrm_state *x, | |
e33f7704 | 2856 | struct xfrm_policy *xp, |
3df98d79 | 2857 | const struct flowi_common *flic) |
20510f2f | 2858 | { |
b1d9e6b0 | 2859 | struct security_hook_list *hp; |
98e828a0 | 2860 | int rc = LSM_RET_DEFAULT(xfrm_state_pol_flow_match); |
b1d9e6b0 CS |
2861 | |
2862 | /* | |
2863 | * Since this function is expected to return 0 or 1, the judgment | |
2864 | * becomes difficult if multiple LSMs supply this call. Fortunately, | |
2865 | * we can use the first LSM's judgment because currently only SELinux | |
2866 | * supplies this call. | |
2867 | * | |
2868 | * For speed optimization, we explicitly break the loop rather than | |
2869 | * using the macro | |
2870 | */ | |
df0ce173 | 2871 | hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match, |
b1d9e6b0 | 2872 | list) { |
3df98d79 | 2873 | rc = hp->hook.xfrm_state_pol_flow_match(x, xp, flic); |
b1d9e6b0 CS |
2874 | break; |
2875 | } | |
2876 | return rc; | |
20510f2f JM |
2877 | } |
2878 | ||
2879 | int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid) | |
2880 | { | |
f25fce3e | 2881 | return call_int_hook(xfrm_decode_session, 0, skb, secid, 1); |
20510f2f JM |
2882 | } |
2883 | ||
3df98d79 | 2884 | void security_skb_classify_flow(struct sk_buff *skb, struct flowi_common *flic) |
20510f2f | 2885 | { |
3df98d79 | 2886 | int rc = call_int_hook(xfrm_decode_session, 0, skb, &flic->flowic_secid, |
f25fce3e | 2887 | 0); |
20510f2f JM |
2888 | |
2889 | BUG_ON(rc); | |
2890 | } | |
2891 | EXPORT_SYMBOL(security_skb_classify_flow); | |
2892 | ||
2893 | #endif /* CONFIG_SECURITY_NETWORK_XFRM */ | |
2894 | ||
2895 | #ifdef CONFIG_KEYS | |
2896 | ||
d84f4f99 DH |
2897 | int security_key_alloc(struct key *key, const struct cred *cred, |
2898 | unsigned long flags) | |
20510f2f | 2899 | { |
f25fce3e | 2900 | return call_int_hook(key_alloc, 0, key, cred, flags); |
20510f2f JM |
2901 | } |
2902 | ||
2903 | void security_key_free(struct key *key) | |
2904 | { | |
f25fce3e | 2905 | call_void_hook(key_free, key); |
20510f2f JM |
2906 | } |
2907 | ||
8c0637e9 DH |
2908 | int security_key_permission(key_ref_t key_ref, const struct cred *cred, |
2909 | enum key_need_perm need_perm) | |
20510f2f | 2910 | { |
8c0637e9 | 2911 | return call_int_hook(key_permission, 0, key_ref, cred, need_perm); |
20510f2f JM |
2912 | } |
2913 | ||
70a5bb72 DH |
2914 | int security_key_getsecurity(struct key *key, char **_buffer) |
2915 | { | |
b1d9e6b0 | 2916 | *_buffer = NULL; |
f25fce3e | 2917 | return call_int_hook(key_getsecurity, 0, key, _buffer); |
70a5bb72 DH |
2918 | } |
2919 | ||
20510f2f | 2920 | #endif /* CONFIG_KEYS */ |
03d37d25 AD |
2921 | |
2922 | #ifdef CONFIG_AUDIT | |
2923 | ||
2924 | int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule) | |
2925 | { | |
f25fce3e | 2926 | return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule); |
03d37d25 AD |
2927 | } |
2928 | ||
2929 | int security_audit_rule_known(struct audit_krule *krule) | |
2930 | { | |
f25fce3e | 2931 | return call_int_hook(audit_rule_known, 0, krule); |
03d37d25 AD |
2932 | } |
2933 | ||
2934 | void security_audit_rule_free(void *lsmrule) | |
2935 | { | |
f25fce3e | 2936 | call_void_hook(audit_rule_free, lsmrule); |
03d37d25 AD |
2937 | } |
2938 | ||
90462a5b | 2939 | int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule) |
03d37d25 | 2940 | { |
90462a5b | 2941 | return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule); |
03d37d25 | 2942 | } |
b1d9e6b0 | 2943 | #endif /* CONFIG_AUDIT */ |
afdb09c7 CF |
2944 | |
2945 | #ifdef CONFIG_BPF_SYSCALL | |
2946 | int security_bpf(int cmd, union bpf_attr *attr, unsigned int size) | |
2947 | { | |
2948 | return call_int_hook(bpf, 0, cmd, attr, size); | |
2949 | } | |
2950 | int security_bpf_map(struct bpf_map *map, fmode_t fmode) | |
2951 | { | |
2952 | return call_int_hook(bpf_map, 0, map, fmode); | |
2953 | } | |
2954 | int security_bpf_prog(struct bpf_prog *prog) | |
2955 | { | |
2956 | return call_int_hook(bpf_prog, 0, prog); | |
2957 | } | |
2958 | int security_bpf_map_alloc(struct bpf_map *map) | |
2959 | { | |
2960 | return call_int_hook(bpf_map_alloc_security, 0, map); | |
2961 | } | |
2962 | int security_bpf_prog_alloc(struct bpf_prog_aux *aux) | |
2963 | { | |
2964 | return call_int_hook(bpf_prog_alloc_security, 0, aux); | |
2965 | } | |
2966 | void security_bpf_map_free(struct bpf_map *map) | |
2967 | { | |
2968 | call_void_hook(bpf_map_free_security, map); | |
2969 | } | |
2970 | void security_bpf_prog_free(struct bpf_prog_aux *aux) | |
2971 | { | |
2972 | call_void_hook(bpf_prog_free_security, aux); | |
2973 | } | |
2974 | #endif /* CONFIG_BPF_SYSCALL */ | |
9e47d31d MG |
2975 | |
2976 | int security_locked_down(enum lockdown_reason what) | |
2977 | { | |
2978 | return call_int_hook(locked_down, 0, what); | |
2979 | } | |
2980 | EXPORT_SYMBOL(security_locked_down); | |
da97e184 JFG |
2981 | |
2982 | #ifdef CONFIG_PERF_EVENTS | |
2983 | int security_perf_event_open(struct perf_event_attr *attr, int type) | |
2984 | { | |
2985 | return call_int_hook(perf_event_open, 0, attr, type); | |
2986 | } | |
2987 | ||
2988 | int security_perf_event_alloc(struct perf_event *event) | |
2989 | { | |
2990 | return call_int_hook(perf_event_alloc, 0, event); | |
2991 | } | |
2992 | ||
2993 | void security_perf_event_free(struct perf_event *event) | |
2994 | { | |
2995 | call_void_hook(perf_event_free, event); | |
2996 | } | |
2997 | ||
2998 | int security_perf_event_read(struct perf_event *event) | |
2999 | { | |
3000 | return call_int_hook(perf_event_read, 0, event); | |
3001 | } | |
3002 | ||
3003 | int security_perf_event_write(struct perf_event *event) | |
3004 | { | |
3005 | return call_int_hook(perf_event_write, 0, event); | |
3006 | } | |
3007 | #endif /* CONFIG_PERF_EVENTS */ | |
cdc1404a PM |
3008 | |
3009 | #ifdef CONFIG_IO_URING | |
3010 | int security_uring_override_creds(const struct cred *new) | |
3011 | { | |
3012 | return call_int_hook(uring_override_creds, 0, new); | |
3013 | } | |
3014 | ||
3015 | int security_uring_sqpoll(void) | |
3016 | { | |
3017 | return call_int_hook(uring_sqpoll, 0); | |
3018 | } | |
2a584012 LC |
3019 | int security_uring_cmd(struct io_uring_cmd *ioucmd) |
3020 | { | |
3021 | return call_int_hook(uring_cmd, 0, ioucmd); | |
3022 | } | |
cdc1404a | 3023 | #endif /* CONFIG_IO_URING */ |