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