Skip to content

Commit 581646c

Browse files
cgzonespcmoore
authored andcommitted
selinux: constify source policy in cond_policydb_dup()
cond_policydb_dup() duplicates conditional parts of an existing policy. Declare the source policy const, since it should not be modified. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> [PM: various line length fixups] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 8515417 commit 581646c

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

security/selinux/ss/conditional.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
603603
}
604604
}
605605

606-
static int cond_dup_av_list(struct cond_av_list *new, struct cond_av_list *orig,
606+
static int cond_dup_av_list(struct cond_av_list *new,
607+
const struct cond_av_list *orig,
607608
struct avtab *avtab)
608609
{
609610
u32 i;
@@ -626,7 +627,7 @@ static int cond_dup_av_list(struct cond_av_list *new, struct cond_av_list *orig,
626627
}
627628

628629
static int duplicate_policydb_cond_list(struct policydb *newp,
629-
struct policydb *origp)
630+
const struct policydb *origp)
630631
{
631632
int rc;
632633
u32 i;
@@ -643,7 +644,7 @@ static int duplicate_policydb_cond_list(struct policydb *newp,
643644

644645
for (i = 0; i < origp->cond_list_len; i++) {
645646
struct cond_node *newn = &newp->cond_list[i];
646-
struct cond_node *orign = &origp->cond_list[i];
647+
const struct cond_node *orign = &origp->cond_list[i];
647648

648649
newp->cond_list_len++;
649650

@@ -683,8 +684,8 @@ static int cond_bools_destroy(void *key, void *datum, void *args)
683684
return 0;
684685
}
685686

686-
static int cond_bools_copy(struct hashtab_node *new, struct hashtab_node *orig,
687-
void *args)
687+
static int cond_bools_copy(struct hashtab_node *new,
688+
const struct hashtab_node *orig, void *args)
688689
{
689690
struct cond_bool_datum *datum;
690691

@@ -710,7 +711,7 @@ static int cond_bools_index(void *key, void *datum, void *args)
710711
}
711712

712713
static int duplicate_policydb_bools(struct policydb *newdb,
713-
struct policydb *orig)
714+
const struct policydb *orig)
714715
{
715716
struct cond_bool_datum **cond_bool_array;
716717
int rc;
@@ -743,7 +744,7 @@ void cond_policydb_destroy_dup(struct policydb *p)
743744
cond_policydb_destroy(p);
744745
}
745746

746-
int cond_policydb_dup(struct policydb *new, struct policydb *orig)
747+
int cond_policydb_dup(struct policydb *new, const struct policydb *orig)
747748
{
748749
cond_policydb_init(new);
749750

security/selinux/ss/conditional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
7979
struct extended_perms_decision *xpermd);
8080
void evaluate_cond_nodes(struct policydb *p);
8181
void cond_policydb_destroy_dup(struct policydb *p);
82-
int cond_policydb_dup(struct policydb *new, struct policydb *orig);
82+
int cond_policydb_dup(struct policydb *new, const struct policydb *orig);
8383

8484
#endif /* _CONDITIONAL_H_ */

security/selinux/ss/hashtab.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
136136
}
137137
#endif /* CONFIG_SECURITY_SELINUX_DEBUG */
138138

139-
int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
139+
int hashtab_duplicate(struct hashtab *new, const struct hashtab *orig,
140140
int (*copy)(struct hashtab_node *new,
141-
struct hashtab_node *orig, void *args),
141+
const struct hashtab_node *orig, void *args),
142142
int (*destroy)(void *k, void *d, void *args), void *args)
143143
{
144+
const struct hashtab_node *orig_cur;
144145
struct hashtab_node *cur, *tmp, *tail;
145146
u32 i;
146147
int rc;
@@ -155,12 +156,13 @@ int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
155156

156157
for (i = 0; i < orig->size; i++) {
157158
tail = NULL;
158-
for (cur = orig->htable[i]; cur; cur = cur->next) {
159+
for (orig_cur = orig->htable[i]; orig_cur;
160+
orig_cur = orig_cur->next) {
159161
tmp = kmem_cache_zalloc(hashtab_node_cachep,
160162
GFP_KERNEL);
161163
if (!tmp)
162164
goto error;
163-
rc = copy(tmp, cur, args);
165+
rc = copy(tmp, orig_cur, args);
164166
if (rc) {
165167
kmem_cache_free(hashtab_node_cachep, tmp);
166168
goto error;

security/selinux/ss/hashtab.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ void hashtab_destroy(struct hashtab *h);
136136
int hashtab_map(struct hashtab *h, int (*apply)(void *k, void *d, void *args),
137137
void *args);
138138

139-
int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
139+
int hashtab_duplicate(struct hashtab *new, const struct hashtab *orig,
140140
int (*copy)(struct hashtab_node *new,
141-
struct hashtab_node *orig, void *args),
141+
const struct hashtab_node *orig, void *args),
142142
int (*destroy)(void *k, void *d, void *args), void *args);
143143

144144
#ifdef CONFIG_SECURITY_SELINUX_DEBUG

0 commit comments

Comments
 (0)