Skip to contentSkip to conversation

postgres: Add neccessary map permissions

PATCH New Luis Ressel 3 participants 7 messages Jan 21, 2018 – Jan 24, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

---
 policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
 policy/modules/services/postgresql.te |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
 	allow $1 hugetlbfs_t:file rw_inherited_file_perms;
 ')
 
+########################################
+## <summary>
+##	Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##	<summary>
+##	Domain allowed access.
+##	</summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+	gen_require(`
+		type hugetlbfs_t;
+	')
+
+	allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
 ########################################
 ## <summary>
 ##	Read and write hugetlbfs files.
policy/modules/services/postgresql.te +2 -1
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
 manage_sock_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
 files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file sock_file })
 fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;
 
 manage_dirs_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
 manage_files_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
 fs_getattr_all_fs(postgresql_t)
 fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
 selinux_get_enforce_mode(postgresql_t)
 selinux_validate_context(postgresql_t)
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

Quoted 2 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

Quoted 62 lines
---
 policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
 policy/modules/services/postgresql.te |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
        allow $1 hugetlbfs_t:file rw_inherited_file_perms;
 ')
 
+########################################
+## <summary>
+##     Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##     <summary>
+##     Domain allowed access.
+##     </summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+       gen_require(`
+               type hugetlbfs_t;
+       ')
+
+       allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
 ########################################
 ## <summary>
 ##     Read and write hugetlbfs files.
policy/modules/services/postgresql.te +2 -2
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
 manage_sock_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
 files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file sock_file })
 fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;
 
 manage_dirs_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
 manage_files_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
 fs_getattr_all_fs(postgresql_t)
 fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
 selinux_get_enforce_mode(postgresql_t)
 selinux_validate_context(postgresql_t)
--

2.15.1

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

Signature · 4 lines
Mike Palmiotto
Software Engineer
Crunchy Data Solutions
https://crunchydata.com
#2 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

Quoted 5 lines · Mike Palmiotto via refpolicy
Quoted 2 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Quoted 7 lines

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

This seems like a possibility, but I'd like more info.

Quoted 55 lines
Quoted 55 lines
---
  policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
  policy/modules/services/postgresql.te |  3 ++-
  2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
         allow $1 hugetlbfs_t:file rw_inherited_file_perms;
  ')
 
+########################################
+## <summary>
+##     Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##     <summary>
+##     Domain allowed access.
+##     </summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+       gen_require(`
+               type hugetlbfs_t;
+       ')
+
+       allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
  ########################################
  ## <summary>
  ##     Read and write hugetlbfs files.
policy/modules/services/postgresql.te +2 -1
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
  manage_sock_files_pattern(postgresql_t, postgresql_tmp_t, postgresql_tmp_t)
  files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file sock_file })
  fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;
 
  manage_dirs_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
  manage_files_pattern(postgresql_t, postgresql_var_run_t, postgresql_var_run_t)
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
  fs_getattr_all_fs(postgresql_t)
  fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
  selinux_get_enforce_mode(postgresql_t)
  selinux_validate_context(postgresql_t)
Signature · 1 line
Chris PeBenito
#6 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

In reply to Mike Palmiotto
Quoted 5 lines · On Sun, 21 Jan 2018 14:52:50 -0500 Mike Palmiotto via refpolicy…
Quoted 2 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Quoted 7 lines

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

postgres uses huge pages by calling mmap() with fd=-1 and flags=MAP_ANONYMOUS|MAP_HUGETLB, which doesn't require the open permission.

I don't use virtd or mysql, so I haven't checked them; I couldn't verify the potential policy changes anyway. If someone else could take care of this, I'd be very grateful.

Cheers,
Luis

#3 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

In reply to Chris PeBenito
Quoted 18 lines · Chris PeBenito
Quoted 8 lines · Mike Palmiotto via refpolicy
Quoted 3 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Quoted 7 lines

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

Quoted 3 lines

This seems like a possibility, but I'd like more info.

From looking through the kernel docs

(https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt), it looks like 'read' system calls are perfectly acceptable, which is what initially lead me to believe that it's valid to open a hugetblfs_t file (fd open => read(fd)).

Candidly, I'm not super familiar with how hugetlbfs works, but the only references I see to it in the postgres source
(https://www.postgresql.org/docs/10/static/runtime-config-resource.html#GUC-HUGE-PAGES)
involve mmap calls. This might explain Luis's comment about 'open' not making sense. If this is the case, my next question is "Are virtd_t and mysqld_t the same?" I haven't had a chance to check yet.

I would like to verify that this change doesn't break hugetlbfs support on postgres. I'll spin up a Vagrant box this week to test it out. In the meantime, maybe we should just go ahead with the added map perms and address the open removal in a later commit (once proper testing and vetting of other domains has been done)?

Quoted 69 lines
Quoted 58 lines
Quoted 58 lines

---
  policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
  policy/modules/services/postgresql.te |  3 ++-
  2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
         allow $1 hugetlbfs_t:file rw_inherited_file_perms;
  ')
 
+########################################
+## <summary>
+##     Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##     <summary>
+##     Domain allowed access.
+##     </summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+       gen_require(`
+               type hugetlbfs_t;
+       ')
+
+       allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
  ########################################
  ## <summary>
  ##     Read and write hugetlbfs files.
policy/modules/services/postgresql.te +0 -0
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t,
 postgresql_tmp_t, postgresql_tmp_t)
  manage_sock_files_pattern(postgresql_t, postgresql_tmp_t,
 postgresql_tmp_t)
  files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file
 sock_file })
  fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file

sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;

manage_dirs_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)
manage_files_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)

policy/modules/services/postgresql.te +0 -0
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
Quoted 7 lines

policy/modules/services/postgresql.te dev_read_urand(postgresql_t) · line 337

Quoted 7 lines
policy/modules/services/postgresql.te +1 -1
  fs_getattr_all_fs(postgresql_t)
  fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
  selinux_get_enforce_mode(postgresql_t)
  selinux_validate_context(postgresql_t)

--
Chris PeBenito

Signature · 4 lines
Mike Palmiotto
Software Engineer
Crunchy Data Solutions
https://crunchydata.com
#4 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

Quoted 34 lines · Mike Palmiotto
Quoted 12 lines · Chris PeBenito
Quoted 11 lines · Mike Palmiotto via refpolicy
Quoted 3 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

Quoted 7 lines
Quoted 4 lines

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

This seems like a possibility, but I'd like more info.

From looking through the kernel docs
(https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt), it looks like 'read' system calls are perfectly acceptable, which is what initially lead me to believe that it's valid to open a hugetblfs_t file (fd open => read(fd)).

Candidly, I'm not super familiar with how hugetlbfs works, but the only references I see to it in the postgres source
(https://www.postgresql.org/docs/10/static/runtime-config-resource.html#GUC-HUGE-PAGES)
involve mmap calls. This might explain Luis's comment about 'open' not making sense. If this is the case, my next question is "Are virtd_t and mysqld_t the same?" I haven't had a chance to check yet.

Quoted 5 lines

I would like to verify that this change doesn't break hugetlbfs support on postgres. I'll spin up a Vagrant box this week to test it out. In the meantime, maybe we should just go ahead with the added map perms and address the open removal in a later commit (once proper testing and vetting of other domains has been done)?

I've verified that I can start postgres in Enforcing without the 'open' perm:
https://gist.github.com/anonymous/c8106ba77d50f87a57cbd875bbe84fbb

I would really like to test this more extensively on a Fedora 27 box, so I can try the full patch -- just haven't had the time yet. Chris/Luis, how do you feel about just adding the map perm and leaving the 'open' removal for a future patch?

Quoted 79 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines



---
  policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
  policy/modules/services/postgresql.te |  3 ++-
  2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
         allow $1 hugetlbfs_t:file rw_inherited_file_perms;
  ')
 
+########################################
+## <summary>
+##     Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##     <summary>
+##     Domain allowed access.
+##     </summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+       gen_require(`
+               type hugetlbfs_t;
+       ')
+
+       allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
  ########################################
  ## <summary>
  ##     Read and write hugetlbfs files.
policy/modules/services/postgresql.te +0 -0
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t,
 postgresql_tmp_t, postgresql_tmp_t)
  manage_sock_files_pattern(postgresql_t, postgresql_tmp_t,
 postgresql_tmp_t)
  files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file
 sock_file })
  fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file

sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;

manage_dirs_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)
manage_files_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)

policy/modules/services/postgresql.te +1 -1
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
  fs_getattr_all_fs(postgresql_t)
  fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
Quoted 6 lines
Quoted 2 lines

policy/modules/services/postgresql.te dev_read_urand(postgresql_t) · line 337

Quoted 2 lines
policy/modules/services/postgresql.te +0 -0
  selinux_get_enforce_mode(postgresql_t)
  selinux_validate_context(postgresql_t)

--
Chris PeBenito

--
Mike Palmiotto
Software Engineer
Crunchy Data Solutions
https://crunchydata.com

Signature · 4 lines
Mike Palmiotto
Software Engineer
Crunchy Data Solutions
https://crunchydata.com
#5 lore raw

PATCH 1/1 postgres: Add neccessary map permissions

Quoted 29 lines · Mike Palmiotto
Quoted 27 lines · Mike Palmiotto
Quoted 12 lines · Chris PeBenito
Quoted 11 lines · Mike Palmiotto via refpolicy
Quoted 3 lines · Luis Ressel via refpolicy

I'm also removing pg's permission to open hugetlbfs_t files, since it doesn't make any sense.

Is this because hugetlbfs_t files are accessed via mmap or read? Doesn't read require an open file descriptor?

Quoted 7 lines
Quoted 4 lines

virtd_t and mysqld_t are also calling the fs_rw_hugetlbfs_files interface. If this is meant to address an issue fundamental to hugetlbfs and not something postgres-specific, perhaps the commit should fix the interface itself and/or virtd_t and mysqld_t as well.

This seems like a possibility, but I'd like more info.

From looking through the kernel docs
(https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt), it looks like 'read' system calls are perfectly acceptable, which is what initially lead me to believe that it's valid to open a hugetblfs_t file (fd open => read(fd)).

Quoted 6 lines
Quoted 6 lines

Candidly, I'm not super familiar with how hugetlbfs works, but the only references I see to it in the postgres source
(https://www.postgresql.org/docs/10/static/runtime-config-resource.html#GUC-HUGE-PAGES)
involve mmap calls. This might explain Luis's comment about 'open' not making sense. If this is the case, my next question is "Are virtd_t and mysqld_t the same?" I haven't had a chance to check yet.

I should have been clearer with my question. I meant to ask if the mmap was intrinsic to hugetlbfs use. Since postgres is explicitly mmapping it, then it would seem the answer is no.

Quoted 6 lines
Quoted 5 lines

I would like to verify that this change doesn't break hugetlbfs support on postgres. I'll spin up a Vagrant box this week to test it out. In the meantime, maybe we should just go ahead with the added map perms and address the open removal in a later commit (once proper testing and vetting of other domains has been done)?

Quoted 7 lines

I've verified that I can start postgres in Enforcing without the 'open' perm:
https://gist.github.com/anonymous/c8106ba77d50f87a57cbd875bbe84fbb

I would really like to test this more extensively on a Fedora 27 box, so I can try the full patch -- just haven't had the time yet. Chris/Luis, how do you feel about just adding the map perm and leaving the 'open' removal for a future patch?

I'd like to delay the open removal too, as I would think you normally would need that too.

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
---
   policy/modules/kernel/filesystem.if   | 18 ++++++++++++++++++
   policy/modules/services/postgresql.te |  3 ++-
   2 files changed, 20 insertions(+), 1 deletion(-)
policy/modules/kernel/filesystem.if +18 -0
index 41f19619..e2a58d8e 100644
@@ -2322,6 +2322,24 @@ interface(`fs_rw_inherited_hugetlbfs_files',`
          allow $1 hugetlbfs_t:file rw_inherited_file_perms;
   ')
 
+########################################
+## <summary>
+##     Read and write inherited hugetlbfs files.
+## </summary>
+## <param name="domain">
+##     <summary>
+##     Domain allowed access.
+##     </summary>
+## </param>
+#
+interface(`fs_mmap_rw_inherited_hugetlbfs_files',`
+       gen_require(`
+               type hugetlbfs_t;
+       ')
+
+       allow $1 hugetlbfs_t:file mmap_rw_inherited_file_perms;
+')
+
   ########################################
   ## <summary>
   ##     Read and write hugetlbfs files.
policy/modules/services/postgresql.te +0 -0
index f118d9d0..97a9d153 100644
@@ -297,6 +297,7 @@ manage_fifo_files_pattern(postgresql_t,
 postgresql_tmp_t, postgresql_tmp_t)
   manage_sock_files_pattern(postgresql_t, postgresql_tmp_t,
 postgresql_tmp_t)
   files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file
 sock_file })
   fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file

sock_file fifo_file })
+allow postgresql_t postgresql_tmp_t:file map;

manage_dirs_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)
manage_files_pattern(postgresql_t, postgresql_var_run_t,
postgresql_var_run_t)

policy/modules/services/postgresql.te +1 -1
@@ -330,7 +331,7 @@ dev_read_urand(postgresql_t)
 
   fs_getattr_all_fs(postgresql_t)
   fs_search_auto_mountpoints(postgresql_t)
-fs_rw_hugetlbfs_files(postgresql_t)
+fs_mmap_rw_inherited_hugetlbfs_files(postgresql_t)
 
   selinux_get_enforce_mode(postgresql_t)
   selinux_validate_context(postgresql_t)
Signature · 1 line
Chris PeBenito