Skip to content

Commit 0fd0b4f

Browse files
cgzonespcmoore
authored andcommitted
selinux: dump statistics for more hash tables
Dump in the SELinux debug configuration the statistics for the conditional rules avtab, the role transition, and class and common permission hash tables. Signed-off-by: Christian Göttsche <[email protected]> [PM: style fixes] Signed-off-by: Paul Moore <[email protected]>
1 parent cdc12eb commit 0fd0b4f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

security/selinux/ss/conditional.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ int cond_init_bool_indexes(struct policydb *p)
169169
p->p_bools.nprim, sizeof(*p->bool_val_to_struct), GFP_KERNEL);
170170
if (!p->bool_val_to_struct)
171171
return -ENOMEM;
172+
173+
avtab_hash_eval(&p->te_cond_avtab, "conditional_rules");
174+
172175
return 0;
173176
}
174177

security/selinux/ss/policydb.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,16 @@ static int (*const index_f[SYM_NUM])(void *key, void *datum, void *datap) = {
672672
/* clang-format on */
673673

674674
#ifdef CONFIG_SECURITY_SELINUX_DEBUG
675-
static void hash_eval(struct hashtab *h, const char *hash_name)
675+
static void hash_eval(struct hashtab *h, const char *hash_name,
676+
const char *hash_details)
676677
{
677678
struct hashtab_info info;
678679

679680
hashtab_stat(h, &info);
680681
pr_debug(
681-
"SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d, sum of chain length^2 %llu\n",
682-
hash_name, h->nel, info.slots_used, h->size, info.max_chain_len,
682+
"SELinux: %s%s%s: %d entries and %d/%d buckets used, longest chain length %d, sum of chain length^2 %llu\n",
683+
hash_name, hash_details ? "@" : "", hash_details ?: "", h->nel,
684+
info.slots_used, h->size, info.max_chain_len,
683685
info.chain2_len_sum);
684686
}
685687

@@ -688,11 +690,12 @@ static void symtab_hash_eval(struct symtab *s)
688690
int i;
689691

690692
for (i = 0; i < SYM_NUM; i++)
691-
hash_eval(&s[i].table, symtab_name[i]);
693+
hash_eval(&s[i].table, symtab_name[i], NULL);
692694
}
693695

694696
#else
695-
static inline void hash_eval(struct hashtab *h, const char *hash_name)
697+
static inline void hash_eval(struct hashtab *h, const char *hash_name,
698+
const char *hash_details)
696699
{
697700
}
698701
static inline void symtab_hash_eval(struct symtab *s)
@@ -1178,6 +1181,8 @@ static int common_read(struct policydb *p, struct symtab *s, void *fp)
11781181
goto bad;
11791182
}
11801183

1184+
hash_eval(&comdatum->permissions.table, "common_permissions", key);
1185+
11811186
rc = symtab_insert(s, key, comdatum);
11821187
if (rc)
11831188
goto bad;
@@ -1358,6 +1363,8 @@ static int class_read(struct policydb *p, struct symtab *s, void *fp)
13581363
goto bad;
13591364
}
13601365

1366+
hash_eval(&cladatum->permissions.table, "class_permissions", key);
1367+
13611368
rc = read_cons_helper(p, &cladatum->constraints, ncons, 0, fp);
13621369
if (rc)
13631370
goto bad;
@@ -1898,7 +1905,7 @@ static int range_read(struct policydb *p, void *fp)
18981905
rt = NULL;
18991906
r = NULL;
19001907
}
1901-
hash_eval(&p->range_tr, "rangetr");
1908+
hash_eval(&p->range_tr, "rangetr", NULL);
19021909
rc = 0;
19031910
out:
19041911
kfree(rt);
@@ -2116,7 +2123,7 @@ static int filename_trans_read(struct policydb *p, void *fp)
21162123
return rc;
21172124
}
21182125
}
2119-
hash_eval(&p->filename_trans, "filenametr");
2126+
hash_eval(&p->filename_trans, "filenametr", NULL);
21202127
return 0;
21212128
}
21222129

@@ -2649,6 +2656,8 @@ int policydb_read(struct policydb *p, void *fp)
26492656
rtd = NULL;
26502657
}
26512658

2659+
hash_eval(&p->role_tr, "roletr", NULL);
2660+
26522661
rc = next_entry(buf, fp, sizeof(u32));
26532662
if (rc)
26542663
goto bad;

0 commit comments

Comments
 (0)