hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/selinux/ss/sidtab.h
....@@ -17,14 +17,15 @@
1717
1818 #include "context.h"
1919
20
-struct sidtab_entry_leaf {
20
+struct sidtab_entry {
2121 u32 sid;
22
+ u32 hash;
2223 struct context context;
24
+#if CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0
25
+ struct sidtab_str_cache __rcu *cache;
26
+#endif
2327 struct hlist_node list;
2428 };
25
-
26
-struct sidtab_node_inner;
27
-struct sidtab_node_leaf;
2829
2930 union sidtab_entry_inner {
3031 struct sidtab_node_inner *ptr_inner;
....@@ -41,7 +42,7 @@
4142 (SIDTAB_NODE_ALLOC_SHIFT - size_to_shift(sizeof(union sidtab_entry_inner)))
4243 #define SIDTAB_INNER_ENTRIES ((size_t)1 << SIDTAB_INNER_SHIFT)
4344 #define SIDTAB_LEAF_ENTRIES \
44
- (SIDTAB_NODE_ALLOC_SIZE / sizeof(struct sidtab_entry_leaf))
45
+ (SIDTAB_NODE_ALLOC_SIZE / sizeof(struct sidtab_entry))
4546
4647 #define SIDTAB_MAX_BITS 32
4748 #define SIDTAB_MAX U32_MAX
....@@ -51,7 +52,7 @@
5152 SIDTAB_INNER_SHIFT)
5253
5354 struct sidtab_node_leaf {
54
- struct sidtab_entry_leaf entries[SIDTAB_LEAF_ENTRIES];
55
+ struct sidtab_entry entries[SIDTAB_LEAF_ENTRIES];
5556 };
5657
5758 struct sidtab_node_inner {
....@@ -60,11 +61,11 @@
6061
6162 struct sidtab_isid_entry {
6263 int set;
63
- struct sidtab_entry_leaf leaf;
64
+ struct sidtab_entry entry;
6465 };
6566
6667 struct sidtab_convert_params {
67
- int (*func)(struct context *oldc, struct context *newc, void *args);
68
+ int (*func)(struct context *oldc, struct context *newc, void *args, gfp_t gfp_flags);
6869 void *args;
6970 struct sidtab *target;
7071 };
....@@ -85,7 +86,15 @@
8586 u32 count;
8687 /* access only under spinlock */
8788 struct sidtab_convert_params *convert;
89
+ bool frozen;
8890 spinlock_t lock;
91
+
92
+#if CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0
93
+ /* SID -> context string cache */
94
+ u32 cache_free_slots;
95
+ struct list_head cache_lru_list;
96
+ spinlock_t cache_lock;
97
+#endif
8998
9099 /* index == SID - 1 (no entry for SECSID_NULL) */
91100 struct sidtab_isid_entry isids[SECINITSID_NUM];
....@@ -96,10 +105,29 @@
96105
97106 int sidtab_init(struct sidtab *s);
98107 int sidtab_set_initial(struct sidtab *s, u32 sid, struct context *context);
99
-struct context *sidtab_search(struct sidtab *s, u32 sid);
100
-struct context *sidtab_search_force(struct sidtab *s, u32 sid);
108
+struct sidtab_entry *sidtab_search_entry(struct sidtab *s, u32 sid);
109
+struct sidtab_entry *sidtab_search_entry_force(struct sidtab *s, u32 sid);
110
+
111
+static inline struct context *sidtab_search(struct sidtab *s, u32 sid)
112
+{
113
+ struct sidtab_entry *entry = sidtab_search_entry(s, sid);
114
+
115
+ return entry ? &entry->context : NULL;
116
+}
117
+
118
+static inline struct context *sidtab_search_force(struct sidtab *s, u32 sid)
119
+{
120
+ struct sidtab_entry *entry = sidtab_search_entry_force(s, sid);
121
+
122
+ return entry ? &entry->context : NULL;
123
+}
101124
102125 int sidtab_convert(struct sidtab *s, struct sidtab_convert_params *params);
126
+
127
+void sidtab_cancel_convert(struct sidtab *s);
128
+
129
+void sidtab_freeze_begin(struct sidtab *s, unsigned long *flags) __acquires(&s->lock);
130
+void sidtab_freeze_end(struct sidtab *s, unsigned long *flags) __releases(&s->lock);
103131
104132 int sidtab_context_to_sid(struct sidtab *s, struct context *context, u32 *sid);
105133
....@@ -107,6 +135,25 @@
107135
108136 int sidtab_hash_stats(struct sidtab *sidtab, char *page);
109137
138
+#if CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0
139
+void sidtab_sid2str_put(struct sidtab *s, struct sidtab_entry *entry,
140
+ const char *str, u32 str_len);
141
+int sidtab_sid2str_get(struct sidtab *s, struct sidtab_entry *entry,
142
+ char **out, u32 *out_len);
143
+#else
144
+static inline void sidtab_sid2str_put(struct sidtab *s,
145
+ struct sidtab_entry *entry,
146
+ const char *str, u32 str_len)
147
+{
148
+}
149
+static inline int sidtab_sid2str_get(struct sidtab *s,
150
+ struct sidtab_entry *entry,
151
+ char **out, u32 *out_len)
152
+{
153
+ return -ENOENT;
154
+}
155
+#endif /* CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0 */
156
+
110157 #endif /* _SS_SIDTAB_H_ */
111158
112159