226ae80d9683cf1560dc07e3f2d0ba59150181c6
[linux-block.git] / security / lsm_syscalls.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * System calls implementing the Linux Security Module API.
4  *
5  *  Copyright (C) 2022 Casey Schaufler <casey@schaufler-ca.com>
6  *  Copyright (C) 2022 Intel Corporation
7  */
8
9 #include <asm/current.h>
10 #include <linux/compiler_types.h>
11 #include <linux/err.h>
12 #include <linux/errno.h>
13 #include <linux/security.h>
14 #include <linux/stddef.h>
15 #include <linux/syscalls.h>
16 #include <linux/types.h>
17 #include <linux/lsm_hooks.h>
18 #include <uapi/linux/lsm.h>
19
20 /**
21  * sys_lsm_set_self_attr - Set current task's security module attribute
22  * @attr: which attribute to set
23  * @ctx: the LSM contexts
24  * @size: size of @ctx
25  * @flags: reserved for future use
26  *
27  * Sets the calling task's LSM context. On success this function
28  * returns 0. If the attribute specified cannot be set a negative
29  * value indicating the reason for the error is returned.
30  */
31 SYSCALL_DEFINE4(lsm_set_self_attr, unsigned int, attr, struct lsm_ctx __user *,
32                 ctx, size_t, size, u32, flags)
33 {
34         return security_setselfattr(attr, ctx, size, flags);
35 }
36
37 /**
38  * sys_lsm_get_self_attr - Return current task's security module attributes
39  * @attr: which attribute to return
40  * @ctx: the user-space destination for the information, or NULL
41  * @size: pointer to the size of space available to receive the data
42  * @flags: special handling options. LSM_FLAG_SINGLE indicates that only
43  * attributes associated with the LSM identified in the passed @ctx be
44  * reported.
45  *
46  * Returns the calling task's LSM contexts. On success this
47  * function returns the number of @ctx array elements. This value
48  * may be zero if there are no LSM contexts assigned. If @size is
49  * insufficient to contain the return data -E2BIG is returned and
50  * @size is set to the minimum required size. In all other cases
51  * a negative value indicating the error is returned.
52  */
53 SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *,
54                 ctx, size_t __user *, size, u32, flags)
55 {
56         return security_getselfattr(attr, ctx, size, flags);
57 }