Skip to contentSkip to conversation

Add int_rlimit_inherit interface

PATCH New David Sugar 3 participants 16 messages Sep 13, 2017 – Sep 15, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -0
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+##	Allow process to inherit resource limits.
+## </summary>
+## <p>
+##	This is applicable with systemd when using the
+##	options to limit resources - see 
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+	gen_require(`
+		type init_t;
+	')
+
+	allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ##	Send init a generic signal.
 ## </summary>
 ## <param name="domain">
Signature · 1 line
2.13.5
#1 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 23 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

---
  policy/modules/system/init.if | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
policy/modules/system/init.if +4 -0
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
  ########################################
  ## <summary>
+##	Allow process to inherit resource limits.
+## </summary>
+## <p>
+##	This is applicable with systemd when using the

policy/modules/system/init.if interface(`init_getpgid',` · line 728

Quoted 10 lines
policy/modules/system/init.if +10 -0
+##	options to limit resources - see
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`

Merged, though I renamed this to init_inherit_rlimit().

Quoted 13 lines
policy/modules/system/init.if +9 -0
+	gen_require(`
+		type init_t;
+	')
+
+	allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
  ##	Send init a generic signal.
  ## </summary>
  ## <param name="domain">
Signature · 1 line
Chris PeBenito
#2 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

In reply to David Sugar
Quoted 5 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Have you tested this?

I just tried this out and i do not seem to need this to get it to work:

https://www.youtube.com/watch?v=f8nFGbMBG0s

Quoted 46 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -0
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+##	Allow process to inherit resource limits.
+## </summary>
+## <p>
+##	This is applicable with systemd when using the
+##	options to limit resources - see 
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+	gen_require(`
+		type init_t;
+	')
+
+	allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ##	Send init a generic signal.
 ## </summary>
 ## <param name="domain">
Signature · 5 lines
2.13.5
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy
Signature · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/84922207/attachment.bin 
#3 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 5 lines · Dominick Grift
Quoted 4 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

Quoted 7 lines
Quoted 1 line

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Have you tested this?

I just tried this out and i do not seem to need this to get it to work:

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

Quoted 52 lines
Quoted 47 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -0
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+##	Allow process to inherit resource limits.
+## </summary>
+## <p>
+##	This is applicable with systemd when using the
+##	options to limit resources - see 
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+	gen_require(`
+		type init_t;
+	')
+
+	allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ##	Send init a generic signal.
 ## </summary>
 ## <param name="domain">
Signature · 5 lines
2.13.5
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com
http://oss.tresys.com/mailman/listinfo/refpolicy
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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/0eb1f8e1/attachment.bin 
#4 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

________________________________________
From: [email protected] [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 7 lines · Dominick Grift
Quoted 5 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Quoted 7 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to work:

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting LimitMSGQUEUE=infinity in my .service file. The service is starting a c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size. I was getting failures to create the message queue (I'm pretty sure the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like). Once I added this permission (and only this one change) the error went away.

I did watch your video and I'm not sure what the difference is between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

I am also using the SELinuxContext= option to explicitly set the target domain. I also don't think this would make a difference, but I wanted to mention it.

Dave Sugar

Quoted 44 lines
Quoted 44 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -1
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the
+## options to limit resources - see
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--

2.13.5
_______________________________________________

Quoted 8 lines
Quoted 3 lines

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

--
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

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 19 lines · David Sugar via refpolicy

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 11 lines · Dominick Grift
Quoted 5 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Have you tested this?

I just tried this out and i do not seem to need this to get it to work:

Quoted 7 lines
Quoted 3 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting LimitMSGQUEUE=infinity in my .service file. The service is starting a c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size. I was getting failures to create the message queue (I'm pretty sure the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like). Once I added this permission (and only this one change) the error went away.

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 70 lines

I did watch your video and I'm not sure what the difference is between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

I am also using the SELinuxContext= option to explicitly set the target domain. I also don't think this would make a difference, but I wanted to mention it.

Dave Sugar

Quoted 44 lines
Quoted 44 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -1
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the
+## options to limit resources - see
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--

2.13.5
_______________________________________________

Quoted 8 lines
Quoted 3 lines

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

--
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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/94e70097/attachment.bin 
#6 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 24 lines · Dominick Grift
Quoted 23 lines · David Sugar via refpolicy

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 14 lines · Dominick Grift
Quoted 5 lines · David Sugar via refpolicy

Create new interface init_rlimit_inherit to allow a process started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Have you tested this?

I just tried this out and i do not seem to need this to get it to work:

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

Quoted 7 lines
Quoted 3 lines

I tested this in the use case that I am working with. I am setting LimitMSGQUEUE=infinity in my .service file. The service is starting a c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size. I was getting failures to create the message queue (I'm pretty sure the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like). Once I added this permission (and only this one change) the error went away.

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

Quoted 76 lines
Quoted 71 lines

I did watch your video and I'm not sure what the difference is between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

I am also using the SELinuxContext= option to explicitly set the target domain. I also don't think this would make a difference, but I wanted to mention it.

Dave Sugar

Quoted 44 lines
Quoted 44 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
policy/modules/system/init.if +23 -1
index 09a20311..bf6e37bc 100644
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the
+## options to limit resources - see
+##  https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--

2.13.5
_______________________________________________

Quoted 8 lines
Quoted 3 lines

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

--
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 · 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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/5bf00c65/attachment.bin 
#7 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 64 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exec.ht
ml

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 1 line
Quoted 1 line

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 1 line
Quoted 1 line

Once I added this permission (and only this one change) the error

went away.

Quoted 3 lines

I can't produce this:

Quoted 7 lines
Quoted 1 line

https://www.youtube.com/watch?v=yRcyBQfkKoE

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

After that I created the interface in init.if and again verified the problem was still solved.

I will try to create a simple binary to reproduce the problem I'm seeing.
Other information that might make a difference, I am running using CentOS 7.3.1611, systemd-219-30.el7_3.9.

Dave

Quoted 92 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 71 lines
Quoted 61 lines

Dave Sugar

Quoted 47 lines
Quoted 47 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +24 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ## options to
+limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.exec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--

2.13.5
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com

Quoted 8 lines
Quoted 1 line

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=0x3B6C5F1D2C7B
6B02
Dominick Grift

Quoted 9 lines

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

Quoted 4 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

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

#8 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 72 lines · David Sugar via refpolicy
Quoted 64 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exec.ht
ml

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 1 line
Quoted 1 line

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 1 line
Quoted 1 line

Once I added this permission (and only this one change) the error

went away.

Quoted 3 lines

I can't produce this:

Quoted 7 lines
Quoted 1 line

https://www.youtube.com/watch?v=yRcyBQfkKoE

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

Quoted 6 lines

I wasn't seeing any denials (which made it harder to diagnose the problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

After that I created the interface in init.if and again verified the problem was still solved.

I will try to create a simple binary to reproduce the problem I'm seeing.
Other information that might make a difference, I am running using CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

Quoted 98 lines

Dave

Quoted 88 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 71 lines
Quoted 61 lines

Dave Sugar

Quoted 47 lines
Quoted 47 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +24 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ## options to
+limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.exec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--

2.13.5
_______________________________________________
refpolicy mailing list
refpolicy at oss.tresys.com

Quoted 8 lines
Quoted 1 line

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=0x3B6C5F1D2C7B
6B02
Dominick Grift

Quoted 9 lines

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

Quoted 4 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

Quoted 4 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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/153b83fe/attachment.bin 
#9 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Quoted 113 lines
Quoted 104 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

Quoted 4 lines

_______________________________________________
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

#10 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 113 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

Quoted 6 lines

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

allow init_t $1:process rlimitinh;

my policy doesnt have that either:

# sesearch -A -s systemd.system.subj -c process -p rlimitinh
#

no returns

Quoted 120 lines

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Quoted 109 lines
Quoted 104 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

Quoted 4 lines

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

Quoted 4 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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/909447dd/attachment-0001.bin 
#11 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

In reply to David Sugar
Quoted 113 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

Quoted 8 lines

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Youre right about the latter

allow init_t $1:process rlimitinh is for soft limits it seems

Quoted 118 lines
Quoted 110 lines
Quoted 105 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

Quoted 4 lines

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

Quoted 4 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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/4f5ffba3/attachment.bin 
#12 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 119 lines · Dominick Grift
Quoted 118 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

Quoted 7 lines
Quoted 3 lines

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Youre right about the latter

allow init_t $1:process rlimitinh is for soft limits it seems

Some info i gathered

"Set soft and hard limits on various resources for executed processes. See setrlimit(2) for details
on the resource limit concept. Resource limits may be specified in two formats: either as single value to set a specific soft and hard limit to the same value, or as colon-separated pair soft:hard to set both limits individually (e.g. "LimitAS=4G:16G")"

"If the rlimitinh permission
is denied, then all soft resource limits are reset to the lower of the current task?s hard limit and the initial task?s soft limit. This control relies on the proper control of the setrlimit permission to prevent untrusted processes from lowering hard limits as well. The inclusion of the initial task?s soft limits into the computation is to avoid resetting soft limits higher than the default soft limit for cases where the default is lower than the hard limit, e.g. RLIMIT_CORE or RLIMIT_STACK."

Setting LimitNPROC=5 for example sets both soft and hard to 5, and this doesnt need rlimitinh Setting LimitNPROC=4:5 for example sets soft to 4 and hard to 5, and this needs rlimitinh

Quoted 124 lines
Quoted 119 lines
Quoted 111 lines
Quoted 106 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

Quoted 4 lines

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

Quoted 4 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 · 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 · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/1943a8e8/attachment-0001.bin 
#13 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 141 lines · Dominick Grift
Quoted 119 lines · Dominick Grift
Quoted 118 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

Quoted 7 lines
Quoted 3 lines

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Youre right about the latter

allow init_t $1:process rlimitinh is for soft limits it seems

Some info i gathered

"Set soft and hard limits on various resources for executed processes. See setrlimit(2) for details
on the resource limit concept. Resource limits may be specified in two formats: either as single value to set a specific soft and hard limit to the same value, or as colon-separated pair soft:hard to set both limits individually (e.g. "LimitAS=4G:16G")"

"If the rlimitinh permission
is denied, then all soft resource limits are reset to the lower of the current task?s hard limit and the initial task?s soft limit. This control relies on the proper control of the setrlimit permission to prevent untrusted processes from lowering hard limits as well. The inclusion of the initial task?s soft limits into the computation is to avoid resetting soft limits higher than the default soft limit for cases where the default is lower than the hard limit, e.g. RLIMIT_CORE or RLIMIT_STACK."

Quoted 2 lines

Setting LimitNPROC=5 for example sets both soft and hard to 5, and this doesnt need rlimitinh Setting LimitNPROC=4:5 for example sets soft to 4 and hard to 5, and this needs rlimitinh

I *suspect* that LimitSIGPENDING= requires siginh, i should try that out ...

Quoted 132 lines
Quoted 125 lines
Quoted 120 lines
Quoted 112 lines
Quoted 107 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

Quoted 4 lines

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

Quoted 4 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 · 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
Signature · 10 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: not available
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20170914/91035efe/attachment-0001.bin 
#14 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

________________________________________
From: [email protected] [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 5:41 PM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 141 lines · Dominick Grift
Quoted 119 lines · Dominick Grift
Quoted 118 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

Quoted 7 lines
Quoted 3 lines

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Youre right about the latter

allow init_t $1:process rlimitinh is for soft limits it seems

Some info i gathered

"Set soft and hard limits on various resources for executed processes. See setrlimit(2) for details
on the resource limit concept. Resource limits may be specified in two formats: either as single value to set a specific soft and hard limit to the same value, or as colon-separated pair soft:hard to set both limits individually (e.g. "LimitAS=4G:16G")"

"If the rlimitinh permission
is denied, then all soft resource limits are reset to the lower of the current task?s hard limit and the initial task?s soft limit. This control relies on the proper control of the setrlimit permission to prevent untrusted processes from lowering hard limits as well. The inclusion of the initial task?s soft limits into the computation is to avoid resetting soft limits higher than the default soft limit for cases where the default is lower than the hard limit, e.g. RLIMIT_CORE or RLIMIT_STACK."

Quoted 4 lines

Setting LimitNPROC=5 for example sets both soft and hard to 5, and this doesnt need rlimitinh Setting LimitNPROC=4:5 for example sets soft to 4 and hard to 5, and this needs rlimitinh

I *suspect* that LimitSIGPENDING= requires siginh, i should try that out ...

Thanks for noticing my error, sorry it took so long to realize I made a silly mistake. I will submit a patch to fix my previous patch.

And as you mentioned before, there are no denials shown for these problems as they are dontaudit'd by default as there would be so many denials. I suspect it will be hard for developers to know what the problem is.

Quoted 128 lines
Quoted 121 lines
Quoted 112 lines
Quoted 112 lines
Quoted 111 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

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

Quoted 8 lines
Quoted 4 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

Quoted 4 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

Quoted 4 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

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

#15 lore raw

PATCH 1/1 Add int_rlimit_inherit interface

Quoted 149 lines · David Sugar via refpolicy

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 5:41 PM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 141 lines · Dominick Grift
Quoted 119 lines · Dominick Grift
Quoted 118 lines · David Sugar via refpolicy
Quoted 104 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:55 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 74 lines · David Sugar via refpolicy
Quoted 74 lines

-----Original Message-----
From: refpolicy-bounces at oss.tresys.com [mailto:refpolicy- bounces at oss.tresys.com] On Behalf Of Dominick Grift via refpolicy
Sent: Thursday, September 14, 2017 10:28 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 2 lines · Dominick Grift

On Thu, Sep 14, 2017 at 01:45:19PM +0000, David Sugar via refpolicy

Quoted 12 lines · wrote:
Quoted 12 lines

________________________________________
From: refpolicy-bounces at oss.tresys.com [refpolicy-bounces at oss.tresys.com] on behalf of Dominick Grift via refpolicy [refpolicy at oss.tresys.com]
Sent: Thursday, September 14, 2017 4:20 AM
To: refpolicy at oss.tresys.com
Subject: Re: [refpolicy] [PATCH 1/1] Add int_rlimit_inherit interface

Quoted 1 line · Dominick Grift

On Wed, Sep 13, 2017 at 08:34:15PM +0000, David Sugar via

Quoted 1 line · refpolicy
Quoted 1 line
Quoted 1 line
Quoted 1 line

Create new interface init_rlimit_inherit to allow a process

started by init to inherit resource limits. systemd allows for setting of resource limits [1] but the default from SELinux is to not allow the inheritance of those limits as a service is started. This interface allows that resource limit inheritance.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The systemd .service options are LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

[1]
https://www.freedesktop.org/software/systemd/man/systemd.exe
c.ht
ml

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Have you tested this?

I just tried this out and i do not seem to need this to get it to

work:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

https://www.youtube.com/watch?v=f8nFGbMBG0s

Instead systemd needs to be able to "setrlimit" (and probably getsched/setsched) on its children i suspect

I tested this in the use case that I am working with. I am setting

LimitMSGQUEUE=infinity in my .service file. The service is starting a
c++ binary which is creating a message queue (using mq_open) with a fairly large message queue size.

Quoted 2 lines
Quoted 2 lines

I was getting failures to create the message queue (I'm pretty sure

the error was EMFILE - I don't have the error message returned from mq_open handy any longer I can rebuild the policy and retest if you would like).

Quoted 2 lines
Quoted 2 lines

Once I added this permission (and only this one change) the error

went away.

Quoted 4 lines

I can't produce this:

https://www.youtube.com/watch?v=yRcyBQfkKoE

Quoted 7 lines
Quoted 5 lines

That test isnt right, but i redid it and it just doesnt even try to rlimitinh In other words the event you allow doesnt even happen IMHO

Did you even see an avc denial before you decided to allow this? Or did you assume that this would be needed?

I wasn't seeing any denials (which made it harder to diagnose the

problem). The problem being the failure of mq_open only when in enforcing. But when I turn off dontaudit's (semodule -DB) I saw that every processes that is exec'ed has denials for noatsecure, siginh, and rlimitinh (from domain_transition_pattern). I then looked up exactly what those permissions were and rlimitinh sounded like something reasonable to try. I then manually added a rule to my policy to grant that permission and then the problem went away.

Quoted 2 lines

After that I created the interface in init.if and again verified the

problem was still solved.

Quoted 2 lines

I will try to create a simple binary to reproduce the problem I'm

Quoted 8 lines

seeing.

Quoted 1 line

Other information that might make a difference, I am running using

CentOS 7.3.1611, systemd-219-30.el7_3.9.

I tried it on bluetooth and bluetooth didnt try to rlimitinh on systemd.

Could you show me an avc denials where an systemd daemon tries to rlimitinh on systemd?

I see what is going on here and it looks like a copy/paste error in my initial patch. Your last comment made it clearer to me and I reviewed the patch again.

It looks like I swapped the two type parameters in the allow rule. It should be:

Quoted 7 lines
Quoted 3 lines

allow init_t $1:process rlimitinh;

I have looked at the patch I made and it matches what I have in my tree. But I now need to figure out why when I have the built policy I'm seeing the correct rule (and not the rule as written). Meaning I have something wrong in my build tree locally.

Youre right about the latter

allow init_t $1:process rlimitinh is for soft limits it seems

Some info i gathered

"Set soft and hard limits on various resources for executed processes. See setrlimit(2) for details
on the resource limit concept. Resource limits may be specified in two formats: either as single value to set a specific soft and hard limit to the same value, or as colon-separated pair soft:hard to set both limits individually (e.g. "LimitAS=4G:16G")"

"If the rlimitinh permission
is denied, then all soft resource limits are reset to the lower of the current task?s hard limit and the initial task?s soft limit. This control relies on the proper control of the setrlimit permission to prevent untrusted processes from lowering hard limits as well. The inclusion of the initial task?s soft limits into the computation is to avoid resetting soft limits higher than the default soft limit for cases where the default is lower than the hard limit, e.g. RLIMIT_CORE or RLIMIT_STACK."

Quoted 8 lines
Quoted 4 lines

Setting LimitNPROC=5 for example sets both soft and hard to 5, and this doesnt need rlimitinh Setting LimitNPROC=4:5 for example sets soft to 4 and hard to 5, and this needs rlimitinh

I *suspect* that LimitSIGPENDING= requires siginh, i should try that out ...

Thanks for noticing my error, sorry it took so long to realize I made a silly mistake. I will submit a patch to fix my previous patch.

And as you mentioned before, there are no denials shown for these problems as they are dontaudit'd by default as there would be so many denials. I suspect it will be hard for developers to know what the problem is.

This stuff is pretty hard yes. Especially in strict environments. Thanks for inspiring me to look into this. Turns out DSSP2 had this all wrong as well.

Quoted 145 lines
Quoted 130 lines
Quoted 123 lines
Quoted 114 lines
Quoted 114 lines
Quoted 113 lines

Dave

Quoted 96 lines
Quoted 4 lines
Quoted 4 lines

I did watch your video and I'm not sure what the difference is

between the two cases. I don't know if making it a bash script is somehow making a difference (I don't know why it would)?

Quoted 2 lines
Quoted 2 lines

I am also using the SELinuxContext= option to explicitly set the

target domain. I also don't think this would make a difference, but I wanted to mention it.

Quoted 77 lines
Quoted 65 lines

Dave Sugar

Quoted 51 lines
Quoted 45 lines
---
 policy/modules/system/init.if | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
(quoted diff) +0 -0

b/policy/modules/system/init.if index 09a20311..bf6e37bc 100644

policy/modules/system/init.if +25 -1
@@ -712,6 +712,29 @@ interface(`init_getpgid',`
 
 ########################################
 ## <summary>
+## Allow process to inherit resource limits.
+## </summary>
+## <p>
+## This is applicable with systemd when using the ##
+options to limit resources - see ##
+https://www.freedesktop.org/software/systemd/man/systemd.ex
+ec.h
+tml#LimitMSGQUEUE=
+## </p>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`init_rlimit_inherit',`
+   gen_require(`
+           type init_t;
+   ')
+
+   allow $1 init_t:process rlimitinh;
+')
+
+########################################
+## <summary>
 ## Send init a generic signal.
 ## </summary>
 ## <param name="domain">
--
Quoted 5 lines

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

Quoted 8 lines

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

Quoted 11 lines

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

Quoted 6 lines

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

Quoted 5 lines

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

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

Quoted 8 lines
Quoted 4 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

Quoted 4 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

Quoted 4 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

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