Skip to content

Commit dee1537

Browse files
cgzonespcmoore
authored andcommitted
selinux: avoid implicit conversions in policydb code
Use the identical type for local variables, e.g. loop counters. Declare members of struct policydb_compat_info unsigned to consistently use unsigned iterators. They hold read-only non-negative numbers in the global variable policydb_compat. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 97842c5 commit dee1537

1 file changed

Lines changed: 37 additions & 32 deletions

File tree

security/selinux/ss/policydb.c

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ static const char *const symtab_name[SYM_NUM] = {
5555
#endif
5656

5757
struct policydb_compat_info {
58-
int version;
59-
int sym_num;
60-
int ocon_num;
58+
unsigned int version;
59+
unsigned int sym_num;
60+
unsigned int ocon_num;
6161
};
6262

6363
/* These need to be updated if SYM_NUM or OCON_NUM changes */
@@ -159,9 +159,9 @@ static const struct policydb_compat_info policydb_compat[] = {
159159
},
160160
};
161161

162-
static const struct policydb_compat_info *policydb_lookup_compat(int version)
162+
static const struct policydb_compat_info *policydb_lookup_compat(unsigned int version)
163163
{
164-
int i;
164+
unsigned int i;
165165

166166
for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) {
167167
if (policydb_compat[i].version == version)
@@ -359,7 +359,7 @@ static int role_tr_destroy(void *key, void *datum, void *p)
359359
return 0;
360360
}
361361

362-
static void ocontext_destroy(struct ocontext *c, int i)
362+
static void ocontext_destroy(struct ocontext *c, unsigned int i)
363363
{
364364
if (!c)
365365
return;
@@ -782,7 +782,7 @@ void policydb_destroy(struct policydb *p)
782782
{
783783
struct ocontext *c, *ctmp;
784784
struct genfs *g, *gtmp;
785-
int i;
785+
u32 i;
786786
struct role_allow *ra, *lra = NULL;
787787

788788
for (i = 0; i < SYM_NUM; i++) {
@@ -1128,8 +1128,8 @@ static int common_read(struct policydb *p, struct symtab *s, void *fp)
11281128
char *key = NULL;
11291129
struct common_datum *comdatum;
11301130
__le32 buf[4];
1131-
u32 len, nel;
1132-
int i, rc;
1131+
u32 i, len, nel;
1132+
int rc;
11331133

11341134
comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL);
11351135
if (!comdatum)
@@ -1194,13 +1194,13 @@ static int type_set_read(struct type_set *t, void *fp)
11941194

11951195
static int read_cons_helper(struct policydb *p,
11961196
struct constraint_node **nodep,
1197-
int ncons, int allowxtarget, void *fp)
1197+
u32 ncons, int allowxtarget, void *fp)
11981198
{
11991199
struct constraint_node *c, *lc;
12001200
struct constraint_expr *e, *le;
12011201
__le32 buf[3];
1202-
u32 nexpr;
1203-
int rc, i, j, depth;
1202+
u32 i, j, nexpr;
1203+
int rc, depth;
12041204

12051205
lc = NULL;
12061206
for (i = 0; i < ncons; i++) {
@@ -1292,8 +1292,8 @@ static int class_read(struct policydb *p, struct symtab *s, void *fp)
12921292
char *key = NULL;
12931293
struct class_datum *cladatum;
12941294
__le32 buf[6];
1295-
u32 len, len2, ncons, nel;
1296-
int i, rc;
1295+
u32 i, len, len2, ncons, nel;
1296+
int rc;
12971297

12981298
cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL);
12991299
if (!cladatum)
@@ -1386,7 +1386,8 @@ static int role_read(struct policydb *p, struct symtab *s, void *fp)
13861386
{
13871387
char *key = NULL;
13881388
struct role_datum *role;
1389-
int rc, to_read = 2;
1389+
int rc;
1390+
unsigned int to_read = 2;
13901391
__le32 buf[3];
13911392
u32 len;
13921393

@@ -1442,7 +1443,8 @@ static int type_read(struct policydb *p, struct symtab *s, void *fp)
14421443
{
14431444
char *key = NULL;
14441445
struct type_datum *typdatum;
1445-
int rc, to_read = 3;
1446+
int rc;
1447+
unsigned int to_read = 3;
14461448
__le32 buf[4];
14471449
u32 len;
14481450

@@ -1516,7 +1518,8 @@ static int user_read(struct policydb *p, struct symtab *s, void *fp)
15161518
{
15171519
char *key = NULL;
15181520
struct user_datum *usrdatum;
1519-
int rc, to_read = 2;
1521+
int rc;
1522+
unsigned int to_read = 2;
15201523
__le32 buf[3];
15211524
u32 len;
15221525

@@ -1657,7 +1660,7 @@ static int user_bounds_sanity_check(void *key, void *datum, void *datap)
16571660
upper = user = datum;
16581661
while (upper->bounds) {
16591662
struct ebitmap_node *node;
1660-
unsigned long bit;
1663+
u32 bit;
16611664

16621665
if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
16631666
pr_err("SELinux: user %s: "
@@ -1693,7 +1696,7 @@ static int role_bounds_sanity_check(void *key, void *datum, void *datap)
16931696
upper = role = datum;
16941697
while (upper->bounds) {
16951698
struct ebitmap_node *node;
1696-
unsigned long bit;
1699+
u32 bit;
16971700

16981701
if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
16991702
pr_err("SELinux: role %s: "
@@ -1808,9 +1811,9 @@ static int range_read(struct policydb *p, void *fp)
18081811
{
18091812
struct range_trans *rt = NULL;
18101813
struct mls_range *r = NULL;
1811-
int i, rc;
1814+
int rc;
18121815
__le32 buf[2];
1813-
u32 nel;
1816+
u32 i, nel;
18141817

18151818
if (p->policyvers < POLICYDB_VERSION_MLS)
18161819
return 0;
@@ -2056,9 +2059,9 @@ static int filename_trans_read_helper(struct policydb *p, void *fp)
20562059

20572060
static int filename_trans_read(struct policydb *p, void *fp)
20582061
{
2059-
u32 nel;
2062+
u32 nel, i;
20602063
__le32 buf[1];
2061-
int rc, i;
2064+
int rc;
20622065

20632066
if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
20642067
return 0;
@@ -2097,8 +2100,8 @@ static int filename_trans_read(struct policydb *p, void *fp)
20972100

20982101
static int genfs_read(struct policydb *p, void *fp)
20992102
{
2100-
int i, j, rc;
2101-
u32 nel, nel2, len, len2;
2103+
int rc;
2104+
u32 i, j, nel, nel2, len, len2;
21022105
__le32 buf[1];
21032106
struct ocontext *l, *c;
21042107
struct ocontext *newc = NULL;
@@ -2211,8 +2214,9 @@ static int genfs_read(struct policydb *p, void *fp)
22112214
static int ocontext_read(struct policydb *p, const struct policydb_compat_info *info,
22122215
void *fp)
22132216
{
2214-
int i, j, rc;
2215-
u32 nel, len;
2217+
int rc;
2218+
unsigned int i;
2219+
u32 j, nel, len;
22162220
__be64 prefixbuf[1];
22172221
__le32 buf[3];
22182222
struct ocontext *l, *c;
@@ -2403,9 +2407,9 @@ int policydb_read(struct policydb *p, void *fp)
24032407
struct role_allow *ra, *lra;
24042408
struct role_trans_key *rtk = NULL;
24052409
struct role_trans_datum *rtd = NULL;
2406-
int i, j, rc;
2410+
int rc;
24072411
__le32 buf[4];
2408-
u32 len, nprim, nel, perm;
2412+
u32 i, j, len, nprim, nel, perm;
24092413

24102414
char *policydb_str;
24112415
const struct policydb_compat_info *info;
@@ -3256,7 +3260,8 @@ static int (*const write_f[SYM_NUM]) (void *key, void *datum, void *datap) = {
32563260
static int ocontext_write(struct policydb *p, const struct policydb_compat_info *info,
32573261
void *fp)
32583262
{
3259-
unsigned int i, j, rc;
3263+
unsigned int i, j;
3264+
int rc;
32603265
size_t nel, len;
32613266
__be64 prefixbuf[1];
32623267
__le32 buf[3];
@@ -3605,10 +3610,10 @@ static int filename_trans_write(struct policydb *p, void *fp)
36053610
*/
36063611
int policydb_write(struct policydb *p, void *fp)
36073612
{
3608-
unsigned int i, num_syms;
3613+
unsigned int num_syms;
36093614
int rc;
36103615
__le32 buf[4];
3611-
u32 config;
3616+
u32 config, i;
36123617
size_t len;
36133618
const struct policydb_compat_info *info;
36143619

0 commit comments

Comments
 (0)