From fb0a3a98c6214f8dd229797a48d21b3d95b9c81f Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Aug 18 2005 21:27:20 +0000 Subject: initial support for compiling loadable modules --- diff --git a/refpolicy/Changelog b/refpolicy/Changelog index ff22523..b8eaac6 100644 --- a/refpolicy/Changelog +++ b/refpolicy/Changelog @@ -1,3 +1,4 @@ + * Add Makefile support for building loadable modules. * Change sedoctool to make required modules part of base by default, otherwise make as modules, in modules.conf. * Fix segenxml to handle modules with no interfaces. diff --git a/refpolicy/Makefile b/refpolicy/Makefile index b3267e0..42e3757 100644 --- a/refpolicy/Makefile +++ b/refpolicy/Makefile @@ -63,24 +63,52 @@ PREFIX := /usr BINDIR := $(PREFIX)/bin SBINDIR := $(PREFIX)/sbin CHECKPOLICY := $(BINDIR)/checkpolicy +CHECKMODULE := $(BINDIR)/checkmodule +SEMOD_PKG := $(BINDIR)/semodule_package LOADPOLICY := $(SBINDIR)/load_policy SETFILES := $(SBINDIR)/setfiles GENHOMEDIRCON := $(SBINDIR)/genhomedircon +XMLLINT := $(BINDIR)/xmllint CFLAGS := -Wall +# policy source layout +POLDIR = policy +MODDIR = $(POLDIR)/modules +FLASKDIR = $(POLDIR)/flask + +# policy building support tools SUPPORT := support GENXML := $(SUPPORT)/segenxml.py GENDOC := $(SUPPORT)/sedoctool.py FCSORT := $(SUPPORT)/fc_sort SETTUN := $(SUPPORT)/set_tunables -XMLLINT := $(BINDIR)/xmllint +# documentation paths +DOCS = doc +POLXML = $(DOCS)/policy.xml +XMLDTD = $(DOCS)/policy.dtd +LAYERXML = metadata.xml +HTMLDIR = $(DOCS)/html +DOCTEMPLATE = $(DOCS)/templates + +# config file paths +GLOBALTUN := $(POLDIR)/global_tunables +MOD_CONF := $(POLDIR)/modules.conf +TUNABLES := $(POLDIR)/tunables.conf + +# install paths +TOPDIR = $(DESTDIR)/etc/selinux +INSTALLDIR = $(TOPDIR)/$(NAME) +SRCPATH = $(INSTALLDIR)/src +USERPATH = $(INSTALLDIR)/users +CONTEXTPATH = $(INSTALLDIR)/contexts # enable MLS if requested. ifneq ($(findstring mls,$(TYPE)),) override M4PARAM += -D enable_mls CHECKPOLICY += -M + CHECKMODULE += -M endif # compile targeted policy if requested. @@ -93,10 +121,6 @@ ifneq ($(DISTRO),) override M4PARAM += -D distro_$(DISTRO) endif -ifeq ($(MONOLITHIC),y) - override M4PARAM += -D monolithic_policy -endif - ifneq ($(OUTPUT_POLICY),) CHECKPOLICY += -c $(OUTPUT_POLICY) endif @@ -118,32 +142,13 @@ endif FC := file_contexts POLVER := policy.$(PV) -# install paths -TOPDIR = $(DESTDIR)/etc/selinux -INSTALLDIR = $(TOPDIR)/$(NAME) -POLICYPATH = $(INSTALLDIR)/policy -SRCPATH = $(INSTALLDIR)/src -USERPATH = $(INSTALLDIR)/users -CONTEXTPATH = $(INSTALLDIR)/contexts -LOADPATH = $(POLICYPATH)/$(POLVER) -FCPATH = $(CONTEXTPATH)/files/file_contexts -HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template - -POLDIR = policy -MODDIR = $(POLDIR)/modules - -BASE_MODULE = $(MODDIR)/kernel -FLASKDIR = $(POLDIR)/flask ifneq ($(findstring targeted,$(TYPE)),) APPCONF := config/appconfig-targeted else APPCONF := config/appconfig-strict endif -M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt) -GLOBALTUN := $(POLDIR)/global_tunables -MOD_CONF := $(POLDIR)/modules.conf -TUNABLES := $(POLDIR)/tunables.conf +M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt) APPDIR := $(CONTEXTPATH) APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media $(INSTALLDIR)/booleans @@ -160,151 +165,31 @@ GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in # when a generated file is already generated DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE)) +# modules.conf setting for base module MODBASE := base + +# modules.conf setting for module MODMOD := module + +# extract settings from modules.conf BASE_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te))) MOD_MODS := $(foreach mod,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null),$(subst ./,,$(shell find -iname $(mod).te))) -# for monolithic policy use all base and module to create policy -# for modular policy, use only base -ifeq ($(MONOLITHIC),y) - ENABLEMOD := $(BASE_MODS) $(MOD_MODS) -else - ENABLEMOD := $(BASE_MODS) -endif - -ALL_MODULES := $(filter $(ENABLEMOD),$(DETECTED_MODS)) - -PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls -ALL_INTERFACES := $(ALL_MODULES:.te=.if) -ALL_TE_FILES := $(ALL_MODULES) -POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints - -ALL_FC_FILES := $(ALL_MODULES:.te=.fc) -HOMEDIR_TEMPLATE = tmp/homedir_template - -POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf - -DOCS = doc -POLXML = $(DOCS)/policy.xml -XMLDTD = $(DOCS)/policy.dtd -LAYERXML = metadata.xml -HTMLDIR = $(DOCS)/html -DOCTEMPLATE = $(DOCS)/templates - -######################################## -# -# default action: build policy locally -# -default: policy - -policy: $(POLVER) - -install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users - -load: tmp/load - ######################################## # -# Build a binary policy locally +# Load appropriate rules # -$(POLVER): policy.conf - @echo "Compiling $(NAME) $(POLVER)" -ifneq ($(PV),$(KV)) - @echo - @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" - @echo -endif - $(QUIET) $(CHECKPOLICY) $^ -o $@ -######################################## -# -# Install a binary policy -# -$(LOADPATH): policy.conf - @mkdir -p $(POLICYPATH) - @echo "Compiling and installing $(NAME) $(LOADPATH)" -ifneq ($(PV),$(KV)) - @echo - @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" - @echo +ifeq ($(MONOLITHIC),y) + include Rules.monolithic +else + include Rules.modular endif - $(QUIET) $(CHECKPOLICY) $^ -o $@ ######################################## # -# Load the binary policy -# -reload tmp/load: $(LOADPATH) $(FCPATH) - @echo "Loading $(NAME) $(LOADPATH)" - $(QUIET) $(LOADPOLICY) -q $(LOADPATH) - @touch tmp/load - -######################################## +# Generated files # -# Construct a monolithic policy.conf -# -policy.conf: $(POLICY_SECTIONS) - @echo "Creating $(NAME) policy.conf" -# checkpolicy can use the #line directives provided by -s for error reporting: - $(QUIET) m4 $(M4PARAM) -s $^ > tmp/$@.tmp - $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@ -# the ordering of these ocontexts matters: - $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true - $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true - $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true - -tmp/pre_te_files.conf: $(PRE_TE_FILES) - @test -d tmp || mkdir -p tmp - $(QUIET) cat $^ > $@ - -tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) -# per-userdomain templates: - @test -d tmp || mkdir -p tmp - $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@ - $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \ - echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \ - >> $@ ;\ - done - $(QUIET) echo "')" >> $@ -# define foo.te - $(QUIET) for i in $(notdir $(ALL_MODULES)); do \ - echo "define(\`$$i')" >> $@ ;\ - done - $(QUIET) $(SETTUN) $(TUNABLES) >> $@ - -tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES) -ifeq ($(ALL_INTERFACES),) - $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") -endif - @test -d tmp || mkdir -p tmp - $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@ - -tmp/all_te_files.conf: $(ALL_TE_FILES) -ifeq ($(ALL_TE_FILES),) - $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") -endif - @test -d tmp || mkdir -p tmp - $(QUIET) cat $^ > $@ - -tmp/post_te_files.conf: $(POST_TE_FILES) - @test -d tmp || mkdir -p tmp - $(QUIET) cat $^ > $@ - -# extract attributes and put them first. extract post te stuff -# like genfscon and put last. portcon, nodecon, and netifcon -# is delayed since they are generated by m4 -tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf - $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true - $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf - $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf - $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true - $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true - $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true - $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \ - -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \ - < tmp/all_te_files.conf > tmp/only_te_rules.conf - $(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in @echo "#" > $@ @echo "# This is a generated file! Instead of modifying this file, the" >> $@ @@ -312,7 +197,7 @@ $(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/ke @echo "#" >> $@ $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@ $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \ - | m4 $(M4PARAM) $(M4SUPPORT) $(MODDIR)/kernel/corenetwork.if.m4 - \ + | m4 -D monolithic_policy $(M4PARAM) $(M4SUPPORT) $(MODDIR)/kernel/corenetwork.if.m4 - \ | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ $(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in @@ -320,76 +205,11 @@ $(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/ke @echo "# This is a generated file! Instead of modifying this file, the" >> $@ @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@ @echo "#" >> $@ - $(QUIET) m4 $(M4PARAM) $(M4SUPPORT) $^ \ + $(QUIET) m4 -D monolithic_policy $(M4PARAM) $(M4SUPPORT) $^ \ | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@ ######################################## # -# Remove the dontaudit rules from the policy.conf -# -enableaudit: policy.conf - @test -d tmp || mkdir -p tmp - @echo "Removing dontaudit rules from policy.conf" - $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit - $(QUIET) mv tmp/policy.audit policy.conf - -######################################## -# -# Construct file_contexts -# -$(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) $(FCSORT) -ifeq ($(ALL_FC_FILES),) - $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") -endif - @echo "Creating file_contexts." - @test -d tmp || mkdir -p tmp - $(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) > tmp/$@.tmp - $(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE) - $(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp - $(QUIET) $(FCSORT) tmp/$@.tmp $@ - -######################################## -# -# Install file_contexts -# -$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users - @echo "Validating file_contexts." - $(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC) - @echo "Installing file_contexts." - @mkdir -p $(CONTEXTPATH)/files - $(QUIET) install -m 644 $(FC) $(FCPATH) - $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH) - $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD) - -######################################## -# -# Filesystem labeling -# -FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';` - -checklabels: $(FC) $(SETFILES) - @if test -z "$(FILESYSTEMS)"; then \ - echo "No filesystems with extended attributes found!" ;\ - false ;\ - fi - $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS) - -restorelabels: $(FC) $(SETFILES) - @if test -z "$(FILESYSTEMS)"; then \ - echo "No filesystems with extended attributes found!" ;\ - false ;\ - fi - $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS) - -relabel: $(FC) $(SETFILES) - @if test -z "$(FILESYSTEMS)"; then \ - echo "No filesystems with extended attributes found!" ;\ - false ;\ - fi - $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS) - -######################################## -# # Create config files # conf: $(MOD_CONF) $(TUNABLES) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC) @@ -434,7 +254,7 @@ $(USERPATH)/system.users: $(USER_FILES) tmp/generated_definitions.conf @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users @echo "# Please edit local.users to make local changes." >> tmp/system.users @echo "#" >> tmp/system.users - $(QUIET) m4 $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \ + $(QUIET) m4 -D monolithic_policy $(M4PARAM) tmp/generated_definitions.conf $(USER_FILES) | \ egrep -v "^[[:space:]]*($$|#)" >> tmp/system.users $(QUIET) install -m 644 tmp/system.users $@ @@ -508,16 +328,6 @@ install-src: ######################################## # -# Clean the sources -# -clean: - rm -fR tmp - rm -f policy.conf - rm -f policy.$(PV) - rm -f $(FC) - -######################################## -# # Clean everything # bare: clean @@ -537,4 +347,4 @@ ifneq ($(GENERATED_FC),) rm -f $(GENERATED_FC) endif -.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel conf clean bare +.PHONY: install-src install-appconfig conf html bare diff --git a/refpolicy/Rules.modular b/refpolicy/Rules.modular new file mode 100644 index 0000000..c04e047 --- /dev/null +++ b/refpolicy/Rules.modular @@ -0,0 +1,160 @@ +######################################## +# +# Rules and Targets for building monolithic policies +# + +ALL_MODULES := $(filter $(BASE_MODS) $(MOD_MODS),$(DETECTED_MODS)) +ALL_INTERFACES := $(ALL_MODULES:.te=.if) + +BASE_PKG := base.pp +BASE_FC := base.fc + +BASE_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf + +BASE_PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls +BASE_TE_FILES := $(BASE_MODS) +BASE_POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints +BASE_FC_FILES := $(BASE_MODS:.te=.fc) + +MOD_MODULES := $(MOD_MODS:.te=.mod) +MOD_PKGS := $(MOD_MODS:.te=.pp) + +######################################## +# +# default action: create all module packages +# +default: base modules + +base: $(BASE_PKG) + +modules: $(MOD_PKGS) + +#policy: $(POLVER) +#install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users +#load: tmp/load + +######################################## +# +# Create a base module package +# +$(BASE_PKG): tmp/base.mod $(BASE_FC) + @echo "Creating $(NAME) base module package" + $(QUIET) $(SEMOD_PKG) $@ $^ + +######################################## +# +# Compile a base module +# +tmp/base.mod: base.conf + @echo "Compiling $(NAME) base module" + $(QUIET) $(CHECKMODULE) $^ -o $@ + +######################################## +# +# Construct a base module policy.conf +# +base.conf: $(BASE_SECTIONS) + @echo "Creating $(NAME) base module policy.conf" +# checkpolicy can use the #line directives provided by -s for error reporting: + $(QUIET) m4 -D monolithic_policy $(M4PARAM) -s $^ > tmp/$@.tmp + $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@ +# the ordering of these ocontexts matters: + $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true + $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true + $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true + +tmp/pre_te_files.conf: $(BASE_PRE_TE_FILES) + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) +# per-userdomain templates: + @test -d tmp || mkdir -p tmp + $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@ + $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \ + echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \ + >> $@ ;\ + done + $(QUIET) echo "')" >> $@ +# define foo.te + $(QUIET) for i in $(notdir $(ALL_MODULES)); do \ + echo "define(\`$$i')" >> $@ ;\ + done + $(QUIET) $(SETTUN) $(TUNABLES) >> $@ + +tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES) +ifeq ($(ALL_INTERFACES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @test -d tmp || mkdir -p tmp + $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@ + +tmp/all_te_files.conf: $(BASE_TE_FILES) +ifeq ($(BASE_TE_FILES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +tmp/post_te_files.conf: $(BASE_POST_TE_FILES) + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +# extract attributes and put them first. extract post te stuff +# like genfscon and put last. portcon, nodecon, and netifcon +# is delayed since they are generated by m4 +tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf + $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true + $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf + $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf + $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \ + -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \ + < tmp/all_te_files.conf > tmp/only_te_rules.conf + +######################################## +# +# Construct base module file contexts +# +$(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) $(FCSORT) +ifeq ($(BASE_FC_FILES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @echo "Creating $(NAME) base module file contexts." + @test -d tmp || mkdir -p tmp + $(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) > tmp/$@.tmp + $(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE) + $(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp + $(QUIET) $(FCSORT) tmp/$@.tmp $@ + +######################################## +# +# Build modules packages +# +%.pp: %.mod %.fc + @echo "Creating $(NAME) $(@F) package" + $(QUIET) $(SEMOD_PKG) $@ %^ + +######################################## +# +# Compile modules +# +%.mod: $(M4SUPPORT) tmp/all_interfaces.conf %.te + @echo "Compiling $(NAME) $(@F) module" + $(QUIET) m4 $(M4PARAM) -s $^ > tmp/$(@F).tmp + $(QUIET) $(CHECKMODULE) -m tmp/$(@F).tmp -o $@ + +######################################## +# +# Clean the sources +# +clean: + rm -fR tmp + rm -f base.conf + rm -f $(BASE_PKG) + find . -iname "*.mod" | xargs rm -f + find . -iname "*.pp" | xargs rm -f + +.PHONY: default base modules clean diff --git a/refpolicy/Rules.monolithic b/refpolicy/Rules.monolithic new file mode 100644 index 0000000..404ef7f --- /dev/null +++ b/refpolicy/Rules.monolithic @@ -0,0 +1,216 @@ +######################################## +# +# Rules and Targets for building monolithic policies +# + +# install paths +POLICYPATH = $(INSTALLDIR)/policy +LOADPATH = $(POLICYPATH)/$(POLVER) +FCPATH = $(CONTEXTPATH)/files/file_contexts +HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template + +# for monolithic policy use all base and module to create policy +ENABLEMOD := $(BASE_MODS) $(MOD_MODS) + +ALL_MODULES := $(filter $(ENABLEMOD),$(DETECTED_MODS)) + +ALL_INTERFACES := $(ALL_MODULES:.te=.if) +ALL_TE_FILES := $(ALL_MODULES) +ALL_FC_FILES := $(ALL_MODULES:.te=.fc) + +PRE_TE_FILES := $(addprefix $(FLASKDIR)/,security_classes initial_sids access_vectors) $(M4SUPPORT) $(POLDIR)/mls +POST_TE_FILES := $(POLDIR)/users $(POLDIR)/constraints + +POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf + +HOMEDIR_TEMPLATE = tmp/homedir_template + +######################################## +# +# default action: build policy locally +# +default: policy + +policy: $(POLVER) + +install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users + +load: tmp/load + +######################################## +# +# Build a binary policy locally +# +$(POLVER): policy.conf + @echo "Compiling $(NAME) $(POLVER)" +ifneq ($(PV),$(KV)) + @echo + @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" + @echo +endif + $(QUIET) $(CHECKPOLICY) $^ -o $@ + +######################################## +# +# Install a binary policy +# +$(LOADPATH): policy.conf + @mkdir -p $(POLICYPATH) + @echo "Compiling and installing $(NAME) $(LOADPATH)" +ifneq ($(PV),$(KV)) + @echo + @echo "WARNING: Policy version mismatch! Is your OUTPUT_POLICY set correctly?" + @echo +endif + $(QUIET) $(CHECKPOLICY) $^ -o $@ + +######################################## +# +# Load the binary policy +# +reload tmp/load: $(LOADPATH) $(FCPATH) + @echo "Loading $(NAME) $(LOADPATH)" + $(QUIET) $(LOADPOLICY) -q $(LOADPATH) + @touch tmp/load + +######################################## +# +# Construct a monolithic policy.conf +# +policy.conf: $(POLICY_SECTIONS) + @echo "Creating $(NAME) policy.conf" +# checkpolicy can use the #line directives provided by -s for error reporting: + $(QUIET) m4 -D monolithic_policy $(M4PARAM) -s $^ > tmp/$@.tmp + $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@ +# the ordering of these ocontexts matters: + $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true + $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true + $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true + +tmp/pre_te_files.conf: $(PRE_TE_FILES) + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +tmp/generated_definitions.conf: $(ALL_LAYERS) $(ALL_TE_FILES) +# per-userdomain templates: + @test -d tmp || mkdir -p tmp + $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@ + $(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \ + echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \ + >> $@ ;\ + done + $(QUIET) echo "')" >> $@ +# define foo.te + $(QUIET) for i in $(notdir $(ALL_MODULES)); do \ + echo "define(\`$$i')" >> $@ ;\ + done + $(QUIET) $(SETTUN) $(TUNABLES) >> $@ + +tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES) +ifeq ($(ALL_INTERFACES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @test -d tmp || mkdir -p tmp + $(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@ + +tmp/all_te_files.conf: $(ALL_TE_FILES) +ifeq ($(ALL_TE_FILES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +tmp/post_te_files.conf: $(POST_TE_FILES) + @test -d tmp || mkdir -p tmp + $(QUIET) cat $^ > $@ + +# extract attributes and put them first. extract post te stuff +# like genfscon and put last. portcon, nodecon, and netifcon +# is delayed since they are generated by m4 +tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf + $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true + $(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf + $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf + $(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true + $(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \ + -e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \ + < tmp/all_te_files.conf > tmp/only_te_rules.conf + +######################################## +# +# Remove the dontaudit rules from the policy.conf +# +enableaudit: policy.conf + @test -d tmp || mkdir -p tmp + @echo "Removing dontaudit rules from policy.conf" + $(QUIET) grep -v dontaudit policy.conf > tmp/policy.audit + $(QUIET) mv tmp/policy.audit policy.conf + +######################################## +# +# Construct file_contexts +# +$(FC): $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) $(FCSORT) +ifeq ($(ALL_FC_FILES),) + $(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf") +endif + @echo "Creating $(NAME) file_contexts." + @test -d tmp || mkdir -p tmp + $(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(ALL_FC_FILES) > tmp/$@.tmp + $(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE) + $(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp + $(QUIET) $(FCSORT) tmp/$@.tmp $@ + +######################################## +# +# Install file_contexts +# +$(FCPATH): $(FC) $(LOADPATH) $(USERPATH)/system.users + @echo "Validating $(NAME) file_contexts." + $(QUIET) $(SETFILES) -q -c $(LOADPATH) $(FC) + @echo "Installing file_contexts." + @mkdir -p $(CONTEXTPATH)/files + $(QUIET) install -m 644 $(FC) $(FCPATH) + $(QUIET) install -m 644 $(HOMEDIR_TEMPLATE) $(HOMEDIRPATH) + $(QUIET) $(GENHOMEDIRCON) -d $(TOPDIR) -t $(NAME) $(USEPWD) + +######################################## +# +# Filesystem labeling +# +FILESYSTEMS := `mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';` + +checklabels: $(FC) $(SETFILES) + @if test -z "$(FILESYSTEMS)"; then \ + echo "No filesystems with extended attributes found!" ;\ + false ;\ + fi + $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS) + +restorelabels: $(FC) $(SETFILES) + @if test -z "$(FILESYSTEMS)"; then \ + echo "No filesystems with extended attributes found!" ;\ + false ;\ + fi + $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS) + +relabel: $(FC) $(SETFILES) + @if test -z "$(FILESYSTEMS)"; then \ + echo "No filesystems with extended attributes found!" ;\ + false ;\ + fi + $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS) + +######################################## +# +# Clean the sources +# +clean: + rm -fR tmp + rm -f policy.conf + rm -f policy.$(PV) + rm -f $(FC) + +.PHONY: default policy install load reload enableaudit checklabels restorelabels relabel clean diff --git a/refpolicy/policy/modules/kernel/devices.if b/refpolicy/policy/modules/kernel/devices.if index a073acd..3fdbba4 100644 --- a/refpolicy/policy/modules/kernel/devices.if +++ b/refpolicy/policy/modules/kernel/devices.if @@ -23,6 +23,9 @@ ## ##

## +## +## Depended on by other required modules. +## ######################################## ## @@ -1410,7 +1413,7 @@ interface(`dev_write_mtrr',` interface(`dev_rw_null_dev',` gen_require(` type device_t, null_device_t; - class device_t:dir r_dir_perms; + class dir r_dir_perms; class chr_file rw_file_perms; ') @@ -2139,7 +2142,7 @@ interface(`dev_dontaudit_setattr_video_dev',` interface(`dev_rw_zero_dev',` gen_require(` type device_t, zero_device_t; - class device_t:dir r_dir_perms; + class dir r_dir_perms; class chr_file r_file_perms; ') diff --git a/refpolicy/policy/modules/kernel/kernel.te b/refpolicy/policy/modules/kernel/kernel.te index 3afc061..2485983 100644 --- a/refpolicy/policy/modules/kernel/kernel.te +++ b/refpolicy/policy/modules/kernel/kernel.te @@ -25,7 +25,7 @@ attribute sysctl_type; # type kernel_t, can_load_kernmodule; role system_r types kernel_t; -domain_type(kernel_t) +domain_base_type(kernel_t) sid kernel context_template(system_u:system_r:kernel_t,s0 - s9:c0.c127) # diff --git a/refpolicy/policy/modules/kernel/terminal.if b/refpolicy/policy/modules/kernel/terminal.if index 15eb72e..c183b0b 100644 --- a/refpolicy/policy/modules/kernel/terminal.if +++ b/refpolicy/policy/modules/kernel/terminal.if @@ -1,4 +1,7 @@ ## Policy for terminals. +## +## Depended on by other required modules. +## ######################################## ## diff --git a/refpolicy/policy/modules/system/domain.if b/refpolicy/policy/modules/system/domain.if index c8e2ac1..4d12709 100644 --- a/refpolicy/policy/modules/system/domain.if +++ b/refpolicy/policy/modules/system/domain.if @@ -7,7 +7,7 @@ # # domain_base_domain_type(domain) # -interface(`domain_base_domain_type',` +interface(`domain_base_type',` gen_require(` attribute domain; class dir r_dir_perms; @@ -42,7 +42,7 @@ interface(`domain_base_domain_type',` # interface(`domain_type',` # start with basic domain - domain_base_domain_type($1) + domain_base_type($1) # Use trusted objects in /dev dev_rw_null_dev($1) @@ -684,7 +684,7 @@ interface(`domain_unconfined',` template(`domain_trans',` gen_require(` class file rx_file_perms; - process { transition noatsecure siginh rlimitinh }; + class process { transition noatsecure siginh rlimitinh }; ') allow $1 $2:file rx_file_perms; diff --git a/refpolicy/policy/support/loadable_module.spt b/refpolicy/policy/support/loadable_module.spt index 1106e3e..479ece7 100644 --- a/refpolicy/policy/support/loadable_module.spt +++ b/refpolicy/policy/support/loadable_module.spt @@ -84,8 +84,10 @@ define(`optional_policy',` ',` optional { $2 + ifelse(`$3',`',`',` } else { $3 + ') } ') ') @@ -127,8 +129,10 @@ define(`tunable_policy',` optional { require { `$1' } $2 + ifelse(`$3',`',`',` } else { $3 + ') } ') ')