hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/selinux/ss/policydb.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * A policy database (policydb) specifies the
34 * configuration data for the security policy.
....@@ -16,15 +17,10 @@
1617 *
1718 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
1819 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
19
- * This program is free software; you can redistribute it and/or modify
20
- * it under the terms of the GNU General Public License as published by
21
- * the Free Software Foundation, version 2.
2220 */
2321
2422 #ifndef _SS_POLICYDB_H_
2523 #define _SS_POLICYDB_H_
26
-
27
-#include <linux/flex_array.h>
2824
2925 #include "symtab.h"
3026 #include "avtab.h"
....@@ -73,6 +69,7 @@
7369 #define DEFAULT_TARGET_LOW 4
7470 #define DEFAULT_TARGET_HIGH 5
7571 #define DEFAULT_TARGET_LOW_HIGH 6
72
+#define DEFAULT_GLBLUB 7
7673 char default_range;
7774 };
7875
....@@ -84,23 +81,26 @@
8481 struct ebitmap types; /* set of authorized types for role */
8582 };
8683
87
-struct role_trans {
84
+struct role_trans_key {
8885 u32 role; /* current role */
8986 u32 type; /* program executable type, or new object type */
9087 u32 tclass; /* process class, or new object class */
91
- u32 new_role; /* new role */
92
- struct role_trans *next;
9388 };
9489
95
-struct filename_trans {
96
- u32 stype; /* current process */
90
+struct role_trans_datum {
91
+ u32 new_role; /* new role */
92
+};
93
+
94
+struct filename_trans_key {
9795 u32 ttype; /* parent dir context */
9896 u16 tclass; /* class of new object */
9997 const char *name; /* last path component */
10098 };
10199
102100 struct filename_trans_datum {
103
- u32 otype; /* expected of new object */
101
+ struct ebitmap stypes; /* bitmap of source types for this otype */
102
+ u32 otype; /* resulting type of new object */
103
+ struct filename_trans_datum *next; /* record for next otype*/
104104 };
105105
106106 struct role_allow {
....@@ -253,32 +253,35 @@
253253 #define p_cats symtab[SYM_CATS]
254254
255255 /* symbol names indexed by (value - 1) */
256
- struct flex_array *sym_val_to_name[SYM_NUM];
256
+ char **sym_val_to_name[SYM_NUM];
257257
258258 /* class, role, and user attributes indexed by (value - 1) */
259259 struct class_datum **class_val_to_struct;
260260 struct role_datum **role_val_to_struct;
261261 struct user_datum **user_val_to_struct;
262
- struct flex_array *type_val_to_struct_array;
262
+ struct type_datum **type_val_to_struct;
263263
264264 /* type enforcement access vectors and transitions */
265265 struct avtab te_avtab;
266266
267267 /* role transitions */
268
- struct role_trans *role_tr;
268
+ struct hashtab role_tr;
269269
270270 /* file transitions with the last path component */
271271 /* quickly exclude lookups when parent ttype has no rules */
272272 struct ebitmap filename_trans_ttypes;
273273 /* actual set of filename_trans rules */
274
- struct hashtab *filename_trans;
274
+ struct hashtab filename_trans;
275
+ /* only used if policyvers < POLICYDB_VERSION_COMP_FTRANS */
276
+ u32 compat_filename_trans_count;
275277
276278 /* bools indexed by (value - 1) */
277279 struct cond_bool_datum **bool_val_to_struct;
278280 /* type enforcement conditional access vectors and transitions */
279281 struct avtab te_cond_avtab;
280
- /* linked list indexing te_cond_avtab by conditional */
282
+ /* array indexing te_cond_avtab by conditional */
281283 struct cond_node *cond_list;
284
+ u32 cond_list_len;
282285
283286 /* role allows */
284287 struct role_allow *role_allow;
....@@ -293,10 +296,10 @@
293296 struct genfs *genfs;
294297
295298 /* range transitions table (range_trans_key -> mls_range) */
296
- struct hashtab *range_tr;
299
+ struct hashtab range_tr;
297300
298301 /* type -> attribute reverse mapping */
299
- struct flex_array *type_attr_map_array;
302
+ struct ebitmap *type_attr_map_array;
300303
301304 struct ebitmap policycaps;
302305
....@@ -312,7 +315,7 @@
312315
313316 u16 process_class;
314317 u32 process_trans_perms;
315
-};
318
+} __randomize_layout;
316319
317320 extern void policydb_destroy(struct policydb *p);
318321 extern int policydb_load_isids(struct policydb *p, struct sidtab *s);
....@@ -323,7 +326,14 @@
323326 extern int policydb_read(struct policydb *p, void *fp);
324327 extern int policydb_write(struct policydb *p, void *fp);
325328
326
-#define PERM_SYMTAB_SIZE 32
329
+extern struct filename_trans_datum *policydb_filenametr_search(
330
+ struct policydb *p, struct filename_trans_key *key);
331
+
332
+extern struct mls_range *policydb_rangetr_search(
333
+ struct policydb *p, struct range_trans *key);
334
+
335
+extern struct role_trans_datum *policydb_roletr_search(
336
+ struct policydb *p, struct role_trans_key *key);
327337
328338 #define POLICYDB_CONFIG_MLS 1
329339 #define POLICYDB_CONFIG_ANDROID_NETLINK_ROUTE (1 << 31)
....@@ -364,6 +374,8 @@
364374 {
365375 size_t len = bytes * num;
366376
377
+ if (len > fp->len)
378
+ return -EINVAL;
367379 memcpy(fp->data, buf, len);
368380 fp->data += len;
369381 fp->len -= len;
....@@ -373,9 +385,7 @@
373385
374386 static inline char *sym_name(struct policydb *p, unsigned int sym_num, unsigned int element_nr)
375387 {
376
- struct flex_array *fa = p->sym_val_to_name[sym_num];
377
-
378
- return flex_array_get_ptr(fa, element_nr);
388
+ return p->sym_val_to_name[sym_num][element_nr];
379389 }
380390
381391 extern u16 string_to_security_class(struct policydb *p, const char *name);