selinux: avoid dereferencing the policy prior to initialization
authorStephen Smalley <stephen.smalley.work@gmail.com>
Wed, 19 Aug 2020 13:45:41 +0000 (09:45 -0400)
committerPaul Moore <paul@paul-moore.com>
Thu, 20 Aug 2020 01:14:41 +0000 (21:14 -0400)
commit37ea433c66070fcef09c6d118492c36299eb72ba
treed3f5cbcd0fdd69e2ecfe1ce597b16b60751a1dd3
parent69ea651c40f7f08962d440a0486fd0212be74b73
selinux: avoid dereferencing the policy prior to initialization

Certain SELinux security server functions (e.g. security_port_sid,
called during bind) were not explicitly testing to see if SELinux
has been initialized (i.e. initial policy loaded) and handling
the no-policy-loaded case.  In the past this happened to work
because the policydb was statically allocated and could always
be accessed, but with the recent encapsulation of policy state
and conversion to dynamic allocation, we can no longer access
the policy state prior to initialization.  Add a test of
!selinux_initialized(state) to all of the exported functions that
were missing them and handle appropriately.

Fixes: 461698026ffa ("selinux: encapsulate policy state, refactor policy load")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Tested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/services.c