Bug 541809

Summary: SELinux is preventing /sbin/setfiles access to a leaked tcp_socket file descriptor.
Product: [Fedora] Fedora Reporter: d. johnson <drjohnson1>
Component: opensshAssignee: Jan F. Chadima <jchadima>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 12CC: carlg, dwalsh, jchadima, mgrepl, nalin, redhat-bugzilla, tmraz
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard: setroubleshoot_trace_hash:f44ee62283ebf89a4fdaed79440f1e815371b4e67747813d6acec6d34d132ad9
Fixed In Version: openssh-5.3p1-15.fc12 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 559542 (view as bug list) Environment:
Last Closed: 2010-03-09 03:33:56 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:
Bug Depends On:    
Bug Blocks: 559542, 642935    

Description d. johnson 2009-11-27 05:26:08 UTC
Summary:

SELinux is preventing /sbin/setfiles access to a leaked tcp_socket file
descriptor.

Detailed Description:

[SELinux is in permissive mode. This access was not denied.]

SELinux denied access requested by the restorecon command. It looks like this is
either a leaked descriptor or restorecon output was redirected to a file it is
not allowed to access. Leaks usually can be ignored since SELinux is just
closing the leak and reporting the error. The application does not use the
descriptor, so it will run properly. If this is a redirection, you will not get
output in the tcp_socket. You should generate a bugzilla on selinux-policy, and
it will get routed to the appropriate package. You can safely ignore this avc.

Allowing Access:

You can generate a local policy module to allow this access - see FAQ
(http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385)

Additional Information:

Source Context                system_u:system_r:setfiles_t:s0-s0:c0.c1023
Target Context                system_u:system_r:sshd_t:s0-s0:c0.c1023
Target Objects                tcp_socket [ tcp_socket ]
Source                        restorecon
Source Path                   /sbin/setfiles
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           policycoreutils-2.0.74-17.fc12
Target RPM Packages           
Policy RPM                    selinux-policy-3.6.32-49.fc12
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Permissive
Plugin Name                   leaks
Host Name                     (removed)
Platform                      Linux (removed) 2.6.31.5-127.fc12.i686.PAE
                              #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 i686
Alert Count                   7
First Seen                    Mon 23 Nov 2009 09:29:48 AM CST
Last Seen                     Thu 26 Nov 2009 11:15:51 PM CST
Local ID                      78eca36e-a438-402f-b982-1b479a482522
Line Numbers                  

Raw Audit Messages            

node=(removed) type=AVC msg=audit(1259298951.440:34): avc:  denied  { read write } for  pid=6676 comm="restorecon" path="socket:[68624]" dev=sockfs ino=68624 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket

node=(removed) type=SYSCALL msg=audit(1259298951.440:34): arch=40000003 syscall=11 success=yes exit=0 a0=961e0b8 a1=961de68 a2=961e140 a3=961de68 items=0 ppid=6675 pid=6676 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=3 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)



Hash String generated from  selinux-policy-3.6.32-49.fc12,leaks,restorecon,setfiles_t,sshd_t,tcp_socket,read,write
audit2allow suggests:

#============= setfiles_t ==============
allow setfiles_t sshd_t:tcp_socket { read write };

Comment 1 d. johnson 2009-11-27 05:33:00 UTC
This AVC gets generated after I reboot or login (not sure which).  Appears to happen every boot up.

Comment 2 Daniel Walsh 2009-11-30 14:56:36 UTC
Are you using ldap for user database?  There was a known problem with nss_ldap leaking file descriptors in previous versions of Fedora, and I wonder if it is back.

Comment 3 d. johnson 2009-11-30 16:37:54 UTC
I have 389-ds installed and running, but not in used for login auth.  nss_ldap-264-8.fc12.i686 is installed if that is sufficient to trigger it.

Comment 4 Daniel Walsh 2009-11-30 19:28:53 UTC
Tomas do you have any ideas?

Comment 5 Tomas Mraz 2009-11-30 20:23:59 UTC
Unfortunately I don't. The sshd should not spawn restorecon at all - at least I do not see any such call in the openssh sources in the F12 package. But I have no other idea how restorecon could get an sshd_t labeled tcp socket even from nss_ldap as sshd is started by default and it would occupy it. And as the reporter is not using the ldap for user info it would not call nss_ldap anyway.

d.j., could you please just after reboot try too look up the process with the pid from the AVC ppid number? In the AVC above it would be pid 6675.

Comment 6 d. johnson 2009-12-01 00:44:08 UTC
It happened again, recently - but I cannot find what the PID wss:

Nov 30 16:23:24 embla setroubleshoot: SELinux is preventing /sbin/setfiles access to a leaked tcp_socket file descriptor. For complete SELinux messages. run sealert -l 78eca36e-a438-402f-b982-1b479a482522


# sealert -l 78eca36e-a438-402f-b982-1b479a482522

Summary:

SELinux is preventing /sbin/setfiles access to a leaked tcp_socket file
descriptor.

Detailed Description:

[SELinux is in permissive mode. This access was not denied.]

SELinux denied access requested by the restorecon command. It looks like this is
either a leaked descriptor or restorecon output was redirected to a file it is
not allowed to access. Leaks usually can be ignored since SELinux is just
closing the leak and reporting the error. The application does not use the
descriptor, so it will run properly. If this is a redirection, you will not get
output in the tcp_socket. You should generate a bugzilla on selinux-policy, and
it will get routed to the appropriate package. You can safely ignore this avc.

Allowing Access:

You can generate a local policy module to allow this access - see FAQ
(http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385)

Additional Information:

Source Context                system_u:system_r:setfiles_t:s0-s0:c0.c1023
Target Context                system_u:system_r:sshd_t:s0-s0:c0.c1023
Target Objects                tcp_socket [ tcp_socket ]
Source                        restorecon
Source Path                   /sbin/setfiles
Port                          <Unknown>
Host                          embla.ether.net
Source RPM Packages           policycoreutils-2.0.74-17.fc12
Target RPM Packages           
Policy RPM                    selinux-policy-3.6.32-49.fc12
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Permissive
Plugin Name                   leaks
Host Name                     embla.ether.net
Platform                      Linux embla.ether.net 2.6.31.6-145.fc12.i686.PAE
                              #1 SMP Sat Nov 21 16:12:37 EST 2009 i686 i686
Alert Count                   10
First Seen                    Mon Nov 23 09:29:48 2009
Last Seen                     Mon Nov 30 16:23:22 2009
Local ID                      78eca36e-a438-402f-b982-1b479a482522
Line Numbers                  

Raw Audit Messages            

node=embla.ether.net type=AVC msg=audit(1259619802.358:67384): avc:  denied  { read write } for  pid=19824 comm="restorecon" path="socket:[185887]" dev=sockfs ino=185887 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket

node=embla.ether.net type=SYSCALL msg=audit(1259619802.358:67384): arch=40000003 syscall=11 success=yes exit=0 a0=8d4b0b8 a1=8d4ae68 a2=8d4b140 a3=8d4ae68 items=0 ppid=19823 pid=19824 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=325 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)

Comment 7 Tomas Mraz 2009-12-01 07:42:31 UTC
The pid of the parent of the setfiles process is shown in the SYSCALL audit message in the ppid value. In the recent case it was 19823.

Please try to get the AVC again and try to find the process.

Comment 8 Carl G. 2010-01-17 03:18:49 UTC
---

Fedora Bugzappers volunteer triage team
https://fedoraproject.org/wiki/BugZappers

Comment 9 d. johnson 2010-01-17 06:09:12 UTC
I can reproduce the message at will, easily.  I have not been able to find the pid mentioned in the avc.

Adding a policy with this makes no more avc's show:

allow setfiles_t sshd_t:tcp_socket { read write };

For me to reproduce the avc, i remove the local-policy, and boot.  Instant avc.  By the time I have a prompt, the pid mentioned is long gone.

Comment 10 Carl G. 2010-01-17 06:27:35 UTC
What version of the selinux-policy are you using now ?

Comment 11 d. johnson 2010-01-17 06:59:37 UTC
Just now removed my local-hack, rebooted, and logged in.

# ausearch -m avc -ts today
----
time->Sun Jan 17 00:57:06 2010
type=SYSCALL msg=audit(1263711426.549:26): arch=40000003 syscall=11 success=yes exit=0 a0=8e27980 a1=8e27730 a2=8e27a08 a3=8e27730 items=0 ppid=3920 pid=3921 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=3 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1263711426.549:26): avc:  denied  { read write } for  pid=3921 comm="restorecon" path="socket:[20532]" dev=sockfs ino=20532 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket

pid=3921 is long gone.

selinux-policy-3.6.32-66.fc12.noarch

Comment 12 Tomas Mraz 2010-01-18 08:35:35 UTC
What about the pid 3920 - the pid of the parent process?

Comment 13 Jan F. Chadima 2010-01-18 09:07:47 UTC
Can you describe how to reproduce the bug.

Comment 14 d. johnson 2010-01-18 15:16:10 UTC
pid 3920 is also long gone.

Jan- Reproduce is simple.  Happens on every boot/login without the policy login mentioned above.  Nothing special required.

Comment 15 Tomas Mraz 2010-01-18 15:20:33 UTC
The only place I can think of that would spawn such restorecon process is some PAM module. What PAM modules do you have in /etc/pam.d/sshd and /etc/pam.d/system-auth?

Comment 16 d. johnson 2010-01-18 16:50:23 UTC
% cat /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        required      pam_deny.so

account     required      pam_access.so
account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     optional      pam_mkhomedir.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so


% cat /etc/pam.d/sshd
#%PAM-1.0
auth       required     pam_sepermit.so
#auth       required     pam_tally2.so deny=4 even_deny_root unlock_time=1200
auth       required     pam_tally2.so deny=5 onerr=fail unlock_time=1200
auth       required     pam_cap.so debug
auth       include      password-auth
account    required     pam_nologin.so
account    required     pam_tally2.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    optional     pam_keyinit.so force revoke
session    required     pam_namespace.so
session    include      password-auth

Comment 17 Daniel Walsh 2010-01-18 17:16:47 UTC
What about password-auth?

Comment 18 d. johnson 2010-01-18 18:26:38 UTC
% cat /etc/pam.d/password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        required      pam_deny.so

account     required      pam_access.so
account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     optional      pam_mkhomedir.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so

Comment 19 Tomas Mraz 2010-01-18 18:56:15 UTC
I see there is pam_namespace module in the sshd session stack. So this is probably the source of the restorecon call as it calls restorecon on initialization of a new directory instance.

As this happens when a pam_open_session() is called, sshd should be fixed to set FD_CLOEXEC on the socket fd obtained from accept() in server_accept_loop() function.

Comment 20 Fedora Update System 2010-01-19 17:37:30 UTC
openssh-5.3p1-15.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/openssh-5.3p1-15.fc12

Comment 21 Jan F. Chadima 2010-01-19 17:39:49 UTC
can you test the openssh-5.3p1-15.fc12 and report if it works.

Comment 22 d. johnson 2010-01-20 06:16:33 UTC
WAS: openssh-5.2p1-31.fc12.i686

# ausearch -m avc -ts yesterday
----
time->Tue Jan 19 23:59:36 2010
type=SYSCALL msg=audit(1263967176.801:55086): arch=40000003 syscall=11 success=yes exit=0 a0=9298990 a1=9298740 a2=9298a18 a3=9298740 items=0 ppid=2809 pid=2810 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=2 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1263967176.801:55086): avc:  denied  { read write } for  pid=2810 comm="restorecon" path="socket:[14943]" dev=sockfs ino=14943 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket
----
time->Tue Jan 19 23:59:36 2010
type=SYSCALL msg=audit(1263967176.907:55087): arch=40000003 syscall=11 success=yes exit=0 a0=9f359a8 a1=9f35580 a2=9f35a18 a3=9f35580 items=0 ppid=2815 pid=2816 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=2 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1263967176.907:55087): avc:  denied  { read write } for  pid=2816 comm="restorecon" path="socket:[14943]" dev=sockfs ino=14943 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket

PIDs 2810 and 2816 are long gone before I have a prompt.


apply new openssh, reboot.  new avcs:

# rpm -q openssh
openssh-5.3p1-15.fc12.i686

# ausearch -m avc -ts today
----
time->Wed Jan 20 00:05:52 2010
type=SYSCALL msg=audit(1263967552.097:58496): arch=40000003 syscall=11 success=yes exit=0 a0=9cc3990 a1=9cc3740 a2=9cc3a18 a3=9cc3740 items=0 ppid=3541 pid=3542 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=3 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1263967552.097:58496): avc:  denied  { read write } for  pid=3542 comm="restorecon" path="socket:[16577]" dev=sockfs ino=16577 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket
----
time->Wed Jan 20 00:05:52 2010
type=SYSCALL msg=audit(1263967552.202:58497): arch=40000003 syscall=11 success=yes exit=0 a0=84099a8 a1=8409580 a2=8409a18 a3=8409580 items=0 ppid=3547 pid=3548 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=3 comm="restorecon" exe="/sbin/setfiles" subj=system_u:system_r:setfiles_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1263967552.202:58497): avc:  denied  { read write } for  pid=3548 comm="restorecon" path="socket:[16577]" dev=sockfs ino=16577 scontext=system_u:system_r:setfiles_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=tcp_socket


PIDs 3542 and 3548 are gone before I have a prompt.


% pstree -p |grep ssh
        |-ssh-agent(3592)
        |-sshd(1885)---sshd(3538)---sshd(3553)---zsh(3554)-+-grep(4503)


Audit2allow still wants:

#============= setfiles_t ==============
allow setfiles_t sshd_t:tcp_socket { read write };

Comment 23 Tomas Mraz 2010-01-20 07:40:51 UTC
Unfortunately with the cloexec set on the listen socket I am out of the ideas how the sshd_t socket could leak. Note that the listening socket is explicitely closed in the child process that is handling the incomming connection.

Comment 24 Daniel Walsh 2010-01-20 20:25:23 UTC
What about the accept socket.

Comment 25 Tomas Mraz 2010-01-20 21:46:12 UTC
Dan, I made a typo above the sentence should be "Unfortunately with the cloexec set on the accept socket...."

Comment 26 Fedora Update System 2010-01-21 00:12:04 UTC
openssh-5.3p1-15.fc12 has been pushed to the Fedora 12 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update openssh'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F12/FEDORA-2010-0857

Comment 27 d. johnson 2010-01-22 04:36:40 UTC
To be clear, that is the version I tested in #22 - and it still reports AVCs and leaks.

Comment 28 Tomas Mraz 2010-01-22 07:51:41 UTC
If you comment out pam_namespace in /etc/pam.d/sshd, does it still happen?

Comment 29 d. johnson 2010-01-23 03:08:12 UTC
Updated to openssh 5.3p1-16.fc12 -- Did not resolve.

Commented out pam_namespace -- Did stop the AVCs.

What tipped you off that it might be the culprit?

Comment 30 Jan F. Chadima 2010-01-25 19:15:39 UTC
please can you test openssh 5.3p1-20.fc13 from rawhide?

Comment 31 d. johnson 2010-01-27 13:14:03 UTC
No AVC with 5.3p1-20.

Was this an upstream patch?

Comment 32 Jan F. Chadima 2010-01-28 09:10:50 UTC
not yet, I'll make update tp F-12 and send it upstream ASAP, thanks for the help.

Comment 33 Fedora Update System 2010-01-28 12:12:16 UTC
openssh-5.3p1-18.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/openssh-5.3p1-18.fc12

Comment 34 Fedora Update System 2010-01-29 03:34:04 UTC
openssh-5.3p1-18.fc12 has been pushed to the Fedora 12 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update openssh'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F12/FEDORA-2010-1222

Comment 35 Daniel Walsh 2010-02-08 19:43:48 UTC
*** Bug 562453 has been marked as a duplicate of this bug. ***

Comment 36 Fedora Update System 2010-03-09 03:33:48 UTC
openssh-5.3p1-15.fc12 has been pushed to the Fedora 12 stable repository.  If problems still persist, please make note of it in this bug report.