Blame SOURCES/0017-sepolicy-generate-Handle-more-reserved-port-types.patch

9bbebd
From 3073efc112929b535f3a832c6f99e0dbe3af29ca Mon Sep 17 00:00:00 2001
9bbebd
From: Masatake YAMATO <yamato@redhat.com>
9bbebd
Date: Thu, 14 Dec 2017 15:57:58 +0900
9bbebd
Subject: [PATCH] sepolicy-generate: Handle more reserved port types
9bbebd
9bbebd
Currently only reserved_port_t, port_t and hi_reserved_port_t are
9bbebd
handled as special when making a ports-dictionary.  However, as fas as
9bbebd
corenetwork.te.in of serefpolicy, unreserved_port_t and
9bbebd
ephemeral_port_t should be handled in the same way, too.
9bbebd
9bbebd
(Details) I found the need of this change when I was using
9bbebd
selinux-polgengui.  Though tcp port 12345, which my application may
9bbebd
use, was given to the gui, selinux-polgengui generates expected te
9bbebd
file and sh file which didn't utilize the tcp port.
9bbebd
9bbebd
selinux-polgengui checks whether a port given via gui is already typed
9bbebd
or not.
9bbebd
9bbebd
If it is already typed, selinux-polgengui generates a te file having
9bbebd
rules to allow the application to use the port. (A)
9bbebd
9bbebd
If not, it seems for me that selinux-polgengui is designed to generate
9bbebd
a te file having rules to allow the application to own(?) the port;
9bbebd
and a sh file having a command line to assign the application own type
9bbebd
to the port. (B)
9bbebd
9bbebd
As we can see the output of `semanage port -l' some of ports for
9bbebd
specified purpose have types already.  The important point is that the
9bbebd
rest of ports also have types already:
9bbebd
9bbebd
    hi_reserved_port_t tcp 512-1023
9bbebd
    hi_reserved_port_t udp 512-1023
9bbebd
    unreserved_port_t tcp 1024-32767, 61001-65535
9bbebd
    unreserved_port_t udp 1024-32767, 61001-65535
9bbebd
    ephemeral_port_t tcp 32768-61000
9bbebd
    ephemeral_port_t udp 32768-61000
9bbebd
9bbebd
As my patch shows, the original selinux-polgengui ignored
9bbebd
hi_reserved_port_t; though hi_reserved_port_t is assigned,
9bbebd
selinux-polgengui considered ports 512-1023 are not used. As the
9bbebd
result selinux-polgengui generates file sets of (B).
9bbebd
9bbebd
For the purpose of selinux-polgengui, I think unreserved_port_t and
9bbebd
ephemeral_port_t are treated as the same as hi_reserved_port_t.
9bbebd
9bbebd
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
9bbebd
9bbebd
Fedora only patch:
9bbebd
https://lore.kernel.org/selinux/20150610.190635.1866127952891120915.yamato@redhat.com/
9bbebd
---
9bbebd
 python/sepolicy/sepolicy/generate.py | 4 +++-
9bbebd
 1 file changed, 3 insertions(+), 1 deletion(-)
9bbebd
9bbebd
diff --git a/python/sepolicy/sepolicy/generate.py b/python/sepolicy/sepolicy/generate.py
9bbebd
index 7175d36b..93caedee 100644
9bbebd
--- a/python/sepolicy/sepolicy/generate.py
9bbebd
+++ b/python/sepolicy/sepolicy/generate.py
9bbebd
@@ -100,7 +100,9 @@ def get_all_ports():
9bbebd
     for p in sepolicy.info(sepolicy.PORT):
9bbebd
         if p['type'] == "reserved_port_t" or \
9bbebd
                 p['type'] == "port_t" or \
9bbebd
-                p['type'] == "hi_reserved_port_t":
9bbebd
+                p['type'] == "hi_reserved_port_t" or \
9bbebd
+                p['type'] == "ephemeral_port_t" or \
9bbebd
+                p['type'] == "unreserved_port_t":
9bbebd
             continue
9bbebd
         dict[(p['low'], p['high'], p['protocol'])] = (p['type'], p.get('range'))
9bbebd
     return dict
9bbebd
-- 
9bbebd
2.21.0
9bbebd