Bug 974158

Summary: semanage wrongly modifies port types
Product: Red Hat Enterprise Linux 6 Reporter: Dalibor Pospíšil <dapospis>
Component: policycoreutilsAssignee: Miroslav Grepl <mgrepl>
Status: CLOSED WONTFIX QA Contact: Milos Malik <mmalik>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.4CC: dwalsh, eparis, mmalik, pmoore, sdsmall
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 974163 (view as bug list) Environment:
Last Closed: 2015-03-03 14:14:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 974163    

Description Dalibor Pospíšil 2013-06-13 14:29:31 UTC
Description of problem:
semanage allow to modify default port type while keeps the assignment to the old type. This leads to situation where one port has two types. Also semanage -o - generates wrong outut which cannot be applied. Moreover after modifying the the port and modyfying it back to the original type I can delete the type for the first time. The second time I get '... is defined in policy, cannot be deleted' message.

Version-Release number of selected component (if applicable):
policycoreutils-python-2.0.83-19.30.el6

How reproducible:
100%

Steps to Reproduce:
[root@rhel6 ~]# semanage port -m -t http_port_t -p tcp 8080
[root@rhel6 ~]# semanage port -l | grep 8080
http_cache_port_t              tcp      3128, 8080, 8118, 8123, 10001-10010
http_port_t                    tcp      8080, 80, 443, 488, 8008, 8009, 8443
[root@rhel6 ~]# semanage -o - | grep 8080
port -a -t http_port_t -p tcp 8080
[root@rhel6 ~]# semanage port -m -t http_cache_port_t -p tcp 8080
[root@rhel6 ~]# semanage port -l | grep 8080
http_cache_port_t              tcp      8080, 3128, 8080, 8118, 8123, 10001-10010
[root@rhel6 ~]# semanage -o - | grep 8080
port -a -t http_cache_port_t -p tcp 8080
[root@rhel6 ~]# semanage port -d -t http_cache_port_t -p tcp 8080
[root@rhel6 ~]# semanage port -d -t http_cache_port_t -p tcp 8080
/usr/sbin/semanage: Port tcp/8080 is defined in policy, cannot be deleted

I would expect that semanage is able to remove default rule as local customization and then add new rule. So the 'semanage port -m' would be internally translated into 'semanage port -d' and 'semanage port -a' sequence.

Comment 2 RHEL Program Management 2013-10-13 23:28:45 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unable to address this
request at this time.

Red Hat invites you to ask your support representative to
propose this request, if appropriate, in the next release of
Red Hat Enterprise Linux.

Comment 3 Daniel Walsh 2013-10-15 17:03:30 UTC
Well in actuality the label is the second label, the tooling is showing it incorrectly, I believe as far as the kernel is concerned the second label wins.

Comment 4 Stephen Smalley 2013-10-15 17:14:34 UTC
First matching entry in the port contexts list wins as far as the kernel is concerned.  But I think semanage and friends are not representing it that way and thus the presented order (a hash walk?) may be arbitrary and unrelated to what is used.  It should just prevent redundant definitions from being added (removing/replacing the old if necessary)

Comment 5 Miroslav Grepl 2014-02-04 13:21:08 UTC
(In reply to Dalibor Pospíšil from comment #0)
> Description of problem:
> semanage allow to modify default port type while keeps the assignment to the
> old type. This leads to situation where one port has two types. Also
> semanage -o - generates wrong outut which cannot be applied. Moreover after
> modifying the the port and modyfying it back to the original type I can
> delete the type for the first time. The second time I get '... is defined in
> policy, cannot be deleted' message.
> 
> Version-Release number of selected component (if applicable):
> policycoreutils-python-2.0.83-19.30.el6
> 
> How reproducible:
> 100%
> 
> Steps to Reproduce:
> [root@rhel6 ~]# semanage port -m -t http_port_t -p tcp 8080
> [root@rhel6 ~]# semanage port -l | grep 8080
> http_cache_port_t              tcp      3128, 8080, 8118, 8123, 10001-10010
> http_port_t                    tcp      8080, 80, 443, 488, 8008, 8009, 8443
> [root@rhel6 ~]# semanage -o - | grep 8080
> port -a -t http_port_t -p tcp 8080
> [root@rhel6 ~]# semanage port -m -t http_cache_port_t -p tcp 8080
> [root@rhel6 ~]# semanage port -l | grep 8080
> http_cache_port_t              tcp      8080, 3128, 8080, 8118, 8123,
> 10001-10010
> [root@rhel6 ~]# semanage -o - | grep 8080
> port -a -t http_cache_port_t -p tcp 8080
> [root@rhel6 ~]# semanage port -d -t http_cache_port_t -p tcp 8080
> [root@rhel6 ~]# semanage port -d -t http_cache_port_t -p tcp 8080
> /usr/sbin/semanage: Port tcp/8080 is defined in policy, cannot be deleted
> 
> I would expect that semanage is able to remove default rule as local
> customization and then add new rule. So the 'semanage port -m' would be
> internally translated into 'semanage port -d' and 'semanage port -a'
> sequence.

We don't want to remove the default port declaration. The local modification is used if you define it.

So it looks it is a bug in "semanage-port -l".

Comment 8 Miroslav Grepl 2015-03-03 14:14:08 UTC
I believe we can close it as WONTFIX in RHEL6 per Comment #5.