Skip to content

Commit df9d474

Browse files
cgzonespcmoore
authored andcommitted
selinux: avoid implicit conversions in avtab code
Return u32 from avtab_hash() instead of int, since the hashing is done on u32 and the result is used as an index on the hash array. Use the type of the limit in for loops. Avoid signed to unsigned conversion of multiplication result in avtab_hash_eval() and perform multiplication in destination type. Use unsigned loop iterator for index operations, to avoid sign extension. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 817199e commit df9d474

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

security/selinux/ss/avtab.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static struct kmem_cache *avtab_xperms_cachep __ro_after_init;
2929
/* Based on MurmurHash3, written by Austin Appleby and placed in the
3030
* public domain.
3131
*/
32-
static inline int avtab_hash(const struct avtab_key *keyp, u32 mask)
32+
static inline u32 avtab_hash(const struct avtab_key *keyp, u32 mask)
3333
{
3434
static const u32 c1 = 0xcc9e2d51;
3535
static const u32 c2 = 0x1b873593;
@@ -66,7 +66,7 @@ static inline int avtab_hash(const struct avtab_key *keyp, u32 mask)
6666
}
6767

6868
static struct avtab_node*
69-
avtab_insert_node(struct avtab *h, int hvalue,
69+
avtab_insert_node(struct avtab *h, u32 hvalue,
7070
struct avtab_node *prev,
7171
const struct avtab_key *key, const struct avtab_datum *datum)
7272
{
@@ -106,7 +106,7 @@ avtab_insert_node(struct avtab *h, int hvalue,
106106
static int avtab_insert(struct avtab *h, const struct avtab_key *key,
107107
const struct avtab_datum *datum)
108108
{
109-
int hvalue;
109+
u32 hvalue;
110110
struct avtab_node *prev, *cur, *newnode;
111111
u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
112112

@@ -152,7 +152,7 @@ struct avtab_node *avtab_insert_nonunique(struct avtab *h,
152152
const struct avtab_key *key,
153153
const struct avtab_datum *datum)
154154
{
155-
int hvalue;
155+
u32 hvalue;
156156
struct avtab_node *prev, *cur;
157157
u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
158158

@@ -186,7 +186,7 @@ struct avtab_node *avtab_insert_nonunique(struct avtab *h,
186186
struct avtab_node *avtab_search_node(struct avtab *h,
187187
const struct avtab_key *key)
188188
{
189-
int hvalue;
189+
u32 hvalue;
190190
struct avtab_node *cur;
191191
u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD);
192192

@@ -246,7 +246,7 @@ avtab_search_node_next(struct avtab_node *node, u16 specified)
246246

247247
void avtab_destroy(struct avtab *h)
248248
{
249-
int i;
249+
u32 i;
250250
struct avtab_node *cur, *temp;
251251

252252
if (!h)
@@ -325,7 +325,7 @@ int avtab_alloc_dup(struct avtab *new, const struct avtab *orig)
325325
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
326326
void avtab_hash_eval(struct avtab *h, const char *tag)
327327
{
328-
int i, chain_len, slots_used, max_chain_len;
328+
u32 i, chain_len, slots_used, max_chain_len;
329329
unsigned long long chain2_len_sum;
330330
struct avtab_node *cur;
331331

@@ -344,7 +344,7 @@ void avtab_hash_eval(struct avtab *h, const char *tag)
344344

345345
if (chain_len > max_chain_len)
346346
max_chain_len = chain_len;
347-
chain2_len_sum += chain_len * chain_len;
347+
chain2_len_sum += (unsigned long long)chain_len * chain_len;
348348
}
349349
}
350350

@@ -374,13 +374,13 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
374374
{
375375
__le16 buf16[4];
376376
u16 enabled;
377-
u32 items, items2, val, vers = pol->policyvers;
377+
u32 items, items2, val, i;
378378
struct avtab_key key;
379379
struct avtab_datum datum;
380380
struct avtab_extended_perms xperms;
381381
__le32 buf32[ARRAY_SIZE(xperms.perms.p)];
382-
int i, rc;
383-
unsigned set;
382+
int rc;
383+
unsigned int set, vers = pol->policyvers;
384384

385385
memset(&key, 0, sizeof(struct avtab_key));
386386
memset(&datum, 0, sizeof(struct avtab_datum));
@@ -616,7 +616,7 @@ int avtab_write_item(struct policydb *p, const struct avtab_node *cur, void *fp)
616616

617617
int avtab_write(struct policydb *p, struct avtab *a, void *fp)
618618
{
619-
unsigned int i;
619+
u32 i;
620620
int rc = 0;
621621
struct avtab_node *cur;
622622
__le32 buf[1];

0 commit comments

Comments
 (0)