Commit f01dd590 authored by Christian Göttsche's avatar Christian Göttsche Committed by Paul Moore

selinux: move debug functions into debug configuration

avtab_hash_eval() and hashtab_stat() are only used in policydb.c when
the configuration SECURITY_SELINUX_DEBUG is enabled.

Move the function definitions under that configuration as well and
provide empty definitions in case SECURITY_SELINUX_DEBUG is disabled, to
avoid using #ifdef in the callers.
Signed-off-by: default avatarChristian Göttsche <cgzones@googlemail.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent 19c5b015
...@@ -322,6 +322,7 @@ int avtab_alloc_dup(struct avtab *new, const struct avtab *orig) ...@@ -322,6 +322,7 @@ int avtab_alloc_dup(struct avtab *new, const struct avtab *orig)
return avtab_alloc_common(new, orig->nslot); return avtab_alloc_common(new, orig->nslot);
} }
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
void avtab_hash_eval(struct avtab *h, const char *tag) void avtab_hash_eval(struct avtab *h, const char *tag)
{ {
int i, chain_len, slots_used, max_chain_len; int i, chain_len, slots_used, max_chain_len;
...@@ -352,6 +353,7 @@ void avtab_hash_eval(struct avtab *h, const char *tag) ...@@ -352,6 +353,7 @@ void avtab_hash_eval(struct avtab *h, const char *tag)
tag, h->nel, slots_used, h->nslot, max_chain_len, tag, h->nel, slots_used, h->nslot, max_chain_len,
chain2_len_sum); chain2_len_sum);
} }
#endif /* CONFIG_SECURITY_SELINUX_DEBUG */
static const uint16_t spec_order[] = { static const uint16_t spec_order[] = {
AVTAB_ALLOWED, AVTAB_ALLOWED,
......
...@@ -91,7 +91,14 @@ void avtab_init(struct avtab *h); ...@@ -91,7 +91,14 @@ void avtab_init(struct avtab *h);
int avtab_alloc(struct avtab *, u32); int avtab_alloc(struct avtab *, u32);
int avtab_alloc_dup(struct avtab *new, const struct avtab *orig); int avtab_alloc_dup(struct avtab *new, const struct avtab *orig);
void avtab_destroy(struct avtab *h); void avtab_destroy(struct avtab *h);
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
void avtab_hash_eval(struct avtab *h, const char *tag); void avtab_hash_eval(struct avtab *h, const char *tag);
#else
static inline void avtab_hash_eval(struct avtab *h, const char *tag)
{
}
#endif
struct policydb; struct policydb;
int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
......
...@@ -103,7 +103,7 @@ int hashtab_map(struct hashtab *h, ...@@ -103,7 +103,7 @@ int hashtab_map(struct hashtab *h,
return 0; return 0;
} }
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
void hashtab_stat(struct hashtab *h, struct hashtab_info *info) void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
{ {
u32 i, chain_len, slots_used, max_chain_len; u32 i, chain_len, slots_used, max_chain_len;
...@@ -129,6 +129,7 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info) ...@@ -129,6 +129,7 @@ void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
info->slots_used = slots_used; info->slots_used = slots_used;
info->max_chain_len = max_chain_len; info->max_chain_len = max_chain_len;
} }
#endif /* CONFIG_SECURITY_SELINUX_DEBUG */
int hashtab_duplicate(struct hashtab *new, struct hashtab *orig, int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
int (*copy)(struct hashtab_node *new, int (*copy)(struct hashtab_node *new,
......
...@@ -142,7 +142,13 @@ int hashtab_duplicate(struct hashtab *new, struct hashtab *orig, ...@@ -142,7 +142,13 @@ int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
int (*destroy)(void *k, void *d, void *args), int (*destroy)(void *k, void *d, void *args),
void *args); void *args);
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
/* Fill info with some hash table statistics */ /* Fill info with some hash table statistics */
void hashtab_stat(struct hashtab *h, struct hashtab_info *info); void hashtab_stat(struct hashtab *h, struct hashtab_info *info);
#else
static inline void hashtab_stat(struct hashtab *h, struct hashtab_info *info)
{
}
#endif
#endif /* _SS_HASHTAB_H */ #endif /* _SS_HASHTAB_H */
...@@ -701,6 +701,9 @@ static void symtab_hash_eval(struct symtab *s) ...@@ -701,6 +701,9 @@ static void symtab_hash_eval(struct symtab *s)
static inline void hash_eval(struct hashtab *h, const char *hash_name) static inline void hash_eval(struct hashtab *h, const char *hash_name)
{ {
} }
static inline void symtab_hash_eval(struct symtab *s)
{
}
#endif /* CONFIG_SECURITY_SELINUX_DEBUG */ #endif /* CONFIG_SECURITY_SELINUX_DEBUG */
/* /*
...@@ -725,10 +728,8 @@ static int policydb_index(struct policydb *p) ...@@ -725,10 +728,8 @@ static int policydb_index(struct policydb *p)
pr_debug("SELinux: %d classes, %d rules\n", pr_debug("SELinux: %d classes, %d rules\n",
p->p_classes.nprim, p->te_avtab.nel); p->p_classes.nprim, p->te_avtab.nel);
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
avtab_hash_eval(&p->te_avtab, "rules"); avtab_hash_eval(&p->te_avtab, "rules");
symtab_hash_eval(p->symtab); symtab_hash_eval(p->symtab);
#endif
p->class_val_to_struct = kcalloc(p->p_classes.nprim, p->class_val_to_struct = kcalloc(p->p_classes.nprim,
sizeof(*p->class_val_to_struct), sizeof(*p->class_val_to_struct),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment