Bug 464312

Summary: sshd configured to allow port forwarding, but SELinux policy blocks it
Product: [Fedora] Fedora Reporter: Ed Avis <ed>
Component: selinux-policyAssignee: Daniel Walsh <dwalsh>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: 9CC: dwalsh, mgrepl, rvokal, zenczykowski
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-06-10 08:21:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ed Avis 2008-09-27 18:44:28 UTC
I ssh'd to my machine using something like

% ssh -R 1234:somehost:1234 ed@myhost

sshd accepted the connection but port forwarding failed with an AVC denial (details below).

It doesn't make sense to ship a default sshd configuration which allows port forwarding but a default SELinux configuration that disallows it.  Either the SELinux policy should be loosened to let sshd connect to the ports it wants, or the sshd configuration should be tightened to disallow port forwarding.


Summary:

SELinux is preventing the sshd (sshd_t) from binding to port 3389.

Detailed Description:

SELinux has denied the sshd from binding to a network port 3389 which does not
have an SELinux type associated with it. If sshd is supposed to be allowed to
listen on this port, you can use the semanage command to add this port to a port
type that sshd_t can bind to. semanage port -l will list all port types. Please
file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against
the selinux-policy package. If sshd is not supposed to bind to this port, this
could signal a intrusion attempt. If this system is running as an NIS Client,
turning on the allow_ypbind boolean, may fix the problem. setsebool -P
allow_ypbind=1.

Allowing Access:

If you want to allow sshd to bind to this port semanage port -a -t PORT_TYPE -p
PROTOCOL 3389 Where PORT_TYPE is a type that sshd_t can bind and PROTOCOL is udp
or tcp.

Additional Information:

Source Context                system_u:system_r:sshd_t:s0-s0:c0.c1023
Target Context                system_u:object_r:port_t:s0
Target Objects                None [ tcp_socket ]
Source                        sshd
Source Path                   /usr/sbin/sshd
Port                          3389
Host                          bad.membled.com
Source RPM Packages           openssh-server-5.1p1-2.fc9
Target RPM Packages           
Policy RPM                    selinux-policy-3.3.1-91.fc9
Selinux Enabled               True
Policy Type                   targeted
MLS Enabled                   True
Enforcing Mode                Enforcing
Plugin Name                   bind_ports
Host Name                     bad.membled.com
Platform                      Linux bad.membled.com 2.6.26.3-29.fc9.x86_64 #1
                              SMP Wed Sep 3 03:16:37 EDT 2008 x86_64 x86_64
Alert Count                   2
First Seen                    Sat 27 Sep 2008 06:44:14 PM BST
Last Seen                     Sat 27 Sep 2008 06:44:14 PM BST
Local ID                      8065284f-fe7a-4249-97ca-7b5815f53a54
Line Numbers                  

Raw Audit Messages            

host=bad.membled.com type=AVC msg=audit(1222537454.848:127): avc:  denied  { name_bind } for  pid=13099 comm="sshd" src=3389 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket

host=bad.membled.com type=SYSCALL msg=audit(1222537454.848:127): arch=c000003e syscall=49 success=no exit=-13 a0=8 a1=7f2a505f3690 a2=10 a3=7fff56e33424 items=0 ppid=13095 pid=13099 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=(none) ses=13 comm="sshd" exe="/usr/sbin/sshd" subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 key=(null)

Comment 1 Daniel Walsh 2008-09-29 15:46:28 UTC
Ok, 

Fixedin selinux-policy-3.3.1-97.fc9

Will allow it to bind to all ports > 1024

Comment 2 Ed Avis 2008-09-30 09:47:09 UTC
I think all ports >= 1024 would be better (the well-known ports are from 0 to 1023 inclusive).

Comment 3 Daniel Walsh 2008-09-30 15:07:08 UTC
Well that is what I meant, and I have a math degree :^(

Comment 4 Maciej Żenczykowski 2008-10-29 09:29:52 UTC
The new policy doesn't appear to fix the entirety of the problem.

Client machine (also fc9 box):
$ ssh -tax -R 24800:localhost:24800 zeus "blah blah"

Server machine (kernel from koji):
$ uname -a
Linux zeus.lan 2.6.26.7-86.fc9.x86_64 #1 SMP Wed Oct 22 22:54:13 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux

$ rpm -qa | egrep 'selinux-policy|openssh' | sort
openssh-5.1p1-2.fc9.x86_64
openssh-askpass-5.1p1-2.fc9.x86_64
openssh-clients-5.1p1-2.fc9.x86_64
openssh-server-5.1p1-2.fc9.x86_64
selinux-policy-3.3.1-99.fc9.noarch
selinux-policy-devel-3.3.1-99.fc9.noarch
selinux-policy-targeted-3.3.1-99.fc9.noarch

$ sudo tail /var/log/messages
...nothing relevant (from audit or otherwise)...

$ sudo tail /var/log/secure
...
Oct 29 01:34:09 zeus sshd[2163]: Accepted publickey for maze from 192.168.1.9 port 43488 ssh2
Oct 29 01:34:09 zeus sshd[2163]: pam_unix(sshd:session): session opened for user maze by (uid=0)
Oct 29 01:34:09 zeus sshd[2166]: error: bind: Permission denied
Oct 29 01:34:09 zeus sshd[2166]: error: channel_setup_fwd_listener: cannot listen to port: 24800
Oct 29 01:59:37 zeus sshd[32736]: pam_unix(sshd:session): session closed for user maze
...

(1616 is the main sshd process)

# strace -s 512 -p 1616 -ff 2>&1 | egrep -C2 24800
[pid  3075] close(8)                    = 0
[pid  3075] socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 8
[pid  3075] connect(8, {sa_family=AF_INET6, sin6_port=htons(24800), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
[pid  3075] getsockname(8, {sa_family=AF_INET6, sin6_port=htons(36551), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [8589934620]) =
 0
[pid  3075] connect(8, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
[pid  3075] connect(8, {sa_family=AF_INET, sin_port=htons(24800), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
[pid  3075] getsockname(8, {sa_family=AF_INET6, sin6_port=htons(41358), inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [8
589934620]) = 0
[pid  3075] close(8)                    = 0
[pid  3075] socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP) = 8
[pid  3075] setsockopt(8, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
[pid  3075] bind(8, {sa_family=AF_INET6, sin6_port=htons(24800), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EACCES (Permi
ssion denied)
[pid  3075] close(8)                    = 0
[pid  3075] socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 8
[pid  3075] setsockopt(8, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
[pid  3075] bind(8, {sa_family=AF_INET, sin_port=htons(24800), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EACCES (Permission denied)
[pid  3075] sendto(4, "<83>Oct 29 02:23:05 sshd[3075]: error: bind: Permission denied", 62, MSG_NOSIGNAL, NULL, 0) = 62
[pid  3075] close(4)                    = 0
--
[pid  3075] fcntl(4, F_SETFD, FD_CLOEXEC) = 0
[pid  3075] connect(4, {sa_family=AF_FILE, path="/dev/log"}, 110) = 0
[pid  3075] sendto(4, "<83>Oct 29 02:23:05 sshd[3075]: error: channel_setup_fwd_listener: cannot listen to port: 24800", 95, MSG_NOSIGNAL, NULL, 0) = 95
[pid  3075] close(4)                    = 0
[pid  3075] write(3, "e\f:>\331l\375\253\210\32\357\315\311\330\312l\302z\244\270\r\303\202\213\254l[\323\274Hp\245", 32) = 32
^C

No idea, why it's opening the port for what is apparently first UDP.
The port in question is not used by any other process in the system (lsof -i -n doesn't list it) and other ports have the same problem, ssh -R from server to client also doesn't work, so the problem is not specific to that one machine.

Comment 5 Maciej Żenczykowski 2008-10-29 09:41:31 UTC
Hmm, interesting, while zeus doesn't log any audit messages (and audit is running), the client machine (on the reverse ssh -R test) does log the following (running with the same selinux-policy version).

kernel: type=1400 audit(1225271310.797:10): avc:  denied  { name_bind } for  pid=5103 comm="sshd" src=24800 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket

not quite sure what's happening, however:

[root@zeus ~]# semanage port -a -t ssh_port_t -p tcp 24800

has 'fixed' the issue, so it was still apparently selinux, not sure why it wasn't getting logged though (and there are _other_ messages from auditd in /var/log/messages).

Comment 6 Daniel Walsh 2008-10-29 15:10:53 UTC
Fixed in selinux-policy-3.3.1-105.fc9

Comment 7 Maciej Żenczykowski 2008-10-31 06:48:08 UTC
Installed new packages from koji on both machines and ran:

[root@zeus ~]# semanage port -d -t ssh_port_t -p tcp 24800

Have not rebooted yet, but port forwarding appears to work correctly now.

Comment 8 Bug Zapper 2009-06-10 02:49:43 UTC
This message is a reminder that Fedora 9 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 9.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '9'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 9's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 9 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping