Skip to content

Commit 4ac3cc8

Browse files
cgzonesgregkh
authored andcommitted
selinux: use u16 for security classes
[ Upstream commit fa79a59 ] Security class identifiers are limited to 2^16, thus use the appropriate type u16 consistently. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com> (cherry picked from commit fa79a59) Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 71ecdc1 commit 4ac3cc8

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

security/selinux/ss/policydb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ int policydb_load_isids(struct policydb *p, struct sidtab *s)
951951
return 0;
952952
}
953953

954-
int policydb_class_isvalid(struct policydb *p, unsigned int class)
954+
int policydb_class_isvalid(struct policydb *p, u16 class)
955955
{
956956
if (!class || class > p->p_classes.nprim)
957957
return 0;
@@ -2039,7 +2039,8 @@ static int filename_trans_read_helper(struct policydb *p, struct policy_file *fp
20392039
struct filename_trans_key *ft = NULL;
20402040
struct filename_trans_datum **dst, *datum, *first = NULL;
20412041
char *name = NULL;
2042-
u32 len, ttype, tclass, ndatum, i;
2042+
u32 len, ttype, ndatum, i;
2043+
u16 tclass;
20432044
__le32 buf[3];
20442045
int rc;
20452046

security/selinux/ss/policydb.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct common_datum {
4848

4949
/* Class attributes */
5050
struct class_datum {
51-
u32 value; /* class value */
51+
u16 value; /* class value */
5252
char *comkey; /* common name */
5353
struct common_datum *comdatum; /* common datum */
5454
struct symtab permissions; /* class-specific permission symbol table */
@@ -82,7 +82,7 @@ struct role_datum {
8282
struct role_trans_key {
8383
u32 role; /* current role */
8484
u32 type; /* program executable type, or new object type */
85-
u32 tclass; /* process class, or new object class */
85+
u16 tclass; /* process class, or new object class */
8686
};
8787

8888
struct role_trans_datum {
@@ -139,7 +139,7 @@ struct cat_datum {
139139
struct range_trans {
140140
u32 source_type;
141141
u32 target_type;
142-
u32 target_class;
142+
u16 target_class;
143143
};
144144

145145
/* Boolean data type */
@@ -195,7 +195,7 @@ struct ocontext {
195195
} ibendport;
196196
} u;
197197
union {
198-
u32 sclass; /* security class for genfs */
198+
u16 sclass; /* security class for genfs */
199199
u32 behavior; /* labeling behavior for fs_use */
200200
} v;
201201
struct context context[2]; /* security context(s) */
@@ -322,7 +322,7 @@ struct policy_file {
322322
extern void policydb_destroy(struct policydb *p);
323323
extern int policydb_load_isids(struct policydb *p, struct sidtab *s);
324324
extern int policydb_context_isvalid(struct policydb *p, struct context *c);
325-
extern int policydb_class_isvalid(struct policydb *p, unsigned int class);
325+
extern int policydb_class_isvalid(struct policydb *p, u16 class);
326326
extern int policydb_type_isvalid(struct policydb *p, unsigned int type);
327327
extern int policydb_role_isvalid(struct policydb *p, unsigned int role);
328328
extern int policydb_read(struct policydb *p, struct policy_file *fp);

security/selinux/ss/services.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,7 @@ static int get_classes_callback(void *k, void *d, void *args)
32903290
{
32913291
struct class_datum *datum = d;
32923292
char *name = k, **classes = args;
3293-
u32 value = datum->value - 1;
3293+
u16 value = datum->value - 1;
32943294

32953295
classes[value] = kstrdup(name, GFP_ATOMIC);
32963296
if (!classes[value])

0 commit comments

Comments
 (0)