All of lore.kernel.org
 help / color / mirror / Atom feed
* [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works
@ 2017-12-08 22:30 David Sugar
  2017-12-09 16:15 ` Dominick Grift
  2017-12-10 19:55 ` Chris PeBenito
  0 siblings, 2 replies; 3+ messages in thread
From: David Sugar @ 2017-12-08 22:30 UTC (permalink / raw)
  To: refpolicy

I am seeing (on RHEL 7.4 w/systemd) that halting the system doesn't work.  It took me a long time (and a lot of help from Steve L.) to figure out what was going on.  It turns out in refpolicy the default label for /usr/lib/systemd/systemd-shutdown is bin_t.  But when systemd tried to execve systemd-shutdown it fails because init_t isn't allowed file entrypoint for bin_t.  When I labeled systemd-shutdown as init_exec_t shutting down the system works.  

I was seeing the following log (from systemd) when I enabled systemd debug logging (which was very useful).

[   59.745037] systemd[1]: Starting Final Step.
[   59.746112] systemd[1]: Starting Power-Off...
[   59.776320] systemd[1]: Shutting down.
[   59.783559] systemd[1]: Failed to execute shutdown binary, freezing: Operation not permitted

At this point everything locks up instead of actually halting the system.

This is a patch to change the label for systemd-shutdown which solves the problem.  I'm happy to go through and make a distinct type of systemd-shutdown if someone doesn't think it is a good idea to share the type with systemd.  But based on what is going on, this might be reasonable.  

Signed-off-by: Dave Sugar <dsugar@tresys.com>
---
 policy/modules/system/init.fc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/policy/modules/system/init.fc b/policy/modules/system/init.fc
index 34bb6a7c..548a8631 100644
--- a/policy/modules/system/init.fc
+++ b/policy/modules/system/init.fc
@@ -29,6 +29,7 @@ ifdef(`distro_gentoo',`
 /usr/bin/upstart	--	gen_context(system_u:object_r:init_exec_t,s0)
 
 /usr/lib/systemd/systemd --	gen_context(system_u:object_r:init_exec_t,s0)
+/usr/lib/systemd/systemd-shutdown	--	gen_context(system_u:object_r:init_exec_t,s0)
 /usr/lib/systemd/system-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
 /usr/lib/systemd/user-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
 /usr/lib/systemd/ntp-units\.d -d gen_context(system_u:object_r:systemd_unit_t,s0)
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works
  2017-12-08 22:30 [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works David Sugar
@ 2017-12-09 16:15 ` Dominick Grift
  2017-12-10 19:55 ` Chris PeBenito
  1 sibling, 0 replies; 3+ messages in thread
From: Dominick Grift @ 2017-12-09 16:15 UTC (permalink / raw)
  To: refpolicy

On Fri, Dec 08, 2017 at 10:30:58PM +0000, David Sugar via refpolicy wrote:
> I am seeing (on RHEL 7.4 w/systemd) that halting the system doesn't work.  It took me a long time (and a lot of help from Steve L.) to figure out what was going on.  It turns out in refpolicy the default label for /usr/lib/systemd/systemd-shutdown is bin_t.  But when systemd tried to execve systemd-shutdown it fails because init_t isn't allowed file entrypoint for bin_t.  When I labeled systemd-shutdown as init_exec_t shutting down the system works.  
> 
> I was seeing the following log (from systemd) when I enabled systemd debug logging (which was very useful).
> 
> [   59.745037] systemd[1]: Starting Final Step.
> [   59.746112] systemd[1]: Starting Power-Off...
> [   59.776320] systemd[1]: Shutting down.
> [   59.783559] systemd[1]: Failed to execute shutdown binary, freezing: Operation not permitted
> 
> At this point everything locks up instead of actually halting the system.
> 
> This is a patch to change the label for systemd-shutdown which solves the problem.  I'm happy to go through and make a distinct type of systemd-shutdown if someone doesn't think it is a good idea to share the type with systemd.  But based on what is going on, this might be reasonable.  

It is very hard to target systemd-shutdown so it may indeed not be worth the trouble. I actually did confine systemd-shutdown in my personal policy but i am not sure if i would do it again with today's knowledge

A couple of aspects that make it hard:

systemd-shutdown actually becomes pid one
systemd-shutdown does a lot of work when pretty much all logging has seized. With a serial console you will be able to get some info but not all, so at some point developing policy for it takes "brute force"/ "reverse engineering"

Its a great exercise though and it give one a great feeling when/if you actually succeed

> 
> Signed-off-by: Dave Sugar <dsugar@tresys.com>
> ---
>  policy/modules/system/init.fc | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/policy/modules/system/init.fc b/policy/modules/system/init.fc
> index 34bb6a7c..548a8631 100644
> --- a/policy/modules/system/init.fc
> +++ b/policy/modules/system/init.fc
> @@ -29,6 +29,7 @@ ifdef(`distro_gentoo',`
>  /usr/bin/upstart	--	gen_context(system_u:object_r:init_exec_t,s0)
>  
>  /usr/lib/systemd/systemd --	gen_context(system_u:object_r:init_exec_t,s0)
> +/usr/lib/systemd/systemd-shutdown	--	gen_context(system_u:object_r:init_exec_t,s0)
>  /usr/lib/systemd/system-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
>  /usr/lib/systemd/user-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
>  /usr/lib/systemd/ntp-units\.d -d gen_context(system_u:object_r:systemd_unit_t,s0)
> -- 
> 2.13.6
> _______________________________________________
> refpolicy mailing list
> refpolicy at oss.tresys.com
> http://oss.tresys.com/mailman/listinfo/refpolicy

-- 
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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20171209/a85e7b1d/attachment.bin 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works
  2017-12-08 22:30 [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works David Sugar
  2017-12-09 16:15 ` Dominick Grift
@ 2017-12-10 19:55 ` Chris PeBenito
  1 sibling, 0 replies; 3+ messages in thread
From: Chris PeBenito @ 2017-12-10 19:55 UTC (permalink / raw)
  To: refpolicy

On 12/08/2017 05:30 PM, David Sugar via refpolicy wrote:
> I am seeing (on RHEL 7.4 w/systemd) that halting the system doesn't work.  It took me a long time (and a lot of help from Steve L.) to figure out what was going on.  It turns out in refpolicy the default label for /usr/lib/systemd/systemd-shutdown is bin_t.  But when systemd tried to execve systemd-shutdown it fails because init_t isn't allowed file entrypoint for bin_t.  When I labeled systemd-shutdown as init_exec_t shutting down the system works.
> 
> I was seeing the following log (from systemd) when I enabled systemd debug logging (which was very useful).
> 
> [   59.745037] systemd[1]: Starting Final Step.
> [   59.746112] systemd[1]: Starting Power-Off...
> [   59.776320] systemd[1]: Shutting down.
> [   59.783559] systemd[1]: Failed to execute shutdown binary, freezing: Operation not permitted
> 
> At this point everything locks up instead of actually halting the system.
> 
> This is a patch to change the label for systemd-shutdown which solves the problem.  I'm happy to go through and make a distinct type of systemd-shutdown if someone doesn't think it is a good idea to share the type with systemd.  But based on what is going on, this might be reasonable.
> 
> Signed-off-by: Dave Sugar <dsugar@tresys.com>
> ---
>   policy/modules/system/init.fc | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/policy/modules/system/init.fc b/policy/modules/system/init.fc
> index 34bb6a7c..548a8631 100644
> --- a/policy/modules/system/init.fc
> +++ b/policy/modules/system/init.fc
> @@ -29,6 +29,7 @@ ifdef(`distro_gentoo',`
>   /usr/bin/upstart	--	gen_context(system_u:object_r:init_exec_t,s0)
>   
>   /usr/lib/systemd/systemd --	gen_context(system_u:object_r:init_exec_t,s0)
> +/usr/lib/systemd/systemd-shutdown	--	gen_context(system_u:object_r:init_exec_t,s0)
>   /usr/lib/systemd/system-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
>   /usr/lib/systemd/user-preset(/.*)? gen_context(system_u:object_r:systemd_unit_t,s0)
>   /usr/lib/systemd/ntp-units\.d -d gen_context(system_u:object_r:systemd_unit_t,s0)

Merged.


-- 
Chris PeBenito

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-10 19:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08 22:30 [refpolicy] [PATCH 1/1] label systemd-shutdown so shutdown works David Sugar
2017-12-09 16:15 ` Dominick Grift
2017-12-10 19:55 ` Chris PeBenito

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.