platform_external_selinux/checkpolicy
Stephen Smalley 8677ce5e8f libsepol,checkpolicy: support omitting unused initial sid contexts
Remove restrictions in libsepol and checkpolicy that required all
declared initial SIDs to be assigned a context.  With this patch,
it is possible to build and load a policy that drops the sid <sidname>
<context> declarations for the unused initial SIDs.  It is still
required to retain the sid <sidname> declarations (in the flask
definitions) in order to preserve the initial SID ordering/values.
The unused initial SIDs can be renamed, e.g. to add an unused_
prefix or similar, if desired, since the names used in the policy
are not stored in the kernel binary policy.

In CIL policies, the (sid ...) and (sidorder (...)) statements
must be left intact for compatibility but the (sidcontext ...)
statements for the unused initial SIDs can be omitted after this change.

With current kernels, if one removes an unused initial SID context
from policy, builds policy with this change applied and loads the
policy into the kernel, cat /sys/fs/selinux/initial_contexts/<sidname>
will show the unlabeled context.  With the kernel patch to remove unused
initial SIDs, the /sys/fs/selinux/initial_contexts/<sidname>
file will not be created for unused initial SIDs in the first place.

NB If an unused initial SID was assigned a context different from
the unlabeled context in existing policy, then it is not safe to
remove that initial SID context from policy and reload policy on
the running kernel that was booted with the original policy.  This
is because that kernel may have assigned that SID to various kernel
objects already and those objects will then be treated as having
the unlabeled context after the removal.  In refpolicy, examples
of such initial SIDs are the "fs" SID and the "sysctl" SID.  Even
though these initial SIDs are not directly used (in code) by the current
kernel, their contexts are being applied to filesystems and sysctl files by
policy and therefore the SIDs are being assigned to objects.

NB The "sysctl" SID was in use by the kernel up until
commit 8e6c96935fcc1ed3dbebc96fddfef3f2f2395afc ("security/selinux:
fix /proc/sys/ labeling) circa v2.6.39.  Removing its context from
policy will cause sysctl(2) or /proc/sys accesses to end up
performing permission checks against the unlabeled context and
likely encounter denials for kernels < 2.6.39.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2020-01-29 10:17:02 -05:00
..
ru Replace www.nsa.gov references by github.com/SELinuxProject 2019-11-08 09:20:29 -05:00
test libsepol,checkpolicy: support omitting unused initial sid contexts 2020-01-29 10:17:02 -05:00
.gitignore Repo: update .gitignore 2011-08-02 13:31:51 -04:00
checkmodule.8 Replace www.nsa.gov references by github.com/SELinuxProject 2019-11-08 09:20:29 -05:00
checkmodule.c checkmodule: add support for specifying module policy version 2019-04-19 13:10:44 -04:00
checkpolicy.8 Replace www.nsa.gov references by github.com/SELinuxProject 2019-11-08 09:20:29 -05:00
checkpolicy.c checkpolicy: allow to write policy to stdout 2019-10-22 08:26:26 -04:00
checkpolicy.h checkpolicy: remove unused te_assertions 2020-01-27 10:51:21 -05:00
COPYING initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
Makefile Allow installing translated man pages 2019-01-28 12:03:57 +01:00
module_compiler.c checkpolicy: destroy the class datum if it fails to initialize 2018-05-30 22:00:13 +02:00
module_compiler.h checkpolicy: Separate tunable from boolean during compile. 2011-09-16 11:54:01 -04:00
parse_util.c Remove redundant if-clause 2019-06-19 09:03:12 -07:00
parse_util.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
policy_define.c Fix many misspellings 2019-09-18 22:47:35 +02:00
policy_define.h checkpolicy: Add support for ibendportcon labels 2017-05-23 16:20:55 -04:00
policy_parse.y Add default_range glblub support 2019-09-10 12:30:29 -04:00
policy_scan.l Add default_range glblub support 2019-09-10 12:30:29 -04:00
queue.c checkpolicy,libselinux,libsepol,policycoreutils: Update my email address 2017-08-17 14:17:12 -04:00
queue.h checkpolicy,libselinux,libsepol,policycoreutils: Update my email address 2017-08-17 14:17:12 -04:00
VERSION Update VERSIONs to 3.0 for release. 2019-11-28 13:46:48 +01:00