Skip to contentSkip to conversation

Do not keep disabled modules during new policy load

PATCH Superseded Guido Trentalancia 3 participants 9 messages Dec 15, 2016 – Dec 17, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Do not keep disabled modules during new policy load

When loading a new modular policy, remove all policy modules that have been previously loaded but have now been explicitly disabled.

If the batch removal process fails, for example because one or more enabled modules depend on one or more modules to be removed, remove each module separately (much slower but most effective).

---
 Rules.modular |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Rules.modular +5 -1
diff -pru a/Rules.modular b/Rules.modular
@@ -21,6 +21,7 @@ base_post_te_files := $(user_files) $(po
 base_fc_files := $(base_mods:.te=.fc)
 
 mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
+off_mod_names := $(basename $(off_mods))
 
 # policy packages to install
 instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))
@@ -48,7 +49,9 @@ install: $(instpkg) $(appfiles)
 
 ########################################
 #
-# Load all configured modules
+# Load all configured modules and remove
+# all modules that have been explicitly
+# disabled
 #
 load: $(instpkg) $(appfiles)
 # make sure two directories exist since they are not
@@ -56,6 +59,7 @@ load: $(instpkg) $(appfiles)
 	@echo "Loading configured modules."
 	@$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
 	$(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))
+	$(verbose) $(SEMODULE) -s $(NAME) -r $(foreach offmod,$(off_mod_names),$(offmod)) || $(foreach offmod,$(off_mod_names),$(SEMODULE) -s $(NAME) -r $(offmod);)
 
 ########################################
 #
#1 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

When loading a new modular policy, remove all policy modules that have been previously loaded but have now been explicitly disabled.

If the batch removal process fails, for example because one or more enabled modules depend on one or more modules to be removed, remove each module separately (much slower but most effective).

---
 Rules.modular |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Rules.modular +5 -1
diff -pru a/Rules.modular b/Rules.modular
@@ -21,6 +21,7 @@ base_post_te_files := $(user_files) $(po
 base_fc_files := $(base_mods:.te=.fc)
 
 mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
+off_mod_names := $(basename $(off_mods))
 
 # policy packages to install
 instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))
@@ -48,7 +49,9 @@ install: $(instpkg) $(appfiles)
 
 ########################################
 #
-# Load all configured modules
+# Load all configured modules and remove
+# all modules that have been explicitly
+# disabled
 #
 load: $(instpkg) $(appfiles)
 # make sure two directories exist since they are not
@@ -56,6 +59,7 @@ load: $(instpkg) $(appfiles)
 	@echo "Loading configured modules."
 	@$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
 	$(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))
+	-$(verbose) $(SEMODULE) -s $(NAME) -r $(foreach offmod,$(off_mod_names),$(offmod)) || $(foreach offmod,$(off_mod_names),$(SEMODULE) -s $(NAME) -r $(offmod);)
 
 ########################################
 #
#2 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

Quoted 6 lines · Guido Trentalancia via refpolicy

When loading a new modular policy, remove all policy modules that have been previously loaded but have now been explicitly disabled.

If the batch removal process fails, for example because one or more enabled modules depend on one or more modules to be removed, remove each module separately (much slower but most effective).

The policy makefiles were never meant to do this. The targets for loading modules are just for convenience, and not meant to add another layer of policy management to what we already have with semodule/semanage.

Quoted 40 lines
---
 Rules.modular |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff -pru a/Rules.modular b/Rules.modular

Rules.modular +5 -1
@@ -21,6 +21,7 @@ base_post_te_files := $(user_files) $(po
 base_fc_files := $(base_mods:.te=.fc)
 
 mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
+off_mod_names := $(basename $(off_mods))
 
 # policy packages to install
 instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))
@@ -48,7 +49,9 @@ install: $(instpkg) $(appfiles)
 
 ########################################
 #
-# Load all configured modules
+# Load all configured modules and remove
+# all modules that have been explicitly
+# disabled
 #
 load: $(instpkg) $(appfiles)
 # make sure two directories exist since they are not
@@ -56,6 +59,7 @@ load: $(instpkg) $(appfiles)
 	@echo "Loading configured modules."
 	@$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
 	$(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir $(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))
+	-$(verbose) $(SEMODULE) -s $(NAME) -r $(foreach offmod,$(off_mod_names),$(offmod)) || $(foreach offmod,$(off_mod_names),$(SEMODULE) -s $(NAME) -r $(offmod);)
 
 ########################################
 #

_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

Signature · 1 line
Chris PeBenito
#3 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

Hello Christopher !

Quoted 9 lines · Chris PeBenito
Quoted 7 lines · Guido Trentalancia via refpolicy

When loading a new modular policy, remove all policy modules that have been previously loaded but have now been explicitly disabled.

If the batch removal process fails, for example because one or more enabled modules depend on one or more modules to be removed, remove each module separately (much slower but most effective).

Quoted 5 lines

The policy makefiles were never meant to do this.??The targets for? loading modules are just for convenience, and not meant to add another?
layer of policy management to what we already have with semodule/semanage.

Even if originally it was not designed to provide such facility, it is never too late to offer something more to the user.

Generally speaking, one would probably expect that the "load" target only loads modules that are enabled in the policy/modules.conf file and not modules that are disabled...

By the way, after removing several modules that I do not use, I came across some strange behaviour of the system, so I wonder if you have any idea of what is actually going on.

The system became unstable due to several permission denied errors and it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

For example:

#?sesearch -t xsession_exec_t -c file -p entrypoint -Ad

shows nothing, while it should show the result of calling the xserver_xsession_entry_type() interface from?xserver_restricted_role() which is called by xserver_role() as usual !

Another example is as follows. Despite the domain module is loaded because "semodule -l" shows that the base is loaded, the following command:

#?sesearch -s domain -c file -Ad

only shows:

Found 5 semantic av rules:
???allow domain ld_so_t : file { ioctl read getattr execute open } ;? ???allow domain ld_so_cache_t : file { ioctl read getattr lock open } ;?
???allow domain cpu_online_t : file { ioctl read getattr lock open } ;? ???allow domain lib_t : file { ioctl read getattr execute open } ;? ???allow domain textrel_shlib_t : file { ioctl read getattr execute execmod open } ;?

while I believe is should at least show other "domain self:file" permissions.

Do you know what is actually going on after I removed the unused modules ? They were all optional stuff that it is not installed on the system...

Quoted 37 lines
Quoted 37 lines

---
?Rules.modular |????6 +++++-
?1 file changed, 5 insertions(+), 1 deletion(-)

diff -pru a/Rules.modular b/Rules.modular

Rules.modular +1 -0
@@ -21,6 +21,7 @@ base_post_te_files := $(user_files) $(po
 ?base_fc_files := $(base_mods:.te=.fc)
 
 ?mod_pkgs := $(addprefix $(builddir),$(notdir $(mod_mods:.te=.pp)))
+off_mod_names := $(basename $(off_mods))
 

?# policy packages to install
?instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))

Rules.modular +0 -0
@@ -48,7 +49,9 @@ install: $(instpkg) $(appfiles)
 

?########################################
?#

Rules.modular +3 -1
-# Load all configured modules
+# Load all configured modules and remove
+# all modules that have been explicitly
+# disabled

?#
?load: $(instpkg) $(appfiles)
?# make sure two directories exist since they are not

Rules.modular +0 -0
@@ -56,6 +59,7 @@ load: $(instpkg) $(appfiles)

? @echo "Loading configured modules."
? @$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
? $(verbose) $(SEMODULE) -s $(NAME) -i $(modpkgdir)/$(notdir
$(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))

Rules.modular +1 -0
+	-$(verbose) $(SEMODULE) -s $(NAME) -r $(foreach

offmod,$(off_mod_names),$(offmod)) || $(foreach offmod,$(off_mod_names),$(SEMODULE) -s $(NAME) -r $(offmod);)

Quoted 2 lines
Quoted 2 lines

?########################################
?#

Regards,

Guido

#4 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

Quoted 32 lines · Guido Trentalancia via refpolicy

Hello Christopher !

Quoted 14 lines · Chris PeBenito
Quoted 11 lines · Guido Trentalancia via refpolicy

When loading a new modular policy, remove all policy modules that have been previously loaded but have now been explicitly disabled.

If the batch removal process fails, for example because one or more
enabled modules depend on one or more modules to be removed, remove
each module separately (much slower but most effective).

Quoted 5 lines

The policy makefiles were never meant to do this.??The targets for? loading modules are just for convenience, and not meant to add another?
layer of policy management to what we already have with semodule/semanage.

Even if originally it was not designed to provide such facility, it is
never too late to offer something more to the user.

Generally speaking, one would probably expect that the "load" target only loads modules that are enabled in the policy/modules.conf file and
not modules that are disabled...

Quoted 8 lines

By the way, after removing several modules that I do not use, I came across some strange behaviour of the system, so I wonder if you have any idea of what is actually going on.

The system became unstable due to several permission denied errors and
it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

I found that part of the problem was due to the removal of the "unconfined" domain.

Quoted 3 lines

For example:

#?sesearch -t xsession_exec_t -c file -p entrypoint -Ad

But, even after re-enabling the unconfined domain, other permissions such as the one above are not found, despite the relevant policy modules have been loaded (in this case the xserver module).

Quoted 72 lines

shows nothing, while it should show the result of calling the xserver_xsession_entry_type() interface from?xserver_restricted_role()
which is called by xserver_role() as usual !

Another example is as follows. Despite the domain module is loaded because "semodule -l" shows that the base is loaded, the following command:

#?sesearch -s domain -c file -Ad

only shows:

Found 5 semantic av rules:
???allow domain ld_so_t : file { ioctl read getattr execute open } ;? ???allow domain ld_so_cache_t : file { ioctl read getattr lock open } ;?
???allow domain cpu_online_t : file { ioctl read getattr lock open } ;?
???allow domain lib_t : file { ioctl read getattr execute open } ;? ???allow domain textrel_shlib_t : file { ioctl read getattr execute execmod open } ;?

while I believe is should at least show other "domain self:file" permissions.

Do you know what is actually going on after I removed the unused modules ? They were all optional stuff that it is not installed on the
system...

Quoted 41 lines
Quoted 41 lines

---
?Rules.modular |????6 +++++-
?1 file changed, 5 insertions(+), 1 deletion(-)

diff -pru a/Rules.modular b/Rules.modular

Rules.modular +0 -0
@@ -21,6 +21,7 @@ base_post_te_files := $(user_files) $(po
 ?base_fc_files := $(base_mods:.te=.fc)
 

?mod_pkgs := $(addprefix $(builddir),$(notdir
$(mod_mods:.te=.pp)))
+off_mod_names := $(basename $(off_mods))

?# policy packages to install
?instpkg := $(addprefix $(modpkgdir)/,$(notdir $(base_pkg)) $(mod_pkgs))

Rules.modular +0 -0
@@ -48,7 +49,9 @@ install: $(instpkg) $(appfiles)
 

?########################################
?#

Rules.modular +3 -1
-# Load all configured modules
+# Load all configured modules and remove
+# all modules that have been explicitly
+# disabled

?#
?load: $(instpkg) $(appfiles)
?# make sure two directories exist since they are not

Rules.modular +0 -0
@@ -56,6 +59,7 @@ load: $(instpkg) $(appfiles)

? @echo "Loading configured modules."
? @$(INSTALL) -d -m 0755 $(policypath) $(dir $(fcpath))
? $(verbose) $(SEMODULE) -s $(NAME) -i
$(modpkgdir)/$(notdir
$(base_pkg)) $(foreach mod,$(mod_pkgs),-i $(modpkgdir)/$(mod))

Rules.modular +1 -0
+	-$(verbose) $(SEMODULE) -s $(NAME) -r $(foreach

offmod,$(off_mod_names),$(offmod)) || $(foreach offmod,$(off_mod_names),$(SEMODULE) -s $(NAME) -r $(offmod);)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

?########################################
?#

Regards,

Guido

#5 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

Quoted 2 lines · Guido Trentalancia via refpolicy

On Fri, 16/12/2016 at 18.18 +0100, Guido Trentalancia via refpolicy wrote:

[...]

Quoted 6 lines
Quoted 6 lines

By the way, after removing several modules that I do not use, I came
across some strange behaviour of the system, so I wonder if you have
any idea of what is actually going on.

Quoted 7 lines
Quoted 4 lines

The system became unstable due to several permission denied errors and
it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

I found that part of the problem was due to the removal of the "unconfined" domain.

It seems that the "unconfined" domain is defined through optional policy in the "kernel" module, but I suppose this is wrong and it should instead be defined outside of an optional block, as the kernel module depends on it. See above.

Regards,

Guido

#6 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

Why is the unconfined module required for the kernel one? I am using a confined kernel_t with the standard debian sid kernel 4.8.11 and a mostly vanilla 4.9 one and the only permissions i had to add were:

dev_setattr_xserver_misc_dev(kernel_t)
allow kernel_t xserver_misc_device_t:chr_file { getattr unlink };

2016-12-16 23:51 GMT+01:00 Guido Trentalancia via refpolicy <[email protected]>:

Quoted 33 lines
Quoted 2 lines · Guido Trentalancia via refpolicy

On Fri, 16/12/2016 at 18.18 +0100, Guido Trentalancia via refpolicy wrote:

[...]

Quoted 6 lines
Quoted 6 lines

By the way, after removing several modules that I do not use, I came
across some strange behaviour of the system, so I wonder if you have
any idea of what is actually going on.

Quoted 7 lines
Quoted 4 lines

The system became unstable due to several permission denied errors and
it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

I found that part of the problem was due to the removal of the "unconfined" domain.

It seems that the "unconfined" domain is defined through optional policy in the "kernel" module, but I suppose this is wrong and it should instead be defined outside of an optional block, as the kernel module depends on it. See above.

Regards,

Guido
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy

#7 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

In reply to Guido Trentalancia
Quoted 13 lines · Guido Trentalancia via refpolicy
Quoted 2 lines · Guido Trentalancia via refpolicy

On Fri, 16/12/2016 at 18.18 +0100, Guido Trentalancia via refpolicy wrote:

[...]

Quoted 6 lines
Quoted 6 lines

By the way, after removing several modules that I do not use, I came
across some strange behaviour of the system, so I wonder if you have
any idea of what is actually going on.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

The system became unstable due to several permission denied errors and
it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

I found that part of the problem was due to the removal of the "unconfined" domain.

I can't reproduce your issue. However, based on your sesearch syntax, you're using setools3, which could potentially have a bug, since it is unmaintained.

Quoted 4 lines

It seems that the "unconfined" domain is defined through optional policy in the "kernel" module, but I suppose this is wrong and it should instead be defined outside of an optional block, as the kernel module depends on it. See above.

The unconfined module must absolutely be optional. If there are missing rules, then they need to be added.

Signature · 1 line
Chris PeBenito
#8 lore raw

PATCH v2 1/1 Do not keep disabled modules during new policy load

In reply to Guido Trentalancia
Quoted 31 lines · Guido Trentalancia via refpolicy

By the way, after removing several modules that I do not use, I came across some strange behaviour of the system, so I wonder if you have any idea of what is actually going on.

The system became unstable due to several permission denied errors and it seems like parts of the policy have not been loaded, despite "semodule -l" shows that the relevant modules are there.

For example:

# sesearch -t xsession_exec_t -c file -p entrypoint -Ad

shows nothing, while it should show the result of calling the xserver_xsession_entry_type() interface from xserver_restricted_role() which is called by xserver_role() as usual !

Another example is as follows. Despite the domain module is loaded because "semodule -l" shows that the base is loaded, the following command:

# sesearch -s domain -c file -Ad

only shows:

Found 5 semantic av rules:

   allow domain ld_so_t : file { ioctl read getattr execute open } ;
   allow domain ld_so_cache_t : file { ioctl read getattr lock open }
;
   allow domain cpu_online_t : file { ioctl read getattr lock open } ;
   allow domain lib_t : file { ioctl read getattr execute open } ;
   allow domain textrel_shlib_t : file { ioctl read getattr execute
Quoted 8 lines

execmod open } ;

while I believe is should at least show other "domain self:file" permissions.

Do you know what is actually going on after I removed the unused modules ? They were all optional stuff that it is not installed on the system...

"self" rules are expanded out in the binary policy, so instead you'd see results like:

allow staff_t staff_t:file { append getattr ioctl lock open read write };

and not:

allow domain self:file { append getattr ioctl lock open read write };

Signature · 1 line
Chris PeBenito