Skip to contentSkip to conversation

fc_sort must be explicitly labeled as executable upon creation

PATCH New Guido Trentalancia 4 participants 10 messages Aug 8, 2016 – Aug 14, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Force a bin_t label on the fc_sort executable after creating it, to avoid execution denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
 ########################################
 #
#1 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 11 lines · Guido Trentalancia

Force a bin_t label on the fc_sort executable after creating it, to avoid execution denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

Makefile $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 7 lines
Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for those that are explicitly for labeling.

Signature · 1 line
Chris PeBenito
#2 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Hello Christopher !

Thanks for getting back on this...

Quoted 20 lines · Chris PeBenito
Quoted 19 lines · Guido Trentalancia

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
?Makefile |????1 +
?1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

(quoted diff) +0 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)

?#
?$(fcsort) : $(support)/fc_sort.c
? $(verbose) $(CC) $(CFLAGS) $^ -o $@

Makefile +1 -0
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
Quoted 6 lines
Quoted 2 lines

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

I'd prefer not to hard code any labeling into make targets except for?
those that are explicitly for labeling.

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Otherwise the fc_sort binary cannot, in general, be executed !

Best regards,

Guido

#3 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 3 lines · Guido Trentalancia

Hello Christopher !

Thanks for getting back on this...

Sorry for the delay.

Quoted 28 lines · Chris PeBenito
Quoted 20 lines · Guido Trentalancia
Quoted 19 lines

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
Quoted 6 lines

Makefile $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 2 lines
Makefile +0 -0
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for
those that are explicitly for labeling.

Quoted 6 lines

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Otherwise the fc_sort binary cannot, in general, be executed !

I don't want to make assumptions about where the policy is being compiled. I don't think that you can assume it is not executable, in general. e.g. if I build refpolicy in my home dir, then I can execute fc_sort, and in that case you may not even be able to chcon to bin_t.

Signature · 1 line
Chris PeBenito
#4 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Hello Chris.

Quoted 34 lines · On 13th August 2016 at 15.00 Chris PeBenito <[email protected]> wrote:
Quoted 33 lines · Chris PeBenito
Quoted 20 lines · Guido Trentalancia
Quoted 19 lines

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
Quoted 6 lines

Makefile $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 2 lines
Makefile +0 -0
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for
those that are explicitly for labeling.

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Quoted 6 lines
Quoted 1 line

Otherwise the fc_sort binary cannot, in general, be executed !

I don't want to make assumptions about where the policy is being compiled. I don't think that you can assume it is not executable, in general. e.g. if I build refpolicy in my home dir, then I can execute fc_sort, and in that case you may not even be able to chcon to bin_t.

As far as I know, system-wide sources are usually installed in /usr/src...

That's why I suppose it ends up mislabeling the executable file context in most cases...

What do you say ?

Regards,

Guido

#5 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 43 lines · guido guido

Hello Chris.

Quoted 34 lines · On 13th August 2016 at 15.00 Chris PeBenito <[email protected]> wrote:
Quoted 33 lines · Chris PeBenito
Quoted 20 lines · Guido Trentalancia
Quoted 19 lines

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
Quoted 6 lines

Makefile $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 2 lines
Makefile +0 -0
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for
those that are explicitly for labeling.

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Quoted 6 lines
Quoted 1 line

Otherwise the fc_sort binary cannot, in general, be executed !

I don't want to make assumptions about where the policy is being compiled. I don't think that you can assume it is not executable, in general. e.g. if I build refpolicy in my home dir, then I can execute fc_sort, and in that case you may not even be able to chcon to bin_t.

Quoted 7 lines

As far as I know, system-wide sources are usually installed in /usr/src...

That's why I suppose it ends up mislabeling the executable file context in most cases...

What do you say ?

How about adding an fc spec for that in refpolicy, and then just run restorecon in the makefile? What is that? like restorecon $DEST/?/support

Quoted 8 lines

Regards,

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

Signature · 11 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 648 bytes
Desc: OpenPGP digital signature
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20160813/2829522d/attachment-0001.bin 
#6 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 46 lines · Dominick Grift
Quoted 45 lines · guido guido

Hello Chris.

Quoted 34 lines · On 13th August 2016 at 15.00 Chris PeBenito <[email protected]> wrote:
Quoted 33 lines · Chris PeBenito
Quoted 20 lines · Guido Trentalancia
Quoted 19 lines

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

Makefile +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
Quoted 6 lines

Makefile $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 2 lines
Makefile +0 -0
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for
those that are explicitly for labeling.

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Quoted 6 lines
Quoted 1 line

Otherwise the fc_sort binary cannot, in general, be executed !

I don't want to make assumptions about where the policy is being compiled. I don't think that you can assume it is not executable, in general. e.g. if I build refpolicy in my home dir, then I can execute fc_sort, and in that case you may not even be able to chcon to bin_t.

As far as I know, system-wide sources are usually installed in /usr/src...

Quoted 8 lines
Quoted 5 lines

That's why I suppose it ends up mislabeling the executable file context in most cases...

What do you say ?

How about adding an fc spec for that in refpolicy, and then just run restorecon in the makefile? What is that? like restorecon $DEST/?/support

src_t is executable tho? why would it need to be changed?
sesearch shows:
allow sysadm_t src_t : file { ioctl read getattr execute execute_no_trans open } ; -- Jason

Quoted 24 lines
Quoted 9 lines

Regards,

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

Signature · 12 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift





_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy
#7 lore raw

PATCH 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 53 lines · Jason Zaman
Quoted 52 lines · Dominick Grift
Quoted 50 lines · guido guido

Hello Chris.

Quoted 34 lines · On 13th August 2016 at 15.00 Chris PeBenito <[email protected]> wrote:
Quoted 33 lines · Chris PeBenito
Quoted 20 lines · Guido Trentalancia
Quoted 19 lines

Force a bin_t label on the fc_sort executable after creating it, to avoid execution
denials (e.g. misplaced generic default labels).

---
 Makefile |    1 +
 1 file changed, 1 insertion(+)

--- refpolicy-04062012/Makefile 2012-05-29
21:13:09.413703575 +0200
+++ refpolicy-04062012-chcon-fc_sort/Makefile 2012-08-04
21:35:57.396092798 +0200

(quoted diff) +1 -0
@@ -400,6 +400,7 @@ $(mod_conf) $(booleans): $(polxml)
 #
 $(fcsort) : $(support)/fc_sort.c
 	$(verbose) $(CC) $(CFLAGS) $^ -o $@
+	chcon system_u:object_r:bin_t:s0 $(tmpdir)/fc_sort
 
Quoted 6 lines

Review $(mod_conf) $(booleans): $(polxml) · line 406

Quoted 2 lines
(quoted diff) +0 -0
 ########################################
 #

I'd prefer not to hard code any labeling into make targets except for
those that are explicitly for labeling.

Can we determine it at runtime then ?

For example by using grep "^/bin/\." on the corecommands.fc file and then with a little bit more processing ?

Quoted 6 lines
Quoted 1 line

Otherwise the fc_sort binary cannot, in general, be executed !

I don't want to make assumptions about where the policy is being compiled. I don't think that you can assume it is not executable, in general. e.g. if I build refpolicy in my home dir, then I can execute fc_sort, and in that case you may not even be able to chcon to bin_t.

As far as I know, system-wide sources are usually installed in /usr/src...

That's why I suppose it ends up mislabeling the executable file context in most cases...

What do you say ?

Quoted 8 lines
Quoted 2 lines

How about adding an fc spec for that in refpolicy, and then just run restorecon in the makefile? What is that? like restorecon $DEST/?/support

src_t is executable tho? why would it need to be changed?
sesearch shows:
allow sysadm_t src_t : file { ioctl read getattr execute execute_no_trans open } ; -- Jason

Quoted 1 line

Good call

Quoted 24 lines
Quoted 23 lines
Quoted 8 lines

Regards,

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

Signature · 12 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift





_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy
Signature · 11 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 648 bytes
Desc: OpenPGP digital signature
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20160813/3973f697/attachment.bin 
#8 lore raw

PATCH v2 1/1 fc_sort must be explicitly labeled as executable upon creation

In reply to guido guido

Install the fc_sort executable system-wide during the make target "install-src" (i.e. prior to make "policy") to avoid execution denials, due to misplaced generic non-executable default file labels, if the Reference Policy is installed in system-wide directories such as /usr/src.

---
 Makefile         |    4 +++-
 Rules.modular    |    4 ++--
 Rules.monolithic |    4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)
Makefile +3 -1
@@ -99,6 +99,7 @@ gendoc := $(PYTHON) -E $(support)/sedoct
 genperm := $(PYTHON) -E $(support)/genclassperms.py
 policyvers := $(PYTHON) -E $(support)/policyvers.py
 fcsort := $(tmpdir)/fc_sort
+fcsortexe := $(BINDIR)/fc_sort
 setbools := $(AWK) -f $(support)/set_bools_tuns.awk
 get_type_attr_decl := $(SED) -r -f $(support)/get_type_attr_decl.sed
 comment_move_decl := $(SED) -r -f $(support)/comment_move_decl.sed
@@ -547,11 +548,12 @@ install-docs: $(tmpdir)/html
 #
 # Install policy sources
 #
-install-src:
+install-src: $(fcsort)
 	rm -rf $(srcpath)/policy.old
 	-mv $(srcpath)/policy $(srcpath)/policy.old
 	mkdir -p $(srcpath)/policy
 	cp -R . $(srcpath)/policy
+	install tmp/fc_sort $(fcsortexe)
 
 ########################################
 #

--- refpolicy-git-06082016-orig/Rules.modular 2016-08-06 21:26:43.257773849
+0200
+++ refpolicy-git-06082016/Rules.modular 2016-08-13 18:32:09.211057621 +0200
@@ -174,8 +174,8 @@ $(tmpdir)/only_te_rules.conf: $(tmpdir)/
#
# Construct a base.fc
#
-$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp $(fcsort)
- $(verbose) $(fcsort) $< $@
+$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp $(fcsortexe)
+ $(verbose) $(fcsortexe) $< $@

$(tmpdir)/$(notdir $(base_fc)).tmp: $(m4support)
$(tmpdir)/generated_definitions.conf $(base_fc_files)
ifeq ($(base_fc_files),)
--- refpolicy-git-06082016-orig/Rules.monolithic 2016-08-06 21:26:43.258773860
+0200
+++ refpolicy-git-06082016/Rules.monolithic 2016-08-13 18:32:40.188493779 +0200
@@ -168,8 +168,8 @@ enableaudit: $(policy_conf)
#
# Construct file_contexts
#
-$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsort)
- $(verbose) $(fcsort) $< $@
+$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsortexe)
+ $(verbose) $(fcsortexe) $< $@
$(verbose) $(GREP) -e HOME -e ROLE -e USER $@ > $(homedir_template) $(verbose) $(SED) -i -e /HOME/d -e /ROLE/d -e /USER/d $@

#9 lore raw

PATCH v2 1/1 fc_sort must be explicitly labeled as executable upon creation

Quoted 5 lines · guido guido

Install the fc_sort executable system-wide during the make target "install-src" (i.e. prior to make "policy") to avoid execution denials, due to misplaced generic non-executable default file labels, if the Reference Policy is installed in system-wide directories such as /usr/src.

I suspect that this will break the case where one simply clones the repo or unpacks a release and simply tries to build it wherever it is, especially if they can't or don't want to run the install-src target.

Quoted 60 lines
---
 Makefile         |    4 +++-
 Rules.modular    |    4 ++--
 Rules.monolithic |    4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)
Makefile +7 -4
@@ -99,6 +99,7 @@ gendoc := $(PYTHON) -E $(support)/sedoct
 genperm := $(PYTHON) -E $(support)/genclassperms.py
 policyvers := $(PYTHON) -E $(support)/policyvers.py
 fcsort := $(tmpdir)/fc_sort
+fcsortexe := $(BINDIR)/fc_sort
 setbools := $(AWK) -f $(support)/set_bools_tuns.awk
 get_type_attr_decl := $(SED) -r -f $(support)/get_type_attr_decl.sed
 comment_move_decl := $(SED) -r -f $(support)/comment_move_decl.sed
@@ -547,11 +548,12 @@ install-docs: $(tmpdir)/html
 #
 # Install policy sources
 #
-install-src:
+install-src: $(fcsort)
 	rm -rf $(srcpath)/policy.old
 	-mv $(srcpath)/policy $(srcpath)/policy.old
 	mkdir -p $(srcpath)/policy
 	cp -R . $(srcpath)/policy
+	install tmp/fc_sort $(fcsortexe)
 
 ########################################
 #
--- refpolicy-git-06082016-orig/Rules.modular	2016-08-06 21:26:43.257773849
+0200
+++ refpolicy-git-06082016/Rules.modular	2016-08-13 18:32:09.211057621 +0200
@@ -174,8 +174,8 @@ $(tmpdir)/only_te_rules.conf: $(tmpdir)/
 #
 # Construct a base.fc
 #
-$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp $(fcsort)
-	$(verbose) $(fcsort) $< $@
+$(base_fc): $(tmpdir)/$(notdir $(base_fc)).tmp $(fcsortexe)
+	$(verbose) $(fcsortexe) $< $@
 
 $(tmpdir)/$(notdir $(base_fc)).tmp: $(m4support)
 $(tmpdir)/generated_definitions.conf $(base_fc_files)

ifeq ($(base_fc_files),)
--- refpolicy-git-06082016-orig/Rules.monolithic 2016-08-06 21:26:43.258773860
+0200
+++ refpolicy-git-06082016/Rules.monolithic 2016-08-13 18:32:40.188493779 +0200

Makefile +2 -2
@@ -168,8 +168,8 @@ enableaudit: $(policy_conf)
 #
 # Construct file_contexts
 #
-$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsort)
-	$(verbose) $(fcsort) $< $@
+$(fc): $(tmpdir)/$(notdir $(fc)).tmp $(fcsortexe)
+	$(verbose) $(fcsortexe) $< $@
 	$(verbose) $(GREP) -e HOME -e ROLE -e USER $@ > $(homedir_template)
 	$(verbose) $(SED) -i -e /HOME/d -e /ROLE/d -e /USER/d $@
 
Signature · 1 line
Chris PeBenito