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 | |
2d4d5119 KC |
34 | /* How many LSMs were built into the kernel? */ |
35 | #define LSM_COUNT (__end_lsm_info - __start_lsm_info) | |
36 | ||
9285c5ad CS |
37 | /* |
38 | * How many LSMs are built into the kernel as determined at | |
39 | * build time. Used to determine fixed array sizes. | |
40 | * The capability module is accounted for by CONFIG_SECURITY | |
41 | */ | |
42 | #define LSM_CONFIG_COUNT ( \ | |
43 | (IS_ENABLED(CONFIG_SECURITY) ? 1 : 0) + \ | |
44 | (IS_ENABLED(CONFIG_SECURITY_SELINUX) ? 1 : 0) + \ | |
45 | (IS_ENABLED(CONFIG_SECURITY_SMACK) ? 1 : 0) + \ | |
46 | (IS_ENABLED(CONFIG_SECURITY_TOMOYO) ? 1 : 0) + \ | |
9285c5ad CS |
47 | (IS_ENABLED(CONFIG_SECURITY_APPARMOR) ? 1 : 0) + \ |
48 | (IS_ENABLED(CONFIG_SECURITY_YAMA) ? 1 : 0) + \ | |
49 | (IS_ENABLED(CONFIG_SECURITY_LOADPIN) ? 1 : 0) + \ | |
50 | (IS_ENABLED(CONFIG_SECURITY_SAFESETID) ? 1 : 0) + \ | |
51 | (IS_ENABLED(CONFIG_SECURITY_LOCKDOWN_LSM) ? 1 : 0) + \ | |
52 | (IS_ENABLED(CONFIG_BPF_LSM) ? 1 : 0) + \ | |
53 | (IS_ENABLED(CONFIG_SECURITY_LANDLOCK) ? 1 : 0)) | |
54 | ||
59438b46 SS |
55 | /* |
56 | * These are descriptions of the reasons that can be passed to the | |
57 | * security_locked_down() LSM hook. Placing this array here allows | |
58 | * all security modules to use the same descriptions for auditing | |
59 | * purposes. | |
60 | */ | |
63c1845b | 61 | const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX + 1] = { |
59438b46 SS |
62 | [LOCKDOWN_NONE] = "none", |
63 | [LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading", | |
64 | [LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port", | |
65 | [LOCKDOWN_EFI_TEST] = "/dev/efi_test access", | |
66 | [LOCKDOWN_KEXEC] = "kexec of unsigned images", | |
67 | [LOCKDOWN_HIBERNATION] = "hibernation", | |
68 | [LOCKDOWN_PCI_ACCESS] = "direct PCI access", | |
69 | [LOCKDOWN_IOPORT] = "raw io port access", | |
70 | [LOCKDOWN_MSR] = "raw MSR access", | |
71 | [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", | |
99df7a28 | 72 | [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", |
59438b46 SS |
73 | [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", |
74 | [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", | |
75 | [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", | |
76 | [LOCKDOWN_MMIOTRACE] = "unsafe mmio", | |
77 | [LOCKDOWN_DEBUGFS] = "debugfs access", | |
78 | [LOCKDOWN_XMON_WR] = "xmon write access", | |
51e1bb9e | 79 | [LOCKDOWN_BPF_WRITE_USER] = "use of bpf to write user RAM", |
eadb2f47 | 80 | [LOCKDOWN_DBG_WRITE_KERNEL] = "use of kgdb/kdb to write kernel RAM", |
b8f3e488 | 81 | [LOCKDOWN_RTAS_ERROR_INJECTION] = "RTAS error injection", |
59438b46 SS |
82 | [LOCKDOWN_INTEGRITY_MAX] = "integrity", |
83 | [LOCKDOWN_KCORE] = "/proc/kcore access", | |
84 | [LOCKDOWN_KPROBES] = "use of kprobes", | |
71330842 | 85 | [LOCKDOWN_BPF_READ_KERNEL] = "use of bpf to read kernel RAM", |
eadb2f47 | 86 | [LOCKDOWN_DBG_READ_KERNEL] = "use of kgdb/kdb to read kernel RAM", |
59438b46 SS |
87 | [LOCKDOWN_PERF] = "unsafe use of perf", |
88 | [LOCKDOWN_TRACEFS] = "use of tracefs", | |
89 | [LOCKDOWN_XMON_RW] = "xmon read and write access", | |
c7a5899e | 90 | [LOCKDOWN_XFRM_SECRET] = "xfrm SA secret", |
59438b46 SS |
91 | [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", |
92 | }; | |
93 | ||
f22f9aaf | 94 | struct security_hook_heads security_hook_heads __ro_after_init; |
42df744c | 95 | static BLOCKING_NOTIFIER_HEAD(blocking_lsm_notifier_chain); |
8f408ab6 | 96 | |
33bf60ca | 97 | static struct kmem_cache *lsm_file_cache; |
afb1cbe3 | 98 | static struct kmem_cache *lsm_inode_cache; |
33bf60ca | 99 | |
d69dece5 | 100 | char *lsm_names; |
f22f9aaf | 101 | static struct lsm_blob_sizes blob_sizes __ro_after_init; |
bbd3662a | 102 | |
076c54c5 | 103 | /* Boot-time LSM user choice */ |
79f7865d | 104 | static __initdata const char *chosen_lsm_order; |
5ef4e419 | 105 | static __initdata const char *chosen_major_lsm; |
1da177e4 | 106 | |
63c1845b | 107 | static __initconst const char *const builtin_lsm_order = CONFIG_LSM; |
13e735c0 | 108 | |
2d4d5119 KC |
109 | /* Ordered list of LSMs to initialize. */ |
110 | static __initdata struct lsm_info **ordered_lsms; | |
14bd99c8 | 111 | static __initdata struct lsm_info *exclusive; |
2d4d5119 | 112 | |
9b8c7c14 KC |
113 | static __initdata bool debug; |
114 | #define init_debug(...) \ | |
115 | do { \ | |
116 | if (debug) \ | |
117 | pr_info(__VA_ARGS__); \ | |
118 | } while (0) | |
119 | ||
f4941d75 KC |
120 | static bool __init is_enabled(struct lsm_info *lsm) |
121 | { | |
a8027fb0 KC |
122 | if (!lsm->enabled) |
123 | return false; | |
f4941d75 | 124 | |
a8027fb0 | 125 | return *lsm->enabled; |
f4941d75 KC |
126 | } |
127 | ||
128 | /* Mark an LSM's enabled flag. */ | |
129 | static int lsm_enabled_true __initdata = 1; | |
130 | static int lsm_enabled_false __initdata = 0; | |
131 | static void __init set_enabled(struct lsm_info *lsm, bool enabled) | |
132 | { | |
133 | /* | |
134 | * When an LSM hasn't configured an enable variable, we can use | |
135 | * a hard-coded location for storing the default enabled state. | |
136 | */ | |
137 | if (!lsm->enabled) { | |
138 | if (enabled) | |
139 | lsm->enabled = &lsm_enabled_true; | |
140 | else | |
141 | lsm->enabled = &lsm_enabled_false; | |
142 | } else if (lsm->enabled == &lsm_enabled_true) { | |
143 | if (!enabled) | |
144 | lsm->enabled = &lsm_enabled_false; | |
145 | } else if (lsm->enabled == &lsm_enabled_false) { | |
146 | if (enabled) | |
147 | lsm->enabled = &lsm_enabled_true; | |
148 | } else { | |
149 | *lsm->enabled = enabled; | |
150 | } | |
151 | } | |
152 | ||
2d4d5119 KC |
153 | /* Is an LSM already listed in the ordered LSMs list? */ |
154 | static bool __init exists_ordered_lsm(struct lsm_info *lsm) | |
155 | { | |
156 | struct lsm_info **check; | |
157 | ||
158 | for (check = ordered_lsms; *check; check++) | |
159 | if (*check == lsm) | |
160 | return true; | |
161 | ||
162 | return false; | |
163 | } | |
164 | ||
165 | /* Append an LSM to the list of ordered LSMs to initialize. */ | |
166 | static int last_lsm __initdata; | |
167 | static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) | |
168 | { | |
169 | /* Ignore duplicate selections. */ | |
170 | if (exists_ordered_lsm(lsm)) | |
171 | return; | |
172 | ||
173 | if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from)) | |
174 | return; | |
175 | ||
a8027fb0 KC |
176 | /* Enable this LSM, if it is not already set. */ |
177 | if (!lsm->enabled) | |
178 | lsm->enabled = &lsm_enabled_true; | |
2d4d5119 | 179 | ordered_lsms[last_lsm++] = lsm; |
a8027fb0 | 180 | |
86ef3c73 KC |
181 | init_debug("%s ordered: %s (%s)\n", from, lsm->name, |
182 | is_enabled(lsm) ? "enabled" : "disabled"); | |
2d4d5119 KC |
183 | } |
184 | ||
f4941d75 KC |
185 | /* Is an LSM allowed to be initialized? */ |
186 | static bool __init lsm_allowed(struct lsm_info *lsm) | |
187 | { | |
188 | /* Skip if the LSM is disabled. */ | |
189 | if (!is_enabled(lsm)) | |
190 | return false; | |
191 | ||
14bd99c8 KC |
192 | /* Not allowed if another exclusive LSM already initialized. */ |
193 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) { | |
194 | init_debug("exclusive disabled: %s\n", lsm->name); | |
195 | return false; | |
196 | } | |
197 | ||
f4941d75 KC |
198 | return true; |
199 | } | |
200 | ||
bbd3662a CS |
201 | static void __init lsm_set_blob_size(int *need, int *lbs) |
202 | { | |
203 | int offset; | |
204 | ||
b9f5ce27 GN |
205 | if (*need <= 0) |
206 | return; | |
207 | ||
208 | offset = ALIGN(*lbs, sizeof(void *)); | |
209 | *lbs = offset + *need; | |
210 | *need = offset; | |
bbd3662a CS |
211 | } |
212 | ||
213 | static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) | |
214 | { | |
215 | if (!needed) | |
216 | return; | |
217 | ||
218 | lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred); | |
33bf60ca | 219 | lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file); |
afb1cbe3 CS |
220 | /* |
221 | * The inode blob gets an rcu_head in addition to | |
222 | * what the modules might need. | |
223 | */ | |
224 | if (needed->lbs_inode && blob_sizes.lbs_inode == 0) | |
225 | blob_sizes.lbs_inode = sizeof(struct rcu_head); | |
226 | lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); | |
ecd5f82e CS |
227 | lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); |
228 | lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); | |
1aea7808 | 229 | lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock); |
f4ad8f2c | 230 | lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task); |
6bcdfd2c RS |
231 | lsm_set_blob_size(&needed->lbs_xattr_count, |
232 | &blob_sizes.lbs_xattr_count); | |
bbd3662a CS |
233 | } |
234 | ||
d8e9bbd4 KC |
235 | /* Prepare LSM for initialization. */ |
236 | static void __init prepare_lsm(struct lsm_info *lsm) | |
f4941d75 KC |
237 | { |
238 | int enabled = lsm_allowed(lsm); | |
239 | ||
240 | /* Record enablement (to handle any following exclusive LSMs). */ | |
241 | set_enabled(lsm, enabled); | |
242 | ||
d8e9bbd4 | 243 | /* If enabled, do pre-initialization work. */ |
f4941d75 | 244 | if (enabled) { |
14bd99c8 KC |
245 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { |
246 | exclusive = lsm; | |
86ef3c73 | 247 | init_debug("exclusive chosen: %s\n", lsm->name); |
14bd99c8 | 248 | } |
bbd3662a CS |
249 | |
250 | lsm_set_blob_sizes(lsm->blobs); | |
d8e9bbd4 KC |
251 | } |
252 | } | |
253 | ||
254 | /* Initialize a given LSM, if it is enabled. */ | |
255 | static void __init initialize_lsm(struct lsm_info *lsm) | |
256 | { | |
257 | if (is_enabled(lsm)) { | |
258 | int ret; | |
14bd99c8 | 259 | |
f4941d75 KC |
260 | init_debug("initializing %s\n", lsm->name); |
261 | ret = lsm->init(); | |
262 | WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret); | |
263 | } | |
264 | } | |
265 | ||
9285c5ad CS |
266 | /* |
267 | * Current index to use while initializing the lsm id list. | |
268 | */ | |
269 | u32 lsm_active_cnt __ro_after_init; | |
270 | const struct lsm_id *lsm_idlist[LSM_CONFIG_COUNT]; | |
271 | ||
13e735c0 | 272 | /* Populate ordered LSMs list from comma-separated LSM name list. */ |
2d4d5119 | 273 | static void __init ordered_lsm_parse(const char *order, const char *origin) |
657d910b KC |
274 | { |
275 | struct lsm_info *lsm; | |
13e735c0 KC |
276 | char *sep, *name, *next; |
277 | ||
e2bc445b KC |
278 | /* LSM_ORDER_FIRST is always first. */ |
279 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
280 | if (lsm->order == LSM_ORDER_FIRST) | |
86ef3c73 | 281 | append_ordered_lsm(lsm, " first"); |
e2bc445b KC |
282 | } |
283 | ||
7e611486 | 284 | /* Process "security=", if given. */ |
7e611486 KC |
285 | if (chosen_major_lsm) { |
286 | struct lsm_info *major; | |
287 | ||
288 | /* | |
289 | * To match the original "security=" behavior, this | |
290 | * explicitly does NOT fallback to another Legacy Major | |
291 | * if the selected one was separately disabled: disable | |
292 | * all non-matching Legacy Major LSMs. | |
293 | */ | |
294 | for (major = __start_lsm_info; major < __end_lsm_info; | |
295 | major++) { | |
296 | if ((major->flags & LSM_FLAG_LEGACY_MAJOR) && | |
297 | strcmp(major->name, chosen_major_lsm) != 0) { | |
298 | set_enabled(major, false); | |
86ef3c73 | 299 | init_debug("security=%s disabled: %s (only one legacy major LSM)\n", |
7e611486 KC |
300 | chosen_major_lsm, major->name); |
301 | } | |
302 | } | |
303 | } | |
5ef4e419 | 304 | |
13e735c0 KC |
305 | sep = kstrdup(order, GFP_KERNEL); |
306 | next = sep; | |
307 | /* Walk the list, looking for matching LSMs. */ | |
308 | while ((name = strsep(&next, ",")) != NULL) { | |
309 | bool found = false; | |
310 | ||
311 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
42994ee3 RS |
312 | if (strcmp(lsm->name, name) == 0) { |
313 | if (lsm->order == LSM_ORDER_MUTABLE) | |
314 | append_ordered_lsm(lsm, origin); | |
13e735c0 KC |
315 | found = true; |
316 | } | |
317 | } | |
318 | ||
319 | if (!found) | |
86ef3c73 KC |
320 | init_debug("%s ignored: %s (not built into kernel)\n", |
321 | origin, name); | |
657d910b | 322 | } |
c91d8106 CS |
323 | |
324 | /* Process "security=", if given. */ | |
325 | if (chosen_major_lsm) { | |
326 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
327 | if (exists_ordered_lsm(lsm)) | |
328 | continue; | |
329 | if (strcmp(lsm->name, chosen_major_lsm) == 0) | |
330 | append_ordered_lsm(lsm, "security="); | |
331 | } | |
332 | } | |
333 | ||
42994ee3 RS |
334 | /* LSM_ORDER_LAST is always last. */ |
335 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
336 | if (lsm->order == LSM_ORDER_LAST) | |
337 | append_ordered_lsm(lsm, " last"); | |
338 | } | |
339 | ||
c91d8106 CS |
340 | /* Disable all LSMs not in the ordered list. */ |
341 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { | |
342 | if (exists_ordered_lsm(lsm)) | |
343 | continue; | |
344 | set_enabled(lsm, false); | |
86ef3c73 KC |
345 | init_debug("%s skipped: %s (not in requested order)\n", |
346 | origin, lsm->name); | |
c91d8106 CS |
347 | } |
348 | ||
13e735c0 | 349 | kfree(sep); |
657d910b KC |
350 | } |
351 | ||
1cfb2a51 TH |
352 | static void __init lsm_early_cred(struct cred *cred); |
353 | static void __init lsm_early_task(struct task_struct *task); | |
354 | ||
e6b1db98 MG |
355 | static int lsm_append(const char *new, char **result); |
356 | ||
86ef3c73 KC |
357 | static void __init report_lsm_order(void) |
358 | { | |
359 | struct lsm_info **lsm, *early; | |
360 | int first = 0; | |
361 | ||
362 | pr_info("initializing lsm="); | |
363 | ||
364 | /* Report each enabled LSM name, comma separated. */ | |
63c1845b PM |
365 | for (early = __start_early_lsm_info; |
366 | early < __end_early_lsm_info; early++) | |
86ef3c73 KC |
367 | if (is_enabled(early)) |
368 | pr_cont("%s%s", first++ == 0 ? "" : ",", early->name); | |
369 | for (lsm = ordered_lsms; *lsm; lsm++) | |
370 | if (is_enabled(*lsm)) | |
371 | pr_cont("%s%s", first++ == 0 ? "" : ",", (*lsm)->name); | |
372 | ||
373 | pr_cont("\n"); | |
374 | } | |
375 | ||
2d4d5119 KC |
376 | static void __init ordered_lsm_init(void) |
377 | { | |
378 | struct lsm_info **lsm; | |
379 | ||
380 | ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), | |
63c1845b | 381 | GFP_KERNEL); |
2d4d5119 | 382 | |
89a9684e KC |
383 | if (chosen_lsm_order) { |
384 | if (chosen_major_lsm) { | |
86ef3c73 KC |
385 | pr_warn("security=%s is ignored because it is superseded by lsm=%s\n", |
386 | chosen_major_lsm, chosen_lsm_order); | |
89a9684e KC |
387 | chosen_major_lsm = NULL; |
388 | } | |
79f7865d | 389 | ordered_lsm_parse(chosen_lsm_order, "cmdline"); |
89a9684e | 390 | } else |
79f7865d | 391 | ordered_lsm_parse(builtin_lsm_order, "builtin"); |
2d4d5119 KC |
392 | |
393 | for (lsm = ordered_lsms; *lsm; lsm++) | |
d8e9bbd4 KC |
394 | prepare_lsm(*lsm); |
395 | ||
86ef3c73 KC |
396 | report_lsm_order(); |
397 | ||
1aea7808 CS |
398 | init_debug("cred blob size = %d\n", blob_sizes.lbs_cred); |
399 | init_debug("file blob size = %d\n", blob_sizes.lbs_file); | |
400 | init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); | |
401 | init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); | |
402 | init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); | |
403 | init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock); | |
404 | init_debug("task blob size = %d\n", blob_sizes.lbs_task); | |
6bcdfd2c | 405 | init_debug("xattr slots = %d\n", blob_sizes.lbs_xattr_count); |
33bf60ca CS |
406 | |
407 | /* | |
408 | * Create any kmem_caches needed for blobs | |
409 | */ | |
410 | if (blob_sizes.lbs_file) | |
411 | lsm_file_cache = kmem_cache_create("lsm_file_cache", | |
412 | blob_sizes.lbs_file, 0, | |
413 | SLAB_PANIC, NULL); | |
afb1cbe3 CS |
414 | if (blob_sizes.lbs_inode) |
415 | lsm_inode_cache = kmem_cache_create("lsm_inode_cache", | |
416 | blob_sizes.lbs_inode, 0, | |
417 | SLAB_PANIC, NULL); | |
bbd3662a | 418 | |
1cfb2a51 TH |
419 | lsm_early_cred((struct cred *) current->cred); |
420 | lsm_early_task(current); | |
d8e9bbd4 KC |
421 | for (lsm = ordered_lsms; *lsm; lsm++) |
422 | initialize_lsm(*lsm); | |
2d4d5119 KC |
423 | |
424 | kfree(ordered_lsms); | |
425 | } | |
426 | ||
e6b1db98 MG |
427 | int __init early_security_init(void) |
428 | { | |
e6b1db98 MG |
429 | struct lsm_info *lsm; |
430 | ||
75c1182e BW |
431 | #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ |
432 | INIT_HLIST_HEAD(&security_hook_heads.NAME); | |
433 | #include "linux/lsm_hook_defs.h" | |
434 | #undef LSM_HOOK | |
e6b1db98 MG |
435 | |
436 | for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) { | |
437 | if (!lsm->enabled) | |
438 | lsm->enabled = &lsm_enabled_true; | |
439 | prepare_lsm(lsm); | |
440 | initialize_lsm(lsm); | |
441 | } | |
442 | ||
443 | return 0; | |
444 | } | |
445 | ||
1da177e4 LT |
446 | /** |
447 | * security_init - initializes the security framework | |
448 | * | |
449 | * This should be called early in the kernel initialization sequence. | |
450 | */ | |
451 | int __init security_init(void) | |
452 | { | |
e6b1db98 | 453 | struct lsm_info *lsm; |
3dfc9b02 | 454 | |
63c1845b | 455 | init_debug("legacy security=%s\n", chosen_major_lsm ? : " *unspecified*"); |
86ef3c73 | 456 | init_debug(" CONFIG_LSM=%s\n", builtin_lsm_order); |
63c1845b | 457 | init_debug("boot arg lsm=%s\n", chosen_lsm_order ? : " *unspecified*"); |
98d29170 | 458 | |
e6b1db98 MG |
459 | /* |
460 | * Append the names of the early LSM modules now that kmalloc() is | |
461 | * available | |
462 | */ | |
463 | for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) { | |
86ef3c73 KC |
464 | init_debug(" early started: %s (%s)\n", lsm->name, |
465 | is_enabled(lsm) ? "enabled" : "disabled"); | |
e6b1db98 MG |
466 | if (lsm->enabled) |
467 | lsm_append(lsm->name, &lsm_names); | |
468 | } | |
1da177e4 | 469 | |
657d910b KC |
470 | /* Load LSMs in specified order. */ |
471 | ordered_lsm_init(); | |
472 | ||
1da177e4 LT |
473 | return 0; |
474 | } | |
475 | ||
076c54c5 | 476 | /* Save user chosen LSM */ |
5ef4e419 | 477 | static int __init choose_major_lsm(char *str) |
076c54c5 | 478 | { |
5ef4e419 | 479 | chosen_major_lsm = str; |
076c54c5 AD |
480 | return 1; |
481 | } | |
5ef4e419 | 482 | __setup("security=", choose_major_lsm); |
076c54c5 | 483 | |
79f7865d KC |
484 | /* Explicitly choose LSM initialization order. */ |
485 | static int __init choose_lsm_order(char *str) | |
486 | { | |
487 | chosen_lsm_order = str; | |
488 | return 1; | |
489 | } | |
490 | __setup("lsm=", choose_lsm_order); | |
491 | ||
9b8c7c14 KC |
492 | /* Enable LSM order debugging. */ |
493 | static int __init enable_debug(char *str) | |
494 | { | |
495 | debug = true; | |
496 | return 1; | |
497 | } | |
498 | __setup("lsm.debug", enable_debug); | |
499 | ||
3bb857e4 MS |
500 | static bool match_last_lsm(const char *list, const char *lsm) |
501 | { | |
502 | const char *last; | |
503 | ||
504 | if (WARN_ON(!list || !lsm)) | |
505 | return false; | |
506 | last = strrchr(list, ','); | |
507 | if (last) | |
508 | /* Pass the comma, strcmp() will check for '\0' */ | |
509 | last++; | |
510 | else | |
511 | last = list; | |
512 | return !strcmp(last, lsm); | |
513 | } | |
514 | ||
e6b1db98 | 515 | static int lsm_append(const char *new, char **result) |
d69dece5 CS |
516 | { |
517 | char *cp; | |
518 | ||
519 | if (*result == NULL) { | |
520 | *result = kstrdup(new, GFP_KERNEL); | |
87ea5843 EB |
521 | if (*result == NULL) |
522 | return -ENOMEM; | |
d69dece5 | 523 | } else { |
3bb857e4 MS |
524 | /* Check if it is the last registered name */ |
525 | if (match_last_lsm(*result, new)) | |
526 | return 0; | |
d69dece5 CS |
527 | cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new); |
528 | if (cp == NULL) | |
529 | return -ENOMEM; | |
530 | kfree(*result); | |
531 | *result = cp; | |
532 | } | |
533 | return 0; | |
534 | } | |
535 | ||
d69dece5 CS |
536 | /** |
537 | * security_add_hooks - Add a modules hooks to the hook lists. | |
538 | * @hooks: the hooks to add | |
539 | * @count: the number of hooks to add | |
f3b8788c | 540 | * @lsmid: the identification information for the security module |
d69dece5 CS |
541 | * |
542 | * Each LSM has to register its hooks with the infrastructure. | |
543 | */ | |
544 | void __init security_add_hooks(struct security_hook_list *hooks, int count, | |
f3b8788c | 545 | const struct lsm_id *lsmid) |
d69dece5 CS |
546 | { |
547 | int i; | |
548 | ||
9285c5ad CS |
549 | /* |
550 | * A security module may call security_add_hooks() more | |
551 | * than once during initialization, and LSM initialization | |
552 | * is serialized. Landlock is one such case. | |
553 | * Look at the previous entry, if there is one, for duplication. | |
554 | */ | |
555 | if (lsm_active_cnt == 0 || lsm_idlist[lsm_active_cnt - 1] != lsmid) { | |
556 | if (lsm_active_cnt >= LSM_CONFIG_COUNT) | |
557 | panic("%s Too many LSMs registered.\n", __func__); | |
558 | lsm_idlist[lsm_active_cnt++] = lsmid; | |
559 | } | |
560 | ||
d69dece5 | 561 | for (i = 0; i < count; i++) { |
f3b8788c | 562 | hooks[i].lsmid = lsmid; |
df0ce173 | 563 | hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); |
d69dece5 | 564 | } |
e6b1db98 MG |
565 | |
566 | /* | |
567 | * Don't try to append during early_security_init(), we'll come back | |
568 | * and fix this up afterwards. | |
569 | */ | |
570 | if (slab_is_available()) { | |
f3b8788c | 571 | if (lsm_append(lsmid->name, &lsm_names) < 0) |
e6b1db98 MG |
572 | panic("%s - Cannot get early memory.\n", __func__); |
573 | } | |
d69dece5 CS |
574 | } |
575 | ||
42df744c | 576 | int call_blocking_lsm_notifier(enum lsm_event event, void *data) |
8f408ab6 | 577 | { |
42df744c JK |
578 | return blocking_notifier_call_chain(&blocking_lsm_notifier_chain, |
579 | event, data); | |
8f408ab6 | 580 | } |
42df744c | 581 | EXPORT_SYMBOL(call_blocking_lsm_notifier); |
8f408ab6 | 582 | |
42df744c | 583 | int register_blocking_lsm_notifier(struct notifier_block *nb) |
8f408ab6 | 584 | { |
42df744c JK |
585 | return blocking_notifier_chain_register(&blocking_lsm_notifier_chain, |
586 | nb); | |
8f408ab6 | 587 | } |
42df744c | 588 | EXPORT_SYMBOL(register_blocking_lsm_notifier); |
8f408ab6 | 589 | |
42df744c | 590 | int unregister_blocking_lsm_notifier(struct notifier_block *nb) |
8f408ab6 | 591 | { |
42df744c JK |
592 | return blocking_notifier_chain_unregister(&blocking_lsm_notifier_chain, |
593 | nb); | |
8f408ab6 | 594 | } |
42df744c | 595 | EXPORT_SYMBOL(unregister_blocking_lsm_notifier); |
8f408ab6 | 596 | |
bbd3662a CS |
597 | /** |
598 | * lsm_cred_alloc - allocate a composite cred blob | |
599 | * @cred: the cred that needs a blob | |
600 | * @gfp: allocation type | |
601 | * | |
602 | * Allocate the cred blob for all the modules | |
603 | * | |
604 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
605 | */ | |
606 | static int lsm_cred_alloc(struct cred *cred, gfp_t gfp) | |
607 | { | |
608 | if (blob_sizes.lbs_cred == 0) { | |
609 | cred->security = NULL; | |
610 | return 0; | |
611 | } | |
612 | ||
613 | cred->security = kzalloc(blob_sizes.lbs_cred, gfp); | |
614 | if (cred->security == NULL) | |
615 | return -ENOMEM; | |
616 | return 0; | |
617 | } | |
618 | ||
619 | /** | |
620 | * lsm_early_cred - during initialization allocate a composite cred blob | |
621 | * @cred: the cred that needs a blob | |
622 | * | |
1cfb2a51 | 623 | * Allocate the cred blob for all the modules |
bbd3662a | 624 | */ |
1cfb2a51 | 625 | static void __init lsm_early_cred(struct cred *cred) |
bbd3662a | 626 | { |
1cfb2a51 | 627 | int rc = lsm_cred_alloc(cred, GFP_KERNEL); |
bbd3662a | 628 | |
bbd3662a CS |
629 | if (rc) |
630 | panic("%s: Early cred alloc failed.\n", __func__); | |
631 | } | |
632 | ||
33bf60ca CS |
633 | /** |
634 | * lsm_file_alloc - allocate a composite file blob | |
635 | * @file: the file that needs a blob | |
636 | * | |
637 | * Allocate the file blob for all the modules | |
638 | * | |
639 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
640 | */ | |
641 | static int lsm_file_alloc(struct file *file) | |
642 | { | |
643 | if (!lsm_file_cache) { | |
644 | file->f_security = NULL; | |
645 | return 0; | |
646 | } | |
647 | ||
648 | file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL); | |
649 | if (file->f_security == NULL) | |
650 | return -ENOMEM; | |
651 | return 0; | |
652 | } | |
653 | ||
afb1cbe3 CS |
654 | /** |
655 | * lsm_inode_alloc - allocate a composite inode blob | |
656 | * @inode: the inode that needs a blob | |
657 | * | |
658 | * Allocate the inode blob for all the modules | |
659 | * | |
660 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
661 | */ | |
662 | int lsm_inode_alloc(struct inode *inode) | |
663 | { | |
664 | if (!lsm_inode_cache) { | |
665 | inode->i_security = NULL; | |
666 | return 0; | |
667 | } | |
668 | ||
669 | inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS); | |
670 | if (inode->i_security == NULL) | |
671 | return -ENOMEM; | |
672 | return 0; | |
673 | } | |
674 | ||
f4ad8f2c CS |
675 | /** |
676 | * lsm_task_alloc - allocate a composite task blob | |
677 | * @task: the task that needs a blob | |
678 | * | |
679 | * Allocate the task blob for all the modules | |
680 | * | |
681 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
682 | */ | |
3e8c7367 | 683 | static int lsm_task_alloc(struct task_struct *task) |
f4ad8f2c CS |
684 | { |
685 | if (blob_sizes.lbs_task == 0) { | |
686 | task->security = NULL; | |
687 | return 0; | |
688 | } | |
689 | ||
690 | task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL); | |
691 | if (task->security == NULL) | |
692 | return -ENOMEM; | |
693 | return 0; | |
694 | } | |
695 | ||
ecd5f82e CS |
696 | /** |
697 | * lsm_ipc_alloc - allocate a composite ipc blob | |
698 | * @kip: the ipc that needs a blob | |
699 | * | |
700 | * Allocate the ipc blob for all the modules | |
701 | * | |
702 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
703 | */ | |
3e8c7367 | 704 | static int lsm_ipc_alloc(struct kern_ipc_perm *kip) |
ecd5f82e CS |
705 | { |
706 | if (blob_sizes.lbs_ipc == 0) { | |
707 | kip->security = NULL; | |
708 | return 0; | |
709 | } | |
710 | ||
711 | kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL); | |
712 | if (kip->security == NULL) | |
713 | return -ENOMEM; | |
714 | return 0; | |
715 | } | |
716 | ||
717 | /** | |
718 | * lsm_msg_msg_alloc - allocate a composite msg_msg blob | |
719 | * @mp: the msg_msg that needs a blob | |
720 | * | |
721 | * Allocate the ipc blob for all the modules | |
722 | * | |
723 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
724 | */ | |
3e8c7367 | 725 | static int lsm_msg_msg_alloc(struct msg_msg *mp) |
ecd5f82e CS |
726 | { |
727 | if (blob_sizes.lbs_msg_msg == 0) { | |
728 | mp->security = NULL; | |
729 | return 0; | |
730 | } | |
731 | ||
732 | mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL); | |
733 | if (mp->security == NULL) | |
734 | return -ENOMEM; | |
735 | return 0; | |
736 | } | |
737 | ||
f4ad8f2c CS |
738 | /** |
739 | * lsm_early_task - during initialization allocate a composite task blob | |
740 | * @task: the task that needs a blob | |
741 | * | |
1cfb2a51 | 742 | * Allocate the task blob for all the modules |
f4ad8f2c | 743 | */ |
1cfb2a51 | 744 | static void __init lsm_early_task(struct task_struct *task) |
f4ad8f2c | 745 | { |
1cfb2a51 | 746 | int rc = lsm_task_alloc(task); |
f4ad8f2c | 747 | |
f4ad8f2c CS |
748 | if (rc) |
749 | panic("%s: Early task alloc failed.\n", __func__); | |
750 | } | |
751 | ||
1aea7808 CS |
752 | /** |
753 | * lsm_superblock_alloc - allocate a composite superblock blob | |
754 | * @sb: the superblock that needs a blob | |
755 | * | |
756 | * Allocate the superblock blob for all the modules | |
757 | * | |
758 | * Returns 0, or -ENOMEM if memory can't be allocated. | |
759 | */ | |
760 | static int lsm_superblock_alloc(struct super_block *sb) | |
761 | { | |
762 | if (blob_sizes.lbs_superblock == 0) { | |
763 | sb->s_security = NULL; | |
764 | return 0; | |
765 | } | |
766 | ||
767 | sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL); | |
768 | if (sb->s_security == NULL) | |
769 | return -ENOMEM; | |
770 | return 0; | |
771 | } | |
772 | ||
e1ca7129 CS |
773 | /** |
774 | * lsm_fill_user_ctx - Fill a user space lsm_ctx structure | |
775 | * @ctx: an LSM context to be filled | |
776 | * @context: the new context value | |
777 | * @context_size: the size of the new context value | |
778 | * @id: LSM id | |
779 | * @flags: LSM defined flags | |
780 | * | |
781 | * Fill all of the fields in a user space lsm_ctx structure. | |
782 | * Caller is assumed to have verified that @ctx has enough space | |
783 | * for @context. | |
784 | * | |
785 | * Returns 0 on success, -EFAULT on a copyout error, -ENOMEM | |
786 | * if memory can't be allocated. | |
787 | */ | |
788 | int lsm_fill_user_ctx(struct lsm_ctx __user *ctx, void *context, | |
789 | size_t context_size, u64 id, u64 flags) | |
790 | { | |
791 | struct lsm_ctx *lctx; | |
792 | size_t locallen = struct_size(lctx, ctx, context_size); | |
793 | int rc = 0; | |
794 | ||
795 | lctx = kzalloc(locallen, GFP_KERNEL); | |
796 | if (lctx == NULL) | |
797 | return -ENOMEM; | |
798 | ||
799 | lctx->id = id; | |
800 | lctx->flags = flags; | |
801 | lctx->ctx_len = context_size; | |
802 | lctx->len = locallen; | |
803 | ||
804 | memcpy(lctx->ctx, context, context_size); | |
805 | ||
806 | if (copy_to_user(ctx, lctx, locallen)) | |
807 | rc = -EFAULT; | |
808 | ||
809 | kfree(lctx); | |
810 | ||
811 | return rc; | |
812 | } | |
813 | ||
98e828a0 KS |
814 | /* |
815 | * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and | |
816 | * can be accessed with: | |
817 | * | |
818 | * LSM_RET_DEFAULT(<hook_name>) | |
819 | * | |
820 | * The macros below define static constants for the default value of each | |
821 | * LSM hook. | |
822 | */ | |
823 | #define LSM_RET_DEFAULT(NAME) (NAME##_default) | |
824 | #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME) | |
825 | #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \ | |
86dd9fd5 | 826 | static const int __maybe_unused LSM_RET_DEFAULT(NAME) = (DEFAULT); |
98e828a0 KS |
827 | #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ |
828 | DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME) | |
829 | ||
830 | #include <linux/lsm_hook_defs.h> | |
831 | #undef LSM_HOOK | |
832 | ||
f25fce3e | 833 | /* |
b1d9e6b0 | 834 | * Hook list operation macros. |
1da177e4 | 835 | * |
f25fce3e CS |
836 | * call_void_hook: |
837 | * This is a hook that does not return a value. | |
1da177e4 | 838 | * |
f25fce3e CS |
839 | * call_int_hook: |
840 | * This is a hook that returns a value. | |
1da177e4 | 841 | */ |
1da177e4 | 842 | |
b1d9e6b0 CS |
843 | #define call_void_hook(FUNC, ...) \ |
844 | do { \ | |
845 | struct security_hook_list *P; \ | |
846 | \ | |
df0ce173 | 847 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \ |
b1d9e6b0 CS |
848 | P->hook.FUNC(__VA_ARGS__); \ |
849 | } while (0) | |
850 | ||
851 | #define call_int_hook(FUNC, IRC, ...) ({ \ | |
852 | int RC = IRC; \ | |
853 | do { \ | |
854 | struct security_hook_list *P; \ | |
855 | \ | |
df0ce173 | 856 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ |
b1d9e6b0 CS |
857 | RC = P->hook.FUNC(__VA_ARGS__); \ |
858 | if (RC != 0) \ | |
859 | break; \ | |
860 | } \ | |
861 | } while (0); \ | |
862 | RC; \ | |
863 | }) | |
1da177e4 | 864 | |
20510f2f JM |
865 | /* Security operations */ |
866 | ||
1427ddbe PM |
867 | /** |
868 | * security_binder_set_context_mgr() - Check if becoming binder ctx mgr is ok | |
869 | * @mgr: task credentials of current binder process | |
870 | * | |
871 | * Check whether @mgr is allowed to be the binder context manager. | |
872 | * | |
873 | * Return: Return 0 if permission is granted. | |
874 | */ | |
52f88693 | 875 | int security_binder_set_context_mgr(const struct cred *mgr) |
79af7307 | 876 | { |
f25fce3e | 877 | return call_int_hook(binder_set_context_mgr, 0, mgr); |
79af7307 SS |
878 | } |
879 | ||
1427ddbe PM |
880 | /** |
881 | * security_binder_transaction() - Check if a binder transaction is allowed | |
882 | * @from: sending process | |
883 | * @to: receiving process | |
884 | * | |
885 | * Check whether @from is allowed to invoke a binder transaction call to @to. | |
886 | * | |
887 | * Return: Returns 0 if permission is granted. | |
888 | */ | |
52f88693 TK |
889 | int security_binder_transaction(const struct cred *from, |
890 | const struct cred *to) | |
79af7307 | 891 | { |
f25fce3e | 892 | return call_int_hook(binder_transaction, 0, from, to); |
79af7307 SS |
893 | } |
894 | ||
1427ddbe PM |
895 | /** |
896 | * security_binder_transfer_binder() - Check if a binder transfer is allowed | |
897 | * @from: sending process | |
898 | * @to: receiving process | |
899 | * | |
900 | * Check whether @from is allowed to transfer a binder reference to @to. | |
901 | * | |
902 | * Return: Returns 0 if permission is granted. | |
903 | */ | |
52f88693 TK |
904 | int security_binder_transfer_binder(const struct cred *from, |
905 | const struct cred *to) | |
79af7307 | 906 | { |
f25fce3e | 907 | return call_int_hook(binder_transfer_binder, 0, from, to); |
79af7307 SS |
908 | } |
909 | ||
1427ddbe PM |
910 | /** |
911 | * security_binder_transfer_file() - Check if a binder file xfer is allowed | |
912 | * @from: sending process | |
913 | * @to: receiving process | |
914 | * @file: file being transferred | |
915 | * | |
916 | * Check whether @from is allowed to transfer @file to @to. | |
917 | * | |
918 | * Return: Returns 0 if permission is granted. | |
919 | */ | |
52f88693 | 920 | int security_binder_transfer_file(const struct cred *from, |
8e4672d6 | 921 | const struct cred *to, const struct file *file) |
79af7307 | 922 | { |
f25fce3e | 923 | return call_int_hook(binder_transfer_file, 0, from, to, file); |
79af7307 SS |
924 | } |
925 | ||
e261301c PM |
926 | /** |
927 | * security_ptrace_access_check() - Check if tracing is allowed | |
928 | * @child: target process | |
929 | * @mode: PTRACE_MODE flags | |
930 | * | |
931 | * Check permission before allowing the current process to trace the @child | |
932 | * process. Security modules may also want to perform a process tracing check | |
933 | * during an execve in the set_security or apply_creds hooks of tracing check | |
934 | * during an execve in the bprm_set_creds hook of binprm_security_ops if the | |
935 | * process is being traced and its security attributes would be changed by the | |
936 | * execve. | |
937 | * | |
938 | * Return: Returns 0 if permission is granted. | |
939 | */ | |
9e48858f | 940 | int security_ptrace_access_check(struct task_struct *child, unsigned int mode) |
20510f2f | 941 | { |
f25fce3e | 942 | return call_int_hook(ptrace_access_check, 0, child, mode); |
5cd9c58f DH |
943 | } |
944 | ||
e261301c PM |
945 | /** |
946 | * security_ptrace_traceme() - Check if tracing is allowed | |
947 | * @parent: tracing process | |
948 | * | |
949 | * Check that the @parent process has sufficient permission to trace the | |
950 | * current process before allowing the current process to present itself to the | |
951 | * @parent process for tracing. | |
952 | * | |
953 | * Return: Returns 0 if permission is granted. | |
954 | */ | |
5cd9c58f DH |
955 | int security_ptrace_traceme(struct task_struct *parent) |
956 | { | |
f25fce3e | 957 | return call_int_hook(ptrace_traceme, 0, parent); |
20510f2f JM |
958 | } |
959 | ||
e261301c PM |
960 | /** |
961 | * security_capget() - Get the capability sets for a process | |
962 | * @target: target process | |
963 | * @effective: effective capability set | |
964 | * @inheritable: inheritable capability set | |
965 | * @permitted: permitted capability set | |
966 | * | |
967 | * Get the @effective, @inheritable, and @permitted capability sets for the | |
968 | * @target process. The hook may also perform permission checking to determine | |
969 | * if the current process is allowed to see the capability sets of the @target | |
970 | * process. | |
971 | * | |
972 | * Return: Returns 0 if the capability sets were successfully obtained. | |
973 | */ | |
6672efbb | 974 | int security_capget(const struct task_struct *target, |
63c1845b PM |
975 | kernel_cap_t *effective, |
976 | kernel_cap_t *inheritable, | |
977 | kernel_cap_t *permitted) | |
20510f2f | 978 | { |
f25fce3e | 979 | return call_int_hook(capget, 0, target, |
63c1845b | 980 | effective, inheritable, permitted); |
20510f2f JM |
981 | } |
982 | ||
e261301c PM |
983 | /** |
984 | * security_capset() - Set the capability sets for a process | |
985 | * @new: new credentials for the target process | |
986 | * @old: current credentials of the target process | |
987 | * @effective: effective capability set | |
988 | * @inheritable: inheritable capability set | |
989 | * @permitted: permitted capability set | |
990 | * | |
991 | * Set the @effective, @inheritable, and @permitted capability sets for the | |
992 | * current process. | |
993 | * | |
994 | * Return: Returns 0 and update @new if permission is granted. | |
995 | */ | |
d84f4f99 DH |
996 | int security_capset(struct cred *new, const struct cred *old, |
997 | const kernel_cap_t *effective, | |
998 | const kernel_cap_t *inheritable, | |
999 | const kernel_cap_t *permitted) | |
20510f2f | 1000 | { |
f25fce3e | 1001 | return call_int_hook(capset, 0, new, old, |
63c1845b | 1002 | effective, inheritable, permitted); |
20510f2f JM |
1003 | } |
1004 | ||
e261301c PM |
1005 | /** |
1006 | * security_capable() - Check if a process has the necessary capability | |
1007 | * @cred: credentials to examine | |
1008 | * @ns: user namespace | |
1009 | * @cap: capability requested | |
1010 | * @opts: capability check options | |
1011 | * | |
1012 | * Check whether the @tsk process has the @cap capability in the indicated | |
1013 | * credentials. @cap contains the capability <include/linux/capability.h>. | |
1014 | * @opts contains options for the capable check <include/linux/security.h>. | |
1015 | * | |
1016 | * Return: Returns 0 if the capability is granted. | |
1017 | */ | |
c1a85a00 MM |
1018 | int security_capable(const struct cred *cred, |
1019 | struct user_namespace *ns, | |
1020 | int cap, | |
1021 | unsigned int opts) | |
20510f2f | 1022 | { |
c1a85a00 | 1023 | return call_int_hook(capable, 0, cred, ns, cap, opts); |
20510f2f JM |
1024 | } |
1025 | ||
e261301c PM |
1026 | /** |
1027 | * security_quotactl() - Check if a quotactl() syscall is allowed for this fs | |
1028 | * @cmds: commands | |
1029 | * @type: type | |
1030 | * @id: id | |
1031 | * @sb: filesystem | |
1032 | * | |
1033 | * Check whether the quotactl syscall is allowed for this @sb. | |
1034 | * | |
1035 | * Return: Returns 0 if permission is granted. | |
1036 | */ | |
25cc71d1 | 1037 | int security_quotactl(int cmds, int type, int id, const struct super_block *sb) |
20510f2f | 1038 | { |
f25fce3e | 1039 | return call_int_hook(quotactl, 0, cmds, type, id, sb); |
20510f2f JM |
1040 | } |
1041 | ||
e261301c PM |
1042 | /** |
1043 | * security_quota_on() - Check if QUOTAON is allowed for a dentry | |
1044 | * @dentry: dentry | |
1045 | * | |
1046 | * Check whether QUOTAON is allowed for @dentry. | |
1047 | * | |
1048 | * Return: Returns 0 if permission is granted. | |
1049 | */ | |
20510f2f JM |
1050 | int security_quota_on(struct dentry *dentry) |
1051 | { | |
f25fce3e | 1052 | return call_int_hook(quota_on, 0, dentry); |
20510f2f JM |
1053 | } |
1054 | ||
e261301c PM |
1055 | /** |
1056 | * security_syslog() - Check if accessing the kernel message ring is allowed | |
1057 | * @type: SYSLOG_ACTION_* type | |
1058 | * | |
1059 | * Check permission before accessing the kernel message ring or changing | |
1060 | * logging to the console. See the syslog(2) manual page for an explanation of | |
1061 | * the @type values. | |
1062 | * | |
1063 | * Return: Return 0 if permission is granted. | |
1064 | */ | |
12b3052c | 1065 | int security_syslog(int type) |
20510f2f | 1066 | { |
f25fce3e | 1067 | return call_int_hook(syslog, 0, type); |
20510f2f JM |
1068 | } |
1069 | ||
e261301c PM |
1070 | /** |
1071 | * security_settime64() - Check if changing the system time is allowed | |
1072 | * @ts: new time | |
1073 | * @tz: timezone | |
1074 | * | |
1075 | * Check permission to change the system time, struct timespec64 is defined in | |
1076 | * <include/linux/time64.h> and timezone is defined in <include/linux/time.h>. | |
1077 | * | |
1078 | * Return: Returns 0 if permission is granted. | |
1079 | */ | |
457db29b | 1080 | int security_settime64(const struct timespec64 *ts, const struct timezone *tz) |
20510f2f | 1081 | { |
f25fce3e | 1082 | return call_int_hook(settime, 0, ts, tz); |
20510f2f JM |
1083 | } |
1084 | ||
e261301c PM |
1085 | /** |
1086 | * security_vm_enough_memory_mm() - Check if allocating a new mem map is allowed | |
1087 | * @mm: mm struct | |
1088 | * @pages: number of pages | |
1089 | * | |
1090 | * Check permissions for allocating a new virtual mapping. If all LSMs return | |
1091 | * a positive value, __vm_enough_memory() will be called with cap_sys_admin | |
1092 | * set. If at least one LSM returns 0 or negative, __vm_enough_memory() will be | |
1093 | * called with cap_sys_admin cleared. | |
1094 | * | |
1095 | * Return: Returns 0 if permission is granted by the LSM infrastructure to the | |
1096 | * caller. | |
1097 | */ | |
20510f2f JM |
1098 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) |
1099 | { | |
b1d9e6b0 CS |
1100 | struct security_hook_list *hp; |
1101 | int cap_sys_admin = 1; | |
1102 | int rc; | |
1103 | ||
1104 | /* | |
1105 | * The module will respond with a positive value if | |
1106 | * it thinks the __vm_enough_memory() call should be | |
1107 | * made with the cap_sys_admin set. If all of the modules | |
1108 | * agree that it should be set it will. If any module | |
1109 | * thinks it should not be set it won't. | |
1110 | */ | |
df0ce173 | 1111 | hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) { |
b1d9e6b0 CS |
1112 | rc = hp->hook.vm_enough_memory(mm, pages); |
1113 | if (rc <= 0) { | |
1114 | cap_sys_admin = 0; | |
1115 | break; | |
1116 | } | |
1117 | } | |
1118 | return __vm_enough_memory(mm, pages, cap_sys_admin); | |
20510f2f JM |
1119 | } |
1120 | ||
1661372c PM |
1121 | /** |
1122 | * security_bprm_creds_for_exec() - Prepare the credentials for exec() | |
1123 | * @bprm: binary program information | |
1124 | * | |
1125 | * If the setup in prepare_exec_creds did not setup @bprm->cred->security | |
1126 | * properly for executing @bprm->file, update the LSM's portion of | |
1127 | * @bprm->cred->security to be what commit_creds needs to install for the new | |
1128 | * program. This hook may also optionally check permissions (e.g. for | |
1129 | * transitions between security domains). The hook must set @bprm->secureexec | |
1130 | * to 1 if AT_SECURE should be set to request libc enable secure mode. @bprm | |
1131 | * contains the linux_binprm structure. | |
1132 | * | |
1133 | * Return: Returns 0 if the hook is successful and permission is granted. | |
1134 | */ | |
b8bff599 | 1135 | int security_bprm_creds_for_exec(struct linux_binprm *bprm) |
20510f2f | 1136 | { |
b8bff599 EB |
1137 | return call_int_hook(bprm_creds_for_exec, 0, bprm); |
1138 | } | |
1139 | ||
1661372c PM |
1140 | /** |
1141 | * security_bprm_creds_from_file() - Update linux_binprm creds based on file | |
1142 | * @bprm: binary program information | |
1143 | * @file: associated file | |
1144 | * | |
1145 | * If @file is setpcap, suid, sgid or otherwise marked to change privilege upon | |
1146 | * exec, update @bprm->cred to reflect that change. This is called after | |
1147 | * finding the binary that will be executed without an interpreter. This | |
1148 | * ensures that the credentials will not be derived from a script that the | |
1149 | * binary will need to reopen, which when reopend may end up being a completely | |
1150 | * different file. This hook may also optionally check permissions (e.g. for | |
1151 | * transitions between security domains). The hook must set @bprm->secureexec | |
1152 | * to 1 if AT_SECURE should be set to request libc enable secure mode. The | |
1153 | * hook must add to @bprm->per_clear any personality flags that should be | |
1154 | * cleared from current->personality. @bprm contains the linux_binprm | |
1155 | * structure. | |
1156 | * | |
1157 | * Return: Returns 0 if the hook is successful and permission is granted. | |
1158 | */ | |
4a00c673 | 1159 | int security_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file) |
20510f2f | 1160 | { |
56305aa9 | 1161 | return call_int_hook(bprm_creds_from_file, 0, bprm, file); |
20510f2f JM |
1162 | } |
1163 | ||
1661372c PM |
1164 | /** |
1165 | * security_bprm_check() - Mediate binary handler search | |
1166 | * @bprm: binary program information | |
1167 | * | |
1168 | * This hook mediates the point when a search for a binary handler will begin. | |
1169 | * It allows a check against the @bprm->cred->security value which was set in | |
1170 | * the preceding creds_for_exec call. The argv list and envp list are reliably | |
1171 | * available in @bprm. This hook may be called multiple times during a single | |
1172 | * execve. @bprm contains the linux_binprm structure. | |
1173 | * | |
1174 | * Return: Returns 0 if the hook is successful and permission is granted. | |
1175 | */ | |
a6f76f23 | 1176 | int security_bprm_check(struct linux_binprm *bprm) |
20510f2f | 1177 | { |
6c21a7fb MZ |
1178 | int ret; |
1179 | ||
f25fce3e | 1180 | ret = call_int_hook(bprm_check_security, 0, bprm); |
6c21a7fb MZ |
1181 | if (ret) |
1182 | return ret; | |
1183 | return ima_bprm_check(bprm); | |
20510f2f JM |
1184 | } |
1185 | ||
1661372c PM |
1186 | /** |
1187 | * security_bprm_committing_creds() - Install creds for a process during exec() | |
1188 | * @bprm: binary program information | |
1189 | * | |
1190 | * Prepare to install the new security attributes of a process being | |
1191 | * transformed by an execve operation, based on the old credentials pointed to | |
1192 | * by @current->cred and the information set in @bprm->cred by the | |
1193 | * bprm_creds_for_exec hook. @bprm points to the linux_binprm structure. This | |
1194 | * hook is a good place to perform state changes on the process such as closing | |
1195 | * open file descriptors to which access will no longer be granted when the | |
1196 | * attributes are changed. This is called immediately before commit_creds(). | |
1197 | */ | |
64fc9526 | 1198 | void security_bprm_committing_creds(const struct linux_binprm *bprm) |
20510f2f | 1199 | { |
f25fce3e | 1200 | call_void_hook(bprm_committing_creds, bprm); |
20510f2f JM |
1201 | } |
1202 | ||
1661372c PM |
1203 | /** |
1204 | * security_bprm_committed_creds() - Tidy up after cred install during exec() | |
1205 | * @bprm: binary program information | |
1206 | * | |
1207 | * Tidy up after the installation of the new security attributes of a process | |
1208 | * being transformed by an execve operation. The new credentials have, by this | |
1209 | * point, been set to @current->cred. @bprm points to the linux_binprm | |
1210 | * structure. This hook is a good place to perform state changes on the | |
1211 | * process such as clearing out non-inheritable signal state. This is called | |
1212 | * immediately after commit_creds(). | |
1213 | */ | |
a721f7b8 | 1214 | void security_bprm_committed_creds(const struct linux_binprm *bprm) |
20510f2f | 1215 | { |
f25fce3e | 1216 | call_void_hook(bprm_committed_creds, bprm); |
20510f2f JM |
1217 | } |
1218 | ||
d80a8f1b DH |
1219 | /** |
1220 | * security_fs_context_submount() - Initialise fc->security | |
1221 | * @fc: new filesystem context | |
1222 | * @reference: dentry reference for submount/remount | |
1223 | * | |
1224 | * Fill out the ->security field for a new fs_context. | |
1225 | * | |
1226 | * Return: Returns 0 on success or negative error code on failure. | |
1227 | */ | |
1228 | int security_fs_context_submount(struct fs_context *fc, struct super_block *reference) | |
1229 | { | |
1230 | return call_int_hook(fs_context_submount, 0, fc, reference); | |
1231 | } | |
1232 | ||
36819f18 PM |
1233 | /** |
1234 | * security_fs_context_dup() - Duplicate a fs_context LSM blob | |
1235 | * @fc: destination filesystem context | |
1236 | * @src_fc: source filesystem context | |
1237 | * | |
1238 | * Allocate and attach a security structure to sc->security. This pointer is | |
1239 | * initialised to NULL by the caller. @fc indicates the new filesystem context. | |
1240 | * @src_fc indicates the original filesystem context. | |
1241 | * | |
1242 | * Return: Returns 0 on success or a negative error code on failure. | |
1243 | */ | |
0b52075e AV |
1244 | int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) |
1245 | { | |
1246 | return call_int_hook(fs_context_dup, 0, fc, src_fc); | |
1247 | } | |
1248 | ||
36819f18 PM |
1249 | /** |
1250 | * security_fs_context_parse_param() - Configure a filesystem context | |
1251 | * @fc: filesystem context | |
1252 | * @param: filesystem parameter | |
1253 | * | |
1254 | * Userspace provided a parameter to configure a superblock. The LSM can | |
1255 | * consume the parameter or return it to the caller for use elsewhere. | |
1256 | * | |
1257 | * Return: If the parameter is used by the LSM it should return 0, if it is | |
1258 | * returned to the caller -ENOPARAM is returned, otherwise a negative | |
1259 | * error code is returned. | |
1260 | */ | |
ecff3057 CS |
1261 | int security_fs_context_parse_param(struct fs_context *fc, |
1262 | struct fs_parameter *param) | |
da2441fd | 1263 | { |
ecff3057 CS |
1264 | struct security_hook_list *hp; |
1265 | int trc; | |
1266 | int rc = -ENOPARAM; | |
1267 | ||
1268 | hlist_for_each_entry(hp, &security_hook_heads.fs_context_parse_param, | |
1269 | list) { | |
1270 | trc = hp->hook.fs_context_parse_param(fc, param); | |
1271 | if (trc == 0) | |
1272 | rc = 0; | |
1273 | else if (trc != -ENOPARAM) | |
1274 | return trc; | |
1275 | } | |
1276 | return rc; | |
da2441fd DH |
1277 | } |
1278 | ||
08526a90 PM |
1279 | /** |
1280 | * security_sb_alloc() - Allocate a super_block LSM blob | |
1281 | * @sb: filesystem superblock | |
1282 | * | |
1283 | * Allocate and attach a security structure to the sb->s_security field. The | |
1284 | * s_security field is initialized to NULL when the structure is allocated. | |
1285 | * @sb contains the super_block structure to be modified. | |
1286 | * | |
1287 | * Return: Returns 0 if operation was successful. | |
1288 | */ | |
20510f2f JM |
1289 | int security_sb_alloc(struct super_block *sb) |
1290 | { | |
1aea7808 CS |
1291 | int rc = lsm_superblock_alloc(sb); |
1292 | ||
1293 | if (unlikely(rc)) | |
1294 | return rc; | |
1295 | rc = call_int_hook(sb_alloc_security, 0, sb); | |
1296 | if (unlikely(rc)) | |
1297 | security_sb_free(sb); | |
1298 | return rc; | |
20510f2f JM |
1299 | } |
1300 | ||
08526a90 PM |
1301 | /** |
1302 | * security_sb_delete() - Release super_block LSM associated objects | |
1303 | * @sb: filesystem superblock | |
1304 | * | |
1305 | * Release objects tied to a superblock (e.g. inodes). @sb contains the | |
1306 | * super_block structure being released. | |
1307 | */ | |
83e804f0 MS |
1308 | void security_sb_delete(struct super_block *sb) |
1309 | { | |
1310 | call_void_hook(sb_delete, sb); | |
20510f2f JM |
1311 | } |
1312 | ||
08526a90 PM |
1313 | /** |
1314 | * security_sb_free() - Free a super_block LSM blob | |
1315 | * @sb: filesystem superblock | |
1316 | * | |
1317 | * Deallocate and clear the sb->s_security field. @sb contains the super_block | |
1318 | * structure to be modified. | |
1319 | */ | |
20510f2f JM |
1320 | void security_sb_free(struct super_block *sb) |
1321 | { | |
f25fce3e | 1322 | call_void_hook(sb_free_security, sb); |
1aea7808 CS |
1323 | kfree(sb->s_security); |
1324 | sb->s_security = NULL; | |
20510f2f JM |
1325 | } |
1326 | ||
08526a90 PM |
1327 | /** |
1328 | * security_free_mnt_opts() - Free memory associated with mount options | |
1e2523d7 | 1329 | * @mnt_opts: LSM processed mount options |
08526a90 PM |
1330 | * |
1331 | * Free memory associated with @mnt_ops. | |
1332 | */ | |
204cc0cc | 1333 | void security_free_mnt_opts(void **mnt_opts) |
20510f2f | 1334 | { |
204cc0cc AV |
1335 | if (!*mnt_opts) |
1336 | return; | |
1337 | call_void_hook(sb_free_mnt_opts, *mnt_opts); | |
1338 | *mnt_opts = NULL; | |
20510f2f | 1339 | } |
204cc0cc | 1340 | EXPORT_SYMBOL(security_free_mnt_opts); |
20510f2f | 1341 | |
08526a90 PM |
1342 | /** |
1343 | * security_sb_eat_lsm_opts() - Consume LSM mount options | |
1344 | * @options: mount options | |
1e2523d7 | 1345 | * @mnt_opts: LSM processed mount options |
08526a90 PM |
1346 | * |
1347 | * Eat (scan @options) and save them in @mnt_opts. | |
1348 | * | |
1349 | * Return: Returns 0 on success, negative values on failure. | |
1350 | */ | |
204cc0cc | 1351 | int security_sb_eat_lsm_opts(char *options, void **mnt_opts) |
ff36fe2c | 1352 | { |
204cc0cc | 1353 | return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts); |
ff36fe2c | 1354 | } |
f5c0c26d | 1355 | EXPORT_SYMBOL(security_sb_eat_lsm_opts); |
ff36fe2c | 1356 | |
08526a90 PM |
1357 | /** |
1358 | * security_sb_mnt_opts_compat() - Check if new mount options are allowed | |
1359 | * @sb: filesystem superblock | |
1360 | * @mnt_opts: new mount options | |
1361 | * | |
1362 | * Determine if the new mount options in @mnt_opts are allowed given the | |
1363 | * existing mounted filesystem at @sb. @sb superblock being compared. | |
1364 | * | |
1365 | * Return: Returns 0 if options are compatible. | |
1366 | */ | |
69c4a42d OK |
1367 | int security_sb_mnt_opts_compat(struct super_block *sb, |
1368 | void *mnt_opts) | |
1369 | { | |
1370 | return call_int_hook(sb_mnt_opts_compat, 0, sb, mnt_opts); | |
1371 | } | |
1372 | EXPORT_SYMBOL(security_sb_mnt_opts_compat); | |
1373 | ||
08526a90 PM |
1374 | /** |
1375 | * security_sb_remount() - Verify no incompatible mount changes during remount | |
1376 | * @sb: filesystem superblock | |
1377 | * @mnt_opts: (re)mount options | |
1378 | * | |
1379 | * Extracts security system specific mount options and verifies no changes are | |
1380 | * being made to those options. | |
1381 | * | |
1382 | * Return: Returns 0 if permission is granted. | |
1383 | */ | |
c039bc3c | 1384 | int security_sb_remount(struct super_block *sb, |
204cc0cc | 1385 | void *mnt_opts) |
20510f2f | 1386 | { |
204cc0cc | 1387 | return call_int_hook(sb_remount, 0, sb, mnt_opts); |
ff36fe2c | 1388 | } |
a65001e8 | 1389 | EXPORT_SYMBOL(security_sb_remount); |
ff36fe2c | 1390 | |
08526a90 PM |
1391 | /** |
1392 | * security_sb_kern_mount() - Check if a kernel mount is allowed | |
1393 | * @sb: filesystem superblock | |
1394 | * | |
1395 | * Mount this @sb if allowed by permissions. | |
1396 | * | |
1397 | * Return: Returns 0 if permission is granted. | |
1398 | */ | |
20a2aa47 | 1399 | int security_sb_kern_mount(const struct super_block *sb) |
20510f2f | 1400 | { |
a10d7c22 | 1401 | return call_int_hook(sb_kern_mount, 0, sb); |
20510f2f JM |
1402 | } |
1403 | ||
08526a90 PM |
1404 | /** |
1405 | * security_sb_show_options() - Output the mount options for a superblock | |
1406 | * @m: output file | |
1407 | * @sb: filesystem superblock | |
1408 | * | |
1409 | * Show (print on @m) mount options for this @sb. | |
1410 | * | |
1411 | * Return: Returns 0 on success, negative values on failure. | |
1412 | */ | |
2069f457 EP |
1413 | int security_sb_show_options(struct seq_file *m, struct super_block *sb) |
1414 | { | |
f25fce3e | 1415 | return call_int_hook(sb_show_options, 0, m, sb); |
2069f457 EP |
1416 | } |
1417 | ||
08526a90 PM |
1418 | /** |
1419 | * security_sb_statfs() - Check if accessing fs stats is allowed | |
1420 | * @dentry: superblock handle | |
1421 | * | |
1422 | * Check permission before obtaining filesystem statistics for the @mnt | |
1423 | * mountpoint. @dentry is a handle on the superblock for the filesystem. | |
1424 | * | |
1425 | * Return: Returns 0 if permission is granted. | |
1426 | */ | |
20510f2f JM |
1427 | int security_sb_statfs(struct dentry *dentry) |
1428 | { | |
f25fce3e | 1429 | return call_int_hook(sb_statfs, 0, dentry); |
20510f2f JM |
1430 | } |
1431 | ||
08526a90 PM |
1432 | /** |
1433 | * security_sb_mount() - Check permission for mounting a filesystem | |
1434 | * @dev_name: filesystem backing device | |
1435 | * @path: mount point | |
1436 | * @type: filesystem type | |
1437 | * @flags: mount flags | |
1438 | * @data: filesystem specific data | |
1439 | * | |
1440 | * Check permission before an object specified by @dev_name is mounted on the | |
1441 | * mount point named by @nd. For an ordinary mount, @dev_name identifies a | |
1442 | * device if the file system type requires a device. For a remount | |
1443 | * (@flags & MS_REMOUNT), @dev_name is irrelevant. For a loopback/bind mount | |
1444 | * (@flags & MS_BIND), @dev_name identifies the pathname of the object being | |
1445 | * mounted. | |
1446 | * | |
1447 | * Return: Returns 0 if permission is granted. | |
1448 | */ | |
8a04c43b | 1449 | int security_sb_mount(const char *dev_name, const struct path *path, |
63c1845b | 1450 | const char *type, unsigned long flags, void *data) |
20510f2f | 1451 | { |
f25fce3e | 1452 | return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data); |
20510f2f JM |
1453 | } |
1454 | ||
08526a90 PM |
1455 | /** |
1456 | * security_sb_umount() - Check permission for unmounting a filesystem | |
1457 | * @mnt: mounted filesystem | |
1458 | * @flags: unmount flags | |
1459 | * | |
1460 | * Check permission before the @mnt file system is unmounted. | |
1461 | * | |
1462 | * Return: Returns 0 if permission is granted. | |
1463 | */ | |
20510f2f JM |
1464 | int security_sb_umount(struct vfsmount *mnt, int flags) |
1465 | { | |
f25fce3e | 1466 | return call_int_hook(sb_umount, 0, mnt, flags); |
20510f2f JM |
1467 | } |
1468 | ||
08526a90 PM |
1469 | /** |
1470 | * security_sb_pivotroot() - Check permissions for pivoting the rootfs | |
1471 | * @old_path: new location for current rootfs | |
1472 | * @new_path: location of the new rootfs | |
1473 | * | |
1474 | * Check permission before pivoting the root filesystem. | |
1475 | * | |
1476 | * Return: Returns 0 if permission is granted. | |
1477 | */ | |
63c1845b PM |
1478 | int security_sb_pivotroot(const struct path *old_path, |
1479 | const struct path *new_path) | |
20510f2f | 1480 | { |
f25fce3e | 1481 | return call_int_hook(sb_pivotroot, 0, old_path, new_path); |
20510f2f JM |
1482 | } |
1483 | ||
08526a90 PM |
1484 | /** |
1485 | * security_sb_set_mnt_opts() - Set the mount options for a filesystem | |
1486 | * @sb: filesystem superblock | |
1487 | * @mnt_opts: binary mount options | |
1488 | * @kern_flags: kernel flags (in) | |
1489 | * @set_kern_flags: kernel flags (out) | |
1490 | * | |
1491 | * Set the security relevant mount options used for a superblock. | |
1492 | * | |
1493 | * Return: Returns 0 on success, error on failure. | |
1494 | */ | |
c9180a57 | 1495 | int security_sb_set_mnt_opts(struct super_block *sb, |
63c1845b PM |
1496 | void *mnt_opts, |
1497 | unsigned long kern_flags, | |
1498 | unsigned long *set_kern_flags) | |
c9180a57 | 1499 | { |
b1d9e6b0 | 1500 | return call_int_hook(sb_set_mnt_opts, |
63c1845b PM |
1501 | mnt_opts ? -EOPNOTSUPP : 0, sb, |
1502 | mnt_opts, kern_flags, set_kern_flags); | |
c9180a57 | 1503 | } |
e0007529 | 1504 | EXPORT_SYMBOL(security_sb_set_mnt_opts); |
c9180a57 | 1505 | |
08526a90 PM |
1506 | /** |
1507 | * security_sb_clone_mnt_opts() - Duplicate superblock mount options | |
1e2523d7 PM |
1508 | * @oldsb: source superblock |
1509 | * @newsb: destination superblock | |
08526a90 PM |
1510 | * @kern_flags: kernel flags (in) |
1511 | * @set_kern_flags: kernel flags (out) | |
1512 | * | |
1513 | * Copy all security options from a given superblock to another. | |
1514 | * | |
1515 | * Return: Returns 0 on success, error on failure. | |
1516 | */ | |
094f7b69 | 1517 | int security_sb_clone_mnt_opts(const struct super_block *oldsb, |
63c1845b PM |
1518 | struct super_block *newsb, |
1519 | unsigned long kern_flags, | |
1520 | unsigned long *set_kern_flags) | |
c9180a57 | 1521 | { |
0b4d3452 | 1522 | return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb, |
63c1845b | 1523 | kern_flags, set_kern_flags); |
c9180a57 | 1524 | } |
e0007529 EP |
1525 | EXPORT_SYMBOL(security_sb_clone_mnt_opts); |
1526 | ||
08526a90 PM |
1527 | /** |
1528 | * security_move_mount() - Check permissions for moving a mount | |
1529 | * @from_path: source mount point | |
1530 | * @to_path: destination mount point | |
1531 | * | |
1532 | * Check permission before a mount is moved. | |
1533 | * | |
1534 | * Return: Returns 0 if permission is granted. | |
1535 | */ | |
63c1845b PM |
1536 | int security_move_mount(const struct path *from_path, |
1537 | const struct path *to_path) | |
2db154b3 DH |
1538 | { |
1539 | return call_int_hook(move_mount, 0, from_path, to_path); | |
1540 | } | |
1541 | ||
916e3258 PM |
1542 | /** |
1543 | * security_path_notify() - Check if setting a watch is allowed | |
1544 | * @path: file path | |
1545 | * @mask: event mask | |
1546 | * @obj_type: file path type | |
1547 | * | |
1548 | * Check permissions before setting a watch on events as defined by @mask, on | |
1549 | * an object at @path, whose type is defined by @obj_type. | |
1550 | * | |
1551 | * Return: Returns 0 if permission is granted. | |
1552 | */ | |
ac5656d8 | 1553 | int security_path_notify(const struct path *path, u64 mask, |
63c1845b | 1554 | unsigned int obj_type) |
ac5656d8 AG |
1555 | { |
1556 | return call_int_hook(path_notify, 0, path, mask, obj_type); | |
1557 | } | |
1558 | ||
916e3258 PM |
1559 | /** |
1560 | * security_inode_alloc() - Allocate an inode LSM blob | |
1561 | * @inode: the inode | |
1562 | * | |
1563 | * Allocate and attach a security structure to @inode->i_security. The | |
1564 | * i_security field is initialized to NULL when the inode structure is | |
1565 | * allocated. | |
1566 | * | |
1567 | * Return: Return 0 if operation was successful. | |
1568 | */ | |
20510f2f JM |
1569 | int security_inode_alloc(struct inode *inode) |
1570 | { | |
afb1cbe3 CS |
1571 | int rc = lsm_inode_alloc(inode); |
1572 | ||
1573 | if (unlikely(rc)) | |
1574 | return rc; | |
1575 | rc = call_int_hook(inode_alloc_security, 0, inode); | |
1576 | if (unlikely(rc)) | |
1577 | security_inode_free(inode); | |
1578 | return rc; | |
1579 | } | |
1580 | ||
1581 | static void inode_free_by_rcu(struct rcu_head *head) | |
1582 | { | |
1583 | /* | |
1584 | * The rcu head is at the start of the inode blob | |
1585 | */ | |
1586 | kmem_cache_free(lsm_inode_cache, head); | |
20510f2f JM |
1587 | } |
1588 | ||
916e3258 PM |
1589 | /** |
1590 | * security_inode_free() - Free an inode's LSM blob | |
1591 | * @inode: the inode | |
1592 | * | |
1593 | * Deallocate the inode security structure and set @inode->i_security to NULL. | |
1594 | */ | |
20510f2f JM |
1595 | void security_inode_free(struct inode *inode) |
1596 | { | |
f381c272 | 1597 | integrity_inode_free(inode); |
f25fce3e | 1598 | call_void_hook(inode_free_security, inode); |
afb1cbe3 CS |
1599 | /* |
1600 | * The inode may still be referenced in a path walk and | |
1601 | * a call to security_inode_permission() can be made | |
1602 | * after inode_free_security() is called. Ideally, the VFS | |
1603 | * wouldn't do this, but fixing that is a much harder | |
1604 | * job. For now, simply free the i_security via RCU, and | |
1605 | * leave the current inode->i_security pointer intact. | |
1606 | * The inode will be freed after the RCU grace period too. | |
1607 | */ | |
1608 | if (inode->i_security) | |
1609 | call_rcu((struct rcu_head *)inode->i_security, | |
63c1845b | 1610 | inode_free_by_rcu); |
20510f2f JM |
1611 | } |
1612 | ||
08526a90 PM |
1613 | /** |
1614 | * security_dentry_init_security() - Perform dentry initialization | |
1615 | * @dentry: the dentry to initialize | |
1616 | * @mode: mode used to determine resource type | |
1617 | * @name: name of the last path component | |
1618 | * @xattr_name: name of the security/LSM xattr | |
1619 | * @ctx: pointer to the resulting LSM context | |
1620 | * @ctxlen: length of @ctx | |
1621 | * | |
1622 | * Compute a context for a dentry as the inode is not yet available since NFSv4 | |
1623 | * has no label backed by an EA anyway. It is important to note that | |
1624 | * @xattr_name does not need to be free'd by the caller, it is a static string. | |
1625 | * | |
1626 | * Return: Returns 0 on success, negative values on failure. | |
1627 | */ | |
d47be3df | 1628 | int security_dentry_init_security(struct dentry *dentry, int mode, |
15bf3239 VG |
1629 | const struct qstr *name, |
1630 | const char **xattr_name, void **ctx, | |
1631 | u32 *ctxlen) | |
d47be3df | 1632 | { |
7f5056b9 VG |
1633 | struct security_hook_list *hp; |
1634 | int rc; | |
1635 | ||
1636 | /* | |
1637 | * Only one module will provide a security context. | |
1638 | */ | |
63c1845b PM |
1639 | hlist_for_each_entry(hp, &security_hook_heads.dentry_init_security, |
1640 | list) { | |
7f5056b9 VG |
1641 | rc = hp->hook.dentry_init_security(dentry, mode, name, |
1642 | xattr_name, ctx, ctxlen); | |
1643 | if (rc != LSM_RET_DEFAULT(dentry_init_security)) | |
1644 | return rc; | |
1645 | } | |
1646 | return LSM_RET_DEFAULT(dentry_init_security); | |
d47be3df DQ |
1647 | } |
1648 | EXPORT_SYMBOL(security_dentry_init_security); | |
1649 | ||
08526a90 PM |
1650 | /** |
1651 | * security_dentry_create_files_as() - Perform dentry initialization | |
1652 | * @dentry: the dentry to initialize | |
1653 | * @mode: mode used to determine resource type | |
1654 | * @name: name of the last path component | |
1655 | * @old: creds to use for LSM context calculations | |
1656 | * @new: creds to modify | |
1657 | * | |
1658 | * Compute a context for a dentry as the inode is not yet available and set | |
1659 | * that context in passed in creds so that new files are created using that | |
1660 | * context. Context is calculated using the passed in creds and not the creds | |
1661 | * of the caller. | |
1662 | * | |
1663 | * Return: Returns 0 on success, error on failure. | |
1664 | */ | |
2602625b VG |
1665 | int security_dentry_create_files_as(struct dentry *dentry, int mode, |
1666 | struct qstr *name, | |
1667 | const struct cred *old, struct cred *new) | |
1668 | { | |
1669 | return call_int_hook(dentry_create_files_as, 0, dentry, mode, | |
63c1845b | 1670 | name, old, new); |
2602625b VG |
1671 | } |
1672 | EXPORT_SYMBOL(security_dentry_create_files_as); | |
1673 | ||
916e3258 PM |
1674 | /** |
1675 | * security_inode_init_security() - Initialize an inode's LSM context | |
1676 | * @inode: the inode | |
1677 | * @dir: parent directory | |
1678 | * @qstr: last component of the pathname | |
1679 | * @initxattrs: callback function to write xattrs | |
1680 | * @fs_data: filesystem specific data | |
1681 | * | |
1682 | * Obtain the security attribute name suffix and value to set on a newly | |
1683 | * created inode and set up the incore security field for the new inode. This | |
1684 | * hook is called by the fs code as part of the inode creation transaction and | |
1685 | * provides for atomic labeling of the inode, unlike the post_create/mkdir/... | |
6bcdfd2c RS |
1686 | * hooks called by the VFS. |
1687 | * | |
1688 | * The hook function is expected to populate the xattrs array, by calling | |
1689 | * lsm_get_xattr_slot() to retrieve the slots reserved by the security module | |
1690 | * with the lbs_xattr_count field of the lsm_blob_sizes structure. For each | |
1691 | * slot, the hook function should set ->name to the attribute name suffix | |
1692 | * (e.g. selinux), to allocate ->value (will be freed by the caller) and set it | |
1693 | * to the attribute value, to set ->value_len to the length of the value. If | |
1694 | * the security module does not use security attributes or does not wish to put | |
1695 | * a security attribute on this particular inode, then it should return | |
1696 | * -EOPNOTSUPP to skip this processing. | |
916e3258 | 1697 | * |
faf302f5 RS |
1698 | * Return: Returns 0 if the LSM successfully initialized all of the inode |
1699 | * security attributes that are required, negative values otherwise. | |
916e3258 | 1700 | */ |
20510f2f | 1701 | int security_inode_init_security(struct inode *inode, struct inode *dir, |
9d8f13ba MZ |
1702 | const struct qstr *qstr, |
1703 | const initxattrs initxattrs, void *fs_data) | |
20510f2f | 1704 | { |
6bcdfd2c RS |
1705 | struct security_hook_list *hp; |
1706 | struct xattr *new_xattrs = NULL; | |
1707 | int ret = -EOPNOTSUPP, xattr_count = 0; | |
9d8f13ba | 1708 | |
20510f2f | 1709 | if (unlikely(IS_PRIVATE(inode))) |
fb88c2b6 | 1710 | return 0; |
9d8f13ba | 1711 | |
6bcdfd2c RS |
1712 | if (!blob_sizes.lbs_xattr_count) |
1713 | return 0; | |
1714 | ||
1715 | if (initxattrs) { | |
1716 | /* Allocate +1 for EVM and +1 as terminator. */ | |
1717 | new_xattrs = kcalloc(blob_sizes.lbs_xattr_count + 2, | |
1718 | sizeof(*new_xattrs), GFP_NOFS); | |
1719 | if (!new_xattrs) | |
1720 | return -ENOMEM; | |
1721 | } | |
1722 | ||
1723 | hlist_for_each_entry(hp, &security_hook_heads.inode_init_security, | |
1724 | list) { | |
1725 | ret = hp->hook.inode_init_security(inode, dir, qstr, new_xattrs, | |
1726 | &xattr_count); | |
1727 | if (ret && ret != -EOPNOTSUPP) | |
1728 | goto out; | |
1729 | /* | |
1730 | * As documented in lsm_hooks.h, -EOPNOTSUPP in this context | |
1731 | * means that the LSM is not willing to provide an xattr, not | |
1732 | * that it wants to signal an error. Thus, continue to invoke | |
1733 | * the remaining LSMs. | |
1734 | */ | |
1735 | } | |
1736 | ||
1737 | /* If initxattrs() is NULL, xattr_count is zero, skip the call. */ | |
1738 | if (!xattr_count) | |
9d8f13ba | 1739 | goto out; |
823eb1cc | 1740 | |
6db7d1de RS |
1741 | ret = evm_inode_init_security(inode, dir, qstr, new_xattrs, |
1742 | &xattr_count); | |
823eb1cc MZ |
1743 | if (ret) |
1744 | goto out; | |
9d8f13ba MZ |
1745 | ret = initxattrs(inode, new_xattrs, fs_data); |
1746 | out: | |
6bcdfd2c RS |
1747 | for (; xattr_count > 0; xattr_count--) |
1748 | kfree(new_xattrs[xattr_count - 1].value); | |
1749 | kfree(new_xattrs); | |
9d8f13ba MZ |
1750 | return (ret == -EOPNOTSUPP) ? 0 : ret; |
1751 | } | |
1752 | EXPORT_SYMBOL(security_inode_init_security); | |
1753 | ||
916e3258 PM |
1754 | /** |
1755 | * security_inode_init_security_anon() - Initialize an anonymous inode | |
1756 | * @inode: the inode | |
1757 | * @name: the anonymous inode class | |
1758 | * @context_inode: an optional related inode | |
1759 | * | |
1760 | * Set up the incore security field for the new anonymous inode and return | |
1761 | * whether the inode creation is permitted by the security module or not. | |
1762 | * | |
1763 | * Return: Returns 0 on success, -EACCES if the security module denies the | |
1764 | * creation of this inode, or another -errno upon other errors. | |
1765 | */ | |
215b674b LG |
1766 | int security_inode_init_security_anon(struct inode *inode, |
1767 | const struct qstr *name, | |
1768 | const struct inode *context_inode) | |
1769 | { | |
1770 | return call_int_hook(inode_init_security_anon, 0, inode, name, | |
1771 | context_inode); | |
1772 | } | |
1773 | ||
be6d3e56 | 1774 | #ifdef CONFIG_SECURITY_PATH |
916e3258 PM |
1775 | /** |
1776 | * security_path_mknod() - Check if creating a special file is allowed | |
1777 | * @dir: parent directory | |
1778 | * @dentry: new file | |
1779 | * @mode: new file mode | |
1780 | * @dev: device number | |
1781 | * | |
1782 | * Check permissions when creating a file. Note that this hook is called even | |
1783 | * if mknod operation is being done for a regular file. | |
1784 | * | |
1785 | * Return: Returns 0 if permission is granted. | |
1786 | */ | |
63c1845b PM |
1787 | int security_path_mknod(const struct path *dir, struct dentry *dentry, |
1788 | umode_t mode, unsigned int dev) | |
be6d3e56 | 1789 | { |
c6f493d6 | 1790 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1791 | return 0; |
f25fce3e | 1792 | return call_int_hook(path_mknod, 0, dir, dentry, mode, dev); |
be6d3e56 KT |
1793 | } |
1794 | EXPORT_SYMBOL(security_path_mknod); | |
1795 | ||
916e3258 PM |
1796 | /** |
1797 | * security_path_mkdir() - Check if creating a new directory is allowed | |
1798 | * @dir: parent directory | |
1799 | * @dentry: new directory | |
1800 | * @mode: new directory mode | |
1801 | * | |
1802 | * Check permissions to create a new directory in the existing directory. | |
1803 | * | |
1804 | * Return: Returns 0 if permission is granted. | |
1805 | */ | |
63c1845b PM |
1806 | int security_path_mkdir(const struct path *dir, struct dentry *dentry, |
1807 | umode_t mode) | |
be6d3e56 | 1808 | { |
c6f493d6 | 1809 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1810 | return 0; |
f25fce3e | 1811 | return call_int_hook(path_mkdir, 0, dir, dentry, mode); |
be6d3e56 | 1812 | } |
82140443 | 1813 | EXPORT_SYMBOL(security_path_mkdir); |
be6d3e56 | 1814 | |
916e3258 PM |
1815 | /** |
1816 | * security_path_rmdir() - Check if removing a directory is allowed | |
1817 | * @dir: parent directory | |
1818 | * @dentry: directory to remove | |
1819 | * | |
1820 | * Check the permission to remove a directory. | |
1821 | * | |
1822 | * Return: Returns 0 if permission is granted. | |
1823 | */ | |
989f74e0 | 1824 | int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
be6d3e56 | 1825 | { |
c6f493d6 | 1826 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1827 | return 0; |
f25fce3e | 1828 | return call_int_hook(path_rmdir, 0, dir, dentry); |
be6d3e56 KT |
1829 | } |
1830 | ||
916e3258 PM |
1831 | /** |
1832 | * security_path_unlink() - Check if removing a hard link is allowed | |
1833 | * @dir: parent directory | |
1834 | * @dentry: file | |
1835 | * | |
1836 | * Check the permission to remove a hard link to a file. | |
1837 | * | |
1838 | * Return: Returns 0 if permission is granted. | |
1839 | */ | |
989f74e0 | 1840 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
be6d3e56 | 1841 | { |
c6f493d6 | 1842 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1843 | return 0; |
f25fce3e | 1844 | return call_int_hook(path_unlink, 0, dir, dentry); |
be6d3e56 | 1845 | } |
82140443 | 1846 | EXPORT_SYMBOL(security_path_unlink); |
be6d3e56 | 1847 | |
916e3258 PM |
1848 | /** |
1849 | * security_path_symlink() - Check if creating a symbolic link is allowed | |
1850 | * @dir: parent directory | |
1851 | * @dentry: symbolic link | |
1852 | * @old_name: file pathname | |
1853 | * | |
1854 | * Check the permission to create a symbolic link to a file. | |
1855 | * | |
1856 | * Return: Returns 0 if permission is granted. | |
1857 | */ | |
d3607752 | 1858 | int security_path_symlink(const struct path *dir, struct dentry *dentry, |
be6d3e56 KT |
1859 | const char *old_name) |
1860 | { | |
c6f493d6 | 1861 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
be6d3e56 | 1862 | return 0; |
f25fce3e | 1863 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
be6d3e56 KT |
1864 | } |
1865 | ||
916e3258 PM |
1866 | /** |
1867 | * security_path_link - Check if creating a hard link is allowed | |
1868 | * @old_dentry: existing file | |
1869 | * @new_dir: new parent directory | |
1870 | * @new_dentry: new link | |
1871 | * | |
1872 | * Check permission before creating a new hard link to a file. | |
1873 | * | |
1874 | * Return: Returns 0 if permission is granted. | |
1875 | */ | |
3ccee46a | 1876 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
be6d3e56 KT |
1877 | struct dentry *new_dentry) |
1878 | { | |
c6f493d6 | 1879 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
be6d3e56 | 1880 | return 0; |
f25fce3e | 1881 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
be6d3e56 KT |
1882 | } |
1883 | ||
916e3258 PM |
1884 | /** |
1885 | * security_path_rename() - Check if renaming a file is allowed | |
1886 | * @old_dir: parent directory of the old file | |
1887 | * @old_dentry: the old file | |
1888 | * @new_dir: parent directory of the new file | |
1889 | * @new_dentry: the new file | |
1890 | * @flags: flags | |
1891 | * | |
1892 | * Check for permission to rename a file or directory. | |
1893 | * | |
1894 | * Return: Returns 0 if permission is granted. | |
1895 | */ | |
3ccee46a AV |
1896 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
1897 | const struct path *new_dir, struct dentry *new_dentry, | |
0b3974eb | 1898 | unsigned int flags) |
be6d3e56 | 1899 | { |
c6f493d6 | 1900 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
63c1845b PM |
1901 | (d_is_positive(new_dentry) && |
1902 | IS_PRIVATE(d_backing_inode(new_dentry))))) | |
be6d3e56 | 1903 | return 0; |
da1ce067 | 1904 | |
f25fce3e | 1905 | return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir, |
63c1845b | 1906 | new_dentry, flags); |
be6d3e56 | 1907 | } |
82140443 | 1908 | EXPORT_SYMBOL(security_path_rename); |
be6d3e56 | 1909 | |
916e3258 PM |
1910 | /** |
1911 | * security_path_truncate() - Check if truncating a file is allowed | |
1912 | * @path: file | |
1913 | * | |
1914 | * Check permission before truncating the file indicated by path. Note that | |
1915 | * truncation permissions may also be checked based on already opened files, | |
1916 | * using the security_file_truncate() hook. | |
1917 | * | |
1918 | * Return: Returns 0 if permission is granted. | |
1919 | */ | |
81f4c506 | 1920 | int security_path_truncate(const struct path *path) |
be6d3e56 | 1921 | { |
c6f493d6 | 1922 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
be6d3e56 | 1923 | return 0; |
f25fce3e | 1924 | return call_int_hook(path_truncate, 0, path); |
be6d3e56 | 1925 | } |
89eda068 | 1926 | |
916e3258 PM |
1927 | /** |
1928 | * security_path_chmod() - Check if changing the file's mode is allowed | |
1929 | * @path: file | |
1930 | * @mode: new mode | |
1931 | * | |
1932 | * Check for permission to change a mode of the file @path. The new mode is | |
1933 | * specified in @mode which is a bitmask of constants from | |
1934 | * <include/uapi/linux/stat.h>. | |
1935 | * | |
1936 | * Return: Returns 0 if permission is granted. | |
1937 | */ | |
be01f9f2 | 1938 | int security_path_chmod(const struct path *path, umode_t mode) |
89eda068 | 1939 | { |
c6f493d6 | 1940 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
89eda068 | 1941 | return 0; |
f25fce3e | 1942 | return call_int_hook(path_chmod, 0, path, mode); |
89eda068 TH |
1943 | } |
1944 | ||
916e3258 PM |
1945 | /** |
1946 | * security_path_chown() - Check if changing the file's owner/group is allowed | |
1947 | * @path: file | |
1948 | * @uid: file owner | |
1949 | * @gid: file group | |
1950 | * | |
1951 | * Check for permission to change owner/group of a file or directory. | |
1952 | * | |
1953 | * Return: Returns 0 if permission is granted. | |
1954 | */ | |
7fd25dac | 1955 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
89eda068 | 1956 | { |
c6f493d6 | 1957 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
89eda068 | 1958 | return 0; |
f25fce3e | 1959 | return call_int_hook(path_chown, 0, path, uid, gid); |
89eda068 | 1960 | } |
8b8efb44 | 1961 | |
916e3258 PM |
1962 | /** |
1963 | * security_path_chroot() - Check if changing the root directory is allowed | |
1964 | * @path: directory | |
1965 | * | |
1966 | * Check for permission to change root directory. | |
1967 | * | |
1968 | * Return: Returns 0 if permission is granted. | |
1969 | */ | |
77b286c0 | 1970 | int security_path_chroot(const struct path *path) |
8b8efb44 | 1971 | { |
f25fce3e | 1972 | return call_int_hook(path_chroot, 0, path); |
8b8efb44 | 1973 | } |
63c1845b | 1974 | #endif /* CONFIG_SECURITY_PATH */ |
be6d3e56 | 1975 | |
916e3258 PM |
1976 | /** |
1977 | * security_inode_create() - Check if creating a file is allowed | |
1978 | * @dir: the parent directory | |
1979 | * @dentry: the file being created | |
1980 | * @mode: requested file mode | |
1981 | * | |
1982 | * Check permission to create a regular file. | |
1983 | * | |
1984 | * Return: Returns 0 if permission is granted. | |
1985 | */ | |
63c1845b PM |
1986 | int security_inode_create(struct inode *dir, struct dentry *dentry, |
1987 | umode_t mode) | |
20510f2f JM |
1988 | { |
1989 | if (unlikely(IS_PRIVATE(dir))) | |
1990 | return 0; | |
f25fce3e | 1991 | return call_int_hook(inode_create, 0, dir, dentry, mode); |
20510f2f | 1992 | } |
800a9647 | 1993 | EXPORT_SYMBOL_GPL(security_inode_create); |
20510f2f | 1994 | |
916e3258 PM |
1995 | /** |
1996 | * security_inode_link() - Check if creating a hard link is allowed | |
1997 | * @old_dentry: existing file | |
1998 | * @dir: new parent directory | |
1999 | * @new_dentry: new link | |
2000 | * | |
2001 | * Check permission before creating a new hard link to a file. | |
2002 | * | |
2003 | * Return: Returns 0 if permission is granted. | |
2004 | */ | |
20510f2f | 2005 | int security_inode_link(struct dentry *old_dentry, struct inode *dir, |
63c1845b | 2006 | struct dentry *new_dentry) |
20510f2f | 2007 | { |
c6f493d6 | 2008 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
20510f2f | 2009 | return 0; |
f25fce3e | 2010 | return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry); |
20510f2f JM |
2011 | } |
2012 | ||
916e3258 PM |
2013 | /** |
2014 | * security_inode_unlink() - Check if removing a hard link is allowed | |
2015 | * @dir: parent directory | |
2016 | * @dentry: file | |
2017 | * | |
2018 | * Check the permission to remove a hard link to a file. | |
2019 | * | |
2020 | * Return: Returns 0 if permission is granted. | |
2021 | */ | |
20510f2f JM |
2022 | int security_inode_unlink(struct inode *dir, struct dentry *dentry) |
2023 | { | |
c6f493d6 | 2024 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2025 | return 0; |
f25fce3e | 2026 | return call_int_hook(inode_unlink, 0, dir, dentry); |
20510f2f JM |
2027 | } |
2028 | ||
916e3258 | 2029 | /** |
1e2523d7 | 2030 | * security_inode_symlink() - Check if creating a symbolic link is allowed |
916e3258 PM |
2031 | * @dir: parent directory |
2032 | * @dentry: symbolic link | |
2033 | * @old_name: existing filename | |
2034 | * | |
2035 | * Check the permission to create a symbolic link to a file. | |
2036 | * | |
2037 | * Return: Returns 0 if permission is granted. | |
2038 | */ | |
20510f2f | 2039 | int security_inode_symlink(struct inode *dir, struct dentry *dentry, |
63c1845b | 2040 | const char *old_name) |
20510f2f JM |
2041 | { |
2042 | if (unlikely(IS_PRIVATE(dir))) | |
2043 | return 0; | |
f25fce3e | 2044 | return call_int_hook(inode_symlink, 0, dir, dentry, old_name); |
20510f2f JM |
2045 | } |
2046 | ||
916e3258 PM |
2047 | /** |
2048 | * security_inode_mkdir() - Check if creation a new director is allowed | |
2049 | * @dir: parent directory | |
2050 | * @dentry: new directory | |
2051 | * @mode: new directory mode | |
2052 | * | |
2053 | * Check permissions to create a new directory in the existing directory | |
2054 | * associated with inode structure @dir. | |
2055 | * | |
2056 | * Return: Returns 0 if permission is granted. | |
2057 | */ | |
18bb1db3 | 2058 | int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
20510f2f JM |
2059 | { |
2060 | if (unlikely(IS_PRIVATE(dir))) | |
2061 | return 0; | |
f25fce3e | 2062 | return call_int_hook(inode_mkdir, 0, dir, dentry, mode); |
20510f2f | 2063 | } |
800a9647 | 2064 | EXPORT_SYMBOL_GPL(security_inode_mkdir); |
20510f2f | 2065 | |
916e3258 PM |
2066 | /** |
2067 | * security_inode_rmdir() - Check if removing a directory is allowed | |
2068 | * @dir: parent directory | |
2069 | * @dentry: directory to be removed | |
2070 | * | |
2071 | * Check the permission to remove a directory. | |
2072 | * | |
2073 | * Return: Returns 0 if permission is granted. | |
2074 | */ | |
20510f2f JM |
2075 | int security_inode_rmdir(struct inode *dir, struct dentry *dentry) |
2076 | { | |
c6f493d6 | 2077 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2078 | return 0; |
f25fce3e | 2079 | return call_int_hook(inode_rmdir, 0, dir, dentry); |
20510f2f JM |
2080 | } |
2081 | ||
916e3258 PM |
2082 | /** |
2083 | * security_inode_mknod() - Check if creating a special file is allowed | |
2084 | * @dir: parent directory | |
2085 | * @dentry: new file | |
2086 | * @mode: new file mode | |
2087 | * @dev: device number | |
2088 | * | |
2089 | * Check permissions when creating a special file (or a socket or a fifo file | |
2090 | * created via the mknod system call). Note that if mknod operation is being | |
2091 | * done for a regular file, then the create hook will be called and not this | |
2092 | * hook. | |
2093 | * | |
2094 | * Return: Returns 0 if permission is granted. | |
2095 | */ | |
63c1845b PM |
2096 | int security_inode_mknod(struct inode *dir, struct dentry *dentry, |
2097 | umode_t mode, dev_t dev) | |
20510f2f JM |
2098 | { |
2099 | if (unlikely(IS_PRIVATE(dir))) | |
2100 | return 0; | |
f25fce3e | 2101 | return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev); |
20510f2f JM |
2102 | } |
2103 | ||
916e3258 PM |
2104 | /** |
2105 | * security_inode_rename() - Check if renaming a file is allowed | |
2106 | * @old_dir: parent directory of the old file | |
2107 | * @old_dentry: the old file | |
2108 | * @new_dir: parent directory of the new file | |
2109 | * @new_dentry: the new file | |
2110 | * @flags: flags | |
2111 | * | |
2112 | * Check for permission to rename a file or directory. | |
2113 | * | |
2114 | * Return: Returns 0 if permission is granted. | |
2115 | */ | |
20510f2f | 2116 | int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, |
63c1845b PM |
2117 | struct inode *new_dir, struct dentry *new_dentry, |
2118 | unsigned int flags) | |
20510f2f | 2119 | { |
63c1845b PM |
2120 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
2121 | (d_is_positive(new_dentry) && | |
2122 | IS_PRIVATE(d_backing_inode(new_dentry))))) | |
20510f2f | 2123 | return 0; |
da1ce067 MS |
2124 | |
2125 | if (flags & RENAME_EXCHANGE) { | |
f25fce3e | 2126 | int err = call_int_hook(inode_rename, 0, new_dir, new_dentry, |
63c1845b | 2127 | old_dir, old_dentry); |
da1ce067 MS |
2128 | if (err) |
2129 | return err; | |
2130 | } | |
2131 | ||
f25fce3e | 2132 | return call_int_hook(inode_rename, 0, old_dir, old_dentry, |
63c1845b | 2133 | new_dir, new_dentry); |
20510f2f JM |
2134 | } |
2135 | ||
916e3258 PM |
2136 | /** |
2137 | * security_inode_readlink() - Check if reading a symbolic link is allowed | |
2138 | * @dentry: link | |
2139 | * | |
2140 | * Check the permission to read the symbolic link. | |
2141 | * | |
2142 | * Return: Returns 0 if permission is granted. | |
2143 | */ | |
20510f2f JM |
2144 | int security_inode_readlink(struct dentry *dentry) |
2145 | { | |
c6f493d6 | 2146 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2147 | return 0; |
f25fce3e | 2148 | return call_int_hook(inode_readlink, 0, dentry); |
20510f2f JM |
2149 | } |
2150 | ||
916e3258 PM |
2151 | /** |
2152 | * security_inode_follow_link() - Check if following a symbolic link is allowed | |
2153 | * @dentry: link dentry | |
2154 | * @inode: link inode | |
2155 | * @rcu: true if in RCU-walk mode | |
2156 | * | |
2157 | * Check permission to follow a symbolic link when looking up a pathname. If | |
2158 | * @rcu is true, @inode is not stable. | |
2159 | * | |
2160 | * Return: Returns 0 if permission is granted. | |
2161 | */ | |
bda0be7a N |
2162 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
2163 | bool rcu) | |
20510f2f | 2164 | { |
bda0be7a | 2165 | if (unlikely(IS_PRIVATE(inode))) |
20510f2f | 2166 | return 0; |
e22619a2 | 2167 | return call_int_hook(inode_follow_link, 0, dentry, inode, rcu); |
20510f2f JM |
2168 | } |
2169 | ||
916e3258 PM |
2170 | /** |
2171 | * security_inode_permission() - Check if accessing an inode is allowed | |
2172 | * @inode: inode | |
2173 | * @mask: access mask | |
2174 | * | |
2175 | * Check permission before accessing an inode. This hook is called by the | |
2176 | * existing Linux permission function, so a security module can use it to | |
2177 | * provide additional checking for existing Linux permission checks. Notice | |
2178 | * that this hook is called when a file is opened (as well as many other | |
2179 | * operations), whereas the file_security_ops permission hook is called when | |
2180 | * the actual read/write operations are performed. | |
2181 | * | |
2182 | * Return: Returns 0 if permission is granted. | |
2183 | */ | |
b77b0646 | 2184 | int security_inode_permission(struct inode *inode, int mask) |
20510f2f JM |
2185 | { |
2186 | if (unlikely(IS_PRIVATE(inode))) | |
2187 | return 0; | |
f25fce3e | 2188 | return call_int_hook(inode_permission, 0, inode, mask); |
20510f2f JM |
2189 | } |
2190 | ||
916e3258 PM |
2191 | /** |
2192 | * security_inode_setattr() - Check if setting file attributes is allowed | |
2193 | * @idmap: idmap of the mount | |
2194 | * @dentry: file | |
2195 | * @attr: new attributes | |
2196 | * | |
2197 | * Check permission before setting file attributes. Note that the kernel call | |
2198 | * to notify_change is performed from several locations, whenever file | |
2199 | * attributes change (such as when a file is truncated, chown/chmod operations, | |
2200 | * transferring disk quotas, etc). | |
2201 | * | |
2202 | * Return: Returns 0 if permission is granted. | |
2203 | */ | |
c1632a0f | 2204 | int security_inode_setattr(struct mnt_idmap *idmap, |
0e363cf3 | 2205 | struct dentry *dentry, struct iattr *attr) |
20510f2f | 2206 | { |
817b54aa MZ |
2207 | int ret; |
2208 | ||
c6f493d6 | 2209 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2210 | return 0; |
f25fce3e | 2211 | ret = call_int_hook(inode_setattr, 0, dentry, attr); |
817b54aa MZ |
2212 | if (ret) |
2213 | return ret; | |
c1632a0f | 2214 | return evm_inode_setattr(idmap, dentry, attr); |
20510f2f | 2215 | } |
b1da47e2 | 2216 | EXPORT_SYMBOL_GPL(security_inode_setattr); |
20510f2f | 2217 | |
916e3258 PM |
2218 | /** |
2219 | * security_inode_getattr() - Check if getting file attributes is allowed | |
2220 | * @path: file | |
2221 | * | |
2222 | * Check permission before obtaining file attributes. | |
2223 | * | |
2224 | * Return: Returns 0 if permission is granted. | |
2225 | */ | |
3f7036a0 | 2226 | int security_inode_getattr(const struct path *path) |
20510f2f | 2227 | { |
c6f493d6 | 2228 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
20510f2f | 2229 | return 0; |
f25fce3e | 2230 | return call_int_hook(inode_getattr, 0, path); |
20510f2f JM |
2231 | } |
2232 | ||
916e3258 PM |
2233 | /** |
2234 | * security_inode_setxattr() - Check if setting file xattrs is allowed | |
2235 | * @idmap: idmap of the mount | |
2236 | * @dentry: file | |
2237 | * @name: xattr name | |
2238 | * @value: xattr value | |
1e2523d7 | 2239 | * @size: size of xattr value |
916e3258 PM |
2240 | * @flags: flags |
2241 | * | |
2242 | * Check permission before setting the extended attributes. | |
2243 | * | |
2244 | * Return: Returns 0 if permission is granted. | |
2245 | */ | |
39f60c1c | 2246 | int security_inode_setxattr(struct mnt_idmap *idmap, |
71bc356f | 2247 | struct dentry *dentry, const char *name, |
8f0cfa52 | 2248 | const void *value, size_t size, int flags) |
20510f2f | 2249 | { |
3e1be52d MZ |
2250 | int ret; |
2251 | ||
c6f493d6 | 2252 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2253 | return 0; |
b1d9e6b0 CS |
2254 | /* |
2255 | * SELinux and Smack integrate the cap call, | |
2256 | * so assume that all LSMs supplying this call do so. | |
2257 | */ | |
39f60c1c | 2258 | ret = call_int_hook(inode_setxattr, 1, idmap, dentry, name, value, |
71bc356f | 2259 | size, flags); |
b1d9e6b0 CS |
2260 | |
2261 | if (ret == 1) | |
2262 | ret = cap_inode_setxattr(dentry, name, value, size, flags); | |
42c63330 MZ |
2263 | if (ret) |
2264 | return ret; | |
2265 | ret = ima_inode_setxattr(dentry, name, value, size); | |
3e1be52d MZ |
2266 | if (ret) |
2267 | return ret; | |
39f60c1c | 2268 | return evm_inode_setxattr(idmap, dentry, name, value, size); |
20510f2f JM |
2269 | } |
2270 | ||
916e3258 PM |
2271 | /** |
2272 | * security_inode_set_acl() - Check if setting posix acls is allowed | |
2273 | * @idmap: idmap of the mount | |
2274 | * @dentry: file | |
2275 | * @acl_name: acl name | |
2276 | * @kacl: acl struct | |
2277 | * | |
2278 | * Check permission before setting posix acls, the posix acls in @kacl are | |
2279 | * identified by @acl_name. | |
2280 | * | |
2281 | * Return: Returns 0 if permission is granted. | |
2282 | */ | |
700b7940 | 2283 | int security_inode_set_acl(struct mnt_idmap *idmap, |
72b3897e CB |
2284 | struct dentry *dentry, const char *acl_name, |
2285 | struct posix_acl *kacl) | |
2286 | { | |
e61b135f CB |
2287 | int ret; |
2288 | ||
72b3897e CB |
2289 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
2290 | return 0; | |
700b7940 | 2291 | ret = call_int_hook(inode_set_acl, 0, idmap, dentry, acl_name, |
e61b135f CB |
2292 | kacl); |
2293 | if (ret) | |
2294 | return ret; | |
700b7940 | 2295 | ret = ima_inode_set_acl(idmap, dentry, acl_name, kacl); |
e61b135f CB |
2296 | if (ret) |
2297 | return ret; | |
700b7940 | 2298 | return evm_inode_set_acl(idmap, dentry, acl_name, kacl); |
72b3897e CB |
2299 | } |
2300 | ||
916e3258 PM |
2301 | /** |
2302 | * security_inode_get_acl() - Check if reading posix acls is allowed | |
2303 | * @idmap: idmap of the mount | |
2304 | * @dentry: file | |
2305 | * @acl_name: acl name | |
2306 | * | |
2307 | * Check permission before getting osix acls, the posix acls are identified by | |
2308 | * @acl_name. | |
2309 | * | |
2310 | * Return: Returns 0 if permission is granted. | |
2311 | */ | |
700b7940 | 2312 | int security_inode_get_acl(struct mnt_idmap *idmap, |
72b3897e CB |
2313 | struct dentry *dentry, const char *acl_name) |
2314 | { | |
2315 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) | |
2316 | return 0; | |
700b7940 | 2317 | return call_int_hook(inode_get_acl, 0, idmap, dentry, acl_name); |
72b3897e CB |
2318 | } |
2319 | ||
916e3258 PM |
2320 | /** |
2321 | * security_inode_remove_acl() - Check if removing a posix acl is allowed | |
2322 | * @idmap: idmap of the mount | |
2323 | * @dentry: file | |
2324 | * @acl_name: acl name | |
2325 | * | |
2326 | * Check permission before removing posix acls, the posix acls are identified | |
2327 | * by @acl_name. | |
2328 | * | |
2329 | * Return: Returns 0 if permission is granted. | |
2330 | */ | |
700b7940 | 2331 | int security_inode_remove_acl(struct mnt_idmap *idmap, |
72b3897e CB |
2332 | struct dentry *dentry, const char *acl_name) |
2333 | { | |
e61b135f CB |
2334 | int ret; |
2335 | ||
72b3897e CB |
2336 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
2337 | return 0; | |
700b7940 | 2338 | ret = call_int_hook(inode_remove_acl, 0, idmap, dentry, acl_name); |
e61b135f CB |
2339 | if (ret) |
2340 | return ret; | |
700b7940 | 2341 | ret = ima_inode_remove_acl(idmap, dentry, acl_name); |
e61b135f CB |
2342 | if (ret) |
2343 | return ret; | |
700b7940 | 2344 | return evm_inode_remove_acl(idmap, dentry, acl_name); |
72b3897e CB |
2345 | } |
2346 | ||
916e3258 PM |
2347 | /** |
2348 | * security_inode_post_setxattr() - Update the inode after a setxattr operation | |
2349 | * @dentry: file | |
2350 | * @name: xattr name | |
2351 | * @value: xattr value | |
2352 | * @size: xattr value size | |
2353 | * @flags: flags | |
2354 | * | |
2355 | * Update inode security field after successful setxattr operation. | |
2356 | */ | |
8f0cfa52 DH |
2357 | void security_inode_post_setxattr(struct dentry *dentry, const char *name, |
2358 | const void *value, size_t size, int flags) | |
20510f2f | 2359 | { |
c6f493d6 | 2360 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2361 | return; |
f25fce3e | 2362 | call_void_hook(inode_post_setxattr, dentry, name, value, size, flags); |
3e1be52d | 2363 | evm_inode_post_setxattr(dentry, name, value, size); |
20510f2f JM |
2364 | } |
2365 | ||
916e3258 PM |
2366 | /** |
2367 | * security_inode_getxattr() - Check if xattr access is allowed | |
2368 | * @dentry: file | |
2369 | * @name: xattr name | |
2370 | * | |
2371 | * Check permission before obtaining the extended attributes identified by | |
2372 | * @name for @dentry. | |
2373 | * | |
2374 | * Return: Returns 0 if permission is granted. | |
2375 | */ | |
8f0cfa52 | 2376 | int security_inode_getxattr(struct dentry *dentry, const char *name) |
20510f2f | 2377 | { |
c6f493d6 | 2378 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2379 | return 0; |
f25fce3e | 2380 | return call_int_hook(inode_getxattr, 0, dentry, name); |
20510f2f JM |
2381 | } |
2382 | ||
916e3258 PM |
2383 | /** |
2384 | * security_inode_listxattr() - Check if listing xattrs is allowed | |
2385 | * @dentry: file | |
2386 | * | |
2387 | * Check permission before obtaining the list of extended attribute names for | |
2388 | * @dentry. | |
2389 | * | |
2390 | * Return: Returns 0 if permission is granted. | |
2391 | */ | |
20510f2f JM |
2392 | int security_inode_listxattr(struct dentry *dentry) |
2393 | { | |
c6f493d6 | 2394 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2395 | return 0; |
f25fce3e | 2396 | return call_int_hook(inode_listxattr, 0, dentry); |
20510f2f JM |
2397 | } |
2398 | ||
916e3258 PM |
2399 | /** |
2400 | * security_inode_removexattr() - Check if removing an xattr is allowed | |
2401 | * @idmap: idmap of the mount | |
2402 | * @dentry: file | |
2403 | * @name: xattr name | |
2404 | * | |
2405 | * Check permission before removing the extended attribute identified by @name | |
2406 | * for @dentry. | |
2407 | * | |
2408 | * Return: Returns 0 if permission is granted. | |
2409 | */ | |
39f60c1c | 2410 | int security_inode_removexattr(struct mnt_idmap *idmap, |
71bc356f | 2411 | struct dentry *dentry, const char *name) |
20510f2f | 2412 | { |
3e1be52d MZ |
2413 | int ret; |
2414 | ||
c6f493d6 | 2415 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
20510f2f | 2416 | return 0; |
b1d9e6b0 CS |
2417 | /* |
2418 | * SELinux and Smack integrate the cap call, | |
2419 | * so assume that all LSMs supplying this call do so. | |
2420 | */ | |
39f60c1c | 2421 | ret = call_int_hook(inode_removexattr, 1, idmap, dentry, name); |
b1d9e6b0 | 2422 | if (ret == 1) |
39f60c1c | 2423 | ret = cap_inode_removexattr(idmap, dentry, name); |
42c63330 MZ |
2424 | if (ret) |
2425 | return ret; | |
2426 | ret = ima_inode_removexattr(dentry, name); | |
3e1be52d MZ |
2427 | if (ret) |
2428 | return ret; | |
39f60c1c | 2429 | return evm_inode_removexattr(idmap, dentry, name); |
20510f2f JM |
2430 | } |
2431 | ||
916e3258 PM |
2432 | /** |
2433 | * security_inode_need_killpriv() - Check if security_inode_killpriv() required | |
2434 | * @dentry: associated dentry | |
2435 | * | |
2436 | * Called when an inode has been changed to determine if | |
2437 | * security_inode_killpriv() should be called. | |
2438 | * | |
2439 | * Return: Return <0 on error to abort the inode change operation, return 0 if | |
2440 | * security_inode_killpriv() does not need to be called, return >0 if | |
2441 | * security_inode_killpriv() does need to be called. | |
2442 | */ | |
b5376771 SH |
2443 | int security_inode_need_killpriv(struct dentry *dentry) |
2444 | { | |
f25fce3e | 2445 | return call_int_hook(inode_need_killpriv, 0, dentry); |
b5376771 SH |
2446 | } |
2447 | ||
916e3258 PM |
2448 | /** |
2449 | * security_inode_killpriv() - The setuid bit is removed, update LSM state | |
2450 | * @idmap: idmap of the mount | |
2451 | * @dentry: associated dentry | |
2452 | * | |
2453 | * The @dentry's setuid bit is being removed. Remove similar security labels. | |
2454 | * Called with the dentry->d_inode->i_mutex held. | |
2455 | * | |
2456 | * Return: Return 0 on success. If error is returned, then the operation | |
2457 | * causing setuid bit removal is failed. | |
2458 | */ | |
39f60c1c | 2459 | int security_inode_killpriv(struct mnt_idmap *idmap, |
71bc356f | 2460 | struct dentry *dentry) |
b5376771 | 2461 | { |
39f60c1c | 2462 | return call_int_hook(inode_killpriv, 0, idmap, dentry); |
b5376771 SH |
2463 | } |
2464 | ||
916e3258 PM |
2465 | /** |
2466 | * security_inode_getsecurity() - Get the xattr security label of an inode | |
2467 | * @idmap: idmap of the mount | |
2468 | * @inode: inode | |
2469 | * @name: xattr name | |
2470 | * @buffer: security label buffer | |
2471 | * @alloc: allocation flag | |
2472 | * | |
2473 | * Retrieve a copy of the extended attribute representation of the security | |
2474 | * label associated with @name for @inode via @buffer. Note that @name is the | |
2475 | * remainder of the attribute name after the security prefix has been removed. | |
2476 | * @alloc is used to specify if the call should return a value via the buffer | |
2477 | * or just the value length. | |
2478 | * | |
2479 | * Return: Returns size of buffer on success. | |
2480 | */ | |
4609e1f1 | 2481 | int security_inode_getsecurity(struct mnt_idmap *idmap, |
71bc356f CB |
2482 | struct inode *inode, const char *name, |
2483 | void **buffer, bool alloc) | |
20510f2f | 2484 | { |
2885c1e3 CS |
2485 | struct security_hook_list *hp; |
2486 | int rc; | |
2487 | ||
20510f2f | 2488 | if (unlikely(IS_PRIVATE(inode))) |
98e828a0 | 2489 | return LSM_RET_DEFAULT(inode_getsecurity); |
2885c1e3 CS |
2490 | /* |
2491 | * Only one module will provide an attribute with a given name. | |
2492 | */ | |
df0ce173 | 2493 | hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { |
63c1845b PM |
2494 | rc = hp->hook.inode_getsecurity(idmap, inode, name, buffer, |
2495 | alloc); | |
98e828a0 | 2496 | if (rc != LSM_RET_DEFAULT(inode_getsecurity)) |
2885c1e3 CS |
2497 | return rc; |
2498 | } | |
98e828a0 | 2499 | return LSM_RET_DEFAULT(inode_getsecurity); |
20510f2f JM |
2500 | } |
2501 | ||
916e3258 PM |
2502 | /** |
2503 | * security_inode_setsecurity() - Set the xattr security label of an inode | |
2504 | * @inode: inode | |
2505 | * @name: xattr name | |
2506 | * @value: security label | |
2507 | * @size: length of security label | |
2508 | * @flags: flags | |
2509 | * | |
2510 | * Set the security label associated with @name for @inode from the extended | |
2511 | * attribute value @value. @size indicates the size of the @value in bytes. | |
2512 | * @flags may be XATTR_CREATE, XATTR_REPLACE, or 0. Note that @name is the | |
2513 | * remainder of the attribute name after the security. prefix has been removed. | |
2514 | * | |
2515 | * Return: Returns 0 on success. | |
2516 | */ | |
63c1845b PM |
2517 | int security_inode_setsecurity(struct inode *inode, const char *name, |
2518 | const void *value, size_t size, int flags) | |
20510f2f | 2519 | { |
2885c1e3 CS |
2520 | struct security_hook_list *hp; |
2521 | int rc; | |
2522 | ||
20510f2f | 2523 | if (unlikely(IS_PRIVATE(inode))) |
98e828a0 | 2524 | return LSM_RET_DEFAULT(inode_setsecurity); |
2885c1e3 CS |
2525 | /* |
2526 | * Only one module will provide an attribute with a given name. | |
2527 | */ | |
df0ce173 | 2528 | hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) { |
2885c1e3 | 2529 | rc = hp->hook.inode_setsecurity(inode, name, value, size, |
63c1845b | 2530 | flags); |
98e828a0 | 2531 | if (rc != LSM_RET_DEFAULT(inode_setsecurity)) |
2885c1e3 CS |
2532 | return rc; |
2533 | } | |
98e828a0 | 2534 | return LSM_RET_DEFAULT(inode_setsecurity); |
20510f2f JM |
2535 | } |
2536 | ||
916e3258 PM |
2537 | /** |
2538 | * security_inode_listsecurity() - List the xattr security label names | |
2539 | * @inode: inode | |
2540 | * @buffer: buffer | |
2541 | * @buffer_size: size of buffer | |
2542 | * | |
2543 | * Copy the extended attribute names for the security labels associated with | |
2544 | * @inode into @buffer. The maximum size of @buffer is specified by | |
2545 | * @buffer_size. @buffer may be NULL to request the size of the buffer | |
2546 | * required. | |
2547 | * | |
2548 | * Return: Returns number of bytes used/required on success. | |
2549 | */ | |
63c1845b PM |
2550 | int security_inode_listsecurity(struct inode *inode, |
2551 | char *buffer, size_t buffer_size) | |
20510f2f JM |
2552 | { |
2553 | if (unlikely(IS_PRIVATE(inode))) | |
2554 | return 0; | |
f25fce3e | 2555 | return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size); |
20510f2f | 2556 | } |
c9bccef6 | 2557 | EXPORT_SYMBOL(security_inode_listsecurity); |
20510f2f | 2558 | |
916e3258 PM |
2559 | /** |
2560 | * security_inode_getsecid() - Get an inode's secid | |
2561 | * @inode: inode | |
2562 | * @secid: secid to return | |
2563 | * | |
2564 | * Get the secid associated with the node. In case of failure, @secid will be | |
2565 | * set to zero. | |
2566 | */ | |
d6335d77 | 2567 | void security_inode_getsecid(struct inode *inode, u32 *secid) |
8a076191 | 2568 | { |
f25fce3e | 2569 | call_void_hook(inode_getsecid, inode, secid); |
8a076191 AD |
2570 | } |
2571 | ||
916e3258 PM |
2572 | /** |
2573 | * security_inode_copy_up() - Create new creds for an overlayfs copy-up op | |
2574 | * @src: union dentry of copy-up file | |
2575 | * @new: newly created creds | |
2576 | * | |
2577 | * A file is about to be copied up from lower layer to upper layer of overlay | |
2578 | * filesystem. Security module can prepare a set of new creds and modify as | |
2579 | * need be and return new creds. Caller will switch to new creds temporarily to | |
2580 | * create new file and release newly allocated creds. | |
2581 | * | |
2582 | * Return: Returns 0 on success or a negative error code on error. | |
2583 | */ | |
d8ad8b49 VG |
2584 | int security_inode_copy_up(struct dentry *src, struct cred **new) |
2585 | { | |
2586 | return call_int_hook(inode_copy_up, 0, src, new); | |
2587 | } | |
2588 | EXPORT_SYMBOL(security_inode_copy_up); | |
2589 | ||
916e3258 PM |
2590 | /** |
2591 | * security_inode_copy_up_xattr() - Filter xattrs in an overlayfs copy-up op | |
2592 | * @name: xattr name | |
2593 | * | |
2594 | * Filter the xattrs being copied up when a unioned file is copied up from a | |
2595 | * lower layer to the union/overlay layer. The caller is responsible for | |
2596 | * reading and writing the xattrs, this hook is merely a filter. | |
2597 | * | |
2598 | * Return: Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP | |
2599 | * if the security module does not know about attribute, or a negative | |
2600 | * error code to abort the copy up. | |
2601 | */ | |
121ab822 VG |
2602 | int security_inode_copy_up_xattr(const char *name) |
2603 | { | |
23e390cd KS |
2604 | struct security_hook_list *hp; |
2605 | int rc; | |
2606 | ||
2607 | /* | |
2608 | * The implementation can return 0 (accept the xattr), 1 (discard the | |
2609 | * xattr), -EOPNOTSUPP if it does not know anything about the xattr or | |
4432b507 | 2610 | * any other error code in case of an error. |
23e390cd KS |
2611 | */ |
2612 | hlist_for_each_entry(hp, | |
63c1845b | 2613 | &security_hook_heads.inode_copy_up_xattr, list) { |
23e390cd KS |
2614 | rc = hp->hook.inode_copy_up_xattr(name); |
2615 | if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr)) | |
2616 | return rc; | |
2617 | } | |
2618 | ||
2619 | return LSM_RET_DEFAULT(inode_copy_up_xattr); | |
121ab822 VG |
2620 | } |
2621 | EXPORT_SYMBOL(security_inode_copy_up_xattr); | |
2622 | ||
9348944b PM |
2623 | /** |
2624 | * security_kernfs_init_security() - Init LSM context for a kernfs node | |
2625 | * @kn_dir: parent kernfs node | |
2626 | * @kn: the kernfs node to initialize | |
2627 | * | |
2628 | * Initialize the security context of a newly created kernfs node based on its | |
2629 | * own and its parent's attributes. | |
2630 | * | |
2631 | * Return: Returns 0 if permission is granted. | |
2632 | */ | |
b230d5ab OM |
2633 | int security_kernfs_init_security(struct kernfs_node *kn_dir, |
2634 | struct kernfs_node *kn) | |
2635 | { | |
2636 | return call_int_hook(kernfs_init_security, 0, kn_dir, kn); | |
2637 | } | |
2638 | ||
a0fd6480 PM |
2639 | /** |
2640 | * security_file_permission() - Check file permissions | |
2641 | * @file: file | |
2642 | * @mask: requested permissions | |
2643 | * | |
2644 | * Check file permissions before accessing an open file. This hook is called | |
2645 | * by various operations that read or write files. A security module can use | |
2646 | * this hook to perform additional checking on these operations, e.g. to | |
2647 | * revalidate permissions on use to support privilege bracketing or policy | |
2648 | * changes. Notice that this hook is used when the actual read/write | |
2649 | * operations are performed, whereas the inode_security_ops hook is called when | |
2650 | * a file is opened (as well as many other operations). Although this hook can | |
2651 | * be used to revalidate permissions for various system call operations that | |
2652 | * read or write files, it does not address the revalidation of permissions for | |
2653 | * memory-mapped files. Security modules must handle this separately if they | |
2654 | * need such revalidation. | |
2655 | * | |
2656 | * Return: Returns 0 if permission is granted. | |
2657 | */ | |
20510f2f JM |
2658 | int security_file_permission(struct file *file, int mask) |
2659 | { | |
c4ec54b4 EP |
2660 | int ret; |
2661 | ||
f25fce3e | 2662 | ret = call_int_hook(file_permission, 0, file, mask); |
c4ec54b4 EP |
2663 | if (ret) |
2664 | return ret; | |
2665 | ||
2666 | return fsnotify_perm(file, mask); | |
20510f2f JM |
2667 | } |
2668 | ||
a0fd6480 PM |
2669 | /** |
2670 | * security_file_alloc() - Allocate and init a file's LSM blob | |
2671 | * @file: the file | |
2672 | * | |
2673 | * Allocate and attach a security structure to the file->f_security field. The | |
2674 | * security field is initialized to NULL when the structure is first created. | |
2675 | * | |
2676 | * Return: Return 0 if the hook is successful and permission is granted. | |
2677 | */ | |
20510f2f JM |
2678 | int security_file_alloc(struct file *file) |
2679 | { | |
33bf60ca CS |
2680 | int rc = lsm_file_alloc(file); |
2681 | ||
2682 | if (rc) | |
2683 | return rc; | |
2684 | rc = call_int_hook(file_alloc_security, 0, file); | |
2685 | if (unlikely(rc)) | |
2686 | security_file_free(file); | |
2687 | return rc; | |
20510f2f JM |
2688 | } |
2689 | ||
a0fd6480 PM |
2690 | /** |
2691 | * security_file_free() - Free a file's LSM blob | |
2692 | * @file: the file | |
2693 | * | |
2694 | * Deallocate and free any security structures stored in file->f_security. | |
2695 | */ | |
20510f2f JM |
2696 | void security_file_free(struct file *file) |
2697 | { | |
33bf60ca CS |
2698 | void *blob; |
2699 | ||
f25fce3e | 2700 | call_void_hook(file_free_security, file); |
33bf60ca CS |
2701 | |
2702 | blob = file->f_security; | |
2703 | if (blob) { | |
2704 | file->f_security = NULL; | |
2705 | kmem_cache_free(lsm_file_cache, blob); | |
2706 | } | |
20510f2f JM |
2707 | } |
2708 | ||
a0fd6480 PM |
2709 | /** |
2710 | * security_file_ioctl() - Check if an ioctl is allowed | |
2711 | * @file: associated file | |
2712 | * @cmd: ioctl cmd | |
2713 | * @arg: ioctl arguments | |
2714 | * | |
2715 | * Check permission for an ioctl operation on @file. Note that @arg sometimes | |
2716 | * represents a user space pointer; in other cases, it may be a simple integer | |
2717 | * value. When @arg represents a user space pointer, it should never be used | |
2718 | * by the security module. | |
2719 | * | |
2720 | * Return: Returns 0 if permission is granted. | |
2721 | */ | |
20510f2f JM |
2722 | int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
2723 | { | |
f25fce3e | 2724 | return call_int_hook(file_ioctl, 0, file, cmd, arg); |
20510f2f | 2725 | } |
292f902a | 2726 | EXPORT_SYMBOL_GPL(security_file_ioctl); |
20510f2f | 2727 | |
98de59bf | 2728 | static inline unsigned long mmap_prot(struct file *file, unsigned long prot) |
20510f2f | 2729 | { |
8b3ec681 | 2730 | /* |
98de59bf AV |
2731 | * Does we have PROT_READ and does the application expect |
2732 | * it to imply PROT_EXEC? If not, nothing to talk about... | |
8b3ec681 | 2733 | */ |
98de59bf AV |
2734 | if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ) |
2735 | return prot; | |
8b3ec681 | 2736 | if (!(current->personality & READ_IMPLIES_EXEC)) |
98de59bf AV |
2737 | return prot; |
2738 | /* | |
2739 | * if that's an anonymous mapping, let it. | |
2740 | */ | |
2741 | if (!file) | |
2742 | return prot | PROT_EXEC; | |
2743 | /* | |
2744 | * ditto if it's not on noexec mount, except that on !MMU we need | |
b4caecd4 | 2745 | * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case |
98de59bf | 2746 | */ |
90f8572b | 2747 | if (!path_noexec(&file->f_path)) { |
8b3ec681 | 2748 | #ifndef CONFIG_MMU |
b4caecd4 CH |
2749 | if (file->f_op->mmap_capabilities) { |
2750 | unsigned caps = file->f_op->mmap_capabilities(file); | |
2751 | if (!(caps & NOMMU_MAP_EXEC)) | |
2752 | return prot; | |
2753 | } | |
8b3ec681 | 2754 | #endif |
98de59bf | 2755 | return prot | PROT_EXEC; |
8b3ec681 | 2756 | } |
98de59bf AV |
2757 | /* anything on noexec mount won't get PROT_EXEC */ |
2758 | return prot; | |
2759 | } | |
2760 | ||
a0fd6480 PM |
2761 | /** |
2762 | * security_mmap_file() - Check if mmap'ing a file is allowed | |
2763 | * @file: file | |
2764 | * @prot: protection applied by the kernel | |
2765 | * @flags: flags | |
2766 | * | |
2767 | * Check permissions for a mmap operation. The @file may be NULL, e.g. if | |
2768 | * mapping anonymous memory. | |
2769 | * | |
2770 | * Return: Returns 0 if permission is granted. | |
2771 | */ | |
98de59bf | 2772 | int security_mmap_file(struct file *file, unsigned long prot, |
63c1845b | 2773 | unsigned long flags) |
98de59bf | 2774 | { |
4971c268 | 2775 | unsigned long prot_adj = mmap_prot(file, prot); |
98de59bf | 2776 | int ret; |
4971c268 RS |
2777 | |
2778 | ret = call_int_hook(mmap_file, 0, file, prot, prot_adj, flags); | |
6c21a7fb MZ |
2779 | if (ret) |
2780 | return ret; | |
4971c268 | 2781 | return ima_file_mmap(file, prot, prot_adj, flags); |
20510f2f JM |
2782 | } |
2783 | ||
a0fd6480 PM |
2784 | /** |
2785 | * security_mmap_addr() - Check if mmap'ing an address is allowed | |
2786 | * @addr: address | |
2787 | * | |
2788 | * Check permissions for a mmap operation at @addr. | |
2789 | * | |
2790 | * Return: Returns 0 if permission is granted. | |
2791 | */ | |
e5467859 AV |
2792 | int security_mmap_addr(unsigned long addr) |
2793 | { | |
f25fce3e | 2794 | return call_int_hook(mmap_addr, 0, addr); |
e5467859 AV |
2795 | } |
2796 | ||
a0fd6480 PM |
2797 | /** |
2798 | * security_file_mprotect() - Check if changing memory protections is allowed | |
2799 | * @vma: memory region | |
2800 | * @reqprot: application requested protection | |
1e2523d7 | 2801 | * @prot: protection applied by the kernel |
a0fd6480 PM |
2802 | * |
2803 | * Check permissions before changing memory access permissions. | |
2804 | * | |
2805 | * Return: Returns 0 if permission is granted. | |
2806 | */ | |
20510f2f | 2807 | int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, |
63c1845b | 2808 | unsigned long prot) |
20510f2f | 2809 | { |
8eb613c0 MZ |
2810 | int ret; |
2811 | ||
2812 | ret = call_int_hook(file_mprotect, 0, vma, reqprot, prot); | |
2813 | if (ret) | |
2814 | return ret; | |
2815 | return ima_file_mprotect(vma, prot); | |
20510f2f JM |
2816 | } |
2817 | ||
a0fd6480 PM |
2818 | /** |
2819 | * security_file_lock() - Check if a file lock is allowed | |
2820 | * @file: file | |
2821 | * @cmd: lock operation (e.g. F_RDLCK, F_WRLCK) | |
2822 | * | |
2823 | * Check permission before performing file locking operations. Note the hook | |
2824 | * mediates both flock and fcntl style locks. | |
2825 | * | |
2826 | * Return: Returns 0 if permission is granted. | |
2827 | */ | |
20510f2f JM |
2828 | int security_file_lock(struct file *file, unsigned int cmd) |
2829 | { | |
f25fce3e | 2830 | return call_int_hook(file_lock, 0, file, cmd); |
20510f2f JM |
2831 | } |
2832 | ||
a0fd6480 PM |
2833 | /** |
2834 | * security_file_fcntl() - Check if fcntl() op is allowed | |
2835 | * @file: file | |
ff72942c | 2836 | * @cmd: fcntl command |
a0fd6480 PM |
2837 | * @arg: command argument |
2838 | * | |
2839 | * Check permission before allowing the file operation specified by @cmd from | |
2840 | * being performed on the file @file. Note that @arg sometimes represents a | |
2841 | * user space pointer; in other cases, it may be a simple integer value. When | |
2842 | * @arg represents a user space pointer, it should never be used by the | |
2843 | * security module. | |
2844 | * | |
2845 | * Return: Returns 0 if permission is granted. | |
2846 | */ | |
20510f2f JM |
2847 | int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) |
2848 | { | |
f25fce3e | 2849 | return call_int_hook(file_fcntl, 0, file, cmd, arg); |
20510f2f JM |
2850 | } |
2851 | ||
a0fd6480 PM |
2852 | /** |
2853 | * security_file_set_fowner() - Set the file owner info in the LSM blob | |
2854 | * @file: the file | |
2855 | * | |
2856 | * Save owner security information (typically from current->security) in | |
2857 | * file->f_security for later use by the send_sigiotask hook. | |
2858 | * | |
2859 | * Return: Returns 0 on success. | |
2860 | */ | |
e0b93edd | 2861 | void security_file_set_fowner(struct file *file) |
20510f2f | 2862 | { |
f25fce3e | 2863 | call_void_hook(file_set_fowner, file); |
20510f2f JM |
2864 | } |
2865 | ||
a0fd6480 PM |
2866 | /** |
2867 | * security_file_send_sigiotask() - Check if sending SIGIO/SIGURG is allowed | |
2868 | * @tsk: target task | |
2869 | * @fown: signal sender | |
2870 | * @sig: signal to be sent, SIGIO is sent if 0 | |
2871 | * | |
2872 | * Check permission for the file owner @fown to send SIGIO or SIGURG to the | |
2873 | * process @tsk. Note that this hook is sometimes called from interrupt. Note | |
2874 | * that the fown_struct, @fown, is never outside the context of a struct file, | |
2875 | * so the file structure (and associated security information) can always be | |
2876 | * obtained: container_of(fown, struct file, f_owner). | |
2877 | * | |
2878 | * Return: Returns 0 if permission is granted. | |
2879 | */ | |
20510f2f | 2880 | int security_file_send_sigiotask(struct task_struct *tsk, |
63c1845b | 2881 | struct fown_struct *fown, int sig) |
20510f2f | 2882 | { |
f25fce3e | 2883 | return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig); |
20510f2f JM |
2884 | } |
2885 | ||
a0fd6480 PM |
2886 | /** |
2887 | * security_file_receive() - Check is receiving a file via IPC is allowed | |
2888 | * @file: file being received | |
2889 | * | |
2890 | * This hook allows security modules to control the ability of a process to | |
2891 | * receive an open file descriptor via socket IPC. | |
2892 | * | |
2893 | * Return: Returns 0 if permission is granted. | |
2894 | */ | |
20510f2f JM |
2895 | int security_file_receive(struct file *file) |
2896 | { | |
f25fce3e | 2897 | return call_int_hook(file_receive, 0, file); |
20510f2f JM |
2898 | } |
2899 | ||
a0fd6480 PM |
2900 | /** |
2901 | * security_file_open() - Save open() time state for late use by the LSM | |
2902 | * @file: | |
2903 | * | |
2904 | * Save open-time permission checking state for later use upon file_permission, | |
2905 | * and recheck access if anything has changed since inode_permission. | |
2906 | * | |
2907 | * Return: Returns 0 if permission is granted. | |
2908 | */ | |
e3f20ae2 | 2909 | int security_file_open(struct file *file) |
20510f2f | 2910 | { |
c4ec54b4 EP |
2911 | int ret; |
2912 | ||
94817692 | 2913 | ret = call_int_hook(file_open, 0, file); |
c4ec54b4 EP |
2914 | if (ret) |
2915 | return ret; | |
2916 | ||
2917 | return fsnotify_perm(file, MAY_OPEN); | |
20510f2f JM |
2918 | } |
2919 | ||
a0fd6480 PM |
2920 | /** |
2921 | * security_file_truncate() - Check if truncating a file is allowed | |
2922 | * @file: file | |
2923 | * | |
2924 | * Check permission before truncating a file, i.e. using ftruncate. Note that | |
2925 | * truncation permission may also be checked based on the path, using the | |
2926 | * @path_truncate hook. | |
2927 | * | |
2928 | * Return: Returns 0 if permission is granted. | |
2929 | */ | |
3350607d GN |
2930 | int security_file_truncate(struct file *file) |
2931 | { | |
2932 | return call_int_hook(file_truncate, 0, file); | |
2933 | } | |
2934 | ||
130c53bf PM |
2935 | /** |
2936 | * security_task_alloc() - Allocate a task's LSM blob | |
2937 | * @task: the task | |
2938 | * @clone_flags: flags indicating what is being shared | |
2939 | * | |
2940 | * Handle allocation of task-related resources. | |
2941 | * | |
2942 | * Return: Returns a zero on success, negative values on failure. | |
2943 | */ | |
e4e55b47 TH |
2944 | int security_task_alloc(struct task_struct *task, unsigned long clone_flags) |
2945 | { | |
f4ad8f2c CS |
2946 | int rc = lsm_task_alloc(task); |
2947 | ||
2948 | if (rc) | |
2949 | return rc; | |
2950 | rc = call_int_hook(task_alloc, 0, task, clone_flags); | |
2951 | if (unlikely(rc)) | |
2952 | security_task_free(task); | |
2953 | return rc; | |
e4e55b47 TH |
2954 | } |
2955 | ||
130c53bf PM |
2956 | /** |
2957 | * security_task_free() - Free a task's LSM blob and related resources | |
2958 | * @task: task | |
2959 | * | |
2960 | * Handle release of task-related resources. Note that this can be called from | |
2961 | * interrupt context. | |
2962 | */ | |
1a2a4d06 KC |
2963 | void security_task_free(struct task_struct *task) |
2964 | { | |
f25fce3e | 2965 | call_void_hook(task_free, task); |
f4ad8f2c CS |
2966 | |
2967 | kfree(task->security); | |
2968 | task->security = NULL; | |
1a2a4d06 KC |
2969 | } |
2970 | ||
130c53bf PM |
2971 | /** |
2972 | * security_cred_alloc_blank() - Allocate the min memory to allow cred_transfer | |
2973 | * @cred: credentials | |
2974 | * @gfp: gfp flags | |
2975 | * | |
2976 | * Only allocate sufficient memory and attach to @cred such that | |
2977 | * cred_transfer() will not get ENOMEM. | |
2978 | * | |
2979 | * Return: Returns 0 on success, negative values on failure. | |
2980 | */ | |
ee18d64c DH |
2981 | int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) |
2982 | { | |
bbd3662a CS |
2983 | int rc = lsm_cred_alloc(cred, gfp); |
2984 | ||
2985 | if (rc) | |
2986 | return rc; | |
2987 | ||
2988 | rc = call_int_hook(cred_alloc_blank, 0, cred, gfp); | |
33bf60ca | 2989 | if (unlikely(rc)) |
bbd3662a CS |
2990 | security_cred_free(cred); |
2991 | return rc; | |
ee18d64c DH |
2992 | } |
2993 | ||
130c53bf PM |
2994 | /** |
2995 | * security_cred_free() - Free the cred's LSM blob and associated resources | |
2996 | * @cred: credentials | |
2997 | * | |
2998 | * Deallocate and clear the cred->security field in a set of credentials. | |
2999 | */ | |
d84f4f99 | 3000 | void security_cred_free(struct cred *cred) |
20510f2f | 3001 | { |
a5795fd3 JM |
3002 | /* |
3003 | * There is a failure case in prepare_creds() that | |
3004 | * may result in a call here with ->security being NULL. | |
3005 | */ | |
3006 | if (unlikely(cred->security == NULL)) | |
3007 | return; | |
3008 | ||
f25fce3e | 3009 | call_void_hook(cred_free, cred); |
bbd3662a CS |
3010 | |
3011 | kfree(cred->security); | |
3012 | cred->security = NULL; | |
20510f2f JM |
3013 | } |
3014 | ||
130c53bf PM |
3015 | /** |
3016 | * security_prepare_creds() - Prepare a new set of credentials | |
3017 | * @new: new credentials | |
3018 | * @old: original credentials | |
3019 | * @gfp: gfp flags | |
3020 | * | |
3021 | * Prepare a new set of credentials by copying the data from the old set. | |
3022 | * | |
3023 | * Return: Returns 0 on success, negative values on failure. | |
3024 | */ | |
d84f4f99 | 3025 | int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp) |
20510f2f | 3026 | { |
bbd3662a CS |
3027 | int rc = lsm_cred_alloc(new, gfp); |
3028 | ||
3029 | if (rc) | |
3030 | return rc; | |
3031 | ||
3032 | rc = call_int_hook(cred_prepare, 0, new, old, gfp); | |
33bf60ca | 3033 | if (unlikely(rc)) |
bbd3662a CS |
3034 | security_cred_free(new); |
3035 | return rc; | |
d84f4f99 DH |
3036 | } |
3037 | ||
130c53bf PM |
3038 | /** |
3039 | * security_transfer_creds() - Transfer creds | |
3040 | * @new: target credentials | |
3041 | * @old: original credentials | |
3042 | * | |
3043 | * Transfer data from original creds to new creds. | |
3044 | */ | |
ee18d64c DH |
3045 | void security_transfer_creds(struct cred *new, const struct cred *old) |
3046 | { | |
f25fce3e | 3047 | call_void_hook(cred_transfer, new, old); |
ee18d64c DH |
3048 | } |
3049 | ||
130c53bf PM |
3050 | /** |
3051 | * security_cred_getsecid() - Get the secid from a set of credentials | |
3052 | * @c: credentials | |
3053 | * @secid: secid value | |
3054 | * | |
3055 | * Retrieve the security identifier of the cred structure @c. In case of | |
3056 | * failure, @secid will be set to zero. | |
3057 | */ | |
3ec30113 MG |
3058 | void security_cred_getsecid(const struct cred *c, u32 *secid) |
3059 | { | |
3060 | *secid = 0; | |
3061 | call_void_hook(cred_getsecid, c, secid); | |
3062 | } | |
3063 | EXPORT_SYMBOL(security_cred_getsecid); | |
3064 | ||
130c53bf PM |
3065 | /** |
3066 | * security_kernel_act_as() - Set the kernel credentials to act as secid | |
3067 | * @new: credentials | |
3068 | * @secid: secid | |
3069 | * | |
3070 | * Set the credentials for a kernel service to act as (subjective context). | |
3071 | * The current task must be the one that nominated @secid. | |
3072 | * | |
3073 | * Return: Returns 0 if successful. | |
3074 | */ | |
3a3b7ce9 DH |
3075 | int security_kernel_act_as(struct cred *new, u32 secid) |
3076 | { | |
f25fce3e | 3077 | return call_int_hook(kernel_act_as, 0, new, secid); |
3a3b7ce9 DH |
3078 | } |
3079 | ||
130c53bf PM |
3080 | /** |
3081 | * security_kernel_create_files_as() - Set file creation context using an inode | |
3082 | * @new: target credentials | |
3083 | * @inode: reference inode | |
3084 | * | |
3085 | * Set the file creation context in a set of credentials to be the same as the | |
3086 | * objective context of the specified inode. The current task must be the one | |
3087 | * that nominated @inode. | |
3088 | * | |
3089 | * Return: Returns 0 if successful. | |
3090 | */ | |
3a3b7ce9 DH |
3091 | int security_kernel_create_files_as(struct cred *new, struct inode *inode) |
3092 | { | |
f25fce3e | 3093 | return call_int_hook(kernel_create_files_as, 0, new, inode); |
3a3b7ce9 DH |
3094 | } |
3095 | ||
130c53bf PM |
3096 | /** |
3097 | * security_kernel_module_request() - Check is loading a module is allowed | |
3098 | * @kmod_name: module name | |
3099 | * | |
3100 | * Ability to trigger the kernel to automatically upcall to userspace for | |
3101 | * userspace to load a kernel module with the given name. | |
3102 | * | |
3103 | * Return: Returns 0 if successful. | |
3104 | */ | |
dd8dbf2e | 3105 | int security_kernel_module_request(char *kmod_name) |
9188499c | 3106 | { |
6eb864c1 MK |
3107 | int ret; |
3108 | ||
3109 | ret = call_int_hook(kernel_module_request, 0, kmod_name); | |
3110 | if (ret) | |
3111 | return ret; | |
3112 | return integrity_kernel_module_request(kmod_name); | |
9188499c EP |
3113 | } |
3114 | ||
130c53bf PM |
3115 | /** |
3116 | * security_kernel_read_file() - Read a file specified by userspace | |
3117 | * @file: file | |
3118 | * @id: file identifier | |
3119 | * @contents: trust if security_kernel_post_read_file() will be called | |
3120 | * | |
3121 | * Read a file specified by userspace. | |
3122 | * | |
3123 | * Return: Returns 0 if permission is granted. | |
3124 | */ | |
2039bda1 KC |
3125 | int security_kernel_read_file(struct file *file, enum kernel_read_file_id id, |
3126 | bool contents) | |
39eeb4fb MZ |
3127 | { |
3128 | int ret; | |
3129 | ||
2039bda1 | 3130 | ret = call_int_hook(kernel_read_file, 0, file, id, contents); |
39eeb4fb MZ |
3131 | if (ret) |
3132 | return ret; | |
2039bda1 | 3133 | return ima_read_file(file, id, contents); |
39eeb4fb MZ |
3134 | } |
3135 | EXPORT_SYMBOL_GPL(security_kernel_read_file); | |
3136 | ||
130c53bf PM |
3137 | /** |
3138 | * security_kernel_post_read_file() - Read a file specified by userspace | |
3139 | * @file: file | |
3140 | * @buf: file contents | |
3141 | * @size: size of file contents | |
3142 | * @id: file identifier | |
3143 | * | |
3144 | * Read a file specified by userspace. This must be paired with a prior call | |
3145 | * to security_kernel_read_file() call that indicated this hook would also be | |
3146 | * called, see security_kernel_read_file() for more information. | |
3147 | * | |
3148 | * Return: Returns 0 if permission is granted. | |
3149 | */ | |
bc8ca5b9 MZ |
3150 | int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, |
3151 | enum kernel_read_file_id id) | |
b44a7dfc | 3152 | { |
cf222217 MZ |
3153 | int ret; |
3154 | ||
3155 | ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id); | |
3156 | if (ret) | |
3157 | return ret; | |
3158 | return ima_post_read_file(file, buf, size, id); | |
b44a7dfc MZ |
3159 | } |
3160 | EXPORT_SYMBOL_GPL(security_kernel_post_read_file); | |
3161 | ||
130c53bf PM |
3162 | /** |
3163 | * security_kernel_load_data() - Load data provided by userspace | |
3164 | * @id: data identifier | |
3165 | * @contents: true if security_kernel_post_load_data() will be called | |
3166 | * | |
3167 | * Load data provided by userspace. | |
3168 | * | |
3169 | * Return: Returns 0 if permission is granted. | |
3170 | */ | |
b64fcae7 | 3171 | int security_kernel_load_data(enum kernel_load_data_id id, bool contents) |
377179cd | 3172 | { |
16c267aa MZ |
3173 | int ret; |
3174 | ||
b64fcae7 | 3175 | ret = call_int_hook(kernel_load_data, 0, id, contents); |
16c267aa MZ |
3176 | if (ret) |
3177 | return ret; | |
b64fcae7 | 3178 | return ima_load_data(id, contents); |
377179cd | 3179 | } |
83a68a06 | 3180 | EXPORT_SYMBOL_GPL(security_kernel_load_data); |
377179cd | 3181 | |
130c53bf PM |
3182 | /** |
3183 | * security_kernel_post_load_data() - Load userspace data from a non-file source | |
3184 | * @buf: data | |
3185 | * @size: size of data | |
3186 | * @id: data identifier | |
3187 | * @description: text description of data, specific to the id value | |
3188 | * | |
3189 | * Load data provided by a non-file source (usually userspace buffer). This | |
3190 | * must be paired with a prior security_kernel_load_data() call that indicated | |
3191 | * this hook would also be called, see security_kernel_load_data() for more | |
3192 | * information. | |
3193 | * | |
3194 | * Return: Returns 0 if permission is granted. | |
3195 | */ | |
b64fcae7 KC |
3196 | int security_kernel_post_load_data(char *buf, loff_t size, |
3197 | enum kernel_load_data_id id, | |
3198 | char *description) | |
3199 | { | |
3200 | int ret; | |
3201 | ||
3202 | ret = call_int_hook(kernel_post_load_data, 0, buf, size, id, | |
3203 | description); | |
3204 | if (ret) | |
3205 | return ret; | |
3206 | return ima_post_load_data(buf, size, id, description); | |
3207 | } | |
3208 | EXPORT_SYMBOL_GPL(security_kernel_post_load_data); | |
3209 | ||
130c53bf PM |
3210 | /** |
3211 | * security_task_fix_setuid() - Update LSM with new user id attributes | |
3212 | * @new: updated credentials | |
3213 | * @old: credentials being replaced | |
3214 | * @flags: LSM_SETID_* flag values | |
3215 | * | |
3216 | * Update the module's state after setting one or more of the user identity | |
3217 | * attributes of the current process. The @flags parameter indicates which of | |
3218 | * the set*uid system calls invoked this hook. If @new is the set of | |
3219 | * credentials that will be installed. Modifications should be made to this | |
3220 | * rather than to @current->cred. | |
3221 | * | |
3222 | * Return: Returns 0 on success. | |
3223 | */ | |
d84f4f99 DH |
3224 | int security_task_fix_setuid(struct cred *new, const struct cred *old, |
3225 | int flags) | |
20510f2f | 3226 | { |
f25fce3e | 3227 | return call_int_hook(task_fix_setuid, 0, new, old, flags); |
20510f2f JM |
3228 | } |
3229 | ||
130c53bf PM |
3230 | /** |
3231 | * security_task_fix_setgid() - Update LSM with new group id attributes | |
3232 | * @new: updated credentials | |
3233 | * @old: credentials being replaced | |
3234 | * @flags: LSM_SETID_* flag value | |
3235 | * | |
3236 | * Update the module's state after setting one or more of the group identity | |
3237 | * attributes of the current process. The @flags parameter indicates which of | |
3238 | * the set*gid system calls invoked this hook. @new is the set of credentials | |
3239 | * that will be installed. Modifications should be made to this rather than to | |
3240 | * @current->cred. | |
3241 | * | |
3242 | * Return: Returns 0 on success. | |
3243 | */ | |
39030e13 | 3244 | int security_task_fix_setgid(struct cred *new, const struct cred *old, |
63c1845b | 3245 | int flags) |
39030e13 TC |
3246 | { |
3247 | return call_int_hook(task_fix_setgid, 0, new, old, flags); | |
3248 | } | |
3249 | ||
130c53bf PM |
3250 | /** |
3251 | * security_task_fix_setgroups() - Update LSM with new supplementary groups | |
3252 | * @new: updated credentials | |
3253 | * @old: credentials being replaced | |
3254 | * | |
3255 | * Update the module's state after setting the supplementary group identity | |
3256 | * attributes of the current process. @new is the set of credentials that will | |
3257 | * be installed. Modifications should be made to this rather than to | |
3258 | * @current->cred. | |
3259 | * | |
3260 | * Return: Returns 0 on success. | |
3261 | */ | |
fcfe0ac2 MM |
3262 | int security_task_fix_setgroups(struct cred *new, const struct cred *old) |
3263 | { | |
3264 | return call_int_hook(task_fix_setgroups, 0, new, old); | |
3265 | } | |
3266 | ||
130c53bf PM |
3267 | /** |
3268 | * security_task_setpgid() - Check if setting the pgid is allowed | |
3269 | * @p: task being modified | |
3270 | * @pgid: new pgid | |
3271 | * | |
3272 | * Check permission before setting the process group identifier of the process | |
3273 | * @p to @pgid. | |
3274 | * | |
3275 | * Return: Returns 0 if permission is granted. | |
3276 | */ | |
20510f2f JM |
3277 | int security_task_setpgid(struct task_struct *p, pid_t pgid) |
3278 | { | |
f25fce3e | 3279 | return call_int_hook(task_setpgid, 0, p, pgid); |
20510f2f JM |
3280 | } |
3281 | ||
130c53bf PM |
3282 | /** |
3283 | * security_task_getpgid() - Check if getting the pgid is allowed | |
3284 | * @p: task | |
3285 | * | |
3286 | * Check permission before getting the process group identifier of the process | |
3287 | * @p. | |
3288 | * | |
3289 | * Return: Returns 0 if permission is granted. | |
3290 | */ | |
20510f2f JM |
3291 | int security_task_getpgid(struct task_struct *p) |
3292 | { | |
f25fce3e | 3293 | return call_int_hook(task_getpgid, 0, p); |
20510f2f JM |
3294 | } |
3295 | ||
130c53bf PM |
3296 | /** |
3297 | * security_task_getsid() - Check if getting the session id is allowed | |
3298 | * @p: task | |
3299 | * | |
3300 | * Check permission before getting the session identifier of the process @p. | |
3301 | * | |
3302 | * Return: Returns 0 if permission is granted. | |
3303 | */ | |
20510f2f JM |
3304 | int security_task_getsid(struct task_struct *p) |
3305 | { | |
f25fce3e | 3306 | return call_int_hook(task_getsid, 0, p); |
20510f2f JM |
3307 | } |
3308 | ||
130c53bf PM |
3309 | /** |
3310 | * security_current_getsecid_subj() - Get the current task's subjective secid | |
3311 | * @secid: secid value | |
3312 | * | |
3313 | * Retrieve the subjective security identifier of the current task and return | |
3314 | * it in @secid. In case of failure, @secid will be set to zero. | |
3315 | */ | |
6326948f | 3316 | void security_current_getsecid_subj(u32 *secid) |
20510f2f | 3317 | { |
b1d9e6b0 | 3318 | *secid = 0; |
6326948f | 3319 | call_void_hook(current_getsecid_subj, secid); |
20510f2f | 3320 | } |
6326948f | 3321 | EXPORT_SYMBOL(security_current_getsecid_subj); |
4ebd7651 | 3322 | |
130c53bf PM |
3323 | /** |
3324 | * security_task_getsecid_obj() - Get a task's objective secid | |
3325 | * @p: target task | |
3326 | * @secid: secid value | |
3327 | * | |
3328 | * Retrieve the objective security identifier of the task_struct in @p and | |
3329 | * return it in @secid. In case of failure, @secid will be set to zero. | |
3330 | */ | |
4ebd7651 PM |
3331 | void security_task_getsecid_obj(struct task_struct *p, u32 *secid) |
3332 | { | |
3333 | *secid = 0; | |
3334 | call_void_hook(task_getsecid_obj, p, secid); | |
3335 | } | |
3336 | EXPORT_SYMBOL(security_task_getsecid_obj); | |
20510f2f | 3337 | |
130c53bf PM |
3338 | /** |
3339 | * security_task_setnice() - Check if setting a task's nice value is allowed | |
3340 | * @p: target task | |
3341 | * @nice: nice value | |
3342 | * | |
3343 | * Check permission before setting the nice value of @p to @nice. | |
3344 | * | |
3345 | * Return: Returns 0 if permission is granted. | |
3346 | */ | |
20510f2f JM |
3347 | int security_task_setnice(struct task_struct *p, int nice) |
3348 | { | |
f25fce3e | 3349 | return call_int_hook(task_setnice, 0, p, nice); |
20510f2f JM |
3350 | } |
3351 | ||
130c53bf PM |
3352 | /** |
3353 | * security_task_setioprio() - Check if setting a task's ioprio is allowed | |
3354 | * @p: target task | |
3355 | * @ioprio: ioprio value | |
3356 | * | |
3357 | * Check permission before setting the ioprio value of @p to @ioprio. | |
3358 | * | |
3359 | * Return: Returns 0 if permission is granted. | |
3360 | */ | |
20510f2f JM |
3361 | int security_task_setioprio(struct task_struct *p, int ioprio) |
3362 | { | |
f25fce3e | 3363 | return call_int_hook(task_setioprio, 0, p, ioprio); |
20510f2f JM |
3364 | } |
3365 | ||
130c53bf PM |
3366 | /** |
3367 | * security_task_getioprio() - Check if getting a task's ioprio is allowed | |
3368 | * @p: task | |
3369 | * | |
3370 | * Check permission before getting the ioprio value of @p. | |
3371 | * | |
3372 | * Return: Returns 0 if permission is granted. | |
3373 | */ | |
20510f2f JM |
3374 | int security_task_getioprio(struct task_struct *p) |
3375 | { | |
f25fce3e | 3376 | return call_int_hook(task_getioprio, 0, p); |
20510f2f JM |
3377 | } |
3378 | ||
130c53bf PM |
3379 | /** |
3380 | * security_task_prlimit() - Check if get/setting resources limits is allowed | |
3381 | * @cred: current task credentials | |
3382 | * @tcred: target task credentials | |
3383 | * @flags: LSM_PRLIMIT_* flag bits indicating a get/set/both | |
3384 | * | |
3385 | * Check permission before getting and/or setting the resource limits of | |
3386 | * another task. | |
3387 | * | |
3388 | * Return: Returns 0 if permission is granted. | |
3389 | */ | |
791ec491 SS |
3390 | int security_task_prlimit(const struct cred *cred, const struct cred *tcred, |
3391 | unsigned int flags) | |
3392 | { | |
3393 | return call_int_hook(task_prlimit, 0, cred, tcred, flags); | |
3394 | } | |
3395 | ||
130c53bf PM |
3396 | /** |
3397 | * security_task_setrlimit() - Check if setting a new rlimit value is allowed | |
3398 | * @p: target task's group leader | |
3399 | * @resource: resource whose limit is being set | |
3400 | * @new_rlim: new resource limit | |
3401 | * | |
3402 | * Check permission before setting the resource limits of process @p for | |
3403 | * @resource to @new_rlim. The old resource limit values can be examined by | |
3404 | * dereferencing (p->signal->rlim + resource). | |
3405 | * | |
3406 | * Return: Returns 0 if permission is granted. | |
3407 | */ | |
8fd00b4d | 3408 | int security_task_setrlimit(struct task_struct *p, unsigned int resource, |
63c1845b | 3409 | struct rlimit *new_rlim) |
20510f2f | 3410 | { |
f25fce3e | 3411 | return call_int_hook(task_setrlimit, 0, p, resource, new_rlim); |
20510f2f JM |
3412 | } |
3413 | ||
130c53bf PM |
3414 | /** |
3415 | * security_task_setscheduler() - Check if setting sched policy/param is allowed | |
3416 | * @p: target task | |
3417 | * | |
3418 | * Check permission before setting scheduling policy and/or parameters of | |
3419 | * process @p. | |
3420 | * | |
3421 | * Return: Returns 0 if permission is granted. | |
3422 | */ | |
b0ae1981 | 3423 | int security_task_setscheduler(struct task_struct *p) |
20510f2f | 3424 | { |
f25fce3e | 3425 | return call_int_hook(task_setscheduler, 0, p); |
20510f2f JM |
3426 | } |
3427 | ||
130c53bf PM |
3428 | /** |
3429 | * security_task_getscheduler() - Check if getting scheduling info is allowed | |
3430 | * @p: target task | |
3431 | * | |
3432 | * Check permission before obtaining scheduling information for process @p. | |
3433 | * | |
3434 | * Return: Returns 0 if permission is granted. | |
3435 | */ | |
20510f2f JM |
3436 | int security_task_getscheduler(struct task_struct *p) |
3437 | { | |
f25fce3e | 3438 | return call_int_hook(task_getscheduler, 0, p); |
20510f2f JM |
3439 | } |
3440 | ||
130c53bf PM |
3441 | /** |
3442 | * security_task_movememory() - Check if moving memory is allowed | |
3443 | * @p: task | |
3444 | * | |
3445 | * Check permission before moving memory owned by process @p. | |
3446 | * | |
3447 | * Return: Returns 0 if permission is granted. | |
3448 | */ | |
20510f2f JM |
3449 | int security_task_movememory(struct task_struct *p) |
3450 | { | |
f25fce3e | 3451 | return call_int_hook(task_movememory, 0, p); |
20510f2f JM |
3452 | } |
3453 | ||
130c53bf PM |
3454 | /** |
3455 | * security_task_kill() - Check if sending a signal is allowed | |
3456 | * @p: target process | |
3457 | * @info: signal information | |
3458 | * @sig: signal value | |
3459 | * @cred: credentials of the signal sender, NULL if @current | |
3460 | * | |
3461 | * Check permission before sending signal @sig to @p. @info can be NULL, the | |
3462 | * constant 1, or a pointer to a kernel_siginfo structure. If @info is 1 or | |
3463 | * SI_FROMKERNEL(info) is true, then the signal should be viewed as coming from | |
3464 | * the kernel and should typically be permitted. SIGIO signals are handled | |
3465 | * separately by the send_sigiotask hook in file_security_ops. | |
3466 | * | |
3467 | * Return: Returns 0 if permission is granted. | |
3468 | */ | |
ae7795bc | 3469 | int security_task_kill(struct task_struct *p, struct kernel_siginfo *info, |
63c1845b | 3470 | int sig, const struct cred *cred) |
20510f2f | 3471 | { |
6b4f3d01 | 3472 | return call_int_hook(task_kill, 0, p, info, sig, cred); |
20510f2f JM |
3473 | } |
3474 | ||
130c53bf PM |
3475 | /** |
3476 | * security_task_prctl() - Check if a prctl op is allowed | |
3477 | * @option: operation | |
3478 | * @arg2: argument | |
3479 | * @arg3: argument | |
3480 | * @arg4: argument | |
3481 | * @arg5: argument | |
3482 | * | |
3483 | * Check permission before performing a process control operation on the | |
3484 | * current process. | |
3485 | * | |
3486 | * Return: Return -ENOSYS if no-one wanted to handle this op, any other value | |
3487 | * to cause prctl() to return immediately with that value. | |
3488 | */ | |
20510f2f | 3489 | int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, |
63c1845b | 3490 | unsigned long arg4, unsigned long arg5) |
20510f2f | 3491 | { |
b1d9e6b0 | 3492 | int thisrc; |
98e828a0 | 3493 | int rc = LSM_RET_DEFAULT(task_prctl); |
b1d9e6b0 CS |
3494 | struct security_hook_list *hp; |
3495 | ||
df0ce173 | 3496 | hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) { |
b1d9e6b0 | 3497 | thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5); |
98e828a0 | 3498 | if (thisrc != LSM_RET_DEFAULT(task_prctl)) { |
b1d9e6b0 CS |
3499 | rc = thisrc; |
3500 | if (thisrc != 0) | |
3501 | break; | |
3502 | } | |
3503 | } | |
3504 | return rc; | |
20510f2f JM |
3505 | } |
3506 | ||
130c53bf PM |
3507 | /** |
3508 | * security_task_to_inode() - Set the security attributes of a task's inode | |
3509 | * @p: task | |
3510 | * @inode: inode | |
3511 | * | |
3512 | * Set the security attributes for an inode based on an associated task's | |
3513 | * security attributes, e.g. for /proc/pid inodes. | |
3514 | */ | |
20510f2f JM |
3515 | void security_task_to_inode(struct task_struct *p, struct inode *inode) |
3516 | { | |
f25fce3e | 3517 | call_void_hook(task_to_inode, p, inode); |
20510f2f JM |
3518 | } |
3519 | ||
130c53bf PM |
3520 | /** |
3521 | * security_create_user_ns() - Check if creating a new userns is allowed | |
3522 | * @cred: prepared creds | |
3523 | * | |
3524 | * Check permission prior to creating a new user namespace. | |
3525 | * | |
3526 | * Return: Returns 0 if successful, otherwise < 0 error code. | |
3527 | */ | |
7cd4c5c2 FL |
3528 | int security_create_user_ns(const struct cred *cred) |
3529 | { | |
3530 | return call_int_hook(userns_create, 0, cred); | |
3531 | } | |
20510f2f | 3532 | |
43fad282 PM |
3533 | /** |
3534 | * security_ipc_permission() - Check if sysv ipc access is allowed | |
3535 | * @ipcp: ipc permission structure | |
1e2523d7 | 3536 | * @flag: requested permissions |
43fad282 PM |
3537 | * |
3538 | * Check permissions for access to IPC. | |
3539 | * | |
3540 | * Return: Returns 0 if permission is granted. | |
3541 | */ | |
20510f2f JM |
3542 | int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) |
3543 | { | |
f25fce3e | 3544 | return call_int_hook(ipc_permission, 0, ipcp, flag); |
20510f2f JM |
3545 | } |
3546 | ||
43fad282 PM |
3547 | /** |
3548 | * security_ipc_getsecid() - Get the sysv ipc object's secid | |
3549 | * @ipcp: ipc permission structure | |
3550 | * @secid: secid pointer | |
3551 | * | |
3552 | * Get the secid associated with the ipc object. In case of failure, @secid | |
3553 | * will be set to zero. | |
3554 | */ | |
8a076191 AD |
3555 | void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) |
3556 | { | |
b1d9e6b0 | 3557 | *secid = 0; |
f25fce3e | 3558 | call_void_hook(ipc_getsecid, ipcp, secid); |
8a076191 AD |
3559 | } |
3560 | ||
43fad282 PM |
3561 | /** |
3562 | * security_msg_msg_alloc() - Allocate a sysv ipc message LSM blob | |
3563 | * @msg: message structure | |
3564 | * | |
3565 | * Allocate and attach a security structure to the msg->security field. The | |
3566 | * security field is initialized to NULL when the structure is first created. | |
3567 | * | |
3568 | * Return: Return 0 if operation was successful and permission is granted. | |
3569 | */ | |
20510f2f JM |
3570 | int security_msg_msg_alloc(struct msg_msg *msg) |
3571 | { | |
ecd5f82e CS |
3572 | int rc = lsm_msg_msg_alloc(msg); |
3573 | ||
3574 | if (unlikely(rc)) | |
3575 | return rc; | |
3576 | rc = call_int_hook(msg_msg_alloc_security, 0, msg); | |
3577 | if (unlikely(rc)) | |
3578 | security_msg_msg_free(msg); | |
3579 | return rc; | |
20510f2f JM |
3580 | } |
3581 | ||
43fad282 PM |
3582 | /** |
3583 | * security_msg_msg_free() - Free a sysv ipc message LSM blob | |
3584 | * @msg: message structure | |
3585 | * | |
3586 | * Deallocate the security structure for this message. | |
3587 | */ | |
20510f2f JM |
3588 | void security_msg_msg_free(struct msg_msg *msg) |
3589 | { | |
f25fce3e | 3590 | call_void_hook(msg_msg_free_security, msg); |
ecd5f82e CS |
3591 | kfree(msg->security); |
3592 | msg->security = NULL; | |
20510f2f JM |
3593 | } |
3594 | ||
43fad282 PM |
3595 | /** |
3596 | * security_msg_queue_alloc() - Allocate a sysv ipc msg queue LSM blob | |
3597 | * @msq: sysv ipc permission structure | |
3598 | * | |
3599 | * Allocate and attach a security structure to @msg. The security field is | |
3600 | * initialized to NULL when the structure is first created. | |
3601 | * | |
3602 | * Return: Returns 0 if operation was successful and permission is granted. | |
3603 | */ | |
d8c6e854 | 3604 | int security_msg_queue_alloc(struct kern_ipc_perm *msq) |
20510f2f | 3605 | { |
ecd5f82e CS |
3606 | int rc = lsm_ipc_alloc(msq); |
3607 | ||
3608 | if (unlikely(rc)) | |
3609 | return rc; | |
3610 | rc = call_int_hook(msg_queue_alloc_security, 0, msq); | |
3611 | if (unlikely(rc)) | |
3612 | security_msg_queue_free(msq); | |
3613 | return rc; | |
20510f2f JM |
3614 | } |
3615 | ||
43fad282 PM |
3616 | /** |
3617 | * security_msg_queue_free() - Free a sysv ipc msg queue LSM blob | |
3618 | * @msq: sysv ipc permission structure | |
3619 | * | |
3620 | * Deallocate security field @perm->security for the message queue. | |
3621 | */ | |
d8c6e854 | 3622 | void security_msg_queue_free(struct kern_ipc_perm *msq) |
20510f2f | 3623 | { |
f25fce3e | 3624 | call_void_hook(msg_queue_free_security, msq); |
ecd5f82e CS |
3625 | kfree(msq->security); |
3626 | msq->security = NULL; | |
20510f2f JM |
3627 | } |
3628 | ||
43fad282 PM |
3629 | /** |
3630 | * security_msg_queue_associate() - Check if a msg queue operation is allowed | |
3631 | * @msq: sysv ipc permission structure | |
3632 | * @msqflg: operation flags | |
3633 | * | |
3634 | * Check permission when a message queue is requested through the msgget system | |
3635 | * call. This hook is only called when returning the message queue identifier | |
3636 | * for an existing message queue, not when a new message queue is created. | |
3637 | * | |
3638 | * Return: Return 0 if permission is granted. | |
3639 | */ | |
d8c6e854 | 3640 | int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg) |
20510f2f | 3641 | { |
f25fce3e | 3642 | return call_int_hook(msg_queue_associate, 0, msq, msqflg); |
20510f2f JM |
3643 | } |
3644 | ||
43fad282 PM |
3645 | /** |
3646 | * security_msg_queue_msgctl() - Check if a msg queue operation is allowed | |
3647 | * @msq: sysv ipc permission structure | |
3648 | * @cmd: operation | |
3649 | * | |
3650 | * Check permission when a message control operation specified by @cmd is to be | |
3651 | * performed on the message queue with permissions. | |
3652 | * | |
3653 | * Return: Returns 0 if permission is granted. | |
3654 | */ | |
d8c6e854 | 3655 | int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd) |
20510f2f | 3656 | { |
f25fce3e | 3657 | return call_int_hook(msg_queue_msgctl, 0, msq, cmd); |
20510f2f JM |
3658 | } |
3659 | ||
43fad282 PM |
3660 | /** |
3661 | * security_msg_queue_msgsnd() - Check if sending a sysv ipc message is allowed | |
3662 | * @msq: sysv ipc permission structure | |
3663 | * @msg: message | |
3664 | * @msqflg: operation flags | |
3665 | * | |
3666 | * Check permission before a message, @msg, is enqueued on the message queue | |
3667 | * with permissions specified in @msq. | |
3668 | * | |
3669 | * Return: Returns 0 if permission is granted. | |
3670 | */ | |
d8c6e854 | 3671 | int security_msg_queue_msgsnd(struct kern_ipc_perm *msq, |
63c1845b | 3672 | struct msg_msg *msg, int msqflg) |
20510f2f | 3673 | { |
f25fce3e | 3674 | return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg); |
20510f2f JM |
3675 | } |
3676 | ||
43fad282 PM |
3677 | /** |
3678 | * security_msg_queue_msgrcv() - Check if receiving a sysv ipc msg is allowed | |
3679 | * @msq: sysv ipc permission structure | |
3680 | * @msg: message | |
3681 | * @target: target task | |
3682 | * @type: type of message requested | |
3683 | * @mode: operation flags | |
3684 | * | |
3685 | * Check permission before a message, @msg, is removed from the message queue. | |
3686 | * The @target task structure contains a pointer to the process that will be | |
3687 | * receiving the message (not equal to the current process when inline receives | |
3688 | * are being performed). | |
3689 | * | |
3690 | * Return: Returns 0 if permission is granted. | |
3691 | */ | |
d8c6e854 | 3692 | int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg, |
63c1845b | 3693 | struct task_struct *target, long type, int mode) |
20510f2f | 3694 | { |
f25fce3e | 3695 | return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode); |
20510f2f JM |
3696 | } |
3697 | ||
43fad282 PM |
3698 | /** |
3699 | * security_shm_alloc() - Allocate a sysv shm LSM blob | |
3700 | * @shp: sysv ipc permission structure | |
3701 | * | |
3702 | * Allocate and attach a security structure to the @shp security field. The | |
3703 | * security field is initialized to NULL when the structure is first created. | |
3704 | * | |
3705 | * Return: Returns 0 if operation was successful and permission is granted. | |
3706 | */ | |
7191adff | 3707 | int security_shm_alloc(struct kern_ipc_perm *shp) |
20510f2f | 3708 | { |
ecd5f82e CS |
3709 | int rc = lsm_ipc_alloc(shp); |
3710 | ||
3711 | if (unlikely(rc)) | |
3712 | return rc; | |
3713 | rc = call_int_hook(shm_alloc_security, 0, shp); | |
3714 | if (unlikely(rc)) | |
3715 | security_shm_free(shp); | |
3716 | return rc; | |
20510f2f JM |
3717 | } |
3718 | ||
43fad282 PM |
3719 | /** |
3720 | * security_shm_free() - Free a sysv shm LSM blob | |
3721 | * @shp: sysv ipc permission structure | |
3722 | * | |
3723 | * Deallocate the security structure @perm->security for the memory segment. | |
3724 | */ | |
7191adff | 3725 | void security_shm_free(struct kern_ipc_perm *shp) |
20510f2f | 3726 | { |
f25fce3e | 3727 | call_void_hook(shm_free_security, shp); |
ecd5f82e CS |
3728 | kfree(shp->security); |
3729 | shp->security = NULL; | |
20510f2f JM |
3730 | } |
3731 | ||
43fad282 PM |
3732 | /** |
3733 | * security_shm_associate() - Check if a sysv shm operation is allowed | |
3734 | * @shp: sysv ipc permission structure | |
3735 | * @shmflg: operation flags | |
3736 | * | |
3737 | * Check permission when a shared memory region is requested through the shmget | |
3738 | * system call. This hook is only called when returning the shared memory | |
3739 | * region identifier for an existing region, not when a new shared memory | |
3740 | * region is created. | |
3741 | * | |
3742 | * Return: Returns 0 if permission is granted. | |
3743 | */ | |
7191adff | 3744 | int security_shm_associate(struct kern_ipc_perm *shp, int shmflg) |
20510f2f | 3745 | { |
f25fce3e | 3746 | return call_int_hook(shm_associate, 0, shp, shmflg); |
20510f2f JM |
3747 | } |
3748 | ||
43fad282 PM |
3749 | /** |
3750 | * security_shm_shmctl() - Check if a sysv shm operation is allowed | |
3751 | * @shp: sysv ipc permission structure | |
3752 | * @cmd: operation | |
3753 | * | |
3754 | * Check permission when a shared memory control operation specified by @cmd is | |
3755 | * to be performed on the shared memory region with permissions in @shp. | |
3756 | * | |
3757 | * Return: Return 0 if permission is granted. | |
3758 | */ | |
7191adff | 3759 | int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd) |
20510f2f | 3760 | { |
f25fce3e | 3761 | return call_int_hook(shm_shmctl, 0, shp, cmd); |
20510f2f JM |
3762 | } |
3763 | ||
43fad282 PM |
3764 | /** |
3765 | * security_shm_shmat() - Check if a sysv shm attach operation is allowed | |
3766 | * @shp: sysv ipc permission structure | |
3767 | * @shmaddr: address of memory region to attach | |
3768 | * @shmflg: operation flags | |
3769 | * | |
3770 | * Check permissions prior to allowing the shmat system call to attach the | |
3771 | * shared memory segment with permissions @shp to the data segment of the | |
3772 | * calling process. The attaching address is specified by @shmaddr. | |
3773 | * | |
3774 | * Return: Returns 0 if permission is granted. | |
3775 | */ | |
63c1845b PM |
3776 | int security_shm_shmat(struct kern_ipc_perm *shp, |
3777 | char __user *shmaddr, int shmflg) | |
20510f2f | 3778 | { |
f25fce3e | 3779 | return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg); |
20510f2f JM |
3780 | } |
3781 | ||
43fad282 PM |
3782 | /** |
3783 | * security_sem_alloc() - Allocate a sysv semaphore LSM blob | |
3784 | * @sma: sysv ipc permission structure | |
3785 | * | |
3786 | * Allocate and attach a security structure to the @sma security field. The | |
3787 | * security field is initialized to NULL when the structure is first created. | |
3788 | * | |
3789 | * Return: Returns 0 if operation was successful and permission is granted. | |
3790 | */ | |
aefad959 | 3791 | int security_sem_alloc(struct kern_ipc_perm *sma) |
20510f2f | 3792 | { |
ecd5f82e CS |
3793 | int rc = lsm_ipc_alloc(sma); |
3794 | ||
3795 | if (unlikely(rc)) | |
3796 | return rc; | |
3797 | rc = call_int_hook(sem_alloc_security, 0, sma); | |
3798 | if (unlikely(rc)) | |
3799 | security_sem_free(sma); | |
3800 | return rc; | |
20510f2f JM |
3801 | } |
3802 | ||
43fad282 PM |
3803 | /** |
3804 | * security_sem_free() - Free a sysv semaphore LSM blob | |
3805 | * @sma: sysv ipc permission structure | |
3806 | * | |
3807 | * Deallocate security structure @sma->security for the semaphore. | |
3808 | */ | |
aefad959 | 3809 | void security_sem_free(struct kern_ipc_perm *sma) |
20510f2f | 3810 | { |
f25fce3e | 3811 | call_void_hook(sem_free_security, sma); |
ecd5f82e CS |
3812 | kfree(sma->security); |
3813 | sma->security = NULL; | |
20510f2f JM |
3814 | } |
3815 | ||
43fad282 PM |
3816 | /** |
3817 | * security_sem_associate() - Check if a sysv semaphore operation is allowed | |
3818 | * @sma: sysv ipc permission structure | |
3819 | * @semflg: operation flags | |
3820 | * | |
3821 | * Check permission when a semaphore is requested through the semget system | |
3822 | * call. This hook is only called when returning the semaphore identifier for | |
3823 | * an existing semaphore, not when a new one must be created. | |
3824 | * | |
3825 | * Return: Returns 0 if permission is granted. | |
3826 | */ | |
aefad959 | 3827 | int security_sem_associate(struct kern_ipc_perm *sma, int semflg) |
20510f2f | 3828 | { |
f25fce3e | 3829 | return call_int_hook(sem_associate, 0, sma, semflg); |
20510f2f JM |
3830 | } |
3831 | ||
43fad282 | 3832 | /** |
1e2523d7 | 3833 | * security_sem_semctl() - Check if a sysv semaphore operation is allowed |
43fad282 PM |
3834 | * @sma: sysv ipc permission structure |
3835 | * @cmd: operation | |
3836 | * | |
3837 | * Check permission when a semaphore operation specified by @cmd is to be | |
3838 | * performed on the semaphore. | |
3839 | * | |
3840 | * Return: Returns 0 if permission is granted. | |
3841 | */ | |
aefad959 | 3842 | int security_sem_semctl(struct kern_ipc_perm *sma, int cmd) |
20510f2f | 3843 | { |
f25fce3e | 3844 | return call_int_hook(sem_semctl, 0, sma, cmd); |
20510f2f JM |
3845 | } |
3846 | ||
43fad282 PM |
3847 | /** |
3848 | * security_sem_semop() - Check if a sysv semaphore operation is allowed | |
3849 | * @sma: sysv ipc permission structure | |
3850 | * @sops: operations to perform | |
3851 | * @nsops: number of operations | |
3852 | * @alter: flag indicating changes will be made | |
3853 | * | |
3854 | * Check permissions before performing operations on members of the semaphore | |
3855 | * set. If the @alter flag is nonzero, the semaphore set may be modified. | |
3856 | * | |
3857 | * Return: Returns 0 if permission is granted. | |
3858 | */ | |
aefad959 | 3859 | int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, |
63c1845b | 3860 | unsigned nsops, int alter) |
20510f2f | 3861 | { |
f25fce3e | 3862 | return call_int_hook(sem_semop, 0, sma, sops, nsops, alter); |
20510f2f JM |
3863 | } |
3864 | ||
916e3258 PM |
3865 | /** |
3866 | * security_d_instantiate() - Populate an inode's LSM state based on a dentry | |
3867 | * @dentry: dentry | |
3868 | * @inode: inode | |
3869 | * | |
3870 | * Fill in @inode security information for a @dentry if allowed. | |
3871 | */ | |
20510f2f JM |
3872 | void security_d_instantiate(struct dentry *dentry, struct inode *inode) |
3873 | { | |
3874 | if (unlikely(inode && IS_PRIVATE(inode))) | |
3875 | return; | |
f25fce3e | 3876 | call_void_hook(d_instantiate, dentry, inode); |
20510f2f JM |
3877 | } |
3878 | EXPORT_SYMBOL(security_d_instantiate); | |
3879 | ||
a04a1198 CS |
3880 | /* |
3881 | * Please keep this in sync with it's counterpart in security/lsm_syscalls.c | |
3882 | */ | |
3883 | ||
3884 | /** | |
3885 | * security_getselfattr - Read an LSM attribute of the current process. | |
3886 | * @attr: which attribute to return | |
3887 | * @uctx: the user-space destination for the information, or NULL | |
3888 | * @size: pointer to the size of space available to receive the data | |
3889 | * @flags: special handling options. LSM_FLAG_SINGLE indicates that only | |
3890 | * attributes associated with the LSM identified in the passed @ctx be | |
3891 | * reported. | |
3892 | * | |
3893 | * A NULL value for @uctx can be used to get both the number of attributes | |
3894 | * and the size of the data. | |
3895 | * | |
3896 | * Returns the number of attributes found on success, negative value | |
3897 | * on error. @size is reset to the total size of the data. | |
3898 | * If @size is insufficient to contain the data -E2BIG is returned. | |
3899 | */ | |
3900 | int security_getselfattr(unsigned int attr, struct lsm_ctx __user *uctx, | |
3901 | size_t __user *size, u32 flags) | |
3902 | { | |
3903 | struct security_hook_list *hp; | |
3904 | struct lsm_ctx lctx = { .id = LSM_ID_UNDEF, }; | |
3905 | u8 __user *base = (u8 __user *)uctx; | |
3906 | size_t total = 0; | |
3907 | size_t entrysize; | |
3908 | size_t left; | |
3909 | bool toobig = false; | |
3910 | bool single = false; | |
3911 | int count = 0; | |
3912 | int rc; | |
3913 | ||
3914 | if (attr == LSM_ATTR_UNDEF) | |
3915 | return -EINVAL; | |
3916 | if (size == NULL) | |
3917 | return -EINVAL; | |
3918 | if (get_user(left, size)) | |
3919 | return -EFAULT; | |
3920 | ||
3921 | if (flags) { | |
3922 | /* | |
3923 | * Only flag supported is LSM_FLAG_SINGLE | |
3924 | */ | |
3925 | if (flags != LSM_FLAG_SINGLE) | |
3926 | return -EINVAL; | |
3927 | if (uctx && copy_from_user(&lctx, uctx, sizeof(lctx))) | |
3928 | return -EFAULT; | |
3929 | /* | |
3930 | * If the LSM ID isn't specified it is an error. | |
3931 | */ | |
3932 | if (lctx.id == LSM_ID_UNDEF) | |
3933 | return -EINVAL; | |
3934 | single = true; | |
3935 | } | |
3936 | ||
3937 | /* | |
3938 | * In the usual case gather all the data from the LSMs. | |
3939 | * In the single case only get the data from the LSM specified. | |
3940 | */ | |
3941 | hlist_for_each_entry(hp, &security_hook_heads.getselfattr, list) { | |
3942 | if (single && lctx.id != hp->lsmid->id) | |
3943 | continue; | |
3944 | entrysize = left; | |
3945 | if (base) | |
3946 | uctx = (struct lsm_ctx __user *)(base + total); | |
3947 | rc = hp->hook.getselfattr(attr, uctx, &entrysize, flags); | |
3948 | if (rc == -EOPNOTSUPP) { | |
3949 | rc = 0; | |
3950 | continue; | |
3951 | } | |
3952 | if (rc == -E2BIG) { | |
3953 | toobig = true; | |
3954 | left = 0; | |
3955 | } else if (rc < 0) | |
3956 | return rc; | |
3957 | else | |
3958 | left -= entrysize; | |
3959 | ||
3960 | total += entrysize; | |
3961 | count += rc; | |
3962 | if (single) | |
3963 | break; | |
3964 | } | |
3965 | if (put_user(total, size)) | |
3966 | return -EFAULT; | |
3967 | if (toobig) | |
3968 | return -E2BIG; | |
3969 | if (count == 0) | |
3970 | return LSM_RET_DEFAULT(getselfattr); | |
3971 | return count; | |
3972 | } | |
3973 | ||
3974 | /* | |
3975 | * Please keep this in sync with it's counterpart in security/lsm_syscalls.c | |
3976 | */ | |
3977 | ||
3978 | /** | |
3979 | * security_setselfattr - Set an LSM attribute on the current process. | |
3980 | * @attr: which attribute to set | |
3981 | * @uctx: the user-space source for the information | |
3982 | * @size: the size of the data | |
3983 | * @flags: reserved for future use, must be 0 | |
3984 | * | |
3985 | * Set an LSM attribute for the current process. The LSM, attribute | |
3986 | * and new value are included in @uctx. | |
3987 | * | |
3988 | * Returns 0 on success, -EINVAL if the input is inconsistent, -EFAULT | |
3989 | * if the user buffer is inaccessible, E2BIG if size is too big, or an | |
3990 | * LSM specific failure. | |
3991 | */ | |
3992 | int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx, | |
3993 | size_t size, u32 flags) | |
3994 | { | |
3995 | struct security_hook_list *hp; | |
3996 | struct lsm_ctx *lctx; | |
3997 | int rc = LSM_RET_DEFAULT(setselfattr); | |
3998 | ||
3999 | if (flags) | |
4000 | return -EINVAL; | |
4001 | if (size < sizeof(*lctx)) | |
4002 | return -EINVAL; | |
4003 | if (size > PAGE_SIZE) | |
4004 | return -E2BIG; | |
4005 | ||
4006 | lctx = kmalloc(size, GFP_KERNEL); | |
4007 | if (lctx == NULL) | |
4008 | return -ENOMEM; | |
4009 | ||
4010 | if (copy_from_user(lctx, uctx, size)) { | |
4011 | rc = -EFAULT; | |
4012 | goto free_out; | |
4013 | } | |
4014 | ||
4015 | if (size < lctx->len || size < lctx->ctx_len + sizeof(*lctx) || | |
4016 | lctx->len < lctx->ctx_len + sizeof(*lctx)) { | |
4017 | rc = -EINVAL; | |
4018 | goto free_out; | |
4019 | } | |
4020 | ||
4021 | hlist_for_each_entry(hp, &security_hook_heads.setselfattr, list) | |
4022 | if ((hp->lsmid->id) == lctx->id) { | |
4023 | rc = hp->hook.setselfattr(attr, lctx, size, flags); | |
4024 | break; | |
4025 | } | |
4026 | ||
4027 | free_out: | |
4028 | kfree(lctx); | |
4029 | return rc; | |
4030 | } | |
4031 | ||
916e3258 PM |
4032 | /** |
4033 | * security_getprocattr() - Read an attribute for a task | |
4034 | * @p: the task | |
267c068e | 4035 | * @lsmid: LSM identification |
916e3258 PM |
4036 | * @name: attribute name |
4037 | * @value: attribute value | |
4038 | * | |
4039 | * Read attribute @name for task @p and store it into @value if allowed. | |
4040 | * | |
4041 | * Return: Returns the length of @value on success, a negative value otherwise. | |
4042 | */ | |
267c068e CS |
4043 | int security_getprocattr(struct task_struct *p, int lsmid, const char *name, |
4044 | char **value) | |
20510f2f | 4045 | { |
6d9c939d CS |
4046 | struct security_hook_list *hp; |
4047 | ||
4048 | hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { | |
267c068e | 4049 | if (lsmid != 0 && lsmid != hp->lsmid->id) |
6d9c939d CS |
4050 | continue; |
4051 | return hp->hook.getprocattr(p, name, value); | |
4052 | } | |
98e828a0 | 4053 | return LSM_RET_DEFAULT(getprocattr); |
20510f2f JM |
4054 | } |
4055 | ||
916e3258 PM |
4056 | /** |
4057 | * security_setprocattr() - Set an attribute for a task | |
267c068e | 4058 | * @lsmid: LSM identification |
916e3258 PM |
4059 | * @name: attribute name |
4060 | * @value: attribute value | |
4061 | * @size: attribute value size | |
4062 | * | |
4063 | * Write (set) the current task's attribute @name to @value, size @size if | |
4064 | * allowed. | |
4065 | * | |
4066 | * Return: Returns bytes written on success, a negative value otherwise. | |
4067 | */ | |
267c068e | 4068 | int security_setprocattr(int lsmid, const char *name, void *value, size_t size) |
20510f2f | 4069 | { |
6d9c939d CS |
4070 | struct security_hook_list *hp; |
4071 | ||
4072 | hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) { | |
267c068e | 4073 | if (lsmid != 0 && lsmid != hp->lsmid->id) |
6d9c939d CS |
4074 | continue; |
4075 | return hp->hook.setprocattr(name, value, size); | |
4076 | } | |
98e828a0 | 4077 | return LSM_RET_DEFAULT(setprocattr); |
20510f2f JM |
4078 | } |
4079 | ||
2bcf51bf PM |
4080 | /** |
4081 | * security_netlink_send() - Save info and check if netlink sending is allowed | |
4082 | * @sk: sending socket | |
4083 | * @skb: netlink message | |
4084 | * | |
4085 | * Save security information for a netlink message so that permission checking | |
4086 | * can be performed when the message is processed. The security information | |
4087 | * can be saved using the eff_cap field of the netlink_skb_parms structure. | |
4088 | * Also may be used to provide fine grained control over message transmission. | |
4089 | * | |
4090 | * Return: Returns 0 if the information was successfully saved and message is | |
4091 | * allowed to be transmitted. | |
4092 | */ | |
20510f2f JM |
4093 | int security_netlink_send(struct sock *sk, struct sk_buff *skb) |
4094 | { | |
f25fce3e | 4095 | return call_int_hook(netlink_send, 0, sk, skb); |
20510f2f | 4096 | } |
20510f2f | 4097 | |
e261301c PM |
4098 | /** |
4099 | * security_ismaclabel() - Check is the named attribute is a MAC label | |
4100 | * @name: full extended attribute name | |
4101 | * | |
4102 | * Check if the extended attribute specified by @name represents a MAC label. | |
4103 | * | |
4104 | * Return: Returns 1 if name is a MAC attribute otherwise returns 0. | |
4105 | */ | |
746df9b5 DQ |
4106 | int security_ismaclabel(const char *name) |
4107 | { | |
f25fce3e | 4108 | return call_int_hook(ismaclabel, 0, name); |
746df9b5 DQ |
4109 | } |
4110 | EXPORT_SYMBOL(security_ismaclabel); | |
4111 | ||
e261301c PM |
4112 | /** |
4113 | * security_secid_to_secctx() - Convert a secid to a secctx | |
4114 | * @secid: secid | |
4115 | * @secdata: secctx | |
4116 | * @seclen: secctx length | |
4117 | * | |
4118 | * Convert secid to security context. If @secdata is NULL the length of the | |
4119 | * result will be returned in @seclen, but no @secdata will be returned. This | |
4120 | * does mean that the length could change between calls to check the length and | |
4121 | * the next call which actually allocates and returns the @secdata. | |
4122 | * | |
4123 | * Return: Return 0 on success, error on failure. | |
4124 | */ | |
20510f2f JM |
4125 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) |
4126 | { | |
0550cfe8 KS |
4127 | struct security_hook_list *hp; |
4128 | int rc; | |
4129 | ||
4130 | /* | |
4131 | * Currently, only one LSM can implement secid_to_secctx (i.e this | |
4132 | * LSM hook is not "stackable"). | |
4133 | */ | |
4134 | hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) { | |
4135 | rc = hp->hook.secid_to_secctx(secid, secdata, seclen); | |
4136 | if (rc != LSM_RET_DEFAULT(secid_to_secctx)) | |
4137 | return rc; | |
4138 | } | |
4139 | ||
4140 | return LSM_RET_DEFAULT(secid_to_secctx); | |
20510f2f JM |
4141 | } |
4142 | EXPORT_SYMBOL(security_secid_to_secctx); | |
4143 | ||
e261301c PM |
4144 | /** |
4145 | * security_secctx_to_secid() - Convert a secctx to a secid | |
4146 | * @secdata: secctx | |
4147 | * @seclen: length of secctx | |
4148 | * @secid: secid | |
4149 | * | |
4150 | * Convert security context to secid. | |
4151 | * | |
4152 | * Return: Returns 0 on success, error on failure. | |
4153 | */ | |
7bf570dc | 4154 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) |
63cb3449 | 4155 | { |
b1d9e6b0 | 4156 | *secid = 0; |
f25fce3e | 4157 | return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid); |
63cb3449 DH |
4158 | } |
4159 | EXPORT_SYMBOL(security_secctx_to_secid); | |
4160 | ||
e261301c PM |
4161 | /** |
4162 | * security_release_secctx() - Free a secctx buffer | |
4163 | * @secdata: secctx | |
4164 | * @seclen: length of secctx | |
4165 | * | |
4166 | * Release the security context. | |
4167 | */ | |
20510f2f JM |
4168 | void security_release_secctx(char *secdata, u32 seclen) |
4169 | { | |
f25fce3e | 4170 | call_void_hook(release_secctx, secdata, seclen); |
20510f2f JM |
4171 | } |
4172 | EXPORT_SYMBOL(security_release_secctx); | |
4173 | ||
e261301c PM |
4174 | /** |
4175 | * security_inode_invalidate_secctx() - Invalidate an inode's security label | |
4176 | * @inode: inode | |
4177 | * | |
4178 | * Notify the security module that it must revalidate the security context of | |
4179 | * an inode. | |
4180 | */ | |
6f3be9f5 AG |
4181 | void security_inode_invalidate_secctx(struct inode *inode) |
4182 | { | |
4183 | call_void_hook(inode_invalidate_secctx, inode); | |
4184 | } | |
4185 | EXPORT_SYMBOL(security_inode_invalidate_secctx); | |
4186 | ||
e261301c | 4187 | /** |
e5085606 | 4188 | * security_inode_notifysecctx() - Notify the LSM of an inode's security label |
e261301c PM |
4189 | * @inode: inode |
4190 | * @ctx: secctx | |
4191 | * @ctxlen: length of secctx | |
4192 | * | |
4193 | * Notify the security module of what the security context of an inode should | |
4194 | * be. Initializes the incore security context managed by the security module | |
4195 | * for this inode. Example usage: NFS client invokes this hook to initialize | |
4196 | * the security context in its incore inode to the value provided by the server | |
4197 | * for the file when the server returned the file's attributes to the client. | |
4198 | * Must be called with inode->i_mutex locked. | |
4199 | * | |
4200 | * Return: Returns 0 on success, error on failure. | |
4201 | */ | |
1ee65e37 DQ |
4202 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) |
4203 | { | |
f25fce3e | 4204 | return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); |
1ee65e37 DQ |
4205 | } |
4206 | EXPORT_SYMBOL(security_inode_notifysecctx); | |
4207 | ||
e261301c PM |
4208 | /** |
4209 | * security_inode_setsecctx() - Change the security label of an inode | |
4210 | * @dentry: inode | |
4211 | * @ctx: secctx | |
4212 | * @ctxlen: length of secctx | |
4213 | * | |
4214 | * Change the security context of an inode. Updates the incore security | |
4215 | * context managed by the security module and invokes the fs code as needed | |
4216 | * (via __vfs_setxattr_noperm) to update any backing xattrs that represent the | |
4217 | * context. Example usage: NFS server invokes this hook to change the security | |
4218 | * context in its incore inode and on the backing filesystem to a value | |
4219 | * provided by the client on a SETATTR operation. Must be called with | |
4220 | * inode->i_mutex locked. | |
4221 | * | |
4222 | * Return: Returns 0 on success, error on failure. | |
4223 | */ | |
1ee65e37 DQ |
4224 | int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) |
4225 | { | |
f25fce3e | 4226 | return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen); |
1ee65e37 DQ |
4227 | } |
4228 | EXPORT_SYMBOL(security_inode_setsecctx); | |
4229 | ||
e261301c PM |
4230 | /** |
4231 | * security_inode_getsecctx() - Get the security label of an inode | |
4232 | * @inode: inode | |
4233 | * @ctx: secctx | |
4234 | * @ctxlen: length of secctx | |
4235 | * | |
4236 | * On success, returns 0 and fills out @ctx and @ctxlen with the security | |
4237 | * context for the given @inode. | |
4238 | * | |
4239 | * Return: Returns 0 on success, error on failure. | |
4240 | */ | |
1ee65e37 DQ |
4241 | int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) |
4242 | { | |
b1d9e6b0 | 4243 | return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); |
1ee65e37 DQ |
4244 | } |
4245 | EXPORT_SYMBOL(security_inode_getsecctx); | |
4246 | ||
344fa64e | 4247 | #ifdef CONFIG_WATCH_QUEUE |
e261301c PM |
4248 | /** |
4249 | * security_post_notification() - Check if a watch notification can be posted | |
4250 | * @w_cred: credentials of the task that set the watch | |
4251 | * @cred: credentials of the task which triggered the watch | |
4252 | * @n: the notification | |
4253 | * | |
4254 | * Check to see if a watch notification can be posted to a particular queue. | |
4255 | * | |
4256 | * Return: Returns 0 if permission is granted. | |
4257 | */ | |
344fa64e DH |
4258 | int security_post_notification(const struct cred *w_cred, |
4259 | const struct cred *cred, | |
4260 | struct watch_notification *n) | |
4261 | { | |
4262 | return call_int_hook(post_notification, 0, w_cred, cred, n); | |
4263 | } | |
4264 | #endif /* CONFIG_WATCH_QUEUE */ | |
4265 | ||
998f5040 | 4266 | #ifdef CONFIG_KEY_NOTIFICATIONS |
e261301c PM |
4267 | /** |
4268 | * security_watch_key() - Check if a task is allowed to watch for key events | |
4269 | * @key: the key to watch | |
4270 | * | |
4271 | * Check to see if a process is allowed to watch for event notifications from | |
4272 | * a key or keyring. | |
4273 | * | |
4274 | * Return: Returns 0 if permission is granted. | |
4275 | */ | |
998f5040 DH |
4276 | int security_watch_key(struct key *key) |
4277 | { | |
4278 | return call_int_hook(watch_key, 0, key); | |
4279 | } | |
63c1845b | 4280 | #endif /* CONFIG_KEY_NOTIFICATIONS */ |
998f5040 | 4281 | |
20510f2f | 4282 | #ifdef CONFIG_SECURITY_NETWORK |
2c2442fd PM |
4283 | /** |
4284 | * security_unix_stream_connect() - Check if a AF_UNIX stream is allowed | |
4285 | * @sock: originating sock | |
4286 | * @other: peer sock | |
4287 | * @newsk: new sock | |
4288 | * | |
4289 | * Check permissions before establishing a Unix domain stream connection | |
4290 | * between @sock and @other. | |
4291 | * | |
4292 | * The @unix_stream_connect and @unix_may_send hooks were necessary because | |
4293 | * Linux provides an alternative to the conventional file name space for Unix | |
4294 | * domain sockets. Whereas binding and connecting to sockets in the file name | |
4295 | * space is mediated by the typical file permissions (and caught by the mknod | |
4296 | * and permission hooks in inode_security_ops), binding and connecting to | |
4297 | * sockets in the abstract name space is completely unmediated. Sufficient | |
4298 | * control of Unix domain sockets in the abstract name space isn't possible | |
4299 | * using only the socket layer hooks, since we need to know the actual target | |
4300 | * socket, which is not looked up until we are inside the af_unix code. | |
4301 | * | |
4302 | * Return: Returns 0 if permission is granted. | |
4303 | */ | |
63c1845b PM |
4304 | int security_unix_stream_connect(struct sock *sock, struct sock *other, |
4305 | struct sock *newsk) | |
20510f2f | 4306 | { |
f25fce3e | 4307 | return call_int_hook(unix_stream_connect, 0, sock, other, newsk); |
20510f2f JM |
4308 | } |
4309 | EXPORT_SYMBOL(security_unix_stream_connect); | |
4310 | ||
2c2442fd PM |
4311 | /** |
4312 | * security_unix_may_send() - Check if AF_UNIX socket can send datagrams | |
4313 | * @sock: originating sock | |
4314 | * @other: peer sock | |
4315 | * | |
4316 | * Check permissions before connecting or sending datagrams from @sock to | |
4317 | * @other. | |
4318 | * | |
4319 | * The @unix_stream_connect and @unix_may_send hooks were necessary because | |
4320 | * Linux provides an alternative to the conventional file name space for Unix | |
4321 | * domain sockets. Whereas binding and connecting to sockets in the file name | |
4322 | * space is mediated by the typical file permissions (and caught by the mknod | |
4323 | * and permission hooks in inode_security_ops), binding and connecting to | |
4324 | * sockets in the abstract name space is completely unmediated. Sufficient | |
4325 | * control of Unix domain sockets in the abstract name space isn't possible | |
4326 | * using only the socket layer hooks, since we need to know the actual target | |
4327 | * socket, which is not looked up until we are inside the af_unix code. | |
4328 | * | |
4329 | * Return: Returns 0 if permission is granted. | |
4330 | */ | |
20510f2f JM |
4331 | int security_unix_may_send(struct socket *sock, struct socket *other) |
4332 | { | |
f25fce3e | 4333 | return call_int_hook(unix_may_send, 0, sock, other); |
20510f2f JM |
4334 | } |
4335 | EXPORT_SYMBOL(security_unix_may_send); | |
4336 | ||
6b6bbe8c PM |
4337 | /** |
4338 | * security_socket_create() - Check if creating a new socket is allowed | |
4339 | * @family: protocol family | |
4340 | * @type: communications type | |
4341 | * @protocol: requested protocol | |
4342 | * @kern: set to 1 if a kernel socket is requested | |
4343 | * | |
4344 | * Check permissions prior to creating a new socket. | |
4345 | * | |
4346 | * Return: Returns 0 if permission is granted. | |
4347 | */ | |
20510f2f JM |
4348 | int security_socket_create(int family, int type, int protocol, int kern) |
4349 | { | |
f25fce3e | 4350 | return call_int_hook(socket_create, 0, family, type, protocol, kern); |
20510f2f JM |
4351 | } |
4352 | ||
6b6bbe8c | 4353 | /** |
1e2523d7 | 4354 | * security_socket_post_create() - Initialize a newly created socket |
6b6bbe8c PM |
4355 | * @sock: socket |
4356 | * @family: protocol family | |
4357 | * @type: communications type | |
4358 | * @protocol: requested protocol | |
4359 | * @kern: set to 1 if a kernel socket is requested | |
4360 | * | |
4361 | * This hook allows a module to update or allocate a per-socket security | |
4362 | * structure. Note that the security field was not added directly to the socket | |
4363 | * structure, but rather, the socket security information is stored in the | |
4364 | * associated inode. Typically, the inode alloc_security hook will allocate | |
4365 | * and attach security information to SOCK_INODE(sock)->i_security. This hook | |
4366 | * may be used to update the SOCK_INODE(sock)->i_security field with additional | |
4367 | * information that wasn't available when the inode was allocated. | |
4368 | * | |
4369 | * Return: Returns 0 if permission is granted. | |
4370 | */ | |
20510f2f JM |
4371 | int security_socket_post_create(struct socket *sock, int family, |
4372 | int type, int protocol, int kern) | |
4373 | { | |
f25fce3e | 4374 | return call_int_hook(socket_post_create, 0, sock, family, type, |
63c1845b | 4375 | protocol, kern); |
20510f2f JM |
4376 | } |
4377 | ||
6b6bbe8c PM |
4378 | /** |
4379 | * security_socket_socketpair() - Check if creating a socketpair is allowed | |
4380 | * @socka: first socket | |
4381 | * @sockb: second socket | |
4382 | * | |
4383 | * Check permissions before creating a fresh pair of sockets. | |
4384 | * | |
4385 | * Return: Returns 0 if permission is granted and the connection was | |
4386 | * established. | |
4387 | */ | |
aae7cfcb DH |
4388 | int security_socket_socketpair(struct socket *socka, struct socket *sockb) |
4389 | { | |
4390 | return call_int_hook(socket_socketpair, 0, socka, sockb); | |
4391 | } | |
4392 | EXPORT_SYMBOL(security_socket_socketpair); | |
4393 | ||
6b6bbe8c PM |
4394 | /** |
4395 | * security_socket_bind() - Check if a socket bind operation is allowed | |
4396 | * @sock: socket | |
4397 | * @address: requested bind address | |
4398 | * @addrlen: length of address | |
4399 | * | |
4400 | * Check permission before socket protocol layer bind operation is performed | |
4401 | * and the socket @sock is bound to the address specified in the @address | |
4402 | * parameter. | |
4403 | * | |
4404 | * Return: Returns 0 if permission is granted. | |
4405 | */ | |
63c1845b PM |
4406 | int security_socket_bind(struct socket *sock, |
4407 | struct sockaddr *address, int addrlen) | |
20510f2f | 4408 | { |
f25fce3e | 4409 | return call_int_hook(socket_bind, 0, sock, address, addrlen); |
20510f2f JM |
4410 | } |
4411 | ||
6b6bbe8c PM |
4412 | /** |
4413 | * security_socket_connect() - Check if a socket connect operation is allowed | |
4414 | * @sock: socket | |
4415 | * @address: address of remote connection point | |
4416 | * @addrlen: length of address | |
4417 | * | |
4418 | * Check permission before socket protocol layer connect operation attempts to | |
4419 | * connect socket @sock to a remote address, @address. | |
4420 | * | |
4421 | * Return: Returns 0 if permission is granted. | |
4422 | */ | |
63c1845b PM |
4423 | int security_socket_connect(struct socket *sock, |
4424 | struct sockaddr *address, int addrlen) | |
20510f2f | 4425 | { |
f25fce3e | 4426 | return call_int_hook(socket_connect, 0, sock, address, addrlen); |
20510f2f JM |
4427 | } |
4428 | ||
6b6bbe8c PM |
4429 | /** |
4430 | * security_socket_listen() - Check if a socket is allowed to listen | |
4431 | * @sock: socket | |
4432 | * @backlog: connection queue size | |
4433 | * | |
4434 | * Check permission before socket protocol layer listen operation. | |
4435 | * | |
4436 | * Return: Returns 0 if permission is granted. | |
4437 | */ | |
20510f2f JM |
4438 | int security_socket_listen(struct socket *sock, int backlog) |
4439 | { | |
f25fce3e | 4440 | return call_int_hook(socket_listen, 0, sock, backlog); |
20510f2f JM |
4441 | } |
4442 | ||
6b6bbe8c PM |
4443 | /** |
4444 | * security_socket_accept() - Check if a socket is allowed to accept connections | |
4445 | * @sock: listening socket | |
4446 | * @newsock: newly creation connection socket | |
4447 | * | |
4448 | * Check permission before accepting a new connection. Note that the new | |
4449 | * socket, @newsock, has been created and some information copied to it, but | |
4450 | * the accept operation has not actually been performed. | |
4451 | * | |
4452 | * Return: Returns 0 if permission is granted. | |
4453 | */ | |
20510f2f JM |
4454 | int security_socket_accept(struct socket *sock, struct socket *newsock) |
4455 | { | |
f25fce3e | 4456 | return call_int_hook(socket_accept, 0, sock, newsock); |
20510f2f JM |
4457 | } |
4458 | ||
6b6bbe8c PM |
4459 | /** |
4460 | * security_socket_sendmsg() - Check is sending a message is allowed | |
4461 | * @sock: sending socket | |
4462 | * @msg: message to send | |
4463 | * @size: size of message | |
4464 | * | |
4465 | * Check permission before transmitting a message to another socket. | |
4466 | * | |
4467 | * Return: Returns 0 if permission is granted. | |
4468 | */ | |
20510f2f JM |
4469 | int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size) |
4470 | { | |
f25fce3e | 4471 | return call_int_hook(socket_sendmsg, 0, sock, msg, size); |
20510f2f JM |
4472 | } |
4473 | ||
6b6bbe8c PM |
4474 | /** |
4475 | * security_socket_recvmsg() - Check if receiving a message is allowed | |
4476 | * @sock: receiving socket | |
4477 | * @msg: message to receive | |
4478 | * @size: size of message | |
4479 | * @flags: operational flags | |
4480 | * | |
4481 | * Check permission before receiving a message from a socket. | |
4482 | * | |
4483 | * Return: Returns 0 if permission is granted. | |
4484 | */ | |
20510f2f JM |
4485 | int security_socket_recvmsg(struct socket *sock, struct msghdr *msg, |
4486 | int size, int flags) | |
4487 | { | |
f25fce3e | 4488 | return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags); |
20510f2f JM |
4489 | } |
4490 | ||
6b6bbe8c PM |
4491 | /** |
4492 | * security_socket_getsockname() - Check if reading the socket addr is allowed | |
4493 | * @sock: socket | |
4494 | * | |
4495 | * Check permission before reading the local address (name) of the socket | |
4496 | * object. | |
4497 | * | |
4498 | * Return: Returns 0 if permission is granted. | |
4499 | */ | |
20510f2f JM |
4500 | int security_socket_getsockname(struct socket *sock) |
4501 | { | |
f25fce3e | 4502 | return call_int_hook(socket_getsockname, 0, sock); |
20510f2f JM |
4503 | } |
4504 | ||
6b6bbe8c PM |
4505 | /** |
4506 | * security_socket_getpeername() - Check if reading the peer's addr is allowed | |
4507 | * @sock: socket | |
4508 | * | |
4509 | * Check permission before the remote address (name) of a socket object. | |
4510 | * | |
4511 | * Return: Returns 0 if permission is granted. | |
4512 | */ | |
20510f2f JM |
4513 | int security_socket_getpeername(struct socket *sock) |
4514 | { | |
f25fce3e | 4515 | return call_int_hook(socket_getpeername, 0, sock); |
20510f2f JM |
4516 | } |
4517 | ||
6b6bbe8c PM |
4518 | /** |
4519 | * security_socket_getsockopt() - Check if reading a socket option is allowed | |
4520 | * @sock: socket | |
4521 | * @level: option's protocol level | |
4522 | * @optname: option name | |
4523 | * | |
4524 | * Check permissions before retrieving the options associated with socket | |
4525 | * @sock. | |
4526 | * | |
4527 | * Return: Returns 0 if permission is granted. | |
4528 | */ | |
20510f2f JM |
4529 | int security_socket_getsockopt(struct socket *sock, int level, int optname) |
4530 | { | |
f25fce3e | 4531 | return call_int_hook(socket_getsockopt, 0, sock, level, optname); |
20510f2f JM |
4532 | } |
4533 | ||
6b6bbe8c PM |
4534 | /** |
4535 | * security_socket_setsockopt() - Check if setting a socket option is allowed | |
4536 | * @sock: socket | |
4537 | * @level: option's protocol level | |
4538 | * @optname: option name | |
4539 | * | |
4540 | * Check permissions before setting the options associated with socket @sock. | |
4541 | * | |
4542 | * Return: Returns 0 if permission is granted. | |
4543 | */ | |
20510f2f JM |
4544 | int security_socket_setsockopt(struct socket *sock, int level, int optname) |
4545 | { | |
f25fce3e | 4546 | return call_int_hook(socket_setsockopt, 0, sock, level, optname); |
20510f2f JM |
4547 | } |
4548 | ||
6b6bbe8c PM |
4549 | /** |
4550 | * security_socket_shutdown() - Checks if shutting down the socket is allowed | |
4551 | * @sock: socket | |
4552 | * @how: flag indicating how sends and receives are handled | |
4553 | * | |
4554 | * Checks permission before all or part of a connection on the socket @sock is | |
4555 | * shut down. | |
4556 | * | |
4557 | * Return: Returns 0 if permission is granted. | |
4558 | */ | |
20510f2f JM |
4559 | int security_socket_shutdown(struct socket *sock, int how) |
4560 | { | |
f25fce3e | 4561 | return call_int_hook(socket_shutdown, 0, sock, how); |
20510f2f JM |
4562 | } |
4563 | ||
6b6bbe8c PM |
4564 | /** |
4565 | * security_sock_rcv_skb() - Check if an incoming network packet is allowed | |
4566 | * @sk: destination sock | |
4567 | * @skb: incoming packet | |
4568 | * | |
4569 | * Check permissions on incoming network packets. This hook is distinct from | |
4570 | * Netfilter's IP input hooks since it is the first time that the incoming | |
4571 | * sk_buff @skb has been associated with a particular socket, @sk. Must not | |
4572 | * sleep inside this hook because some callers hold spinlocks. | |
4573 | * | |
4574 | * Return: Returns 0 if permission is granted. | |
4575 | */ | |
20510f2f JM |
4576 | int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) |
4577 | { | |
f25fce3e | 4578 | return call_int_hook(socket_sock_rcv_skb, 0, sk, skb); |
20510f2f JM |
4579 | } |
4580 | EXPORT_SYMBOL(security_sock_rcv_skb); | |
4581 | ||
6b6bbe8c PM |
4582 | /** |
4583 | * security_socket_getpeersec_stream() - Get the remote peer label | |
4584 | * @sock: socket | |
4585 | * @optval: destination buffer | |
4586 | * @optlen: size of peer label copied into the buffer | |
4587 | * @len: maximum size of the destination buffer | |
4588 | * | |
4589 | * This hook allows the security module to provide peer socket security state | |
4590 | * for unix or connected tcp sockets to userspace via getsockopt SO_GETPEERSEC. | |
4591 | * For tcp sockets this can be meaningful if the socket is associated with an | |
4592 | * ipsec SA. | |
4593 | * | |
4594 | * Return: Returns 0 if all is well, otherwise, typical getsockopt return | |
4595 | * values. | |
4596 | */ | |
b10b9c34 PM |
4597 | int security_socket_getpeersec_stream(struct socket *sock, sockptr_t optval, |
4598 | sockptr_t optlen, unsigned int len) | |
20510f2f | 4599 | { |
b1d9e6b0 | 4600 | return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock, |
b10b9c34 | 4601 | optval, optlen, len); |
20510f2f JM |
4602 | } |
4603 | ||
6b6bbe8c PM |
4604 | /** |
4605 | * security_socket_getpeersec_dgram() - Get the remote peer label | |
4606 | * @sock: socket | |
4607 | * @skb: datagram packet | |
4608 | * @secid: remote peer label secid | |
4609 | * | |
4610 | * This hook allows the security module to provide peer socket security state | |
4611 | * for udp sockets on a per-packet basis to userspace via getsockopt | |
4612 | * SO_GETPEERSEC. The application must first have indicated the IP_PASSSEC | |
4613 | * option via getsockopt. It can then retrieve the security state returned by | |
4614 | * this hook for a packet via the SCM_SECURITY ancillary message type. | |
4615 | * | |
4616 | * Return: Returns 0 on success, error on failure. | |
4617 | */ | |
63c1845b PM |
4618 | int security_socket_getpeersec_dgram(struct socket *sock, |
4619 | struct sk_buff *skb, u32 *secid) | |
20510f2f | 4620 | { |
e308fd3b JB |
4621 | return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, |
4622 | skb, secid); | |
20510f2f JM |
4623 | } |
4624 | EXPORT_SYMBOL(security_socket_getpeersec_dgram); | |
4625 | ||
6b6bbe8c PM |
4626 | /** |
4627 | * security_sk_alloc() - Allocate and initialize a sock's LSM blob | |
4628 | * @sk: sock | |
4629 | * @family: protocol family | |
1e2523d7 | 4630 | * @priority: gfp flags |
6b6bbe8c PM |
4631 | * |
4632 | * Allocate and attach a security structure to the sk->sk_security field, which | |
4633 | * is used to copy security attributes between local stream sockets. | |
4634 | * | |
4635 | * Return: Returns 0 on success, error on failure. | |
4636 | */ | |
20510f2f JM |
4637 | int security_sk_alloc(struct sock *sk, int family, gfp_t priority) |
4638 | { | |
f25fce3e | 4639 | return call_int_hook(sk_alloc_security, 0, sk, family, priority); |
20510f2f JM |
4640 | } |
4641 | ||
6b6bbe8c PM |
4642 | /** |
4643 | * security_sk_free() - Free the sock's LSM blob | |
4644 | * @sk: sock | |
4645 | * | |
4646 | * Deallocate security structure. | |
4647 | */ | |
20510f2f JM |
4648 | void security_sk_free(struct sock *sk) |
4649 | { | |
f25fce3e | 4650 | call_void_hook(sk_free_security, sk); |
20510f2f JM |
4651 | } |
4652 | ||
6b6bbe8c PM |
4653 | /** |
4654 | * security_sk_clone() - Clone a sock's LSM state | |
4655 | * @sk: original sock | |
4656 | * @newsk: target sock | |
4657 | * | |
4658 | * Clone/copy security structure. | |
4659 | */ | |
20510f2f JM |
4660 | void security_sk_clone(const struct sock *sk, struct sock *newsk) |
4661 | { | |
f25fce3e | 4662 | call_void_hook(sk_clone_security, sk, newsk); |
20510f2f | 4663 | } |
6230c9b4 | 4664 | EXPORT_SYMBOL(security_sk_clone); |
20510f2f | 4665 | |
bd1f5934 KK |
4666 | /** |
4667 | * security_sk_classify_flow() - Set a flow's secid based on socket | |
4668 | * @sk: original socket | |
4669 | * @flic: target flow | |
4670 | * | |
4671 | * Set the target flow's secid to socket's secid. | |
4672 | */ | |
5b52ad34 | 4673 | void security_sk_classify_flow(const struct sock *sk, struct flowi_common *flic) |
20510f2f | 4674 | { |
3df98d79 | 4675 | call_void_hook(sk_getsecid, sk, &flic->flowic_secid); |
20510f2f JM |
4676 | } |
4677 | EXPORT_SYMBOL(security_sk_classify_flow); | |
4678 | ||
6b6bbe8c PM |
4679 | /** |
4680 | * security_req_classify_flow() - Set a flow's secid based on request_sock | |
4681 | * @req: request_sock | |
4682 | * @flic: target flow | |
4683 | * | |
4684 | * Sets @flic's secid to @req's secid. | |
4685 | */ | |
3df98d79 PM |
4686 | void security_req_classify_flow(const struct request_sock *req, |
4687 | struct flowi_common *flic) | |
20510f2f | 4688 | { |
3df98d79 | 4689 | call_void_hook(req_classify_flow, req, flic); |
20510f2f JM |
4690 | } |
4691 | EXPORT_SYMBOL(security_req_classify_flow); | |
4692 | ||
6b6bbe8c PM |
4693 | /** |
4694 | * security_sock_graft() - Reconcile LSM state when grafting a sock on a socket | |
4695 | * @sk: sock being grafted | |
1e2523d7 | 4696 | * @parent: target parent socket |
6b6bbe8c | 4697 | * |
1e2523d7 PM |
4698 | * Sets @parent's inode secid to @sk's secid and update @sk with any necessary |
4699 | * LSM state from @parent. | |
6b6bbe8c | 4700 | */ |
20510f2f JM |
4701 | void security_sock_graft(struct sock *sk, struct socket *parent) |
4702 | { | |
f25fce3e | 4703 | call_void_hook(sock_graft, sk, parent); |
20510f2f JM |
4704 | } |
4705 | EXPORT_SYMBOL(security_sock_graft); | |
4706 | ||
6b6bbe8c PM |
4707 | /** |
4708 | * security_inet_conn_request() - Set request_sock state using incoming connect | |
4709 | * @sk: parent listening sock | |
4710 | * @skb: incoming connection | |
4711 | * @req: new request_sock | |
4712 | * | |
4713 | * Initialize the @req LSM state based on @sk and the incoming connect in @skb. | |
4714 | * | |
4715 | * Return: Returns 0 if permission is granted. | |
4716 | */ | |
41dd9596 | 4717 | int security_inet_conn_request(const struct sock *sk, |
63c1845b | 4718 | struct sk_buff *skb, struct request_sock *req) |
20510f2f | 4719 | { |
f25fce3e | 4720 | return call_int_hook(inet_conn_request, 0, sk, skb, req); |
20510f2f JM |
4721 | } |
4722 | EXPORT_SYMBOL(security_inet_conn_request); | |
4723 | ||
6b6bbe8c PM |
4724 | /** |
4725 | * security_inet_csk_clone() - Set new sock LSM state based on request_sock | |
4726 | * @newsk: new sock | |
4727 | * @req: connection request_sock | |
4728 | * | |
4729 | * Set that LSM state of @sock using the LSM state from @req. | |
4730 | */ | |
20510f2f | 4731 | void security_inet_csk_clone(struct sock *newsk, |
63c1845b | 4732 | const struct request_sock *req) |
20510f2f | 4733 | { |
f25fce3e | 4734 | call_void_hook(inet_csk_clone, newsk, req); |
20510f2f JM |
4735 | } |
4736 | ||
6b6bbe8c PM |
4737 | /** |
4738 | * security_inet_conn_established() - Update sock's LSM state with connection | |
4739 | * @sk: sock | |
4740 | * @skb: connection packet | |
4741 | * | |
4742 | * Update @sock's LSM state to represent a new connection from @skb. | |
4743 | */ | |
20510f2f | 4744 | void security_inet_conn_established(struct sock *sk, |
63c1845b | 4745 | struct sk_buff *skb) |
20510f2f | 4746 | { |
f25fce3e | 4747 | call_void_hook(inet_conn_established, sk, skb); |
20510f2f | 4748 | } |
72e89f50 | 4749 | EXPORT_SYMBOL(security_inet_conn_established); |
20510f2f | 4750 | |
6b6bbe8c PM |
4751 | /** |
4752 | * security_secmark_relabel_packet() - Check if setting a secmark is allowed | |
4753 | * @secid: new secmark value | |
4754 | * | |
4755 | * Check if the process should be allowed to relabel packets to @secid. | |
4756 | * | |
4757 | * Return: Returns 0 if permission is granted. | |
4758 | */ | |
2606fd1f EP |
4759 | int security_secmark_relabel_packet(u32 secid) |
4760 | { | |
f25fce3e | 4761 | return call_int_hook(secmark_relabel_packet, 0, secid); |
2606fd1f EP |
4762 | } |
4763 | EXPORT_SYMBOL(security_secmark_relabel_packet); | |
4764 | ||
6b6bbe8c PM |
4765 | /** |
4766 | * security_secmark_refcount_inc() - Increment the secmark labeling rule count | |
4767 | * | |
4768 | * Tells the LSM to increment the number of secmark labeling rules loaded. | |
4769 | */ | |
2606fd1f EP |
4770 | void security_secmark_refcount_inc(void) |
4771 | { | |
f25fce3e | 4772 | call_void_hook(secmark_refcount_inc); |
2606fd1f EP |
4773 | } |
4774 | EXPORT_SYMBOL(security_secmark_refcount_inc); | |
4775 | ||
6b6bbe8c PM |
4776 | /** |
4777 | * security_secmark_refcount_dec() - Decrement the secmark labeling rule count | |
4778 | * | |
4779 | * Tells the LSM to decrement the number of secmark labeling rules loaded. | |
4780 | */ | |
2606fd1f EP |
4781 | void security_secmark_refcount_dec(void) |
4782 | { | |
f25fce3e | 4783 | call_void_hook(secmark_refcount_dec); |
2606fd1f EP |
4784 | } |
4785 | EXPORT_SYMBOL(security_secmark_refcount_dec); | |
4786 | ||
6b6bbe8c PM |
4787 | /** |
4788 | * security_tun_dev_alloc_security() - Allocate a LSM blob for a TUN device | |
4789 | * @security: pointer to the LSM blob | |
4790 | * | |
4791 | * This hook allows a module to allocate a security structure for a TUN device, | |
4792 | * returning the pointer in @security. | |
4793 | * | |
4794 | * Return: Returns a zero on success, negative values on failure. | |
4795 | */ | |
5dbbaf2d PM |
4796 | int security_tun_dev_alloc_security(void **security) |
4797 | { | |
f25fce3e | 4798 | return call_int_hook(tun_dev_alloc_security, 0, security); |
5dbbaf2d PM |
4799 | } |
4800 | EXPORT_SYMBOL(security_tun_dev_alloc_security); | |
4801 | ||
6b6bbe8c PM |
4802 | /** |
4803 | * security_tun_dev_free_security() - Free a TUN device LSM blob | |
4804 | * @security: LSM blob | |
4805 | * | |
4806 | * This hook allows a module to free the security structure for a TUN device. | |
4807 | */ | |
5dbbaf2d PM |
4808 | void security_tun_dev_free_security(void *security) |
4809 | { | |
f25fce3e | 4810 | call_void_hook(tun_dev_free_security, security); |
5dbbaf2d PM |
4811 | } |
4812 | EXPORT_SYMBOL(security_tun_dev_free_security); | |
4813 | ||
6b6bbe8c PM |
4814 | /** |
4815 | * security_tun_dev_create() - Check if creating a TUN device is allowed | |
4816 | * | |
4817 | * Check permissions prior to creating a new TUN device. | |
4818 | * | |
4819 | * Return: Returns 0 if permission is granted. | |
4820 | */ | |
2b980dbd PM |
4821 | int security_tun_dev_create(void) |
4822 | { | |
f25fce3e | 4823 | return call_int_hook(tun_dev_create, 0); |
2b980dbd PM |
4824 | } |
4825 | EXPORT_SYMBOL(security_tun_dev_create); | |
4826 | ||
6b6bbe8c PM |
4827 | /** |
4828 | * security_tun_dev_attach_queue() - Check if attaching a TUN queue is allowed | |
4829 | * @security: TUN device LSM blob | |
4830 | * | |
4831 | * Check permissions prior to attaching to a TUN device queue. | |
4832 | * | |
4833 | * Return: Returns 0 if permission is granted. | |
4834 | */ | |
5dbbaf2d | 4835 | int security_tun_dev_attach_queue(void *security) |
2b980dbd | 4836 | { |
f25fce3e | 4837 | return call_int_hook(tun_dev_attach_queue, 0, security); |
2b980dbd | 4838 | } |
5dbbaf2d | 4839 | EXPORT_SYMBOL(security_tun_dev_attach_queue); |
2b980dbd | 4840 | |
6b6bbe8c PM |
4841 | /** |
4842 | * security_tun_dev_attach() - Update TUN device LSM state on attach | |
4843 | * @sk: associated sock | |
4844 | * @security: TUN device LSM blob | |
4845 | * | |
4846 | * This hook can be used by the module to update any security state associated | |
4847 | * with the TUN device's sock structure. | |
4848 | * | |
4849 | * Return: Returns 0 if permission is granted. | |
4850 | */ | |
5dbbaf2d | 4851 | int security_tun_dev_attach(struct sock *sk, void *security) |
2b980dbd | 4852 | { |
f25fce3e | 4853 | return call_int_hook(tun_dev_attach, 0, sk, security); |
2b980dbd PM |
4854 | } |
4855 | EXPORT_SYMBOL(security_tun_dev_attach); | |
4856 | ||
6b6bbe8c PM |
4857 | /** |
4858 | * security_tun_dev_open() - Update TUN device LSM state on open | |
4859 | * @security: TUN device LSM blob | |
4860 | * | |
4861 | * This hook can be used by the module to update any security state associated | |
4862 | * with the TUN device's security structure. | |
4863 | * | |
4864 | * Return: Returns 0 if permission is granted. | |
4865 | */ | |
5dbbaf2d PM |
4866 | int security_tun_dev_open(void *security) |
4867 | { | |
f25fce3e | 4868 | return call_int_hook(tun_dev_open, 0, security); |
5dbbaf2d PM |
4869 | } |
4870 | EXPORT_SYMBOL(security_tun_dev_open); | |
4871 | ||
4a49f592 PM |
4872 | /** |
4873 | * security_sctp_assoc_request() - Update the LSM on a SCTP association req | |
4874 | * @asoc: SCTP association | |
4875 | * @skb: packet requesting the association | |
4876 | * | |
4877 | * Passes the @asoc and @chunk->skb of the association INIT packet to the LSM. | |
4878 | * | |
4879 | * Return: Returns 0 on success, error on failure. | |
4880 | */ | |
63c1845b PM |
4881 | int security_sctp_assoc_request(struct sctp_association *asoc, |
4882 | struct sk_buff *skb) | |
72e89f50 | 4883 | { |
c081d53f | 4884 | return call_int_hook(sctp_assoc_request, 0, asoc, skb); |
72e89f50 RH |
4885 | } |
4886 | EXPORT_SYMBOL(security_sctp_assoc_request); | |
4887 | ||
4a49f592 PM |
4888 | /** |
4889 | * security_sctp_bind_connect() - Validate a list of addrs for a SCTP option | |
4890 | * @sk: socket | |
4891 | * @optname: SCTP option to validate | |
4892 | * @address: list of IP addresses to validate | |
4893 | * @addrlen: length of the address list | |
4894 | * | |
4895 | * Validiate permissions required for each address associated with sock @sk. | |
4896 | * Depending on @optname, the addresses will be treated as either a connect or | |
4897 | * bind service. The @addrlen is calculated on each IPv4 and IPv6 address using | |
4898 | * sizeof(struct sockaddr_in) or sizeof(struct sockaddr_in6). | |
4899 | * | |
4900 | * Return: Returns 0 on success, error on failure. | |
4901 | */ | |
72e89f50 RH |
4902 | int security_sctp_bind_connect(struct sock *sk, int optname, |
4903 | struct sockaddr *address, int addrlen) | |
4904 | { | |
4905 | return call_int_hook(sctp_bind_connect, 0, sk, optname, | |
4906 | address, addrlen); | |
4907 | } | |
4908 | EXPORT_SYMBOL(security_sctp_bind_connect); | |
4909 | ||
4a49f592 PM |
4910 | /** |
4911 | * security_sctp_sk_clone() - Clone a SCTP sock's LSM state | |
4912 | * @asoc: SCTP association | |
4913 | * @sk: original sock | |
4914 | * @newsk: target sock | |
4915 | * | |
4916 | * Called whenever a new socket is created by accept(2) (i.e. a TCP style | |
4917 | * socket) or when a socket is 'peeled off' e.g userspace calls | |
4918 | * sctp_peeloff(3). | |
4919 | */ | |
c081d53f | 4920 | void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk, |
72e89f50 RH |
4921 | struct sock *newsk) |
4922 | { | |
c081d53f | 4923 | call_void_hook(sctp_sk_clone, asoc, sk, newsk); |
72e89f50 RH |
4924 | } |
4925 | EXPORT_SYMBOL(security_sctp_sk_clone); | |
4926 | ||
4a49f592 PM |
4927 | /** |
4928 | * security_sctp_assoc_established() - Update LSM state when assoc established | |
4929 | * @asoc: SCTP association | |
4930 | * @skb: packet establishing the association | |
4931 | * | |
4932 | * Passes the @asoc and @chunk->skb of the association COOKIE_ACK packet to the | |
4933 | * security module. | |
4934 | * | |
4935 | * Return: Returns 0 if permission is granted. | |
4936 | */ | |
5e50f5d4 OM |
4937 | int security_sctp_assoc_established(struct sctp_association *asoc, |
4938 | struct sk_buff *skb) | |
4939 | { | |
4940 | return call_int_hook(sctp_assoc_established, 0, asoc, skb); | |
4941 | } | |
4942 | EXPORT_SYMBOL(security_sctp_assoc_established); | |
4943 | ||
e3d9387f PA |
4944 | /** |
4945 | * security_mptcp_add_subflow() - Inherit the LSM label from the MPTCP socket | |
4946 | * @sk: the owning MPTCP socket | |
4947 | * @ssk: the new subflow | |
4948 | * | |
4949 | * Update the labeling for the given MPTCP subflow, to match the one of the | |
4950 | * owning MPTCP socket. This hook has to be called after the socket creation and | |
4951 | * initialization via the security_socket_create() and | |
4952 | * security_socket_post_create() LSM hooks. | |
4953 | * | |
4954 | * Return: Returns 0 on success or a negative error code on failure. | |
4955 | */ | |
4956 | int security_mptcp_add_subflow(struct sock *sk, struct sock *ssk) | |
4957 | { | |
4958 | return call_int_hook(mptcp_add_subflow, 0, sk, ssk); | |
4959 | } | |
4960 | ||
20510f2f JM |
4961 | #endif /* CONFIG_SECURITY_NETWORK */ |
4962 | ||
d291f1a6 | 4963 | #ifdef CONFIG_SECURITY_INFINIBAND |
ac318aed PM |
4964 | /** |
4965 | * security_ib_pkey_access() - Check if access to an IB pkey is allowed | |
4966 | * @sec: LSM blob | |
4967 | * @subnet_prefix: subnet prefix of the port | |
4968 | * @pkey: IB pkey | |
4969 | * | |
4432b507 | 4970 | * Check permission to access a pkey when modifying a QP. |
ac318aed PM |
4971 | * |
4972 | * Return: Returns 0 if permission is granted. | |
4973 | */ | |
d291f1a6 DJ |
4974 | int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey) |
4975 | { | |
4976 | return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey); | |
4977 | } | |
4978 | EXPORT_SYMBOL(security_ib_pkey_access); | |
4979 | ||
ac318aed PM |
4980 | /** |
4981 | * security_ib_endport_manage_subnet() - Check if SMPs traffic is allowed | |
4982 | * @sec: LSM blob | |
4983 | * @dev_name: IB device name | |
4984 | * @port_num: port number | |
4985 | * | |
4986 | * Check permissions to send and receive SMPs on a end port. | |
4987 | * | |
4988 | * Return: Returns 0 if permission is granted. | |
4989 | */ | |
63c1845b PM |
4990 | int security_ib_endport_manage_subnet(void *sec, |
4991 | const char *dev_name, u8 port_num) | |
47a2b338 | 4992 | { |
63c1845b PM |
4993 | return call_int_hook(ib_endport_manage_subnet, 0, sec, |
4994 | dev_name, port_num); | |
47a2b338 DJ |
4995 | } |
4996 | EXPORT_SYMBOL(security_ib_endport_manage_subnet); | |
4997 | ||
ac318aed PM |
4998 | /** |
4999 | * security_ib_alloc_security() - Allocate an Infiniband LSM blob | |
5000 | * @sec: LSM blob | |
5001 | * | |
5002 | * Allocate a security structure for Infiniband objects. | |
5003 | * | |
5004 | * Return: Returns 0 on success, non-zero on failure. | |
5005 | */ | |
d291f1a6 DJ |
5006 | int security_ib_alloc_security(void **sec) |
5007 | { | |
5008 | return call_int_hook(ib_alloc_security, 0, sec); | |
5009 | } | |
5010 | EXPORT_SYMBOL(security_ib_alloc_security); | |
5011 | ||
ac318aed PM |
5012 | /** |
5013 | * security_ib_free_security() - Free an Infiniband LSM blob | |
5014 | * @sec: LSM blob | |
5015 | * | |
5016 | * Deallocate an Infiniband security structure. | |
5017 | */ | |
d291f1a6 DJ |
5018 | void security_ib_free_security(void *sec) |
5019 | { | |
5020 | call_void_hook(ib_free_security, sec); | |
5021 | } | |
5022 | EXPORT_SYMBOL(security_ib_free_security); | |
5023 | #endif /* CONFIG_SECURITY_INFINIBAND */ | |
5024 | ||
20510f2f | 5025 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
742b9945 PM |
5026 | /** |
5027 | * security_xfrm_policy_alloc() - Allocate a xfrm policy LSM blob | |
5028 | * @ctxp: xfrm security context being added to the SPD | |
5029 | * @sec_ctx: security label provided by userspace | |
5030 | * @gfp: gfp flags | |
5031 | * | |
5032 | * Allocate a security structure to the xp->security field; the security field | |
5033 | * is initialized to NULL when the xfrm_policy is allocated. | |
5034 | * | |
5035 | * Return: Return 0 if operation was successful. | |
5036 | */ | |
52a4c640 NA |
5037 | int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, |
5038 | struct xfrm_user_sec_ctx *sec_ctx, | |
5039 | gfp_t gfp) | |
20510f2f | 5040 | { |
f25fce3e | 5041 | return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp); |
20510f2f JM |
5042 | } |
5043 | EXPORT_SYMBOL(security_xfrm_policy_alloc); | |
5044 | ||
742b9945 PM |
5045 | /** |
5046 | * security_xfrm_policy_clone() - Clone xfrm policy LSM state | |
5047 | * @old_ctx: xfrm security context | |
5048 | * @new_ctxp: target xfrm security context | |
5049 | * | |
5050 | * Allocate a security structure in new_ctxp that contains the information from | |
5051 | * the old_ctx structure. | |
5052 | * | |
5053 | * Return: Return 0 if operation was successful. | |
5054 | */ | |
03e1ad7b | 5055 | int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
63c1845b | 5056 | struct xfrm_sec_ctx **new_ctxp) |
20510f2f | 5057 | { |
f25fce3e | 5058 | return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp); |
20510f2f JM |
5059 | } |
5060 | ||
742b9945 PM |
5061 | /** |
5062 | * security_xfrm_policy_free() - Free a xfrm security context | |
5063 | * @ctx: xfrm security context | |
5064 | * | |
5065 | * Free LSM resources associated with @ctx. | |
5066 | */ | |
03e1ad7b | 5067 | void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) |
20510f2f | 5068 | { |
f25fce3e | 5069 | call_void_hook(xfrm_policy_free_security, ctx); |
20510f2f JM |
5070 | } |
5071 | EXPORT_SYMBOL(security_xfrm_policy_free); | |
5072 | ||
742b9945 PM |
5073 | /** |
5074 | * security_xfrm_policy_delete() - Check if deleting a xfrm policy is allowed | |
5075 | * @ctx: xfrm security context | |
5076 | * | |
5077 | * Authorize deletion of a SPD entry. | |
5078 | * | |
5079 | * Return: Returns 0 if permission is granted. | |
5080 | */ | |
03e1ad7b | 5081 | int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) |
20510f2f | 5082 | { |
f25fce3e | 5083 | return call_int_hook(xfrm_policy_delete_security, 0, ctx); |
20510f2f JM |
5084 | } |
5085 | ||
742b9945 PM |
5086 | /** |
5087 | * security_xfrm_state_alloc() - Allocate a xfrm state LSM blob | |
5088 | * @x: xfrm state being added to the SAD | |
5089 | * @sec_ctx: security label provided by userspace | |
5090 | * | |
5091 | * Allocate a security structure to the @x->security field; the security field | |
5092 | * is initialized to NULL when the xfrm_state is allocated. Set the context to | |
5093 | * correspond to @sec_ctx. | |
5094 | * | |
5095 | * Return: Return 0 if operation was successful. | |
5096 | */ | |
2e5aa866 PM |
5097 | int security_xfrm_state_alloc(struct xfrm_state *x, |
5098 | struct xfrm_user_sec_ctx *sec_ctx) | |
20510f2f | 5099 | { |
f25fce3e | 5100 | return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx); |
20510f2f JM |
5101 | } |
5102 | EXPORT_SYMBOL(security_xfrm_state_alloc); | |
5103 | ||
742b9945 PM |
5104 | /** |
5105 | * security_xfrm_state_alloc_acquire() - Allocate a xfrm state LSM blob | |
5106 | * @x: xfrm state being added to the SAD | |
5107 | * @polsec: associated policy's security context | |
5108 | * @secid: secid from the flow | |
5109 | * | |
5110 | * Allocate a security structure to the x->security field; the security field | |
5111 | * is initialized to NULL when the xfrm_state is allocated. Set the context to | |
5112 | * correspond to secid. | |
5113 | * | |
5114 | * Return: Returns 0 if operation was successful. | |
5115 | */ | |
20510f2f JM |
5116 | int security_xfrm_state_alloc_acquire(struct xfrm_state *x, |
5117 | struct xfrm_sec_ctx *polsec, u32 secid) | |
5118 | { | |
f25fce3e | 5119 | return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid); |
20510f2f JM |
5120 | } |
5121 | ||
742b9945 PM |
5122 | /** |
5123 | * security_xfrm_state_delete() - Check if deleting a xfrm state is allowed | |
5124 | * @x: xfrm state | |
5125 | * | |
5126 | * Authorize deletion of x->security. | |
5127 | * | |
5128 | * Return: Returns 0 if permission is granted. | |
5129 | */ | |
20510f2f JM |
5130 | int security_xfrm_state_delete(struct xfrm_state *x) |
5131 | { | |
f25fce3e | 5132 | return call_int_hook(xfrm_state_delete_security, 0, x); |
20510f2f JM |
5133 | } |
5134 | EXPORT_SYMBOL(security_xfrm_state_delete); | |
5135 | ||
742b9945 PM |
5136 | /** |
5137 | * security_xfrm_state_free() - Free a xfrm state | |
5138 | * @x: xfrm state | |
5139 | * | |
5140 | * Deallocate x->security. | |
5141 | */ | |
20510f2f JM |
5142 | void security_xfrm_state_free(struct xfrm_state *x) |
5143 | { | |
f25fce3e | 5144 | call_void_hook(xfrm_state_free_security, x); |
20510f2f JM |
5145 | } |
5146 | ||
742b9945 PM |
5147 | /** |
5148 | * security_xfrm_policy_lookup() - Check if using a xfrm policy is allowed | |
5149 | * @ctx: target xfrm security context | |
5150 | * @fl_secid: flow secid used to authorize access | |
5151 | * | |
5152 | * Check permission when a flow selects a xfrm_policy for processing XFRMs on a | |
5153 | * packet. The hook is called when selecting either a per-socket policy or a | |
5154 | * generic xfrm policy. | |
5155 | * | |
5156 | * Return: Return 0 if permission is granted, -ESRCH otherwise, or -errno on | |
5157 | * other errors. | |
5158 | */ | |
8a922805 | 5159 | int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid) |
20510f2f | 5160 | { |
8a922805 | 5161 | return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid); |
20510f2f JM |
5162 | } |
5163 | ||
742b9945 PM |
5164 | /** |
5165 | * security_xfrm_state_pol_flow_match() - Check for a xfrm match | |
5166 | * @x: xfrm state to match | |
1e2523d7 | 5167 | * @xp: xfrm policy to check for a match |
742b9945 PM |
5168 | * @flic: flow to check for a match. |
5169 | * | |
5170 | * Check @xp and @flic for a match with @x. | |
5171 | * | |
5172 | * Return: Returns 1 if there is a match. | |
5173 | */ | |
20510f2f | 5174 | int security_xfrm_state_pol_flow_match(struct xfrm_state *x, |
e33f7704 | 5175 | struct xfrm_policy *xp, |
3df98d79 | 5176 | const struct flowi_common *flic) |
20510f2f | 5177 | { |
b1d9e6b0 | 5178 | struct security_hook_list *hp; |
98e828a0 | 5179 | int rc = LSM_RET_DEFAULT(xfrm_state_pol_flow_match); |
b1d9e6b0 CS |
5180 | |
5181 | /* | |
5182 | * Since this function is expected to return 0 or 1, the judgment | |
5183 | * becomes difficult if multiple LSMs supply this call. Fortunately, | |
5184 | * we can use the first LSM's judgment because currently only SELinux | |
5185 | * supplies this call. | |
5186 | * | |
5187 | * For speed optimization, we explicitly break the loop rather than | |
5188 | * using the macro | |
5189 | */ | |
df0ce173 | 5190 | hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match, |
63c1845b | 5191 | list) { |
3df98d79 | 5192 | rc = hp->hook.xfrm_state_pol_flow_match(x, xp, flic); |
b1d9e6b0 CS |
5193 | break; |
5194 | } | |
5195 | return rc; | |
20510f2f JM |
5196 | } |
5197 | ||
742b9945 PM |
5198 | /** |
5199 | * security_xfrm_decode_session() - Determine the xfrm secid for a packet | |
5200 | * @skb: xfrm packet | |
5201 | * @secid: secid | |
5202 | * | |
5203 | * Decode the packet in @skb and return the security label in @secid. | |
5204 | * | |
5205 | * Return: Return 0 if all xfrms used have the same secid. | |
5206 | */ | |
20510f2f JM |
5207 | int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid) |
5208 | { | |
f25fce3e | 5209 | return call_int_hook(xfrm_decode_session, 0, skb, secid, 1); |
20510f2f JM |
5210 | } |
5211 | ||
3df98d79 | 5212 | void security_skb_classify_flow(struct sk_buff *skb, struct flowi_common *flic) |
20510f2f | 5213 | { |
3df98d79 | 5214 | int rc = call_int_hook(xfrm_decode_session, 0, skb, &flic->flowic_secid, |
63c1845b | 5215 | 0); |
20510f2f JM |
5216 | |
5217 | BUG_ON(rc); | |
5218 | } | |
5219 | EXPORT_SYMBOL(security_skb_classify_flow); | |
20510f2f JM |
5220 | #endif /* CONFIG_SECURITY_NETWORK_XFRM */ |
5221 | ||
5222 | #ifdef CONFIG_KEYS | |
ecc419a4 PM |
5223 | /** |
5224 | * security_key_alloc() - Allocate and initialize a kernel key LSM blob | |
5225 | * @key: key | |
5226 | * @cred: credentials | |
5227 | * @flags: allocation flags | |
5228 | * | |
5229 | * Permit allocation of a key and assign security data. Note that key does not | |
5230 | * have a serial number assigned at this point. | |
5231 | * | |
5232 | * Return: Return 0 if permission is granted, -ve error otherwise. | |
5233 | */ | |
d84f4f99 DH |
5234 | int security_key_alloc(struct key *key, const struct cred *cred, |
5235 | unsigned long flags) | |
20510f2f | 5236 | { |
f25fce3e | 5237 | return call_int_hook(key_alloc, 0, key, cred, flags); |
20510f2f JM |
5238 | } |
5239 | ||
ecc419a4 PM |
5240 | /** |
5241 | * security_key_free() - Free a kernel key LSM blob | |
5242 | * @key: key | |
5243 | * | |
5244 | * Notification of destruction; free security data. | |
5245 | */ | |
20510f2f JM |
5246 | void security_key_free(struct key *key) |
5247 | { | |
f25fce3e | 5248 | call_void_hook(key_free, key); |
20510f2f JM |
5249 | } |
5250 | ||
ecc419a4 PM |
5251 | /** |
5252 | * security_key_permission() - Check if a kernel key operation is allowed | |
5253 | * @key_ref: key reference | |
5254 | * @cred: credentials of actor requesting access | |
5255 | * @need_perm: requested permissions | |
5256 | * | |
5257 | * See whether a specific operational right is granted to a process on a key. | |
5258 | * | |
5259 | * Return: Return 0 if permission is granted, -ve error otherwise. | |
5260 | */ | |
8c0637e9 DH |
5261 | int security_key_permission(key_ref_t key_ref, const struct cred *cred, |
5262 | enum key_need_perm need_perm) | |
20510f2f | 5263 | { |
8c0637e9 | 5264 | return call_int_hook(key_permission, 0, key_ref, cred, need_perm); |
20510f2f JM |
5265 | } |
5266 | ||
ecc419a4 PM |
5267 | /** |
5268 | * security_key_getsecurity() - Get the key's security label | |
5269 | * @key: key | |
b3816cf8 | 5270 | * @buffer: security label buffer |
ecc419a4 PM |
5271 | * |
5272 | * Get a textual representation of the security context attached to a key for | |
5273 | * the purposes of honouring KEYCTL_GETSECURITY. This function allocates the | |
5274 | * storage for the NUL-terminated string and the caller should free it. | |
5275 | * | |
b3816cf8 | 5276 | * Return: Returns the length of @buffer (including terminating NUL) or -ve if |
ecc419a4 PM |
5277 | * an error occurs. May also return 0 (and a NULL buffer pointer) if |
5278 | * there is no security label assigned to the key. | |
5279 | */ | |
b3816cf8 | 5280 | int security_key_getsecurity(struct key *key, char **buffer) |
70a5bb72 | 5281 | { |
b3816cf8 PM |
5282 | *buffer = NULL; |
5283 | return call_int_hook(key_getsecurity, 0, key, buffer); | |
70a5bb72 | 5284 | } |
20510f2f | 5285 | #endif /* CONFIG_KEYS */ |
03d37d25 AD |
5286 | |
5287 | #ifdef CONFIG_AUDIT | |
b14faf9c PM |
5288 | /** |
5289 | * security_audit_rule_init() - Allocate and init an LSM audit rule struct | |
5290 | * @field: audit action | |
5291 | * @op: rule operator | |
5292 | * @rulestr: rule context | |
5293 | * @lsmrule: receive buffer for audit rule struct | |
5294 | * | |
5295 | * Allocate and initialize an LSM audit rule structure. | |
5296 | * | |
5297 | * Return: Return 0 if @lsmrule has been successfully set, -EINVAL in case of | |
5298 | * an invalid rule. | |
5299 | */ | |
03d37d25 AD |
5300 | int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule) |
5301 | { | |
f25fce3e | 5302 | return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule); |
03d37d25 AD |
5303 | } |
5304 | ||
b14faf9c PM |
5305 | /** |
5306 | * security_audit_rule_known() - Check if an audit rule contains LSM fields | |
5307 | * @krule: audit rule | |
5308 | * | |
5309 | * Specifies whether given @krule contains any fields related to the current | |
5310 | * LSM. | |
5311 | * | |
5312 | * Return: Returns 1 in case of relation found, 0 otherwise. | |
5313 | */ | |
03d37d25 AD |
5314 | int security_audit_rule_known(struct audit_krule *krule) |
5315 | { | |
f25fce3e | 5316 | return call_int_hook(audit_rule_known, 0, krule); |
03d37d25 AD |
5317 | } |
5318 | ||
b14faf9c PM |
5319 | /** |
5320 | * security_audit_rule_free() - Free an LSM audit rule struct | |
5321 | * @lsmrule: audit rule struct | |
5322 | * | |
5323 | * Deallocate the LSM audit rule structure previously allocated by | |
5324 | * audit_rule_init(). | |
5325 | */ | |
03d37d25 AD |
5326 | void security_audit_rule_free(void *lsmrule) |
5327 | { | |
f25fce3e | 5328 | call_void_hook(audit_rule_free, lsmrule); |
03d37d25 AD |
5329 | } |
5330 | ||
b14faf9c PM |
5331 | /** |
5332 | * security_audit_rule_match() - Check if a label matches an audit rule | |
5333 | * @secid: security label | |
5334 | * @field: LSM audit field | |
5335 | * @op: matching operator | |
5336 | * @lsmrule: audit rule | |
5337 | * | |
5338 | * Determine if given @secid matches a rule previously approved by | |
5339 | * security_audit_rule_known(). | |
5340 | * | |
5341 | * Return: Returns 1 if secid matches the rule, 0 if it does not, -ERRNO on | |
5342 | * failure. | |
5343 | */ | |
90462a5b | 5344 | int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule) |
03d37d25 | 5345 | { |
90462a5b | 5346 | return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule); |
03d37d25 | 5347 | } |
b1d9e6b0 | 5348 | #endif /* CONFIG_AUDIT */ |
afdb09c7 CF |
5349 | |
5350 | #ifdef CONFIG_BPF_SYSCALL | |
55e85320 PM |
5351 | /** |
5352 | * security_bpf() - Check if the bpf syscall operation is allowed | |
5353 | * @cmd: command | |
5354 | * @attr: bpf attribute | |
5355 | * @size: size | |
5356 | * | |
5357 | * Do a initial check for all bpf syscalls after the attribute is copied into | |
5358 | * the kernel. The actual security module can implement their own rules to | |
5359 | * check the specific cmd they need. | |
5360 | * | |
5361 | * Return: Returns 0 if permission is granted. | |
5362 | */ | |
afdb09c7 CF |
5363 | int security_bpf(int cmd, union bpf_attr *attr, unsigned int size) |
5364 | { | |
5365 | return call_int_hook(bpf, 0, cmd, attr, size); | |
5366 | } | |
55e85320 PM |
5367 | |
5368 | /** | |
5369 | * security_bpf_map() - Check if access to a bpf map is allowed | |
5370 | * @map: bpf map | |
5371 | * @fmode: mode | |
5372 | * | |
5373 | * Do a check when the kernel generates and returns a file descriptor for eBPF | |
5374 | * maps. | |
5375 | * | |
5376 | * Return: Returns 0 if permission is granted. | |
5377 | */ | |
afdb09c7 CF |
5378 | int security_bpf_map(struct bpf_map *map, fmode_t fmode) |
5379 | { | |
5380 | return call_int_hook(bpf_map, 0, map, fmode); | |
5381 | } | |
55e85320 PM |
5382 | |
5383 | /** | |
5384 | * security_bpf_prog() - Check if access to a bpf program is allowed | |
5385 | * @prog: bpf program | |
5386 | * | |
5387 | * Do a check when the kernel generates and returns a file descriptor for eBPF | |
5388 | * programs. | |
5389 | * | |
5390 | * Return: Returns 0 if permission is granted. | |
5391 | */ | |
afdb09c7 CF |
5392 | int security_bpf_prog(struct bpf_prog *prog) |
5393 | { | |
5394 | return call_int_hook(bpf_prog, 0, prog); | |
5395 | } | |
55e85320 PM |
5396 | |
5397 | /** | |
5398 | * security_bpf_map_alloc() - Allocate a bpf map LSM blob | |
5399 | * @map: bpf map | |
5400 | * | |
5401 | * Initialize the security field inside bpf map. | |
5402 | * | |
5403 | * Return: Returns 0 on success, error on failure. | |
5404 | */ | |
afdb09c7 CF |
5405 | int security_bpf_map_alloc(struct bpf_map *map) |
5406 | { | |
5407 | return call_int_hook(bpf_map_alloc_security, 0, map); | |
5408 | } | |
55e85320 PM |
5409 | |
5410 | /** | |
5411 | * security_bpf_prog_alloc() - Allocate a bpf program LSM blob | |
5412 | * @aux: bpf program aux info struct | |
5413 | * | |
5414 | * Initialize the security field inside bpf program. | |
5415 | * | |
5416 | * Return: Returns 0 on success, error on failure. | |
5417 | */ | |
afdb09c7 CF |
5418 | int security_bpf_prog_alloc(struct bpf_prog_aux *aux) |
5419 | { | |
5420 | return call_int_hook(bpf_prog_alloc_security, 0, aux); | |
5421 | } | |
55e85320 PM |
5422 | |
5423 | /** | |
5424 | * security_bpf_map_free() - Free a bpf map's LSM blob | |
5425 | * @map: bpf map | |
5426 | * | |
5427 | * Clean up the security information stored inside bpf map. | |
5428 | */ | |
afdb09c7 CF |
5429 | void security_bpf_map_free(struct bpf_map *map) |
5430 | { | |
5431 | call_void_hook(bpf_map_free_security, map); | |
5432 | } | |
55e85320 PM |
5433 | |
5434 | /** | |
5435 | * security_bpf_prog_free() - Free a bpf program's LSM blob | |
5436 | * @aux: bpf program aux info struct | |
5437 | * | |
5438 | * Clean up the security information stored inside bpf prog. | |
5439 | */ | |
afdb09c7 CF |
5440 | void security_bpf_prog_free(struct bpf_prog_aux *aux) |
5441 | { | |
5442 | call_void_hook(bpf_prog_free_security, aux); | |
5443 | } | |
5444 | #endif /* CONFIG_BPF_SYSCALL */ | |
9e47d31d | 5445 | |
e261301c PM |
5446 | /** |
5447 | * security_locked_down() - Check if a kernel feature is allowed | |
5448 | * @what: requested kernel feature | |
5449 | * | |
5450 | * Determine whether a kernel feature that potentially enables arbitrary code | |
5451 | * execution in kernel space should be permitted. | |
5452 | * | |
5453 | * Return: Returns 0 if permission is granted. | |
5454 | */ | |
9e47d31d MG |
5455 | int security_locked_down(enum lockdown_reason what) |
5456 | { | |
5457 | return call_int_hook(locked_down, 0, what); | |
5458 | } | |
5459 | EXPORT_SYMBOL(security_locked_down); | |
da97e184 JFG |
5460 | |
5461 | #ifdef CONFIG_PERF_EVENTS | |
452b670c PM |
5462 | /** |
5463 | * security_perf_event_open() - Check if a perf event open is allowed | |
5464 | * @attr: perf event attribute | |
5465 | * @type: type of event | |
5466 | * | |
5467 | * Check whether the @type of perf_event_open syscall is allowed. | |
5468 | * | |
5469 | * Return: Returns 0 if permission is granted. | |
5470 | */ | |
da97e184 JFG |
5471 | int security_perf_event_open(struct perf_event_attr *attr, int type) |
5472 | { | |
5473 | return call_int_hook(perf_event_open, 0, attr, type); | |
5474 | } | |
5475 | ||
452b670c PM |
5476 | /** |
5477 | * security_perf_event_alloc() - Allocate a perf event LSM blob | |
5478 | * @event: perf event | |
5479 | * | |
5480 | * Allocate and save perf_event security info. | |
5481 | * | |
5482 | * Return: Returns 0 on success, error on failure. | |
5483 | */ | |
da97e184 JFG |
5484 | int security_perf_event_alloc(struct perf_event *event) |
5485 | { | |
5486 | return call_int_hook(perf_event_alloc, 0, event); | |
5487 | } | |
5488 | ||
452b670c PM |
5489 | /** |
5490 | * security_perf_event_free() - Free a perf event LSM blob | |
5491 | * @event: perf event | |
5492 | * | |
5493 | * Release (free) perf_event security info. | |
5494 | */ | |
da97e184 JFG |
5495 | void security_perf_event_free(struct perf_event *event) |
5496 | { | |
5497 | call_void_hook(perf_event_free, event); | |
5498 | } | |
5499 | ||
452b670c PM |
5500 | /** |
5501 | * security_perf_event_read() - Check if reading a perf event label is allowed | |
5502 | * @event: perf event | |
5503 | * | |
5504 | * Read perf_event security info if allowed. | |
5505 | * | |
5506 | * Return: Returns 0 if permission is granted. | |
5507 | */ | |
da97e184 JFG |
5508 | int security_perf_event_read(struct perf_event *event) |
5509 | { | |
5510 | return call_int_hook(perf_event_read, 0, event); | |
5511 | } | |
5512 | ||
452b670c PM |
5513 | /** |
5514 | * security_perf_event_write() - Check if writing a perf event label is allowed | |
5515 | * @event: perf event | |
5516 | * | |
5517 | * Write perf_event security info if allowed. | |
5518 | * | |
5519 | * Return: Returns 0 if permission is granted. | |
5520 | */ | |
da97e184 JFG |
5521 | int security_perf_event_write(struct perf_event *event) |
5522 | { | |
5523 | return call_int_hook(perf_event_write, 0, event); | |
5524 | } | |
5525 | #endif /* CONFIG_PERF_EVENTS */ | |
cdc1404a PM |
5526 | |
5527 | #ifdef CONFIG_IO_URING | |
1cd2aca6 PM |
5528 | /** |
5529 | * security_uring_override_creds() - Check if overriding creds is allowed | |
5530 | * @new: new credentials | |
5531 | * | |
5532 | * Check if the current task, executing an io_uring operation, is allowed to | |
5533 | * override it's credentials with @new. | |
5534 | * | |
5535 | * Return: Returns 0 if permission is granted. | |
5536 | */ | |
cdc1404a PM |
5537 | int security_uring_override_creds(const struct cred *new) |
5538 | { | |
5539 | return call_int_hook(uring_override_creds, 0, new); | |
5540 | } | |
5541 | ||
1cd2aca6 PM |
5542 | /** |
5543 | * security_uring_sqpoll() - Check if IORING_SETUP_SQPOLL is allowed | |
5544 | * | |
5545 | * Check whether the current task is allowed to spawn a io_uring polling thread | |
5546 | * (IORING_SETUP_SQPOLL). | |
5547 | * | |
5548 | * Return: Returns 0 if permission is granted. | |
5549 | */ | |
cdc1404a PM |
5550 | int security_uring_sqpoll(void) |
5551 | { | |
5552 | return call_int_hook(uring_sqpoll, 0); | |
5553 | } | |
1cd2aca6 PM |
5554 | |
5555 | /** | |
5556 | * security_uring_cmd() - Check if a io_uring passthrough command is allowed | |
5557 | * @ioucmd: command | |
5558 | * | |
5559 | * Check whether the file_operations uring_cmd is allowed to run. | |
5560 | * | |
5561 | * Return: Returns 0 if permission is granted. | |
5562 | */ | |
2a584012 LC |
5563 | int security_uring_cmd(struct io_uring_cmd *ioucmd) |
5564 | { | |
5565 | return call_int_hook(uring_cmd, 0, ioucmd); | |
5566 | } | |
cdc1404a | 5567 | #endif /* CONFIG_IO_URING */ |