Commit bb242497474da317a7169cc939c741ccf2e79e8c
Committed by
James Morris
1 parent
5c45899879
Exists in
master
and in
7 other branches
SELinux: ensure keys constant in hashtab_search
Makes the key argument passed into hashtab_search and all the functions it calls constant. These functions include hash table function pointers hash_value and keycmp. The only implementations of these currently are symhash and symcmp, which do not modify the key. The key parameter should never be changed by any of these, so it should be const. This is necessary to allow calling these functions with keys found in kernel object class and permission definitions. Signed-off-by: Chad Sellers <csellers@tresys.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: James Morris <jmorris@namei.org>
Showing 3 changed files with 12 additions and 12 deletions Side-by-side Diff
security/selinux/ss/hashtab.c
... | ... | @@ -8,8 +8,8 @@ |
8 | 8 | #include <linux/errno.h> |
9 | 9 | #include "hashtab.h" |
10 | 10 | |
11 | -struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, void *key), | |
12 | - int (*keycmp)(struct hashtab *h, void *key1, void *key2), | |
11 | +struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void *key), | |
12 | + int (*keycmp)(struct hashtab *h, const void *key1, const void *key2), | |
13 | 13 | u32 size) |
14 | 14 | { |
15 | 15 | struct hashtab *p; |
... | ... | @@ -71,7 +71,7 @@ |
71 | 71 | return 0; |
72 | 72 | } |
73 | 73 | |
74 | -void *hashtab_search(struct hashtab *h, void *key) | |
74 | +void *hashtab_search(struct hashtab *h, const void *key) | |
75 | 75 | { |
76 | 76 | u32 hvalue; |
77 | 77 | struct hashtab_node *cur; |
security/selinux/ss/hashtab.h
... | ... | @@ -22,9 +22,9 @@ |
22 | 22 | struct hashtab_node **htable; /* hash table */ |
23 | 23 | u32 size; /* number of slots in hash table */ |
24 | 24 | u32 nel; /* number of elements in hash table */ |
25 | - u32 (*hash_value)(struct hashtab *h, void *key); | |
25 | + u32 (*hash_value)(struct hashtab *h, const void *key); | |
26 | 26 | /* hash function */ |
27 | - int (*keycmp)(struct hashtab *h, void *key1, void *key2); | |
27 | + int (*keycmp)(struct hashtab *h, const void *key1, const void *key2); | |
28 | 28 | /* key comparison function */ |
29 | 29 | }; |
30 | 30 | |
... | ... | @@ -39,8 +39,8 @@ |
39 | 39 | * Returns NULL if insufficent space is available or |
40 | 40 | * the new hash table otherwise. |
41 | 41 | */ |
42 | -struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, void *key), | |
43 | - int (*keycmp)(struct hashtab *h, void *key1, void *key2), | |
42 | +struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void *key), | |
43 | + int (*keycmp)(struct hashtab *h, const void *key1, const void *key2), | |
44 | 44 | u32 size); |
45 | 45 | |
46 | 46 | /* |
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | * Returns NULL if no entry has the specified key or |
60 | 60 | * the datum of the entry otherwise. |
61 | 61 | */ |
62 | -void *hashtab_search(struct hashtab *h, void *k); | |
62 | +void *hashtab_search(struct hashtab *h, const void *k); | |
63 | 63 | |
64 | 64 | /* |
65 | 65 | * Destroys the specified hash table. |
security/selinux/ss/symtab.c
... | ... | @@ -9,9 +9,9 @@ |
9 | 9 | #include <linux/errno.h> |
10 | 10 | #include "symtab.h" |
11 | 11 | |
12 | -static unsigned int symhash(struct hashtab *h, void *key) | |
12 | +static unsigned int symhash(struct hashtab *h, const void *key) | |
13 | 13 | { |
14 | - char *p, *keyp; | |
14 | + const char *p, *keyp; | |
15 | 15 | unsigned int size; |
16 | 16 | unsigned int val; |
17 | 17 | |
18 | 18 | |
... | ... | @@ -23,9 +23,9 @@ |
23 | 23 | return val & (h->size - 1); |
24 | 24 | } |
25 | 25 | |
26 | -static int symcmp(struct hashtab *h, void *key1, void *key2) | |
26 | +static int symcmp(struct hashtab *h, const void *key1, const void *key2) | |
27 | 27 | { |
28 | - char *keyp1, *keyp2; | |
28 | + const char *keyp1, *keyp2; | |
29 | 29 | |
30 | 30 | keyp1 = key1; |
31 | 31 | keyp2 = key2; |