2 * Linux Security Module interfaces
8 * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
9 * Copyright (C) 2015 Intel Corporation.
11 * Copyright (C) 2016 Mellanox Techonologies
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * Due to this file being licensed under the GPL there is controversy over
19 * whether this permits you to write a module that #includes this file
20 * without placing your module under the GPL. Please consult a lawyer for
21 * advice before doing this.
25 #ifndef __LINUX_LSM_HOOKS_H
26 #define __LINUX_LSM_HOOKS_H
28 #include <uapi/linux/lsm.h>
29 #include <linux/security.h>
30 #include <linux/init.h>
31 #include <linux/rculist.h>
32 #include <linux/xattr.h>
34 union security_list_options {
35 #define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
36 #include "lsm_hook_defs.h"
40 struct security_hook_heads {
41 #define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME;
42 #include "lsm_hook_defs.h"
47 * struct lsm_id - Identify a Linux Security Module.
48 * @lsm: name of the LSM, must be approved by the LSM maintainers
49 * @id: LSM ID number from uapi/linux/lsm.h
51 * Contains the information that identifies the LSM.
59 * Security module hook list structure.
60 * For use with generic list macros for common operations.
62 struct security_hook_list {
63 struct hlist_node list;
64 struct hlist_head *head;
65 union security_list_options hook;
66 const struct lsm_id *lsmid;
70 * Security blob size or offset data.
72 struct lsm_blob_sizes {
80 int lbs_xattr_count; /* number of xattr slots in new_xattrs array */
84 * lsm_get_xattr_slot - Return the next available slot and increment the index
85 * @xattrs: array storing LSM-provided xattrs
86 * @xattr_count: number of already stored xattrs (updated)
88 * Retrieve the first available slot in the @xattrs array to fill with an xattr,
89 * and increment @xattr_count.
91 * Return: The slot to fill in @xattrs if non-NULL, NULL otherwise.
93 static inline struct xattr *lsm_get_xattr_slot(struct xattr *xattrs,
96 if (unlikely(!xattrs))
98 return &xattrs[(*xattr_count)++];
102 * LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void
103 * LSM hooks (in include/linux/lsm_hook_defs.h).
105 #define LSM_RET_VOID ((void) 0)
108 * Initializing a security_hook_list structure takes
109 * up a lot of space in a source file. This macro takes
110 * care of the common case and reduces the amount of
113 #define LSM_HOOK_INIT(HEAD, HOOK) \
114 { .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } }
116 extern struct security_hook_heads security_hook_heads;
117 extern char *lsm_names;
119 extern void security_add_hooks(struct security_hook_list *hooks, int count,
120 const struct lsm_id *lsmid);
122 #define LSM_FLAG_LEGACY_MAJOR BIT(0)
123 #define LSM_FLAG_EXCLUSIVE BIT(1)
126 LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
127 LSM_ORDER_MUTABLE = 0,
128 LSM_ORDER_LAST = 1, /* This is only for integrity. */
132 const char *name; /* Required. */
133 enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
134 unsigned long flags; /* Optional: flags describing LSM */
135 int *enabled; /* Optional: controlled by CONFIG_LSM */
136 int (*init)(void); /* Required. */
137 struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
140 extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
141 extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[];
143 #define DEFINE_LSM(lsm) \
144 static struct lsm_info __lsm_##lsm \
145 __used __section(".lsm_info.init") \
146 __aligned(sizeof(unsigned long))
148 #define DEFINE_EARLY_LSM(lsm) \
149 static struct lsm_info __early_lsm_##lsm \
150 __used __section(".early_lsm_info.init") \
151 __aligned(sizeof(unsigned long))
153 extern int lsm_inode_alloc(struct inode *inode);
155 #endif /* ! __LINUX_LSM_HOOKS_H */