Skip to contentSkip to conversation

mcstrans: start early and stop late

PATCH Applied Dominick Grift 3 participants 9 messages Dec 11, 2019 – May 13, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mcstrans: start early and stop late

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

v2: stop late, but do stop

---
 mcstrans/src/mcstrans.service | 3 +++
 1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
 Description=Translates SELinux MCS/MLS labels to human readable form
 Documentation=man:mcstransd(8)
 ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
 
 [Service]
 ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
#1 lore raw
Quoted 6 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

Quoted 24 lines

v2: stop late, but do stop

---
 mcstrans/src/mcstrans.service | 3 +++
 1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
 Description=Translates SELinux MCS/MLS labels to human readable form
 Documentation=man:mcstransd(8)
 ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
 
 [Service]
 ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
Signature · 3 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
#2 lore raw
Quoted 11 lines · Dominick Grift
Quoted 6 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

I'm a little unclear on where the bug lies - you show a sudo denial, but refer to systemd as the culprit?

If we don't care about being able to use translated contexts in systemd unit files or options, it could always use the _raw interfaces to ensure that it is always dealing with the raw kernel contexts. The translated contexts are mostly for display purposes for MLS labels/policies.

Quoted 26 lines
Quoted 25 lines

v2: stop late, but do stop

---
  mcstrans/src/mcstrans.service | 3 +++
  1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
  Description=Translates SELinux MCS/MLS labels to human readable form
  Documentation=man:mcstransd(8)
  ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
 
  [Service]
  ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
#3 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Dominick Grift
Quoted 5 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

I'm a little unclear on where the bug lies - you show a sudo denial, but refer to systemd as the culprit?

The sudo bug is fixed here: https://github.com/sudo-project/sudo/commit/718e6997fcaae6ea065ce74d08dd4aae5917df5e

Quoted 5 lines

If we don't care about being able to use translated contexts in systemd unit files or options, it could always use the _raw interfaces to ensure that it is always dealing with the raw kernel contexts. The translated contexts are mostly for display purposes for MLS labels/policies.

The thing with systemd is that since systemd runs before mcstrans is started it doesnt use mcstrans. So if you try to reference translated contexts using systemd then it will refuse.
Running a systemctl daemon-reexec after mcstrans is started fixes that issue but that is not really an option.

I am wondering what causes this behavior, i suppose this is some libselinux thing.

Regardless of all the above though, i think it makes sense for mcstrans to start early and stop late.

Quoted 27 lines
Quoted 26 lines
Quoted 25 lines

v2: stop late, but do stop

---
  mcstrans/src/mcstrans.service | 3 +++
  1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
  Description=Translates SELinux MCS/MLS labels to human readable form
  Documentation=man:mcstransd(8)
  ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
  [Service]
  ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
Signature · 3 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
#4 lore raw
Quoted 10 lines · Dominick Grift
Quoted 9 lines · Stephen Smalley
Quoted 8 lines · Dominick Grift
Quoted 6 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

I'm a little unclear on where the bug lies - you show a sudo denial, but refer to systemd as the culprit?

The sudo bug is fixed here: https://github.com/sudo-project/sudo/commit/718e6997fcaae6ea065ce74d08dd4aae5917df5e

Quoted 5 lines

If we don't care about being able to use translated contexts in systemd unit files or options, it could always use the _raw interfaces to ensure that it is always dealing with the raw kernel contexts. The translated contexts are mostly for display purposes for MLS labels/policies.

The bevavior of mcstrans seems to contradict your suggestion that its mostly for display purposes.

If you reference a set of categories in the raw manner then mcstrans seems to not resolve that until that same set of categories is referenced in human readable form. It think it actually makes sense that people reference catagories in human readable form rather than in a raw manner when they opt in for mcstrans.

Quoted 41 lines

The thing with systemd is that since systemd runs before mcstrans is started it doesnt use mcstrans. So if you try to reference translated contexts using systemd then it will refuse.
Running a systemctl daemon-reexec after mcstrans is started fixes that issue but that is not really an option.

I am wondering what causes this behavior, i suppose this is some libselinux thing.

Regardless of all the above though, i think it makes sense for mcstrans to start early and stop late.

Quoted 27 lines
Quoted 26 lines
Quoted 25 lines

v2: stop late, but do stop

---
  mcstrans/src/mcstrans.service | 3 +++
  1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
  Description=Translates SELinux MCS/MLS labels to human readable form
  Documentation=man:mcstransd(8)
  ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
  [Service]
  ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
Signature · 3 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
Signature · 3 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
#5 lore raw
In reply to Dominick Grift
Quoted 25 lines · Dominick Grift
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Dominick Grift
Quoted 5 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

I'm a little unclear on where the bug lies - you show a sudo denial, but refer to systemd as the culprit?

The sudo bug is fixed here: https://github.com/sudo-project/sudo/commit/718e6997fcaae6ea065ce74d08dd4aae5917df5e

Quoted 5 lines

If we don't care about being able to use translated contexts in systemd unit files or options, it could always use the _raw interfaces to ensure that it is always dealing with the raw kernel contexts. The translated contexts are mostly for display purposes for MLS labels/policies.

Quoted 5 lines

The thing with systemd is that since systemd runs before mcstrans is started it doesnt use mcstrans. So if you try to reference translated contexts using systemd then it will refuse.
Running a systemctl daemon-reexec after mcstrans is started fixes that issue but that is not really an option.

I am wondering what causes this behavior, i suppose this is some libselinux thing.

Yes, libselinux checks for the existence of the mcstrans socket exactly once on the first attempted translation, and if it does not exist at that time, it never tries again. That is to avoid overhead on systems that are not running mcstrans, which is the majority of systems. mcstrans is only really needed for MLS policies and those are a minority of SELinux systems.

Quoted 1 line

Regardless of all the above though, i think it makes sense for mcstrans to start early and stop late.

Perhaps; I'll defer to the distro maintainers on that. I don't really recommend using mcstrans unless you truly need it.

Quoted 29 lines
Quoted 28 lines
Quoted 27 lines
Quoted 26 lines

v2: stop late, but do stop

---
   mcstrans/src/mcstrans.service | 3 +++
   1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
   Description=Translates SELinux MCS/MLS labels to human readable form
   Documentation=man:mcstransd(8)
   ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
   [Service]
   ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
#6 lore raw
Quoted 38 lines · Stephen Smalley
Quoted 25 lines · Dominick Grift
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Dominick Grift
Quoted 5 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

Unfortunately it does not quite seem to address this challenge, at least currently, but still
I think systemd would need to refresh its label cache when mcstrans is started, as per systemd v245 that should be a little less painful than it is today Something like a: ExecStartPost=/bin/systemctl daemon-reload would do that then

I'm a little unclear on where the bug lies - you show a sudo denial, but refer to systemd as the culprit?

The sudo bug is fixed here: https://github.com/sudo-project/sudo/commit/718e6997fcaae6ea065ce74d08dd4aae5917df5e

Quoted 5 lines

If we don't care about being able to use translated contexts in systemd unit files or options, it could always use the _raw interfaces to ensure that it is always dealing with the raw kernel contexts. The translated contexts are mostly for display purposes for MLS labels/policies.

Quoted 5 lines

The thing with systemd is that since systemd runs before mcstrans is started it doesnt use mcstrans. So if you try to reference translated contexts using systemd then it will refuse.
Running a systemctl daemon-reexec after mcstrans is started fixes that issue but that is not really an option.

I am wondering what causes this behavior, i suppose this is some libselinux thing.

Yes, libselinux checks for the existence of the mcstrans socket exactly once on the first attempted translation, and if it does not exist at that time, it never tries again. That is to avoid overhead on systems that are not running mcstrans, which is the majority of systems. mcstrans is only really needed for MLS policies and those are a minority of SELinux systems.

Quoted 4 lines
Quoted 1 line

Regardless of all the above though, i think it makes sense for mcstrans to start early and stop late.

Perhaps; I'll defer to the distro maintainers on that. I don't really recommend using mcstrans unless you truly need it.

Me neither. There was a request for support on IRC. So i looked into it. I certainly think I made it clear to stay away from it if possible.

Quoted 31 lines
Quoted 30 lines
Quoted 29 lines
Quoted 28 lines
Quoted 27 lines

v2: stop late, but do stop

---
   mcstrans/src/mcstrans.service | 3 +++
   1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
   Description=Translates SELinux MCS/MLS labels to human readable form
   Documentation=man:mcstransd(8)
   ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
   [Service]
   ExecStart=/sbin/mcstransd -f
Signature · 1 line
2.24.0
Signature · 3 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
Acked-by on v2 1/1
#7 lore raw
In reply to Dominick Grift
Quoted 9 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

v2: stop late, but do stop

I've asked for review one of Fedora systemd maintainers and he's fine with this change. He even suggested to follow udev and to drop 'Conflicts=shutdown.target' and let mstrans to be stopped by a signal when everything else is stopped as it was in your first version.

I'm fine with both versions.

Quoted 18 lines
---
 mcstrans/src/mcstrans.service | 3 +++
 1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
 Description=Translates SELinux MCS/MLS labels to human readable form
 Documentation=man:mcstransd(8)
 ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
 
 [Service]
 ExecStart=/sbin/mcstransd -f
#8 lore raw
In reply to Dominick Grift
Quoted 10 lines · Dominick Grift

It stopped too early, exposing a bug in sudo selinux_restore_tty():

SELINUX_ERR op=setxattr invalid_context="wheel.id:wheel.role:users.terminals.pty.pty_file:SystemLow"
avc: denied { mac_admin } for pid=859 comm="sudo" capability=33 scontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tcontext=wheel.id:wheel.role:sudo.wheel.subj:s0 tclass=capability2 permissive=0

If we want to be able to reference human readable contexts in SELinuxContext= and nspawn -Z and -L then we need mcstrans ASAP

v2: stop late, but do stop

Applied, thanks!

Quoted 18 lines
---
 mcstrans/src/mcstrans.service | 3 +++
 1 file changed, 3 insertions(+)
mcstrans/src/mcstrans.service +3 -0
index 09529432..c13cd09a 100644
@@ -2,6 +2,9 @@
 Description=Translates SELinux MCS/MLS labels to human readable form
 Documentation=man:mcstransd(8)
 ConditionSecurity=selinux
+DefaultDependencies=no
+Before=shutdown.target sysinit.target
+Conflicts=shutdown.target
 
 [Service]
 ExecStart=/sbin/mcstransd -f
Signature · 2 lines
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments