Skip to content

Commit 47f2878

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 8e14b42 commit 47f2878

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
@@ -939,7 +939,7 @@ int policydb_load_isids(struct policydb *p, struct sidtab *s)
939939
return 0;
940940
}
941941

942-
int policydb_class_isvalid(struct policydb *p, unsigned int class)
942+
int policydb_class_isvalid(struct policydb *p, u16 class)
943943
{
944944
if (!class || class > p->p_classes.nprim)
945945
return 0;
@@ -2027,7 +2027,8 @@ static int filename_trans_read_helper(struct policydb *p, struct policy_file *fp
20272027
struct filename_trans_key *ft = NULL;
20282028
struct filename_trans_datum **dst, *datum, *first = NULL;
20292029
char *name = NULL;
2030-
u32 len, ttype, tclass, ndatum, i;
2030+
u32 len, ttype, ndatum, i;
2031+
u16 tclass;
20312032
__le32 buf[3];
20322033
int rc;
20332034

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) */
@@ -320,7 +320,7 @@ struct policy_file {
320320
extern void policydb_destroy(struct policydb *p);
321321
extern int policydb_load_isids(struct policydb *p, struct sidtab *s);
322322
extern int policydb_context_isvalid(struct policydb *p, struct context *c);
323-
extern int policydb_class_isvalid(struct policydb *p, unsigned int class);
323+
extern int policydb_class_isvalid(struct policydb *p, u16 class);
324324
extern int policydb_type_isvalid(struct policydb *p, unsigned int type);
325325
extern int policydb_role_isvalid(struct policydb *p, unsigned int role);
326326
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
@@ -3354,7 +3354,7 @@ static int get_classes_callback(void *k, void *d, void *args)
33543354
{
33553355
struct class_datum *datum = d;
33563356
char *name = k, **classes = args;
3357-
u32 value = datum->value - 1;
3357+
u16 value = datum->value - 1;
33583358

33593359
classes[value] = kstrdup(name, GFP_ATOMIC);
33603360
if (!classes[value])

0 commit comments

Comments
 (0)