diff mbox series

selinux: ensure the policy has been loaded before reading the sidtab stats

Message ID 157714208320.505827.13006028554511851520.stgit@chester (mailing list archive)
State Accepted
Headers show
Series selinux: ensure the policy has been loaded before reading the sidtab stats | expand

Commit Message

Paul Moore Dec. 23, 2019, 11:01 p.m. UTC
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 <lkp@intel.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
---
 security/selinux/ss/services.c |    6 ++++++
 1 file changed, 6 insertions(+)

Comments

Paul Moore Dec. 23, 2019, 11:03 p.m. UTC | #1
On Mon, Dec 23, 2019 at 6:01 PM Paul Moore <paul@paul-moore.com> wrote:
>
> 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 <lkp@intel.com>
> Signed-off-by: Paul Moore <paul@paul-moore.com>
> ---
>  security/selinux/ss/services.c |    6 ++++++
>  1 file changed, 6 insertions(+)

Merged into selinux/next.
diff mbox series

Patch

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 743b85ede4ef..c9e38f1ede02 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1286,6 +1286,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);