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

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