From d13bce8908ca5006e5d80d96b77101369393f98b Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Mon, 23 Dec 2019 16:38:36 -0500 Subject: [PATCH] selinux: ensure the policy has been loaded before reading the sidtab stats Check to make sure we have loaded a policy before we query the sidtab's hash stats. Failure to do so could result in a kernel panic/oops due to a dereferenced NULL pointer. Fixes: 66f8e2f03c02 ("selinux: sidtab reverse lookup hash table") Reported-by: kernel test robot Signed-off-by: Paul Moore Signed-off-by: UtsavBalar1231 --- security/selinux/ss/services.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index c0fa912bd925..38f9f27e8908 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -1293,6 +1293,12 @@ int security_sidtab_hash_stats(struct selinux_state *state, char *page) { int rc; + if (!state->initialized) { + pr_err("SELinux: %s: called before initial load_policy\n", + __func__); + return -EINVAL; + } + read_lock(&state->ss->policy_rwlock); rc = sidtab_hash_stats(state->ss->sidtab, page); read_unlock(&state->ss->policy_rwlock);