Skip to contentSkip to conversation

cups: read permission for cupsd_var_run_t socket files in cups_stream_connect()

PATCH Superseded Guido Trentalancia 4 participants 14 messages Feb 9, 2017 – Feb 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cups: read permission for cupsd_var_run_t socket files in cups_stream_connect()

Modify the cups_stream_connect() interface so that it can also read cupsd_var_run_t socket files in addition to writing them.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)
policy/modules/contrib/cups.if +1 -0
diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if
@@ -69,6 +69,7 @@ interface(`cups_stream_connect',`
 	')
 
 	files_search_pids($1)
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 	stream_connect_pattern($1, cupsd_var_run_t, cupsd_var_run_t, cupsd_t)
 ')
 
#1 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Modify the cups_read_pid_files() interface so that it allows to read socket files of the cupsd_var_run_t type and not only standard files.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)
policy/modules/contrib/cups.if +1 -0
diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if
@@ -124,6 +124,7 @@ interface(`cups_read_pid_files',`
 
 	files_search_pids($1)
 	allow $1 cupsd_var_run_t:file read_file_perms;
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 ')
 
 ########################################
#2 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Quoted 13 lines · Guido Trentalancia via refpolicy

Modify the cups_read_pid_files() interface so that it allows to read socket files of the cupsd_var_run_t type and not only standard files.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)

diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if

policy/modules/contrib/cups.if interface(`cups_read_pid_files',` · line 130

Quoted 7 lines
policy/modules/contrib/cups.if +1 -0
@@ -124,6 +124,7 @@ interface(`cups_read_pid_files',`
 
 	files_search_pids($1)
 	allow $1 cupsd_var_run_t:file read_file_perms;
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 ')
 
 ########################################

You really saw sock_file read? I don't think I've ever seen that. Regardless, this should be a separate interface.

Signature · 1 line
Chris PeBenito
#3 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Yes, I confirm, sock_file read permissions are needed to print.

Quoted 27 lines · Chris PeBenito
Quoted 10 lines · Guido Trentalancia via refpolicy

Modify the cups_read_pid_files() interface so that it allows to read socket files of the cupsd_var_run_t type and not only standard files.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)

diff -pru a/policy/modules/contrib/cups.if

b/policy/modules/contrib/cups.if

Quoted 1 line

--- a/policy/modules/contrib/cups.if 2017-01-24 18:56:19.569106107

+0100

Quoted 1 line

+++ b/policy/modules/contrib/cups.if 2017-02-09 16:46:23.649827258

+0100

policy/modules/contrib/cups.if interface(`cups_read_pid_files',` · line 130

Quoted 8 lines
policy/modules/contrib/cups.if +1 -0
@@ -124,6 +124,7 @@ interface(`cups_read_pid_files',`
 
 	files_search_pids($1)
 	allow $1 cupsd_var_run_t:file read_file_perms;
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 ')
 
 ########################################

You really saw sock_file read? I don't think I've ever seen that. Regardless, this should be a separate interface.

#4 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Quoted 1 line · Guido Trentalancia via refpolicy

Yes, I confirm, sock_file read permissions are needed to print.

Just to be clear: So it does not work if you do not allow the read? Sounds to me like this might be a leaked file descriptor issue instead

Quoted 35 lines · Chris PeBenito
Quoted 23 lines · Guido Trentalancia via refpolicy
Quoted 10 lines

Modify the cups_read_pid_files() interface so that it allows to read socket files of the cupsd_var_run_t type and not only standard files.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)

diff -pru a/policy/modules/contrib/cups.if

b/policy/modules/contrib/cups.if

Quoted 1 line

--- a/policy/modules/contrib/cups.if 2017-01-24 18:56:19.569106107

+0100

Quoted 1 line

+++ b/policy/modules/contrib/cups.if 2017-02-09 16:46:23.649827258

+0100

Quoted 7 lines
policy/modules/contrib/cups.if +1 -0
@@ -124,6 +124,7 @@ interface(`cups_read_pid_files',`
 
 	files_search_pids($1)
 	allow $1 cupsd_var_run_t:file read_file_perms;
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 ')
 
Quoted 4 lines

policy/modules/contrib/cups.if interface(`cups_read_pid_files',` · line 130

Quoted 1 line
policy/modules/contrib/cups.if +0 -0
 ########################################

You really saw sock_file read? I don't think I've ever seen that. Regardless, this should be a separate interface.

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

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

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

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

No, it is not able to detect printers without the permission to read cupsd_var_run_t socket files...

Quoted 42 lines · Dominick Grift via refpolicy
Quoted 1 line · Guido Trentalancia via refpolicy

Yes, I confirm, sock_file read permissions are needed to print.

Just to be clear: So it does not work if you do not allow the read? Sounds to me like this might be a leaked file descriptor issue instead

Quoted 2 lines

On the 11th of February 2017 20:54:00 CET, Chris PeBenito

Quoted 33 lines · <[email protected]> wrote:
Quoted 23 lines · Guido Trentalancia via refpolicy
Quoted 10 lines

Modify the cups_read_pid_files() interface so that it allows to read socket files of the cupsd_var_run_t type and not only standard files.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)

diff -pru a/policy/modules/contrib/cups.if

b/policy/modules/contrib/cups.if

Quoted 1 line

--- a/policy/modules/contrib/cups.if 2017-01-24 18:56:19.569106107

+0100

Quoted 1 line

+++ b/policy/modules/contrib/cups.if 2017-02-09 16:46:23.649827258

+0100

Quoted 7 lines
policy/modules/contrib/cups.if +1 -0
@@ -124,6 +124,7 @@ interface(`cups_read_pid_files',`
 
 	files_search_pids($1)
 	allow $1 cupsd_var_run_t:file read_file_perms;
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 ')
 
Quoted 4 lines

policy/modules/contrib/cups.if interface(`cups_read_pid_files',` · line 130

Quoted 1 line
policy/modules/contrib/cups.if +0 -0
 ########################################

You really saw sock_file read? I don't think I've ever seen that. Regardless, this should be a separate interface.

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

#6 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

In reply to Guido Trentalancia
Quoted 1 line · AEDT Guido Trentalancia via refpolicy

Yes, I confirm, sock_file read permissions are needed to print.

I've seen that too. I have something similar in the Debian policy.

It's not needed to print, it's needed in some configurations which are the default for some situations. It should be possible to configure cups to not need that if you don't need lpr/lpq type functionality - but that may not be possible for all clients.

Signature · 2 lines
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/
#7 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Quoted 10 lines · Russell Coker via refpolicy
Quoted 1 line · AEDT Guido Trentalancia via refpolicy

Yes, I confirm, sock_file read permissions are needed to print.

I've seen that too. I have something similar in the Debian policy.

It's not needed to print, it's needed in some configurations which are the default for some situations. It should be possible to configure cups to not need that if you don't need lpr/lpq type functionality - but that may not be possible for all clients.

It's interesting. Years ago when I put together the socket pattern macros I couldn't trigger a sock_file:read, though I didn't try every single UNIX stream socket function. I'll have to look at the kernel code again in case it warrants an update to one of the patterns.

Signature · 1 line
Chris PeBenito
#8 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

In reply to Russell Coker
Quoted 11 lines · AEDT Russell Coker via refpolicy
Quoted 1 line · AEDT Guido Trentalancia via refpolicy

Yes, I confirm, sock_file read permissions are needed to print.

I've seen that too. I have something similar in the Debian policy.

It's not needed to print, it's needed in some configurations which are the default for some situations. It should be possible to configure cups to not need that if you don't need lpr/lpq type functionality - but that may not be possible for all clients.

Does it make sense to have a cups_read_sock_files when the cups clients need read/write access? Why not just have a single interface granting read-write?

In Debian I used the below patch to make cups_stream_connect do what is necessary. Otherwise you will just have to add cups_read_sock_files after every call to cups_stream_connect.

policy/modules/contrib/cups.if +3 -1
Index: refpolicy-2.20170212/policy/modules/contrib/cups.if
===================================================================
@@ -69,7 +69,9 @@ interface(`cups_stream_connect',`
        ')
 
        files_search_pids($1)
-       stream_connect_pattern($1, cupsd_var_run_t, cupsd_var_run_t, cupsd_t)
+        allow $1 cupsd_var_run_t:dir search_dir_perms;
+       allow $1 cupsd_var_run_t:sock_file  { read write_sock_file_perms };
+       allow $1 cupsd_t:unix_stream_socket connectto;
 ')
 
 ########################################
Signature · 2 lines
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/
#9 lore raw

PATCH 2/2 cups: read permission for cupsd_var_run_t socket files in cups_read_pid_files()

Quoted 3 lines · AEDT Russell Coker

Does it make sense to have a cups_read_sock_files when the cups clients need read/write access? Why not just have a single interface granting read-write?

I just noticed you added read access to cups_stream_connect so cups_read_sock_files is redundant.

Signature · 2 lines
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/
#10 lore raw

PATCH v2 2/2 cups/lpd: read permission for cupsd_var_run_t socket files

In reply to Chris PeBenito

Introduce a new interface in the cups module to read cups socket files and call such interface from the lpd module.

Thanks to Christpher PeBenito for revising this patch.

---
 policy/modules/contrib/cups.if |   19 +++++++++++++++++++
 policy/modules/contrib/lpd.te  |    1 +
 2 files changed, 20 insertions(+)
policy/modules/contrib/cups.if +19 -0
diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if
@@ -128,6 +128,25 @@ interface(`cups_read_pid_files',`
 
 ########################################
 ## <summary>
+##	Read cups socket files.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`cups_read_sock_files',`
+	gen_require(`
+		type cupsd_var_run_t;
+	')
+
+	files_search_pids($1)
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
+')
+
+########################################
+## <summary>
 ##	Execute cups_config in the
 ##	cups config domain.
 ## </summary>
policy/modules/contrib/lpd.te +1 -0
diff -pru a/policy/modules/contrib/lpd.te b/policy/modules/contrib/lpd.te
@@ -295,6 +295,7 @@ optional_policy(`
 	cups_read_config(lpr_t)
 	cups_stream_connect(lpr_t)
 	cups_read_pid_files(lpr_t)
+	cups_read_sock_files(lpr_t)
 ')
 
 optional_policy(`
#11 lore raw

PATCH v2 2/2 cups/lpd: read permission for cupsd_var_run_t socket files

Quoted 44 lines · Guido Trentalancia via refpolicy

Introduce a new interface in the cups module to read cups socket files and call such interface from the lpd module.

Thanks to Christpher PeBenito for revising this patch.

---
 policy/modules/contrib/cups.if |   19 +++++++++++++++++++
 policy/modules/contrib/lpd.te  |    1 +
 2 files changed, 20 insertions(+)

diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if

policy/modules/contrib/cups.if +19 -0
@@ -128,6 +128,25 @@ interface(`cups_read_pid_files',`
 
 ########################################
 ## <summary>
+##	Read cups socket files.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`cups_read_sock_files',`
+	gen_require(`
+		type cupsd_var_run_t;
+	')
+
+	files_search_pids($1)
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
+')
+
+########################################
+## <summary>
 ##	Execute cups_config in the
 ##	cups config domain.
 ## </summary>

diff -pru a/policy/modules/contrib/lpd.te b/policy/modules/contrib/lpd.te

policy/modules/contrib/lpd.te optional_policy(` · line 301

Quoted 7 lines
policy/modules/contrib/lpd.te +1 -0
@@ -295,6 +295,7 @@ optional_policy(`
 	cups_read_config(lpr_t)
 	cups_stream_connect(lpr_t)
 	cups_read_pid_files(lpr_t)
+	cups_read_sock_files(lpr_t)
 ')
 
 optional_policy(`

Merged.

Signature · 1 line
Chris PeBenito
#12 lore raw

PATCH v2 2/2 cups/lpd: read permission for cupsd_var_run_t socket files

Hello.

As correctly noted by Russell Coker, this patch is unneeded after part 1/2 is applied.

So, part 2/2 can be safely reverted.

Regards,

Guido

Quoted 60 lines · Chris PeBenito
Quoted 5 lines · Guido Trentalancia via refpolicy

Introduce a new interface in the cups module to read cups socket files and call such interface from the lpd module.

Thanks to Christpher PeBenito for revising this patch.

Quoted 7 lines
---
 policy/modules/contrib/cups.if |   19 +++++++++++++++++++
 policy/modules/contrib/lpd.te  |    1 +
 2 files changed, 20 insertions(+)

diff -pru a/policy/modules/contrib/cups.if

b/policy/modules/contrib/cups.if

Quoted 1 line

--- a/policy/modules/contrib/cups.if 2017-01-24 18:56:19.569106107

+0100

Quoted 1 line

+++ b/policy/modules/contrib/cups.if 2017-02-11 21:04:00.346144792

+0100

Quoted 26 lines
policy/modules/contrib/cups.if +19 -0
@@ -128,6 +128,25 @@ interface(`cups_read_pid_files',`
 
 ########################################
 ## <summary>
+##	Read cups socket files.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`cups_read_sock_files',`
+	gen_require(`
+		type cupsd_var_run_t;
+	')
+
+	files_search_pids($1)
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
+')
+
+########################################
+## <summary>
 ##	Execute cups_config in the
 ##	cups config domain.
 ## </summary>
Quoted 1 line

diff -pru a/policy/modules/contrib/lpd.te

b/policy/modules/contrib/lpd.te

Quoted 1 line

--- a/policy/modules/contrib/lpd.te 2016-12-22 23:12:59.385081782

+0100

Quoted 1 line

+++ b/policy/modules/contrib/lpd.te 2017-02-11 21:04:28.457255575

+0100

policy/modules/contrib/lpd.te optional_policy(` · line 301

Quoted 8 lines
policy/modules/contrib/lpd.te +1 -0
@@ -295,6 +295,7 @@ optional_policy(`
 	cups_read_config(lpr_t)
 	cups_stream_connect(lpr_t)
 	cups_read_pid_files(lpr_t)
+	cups_read_sock_files(lpr_t)
 ')
 
 optional_policy(`

Merged.

#13 lore raw

PATCH 1/2 cups: read permission for cupsd_var_run_t socket files in cups_stream_connect()

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

Modify the cups_stream_connect() interface so that it can also read cupsd_var_run_t socket files in addition to writing them.

---
 policy/modules/contrib/cups.if |    1 +
 1 file changed, 1 insertion(+)

diff -pru a/policy/modules/contrib/cups.if b/policy/modules/contrib/cups.if

policy/modules/contrib/cups.if interface(`cups_stream_connect',` · line 74

Quoted 6 lines
policy/modules/contrib/cups.if +1 -0
@@ -69,6 +69,7 @@ interface(`cups_stream_connect',`
 	')
 
 	files_search_pids($1)
+	allow $1 cupsd_var_run_t:sock_file read_sock_file_perms;
 	stream_connect_pattern($1, cupsd_var_run_t, cupsd_var_run_t, cupsd_t)
 ')

Merged.

Signature · 1 line
Chris PeBenito