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