Bug 564413 - SELinux is preventing the ftp daemon from writing files outside the home directory (/var/run/proftpd.score).
Summary: SELinux is preventing the ftp daemon from writing files outside the home dire...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 12
Hardware: x86_64
OS: Linux
low
medium
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: setroubleshoot_trace_hash:116889a31a6...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-02-12 16:58 UTC by Matt Castelein
Modified: 2010-03-04 00:14 UTC (History)
4 users (show)

Fixed In Version: selinux-policy-3.6.32-92.fc12
Clone Of:
Environment:
Last Closed: 2010-03-04 00:14:56 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Matt Castelein 2010-02-12 16:58:50 UTC
Summary:

SELinux is preventing the ftp daemon from writing files outside the home
directory (/var/run/proftpd.score).

Detailed Description:

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

SELinux has denied the ftp daemon write access to directories outside the home
directory (/var/run/proftpd.score). Someone has logged in via your ftp daemon
and is trying to create or write a file. If you only setup ftp to allow
anonymous ftp, this could signal an intrusion attempt.

Allowing Access:

If you do not want SELinux preventing ftp from writing files anywhere on the
system you need to turn on the allow_ftpd_full_access boolean: "setsebool -P
allow_ftpd_full_access=1"

Fix Command:

setsebool -P allow_ftpd_full_access=1

Additional Information:

Source Context                system_u:system_r:ftpd_t:s0-s0:c0.c1023
Target Context                system_u:object_r:var_run_t:s0
Target Objects                /var/run/proftpd.score [ file ]
Source                        proftpd
Source Path                   /usr/sbin/proftpd
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           proftpd-1.3.2c-1.fc12
Target RPM Packages           
Policy RPM                    selinux-policy-3.6.32-84.fc12
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Permissive
Plugin Name                   allow_ftpd_full_access
Host Name                     (removed)
Platform                      Linux arturo.coldnuke.dyndns.org
                              2.6.31.12-174.2.3.fc12.x86_64 #1 SMP Mon Jan 18
                              19:52:07 UTC 2010 x86_64 x86_64
Alert Count                   5
First Seen                    Fri 12 Feb 2010 11:45:28 AM EST
Last Seen                     Fri 12 Feb 2010 11:57:05 AM EST
Local ID                      430b3ad4-de91-4b08-b819-163ff8400e53
Line Numbers                  

Raw Audit Messages            

node=arturo.coldnuke.dyndns.org type=AVC msg=audit(1265993825.421:10733): avc:  denied  { write } for  pid=1875 comm="proftpd" name="proftpd.score" dev=sda3 ino=6086791 scontext=system_u:system_r:ftpd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:var_run_t:s0 tclass=file

node=arturo.coldnuke.dyndns.org type=SYSCALL msg=audit(1265993825.421:10733): arch=c000003e syscall=2 success=yes exit=2 a0=6b0b40 a1=2 a2=0 a3=8 items=0 ppid=1 pid=1875 auid=4294967295 uid=0 gid=99 euid=0 suid=0 fsuid=0 egid=0 sgid=99 fsgid=0 tty=(none) ses=4294967295 comm="proftpd" exe="/usr/sbin/proftpd" subj=system_u:system_r:ftpd_t:s0-s0:c0.c1023 key=(null)



Hash String generated from  selinux-policy-3.6.32-84.fc12,allow_ftpd_full_access,proftpd,ftpd_t,var_run_t,file,write
audit2allow suggests:

#============= ftpd_t ==============
#!!!! This avc can be allowed using the boolean 'allow_ftpd_full_access'

allow ftpd_t var_run_t:file write;

Comment 1 Matt Castelein 2010-02-12 17:00:48 UTC
It seems to me that proftpd should be able to write this file without enabling it to write anything anywhere.

Comment 2 Daniel Walsh 2010-02-13 12:39:16 UTC
Yes any idea why this file is not in 

/var/run/proftpd  which should have the proper labeling for this.

chcon -t ftpd_var_run_t /var/run/proftpd* will fix. 


Miroslav

Lets change the labeling to

/var/run/proftpd.* 		gen_context(system_u:object_r:ftpd_var_run_t,s0)

Comment 3 Matt Castelein 2010-02-13 19:29:21 UTC
(In reply to comment #2)
> Yes any idea why this file is not in 
> 
> /var/run/proftpd  which should have the proper labeling for this.

in /var/run/proftpd/ I have: proftpd.delay  proftpd.sock

But proftpd.score and proftpd.pid are one level up in /var/run.. 

Now the location of the scoreboard file is adjustable in proftpd.conf but I don't think it's been changed from the default.  Also the pid file shown in the init script matches what exists on my system.. Perhaps the proftpd package needs to be altered to put all these in /var/run/proftpd?

One other thing that's confusing me, the context reported by the audit is not the context on the file..

-rw-r--r--. root      root      system_u:object_r:ftpd_var_run_t:s0 proftpd.pid
-rw-r--r--. root      root      system_u:object_r:ftpd_var_run_t:s0 proftpd.score

...So why the denial?

Comment 4 Daniel Walsh 2010-02-14 14:47:10 UTC
At the time the avc happened it had the wrong label.  Yes these files should be put into the directory.  And we will also fix the label in case people do not have the fixed proftpd package.

Comment 5 Paul Howarth 2010-02-14 19:10:02 UTC
The out of the box configuration of proftpd in Fedora does not include a ScoreboardFile directive in the configuration; the scoreboard file should therefore be written to the default location, which is /var/run/proftpd/proftpd.scoreboard. The PID file is also written to that directory by default.

If you have a ScoreboardFile directive in your proftpd.conf, it's probably a hangover from an update from an older version, and the changes from the current config haven't been merged in.

Comment 6 Matt Castelein 2010-02-15 01:46:51 UTC
(In reply to comment #5)
> If you have a ScoreboardFile directive in your proftpd.conf, it's probably a
> hangover from an update from an older version, and the changes from the current
> config haven't been merged in.    

Quite likely, since the machine in question has been upgraded over time from Fedora 6.. It's difficult to catch every change.

Comment 7 Matt Castelein 2010-02-15 03:56:31 UTC
I've altered my proftpd.conf to create the scoreboard within /var/run/proftpd/ and I'm not seeing the denial anymore.  I've also added a line "PidFile /var/run/proftpd/proftpd.pid" to the file to make sure it creates the pid file in there too, and altered the comment in /etc/init.d/proftpd to reflect the change.. apparently the default is to use /var/run/proftp.pid if this directive is not present.. Is that going to be changed in proftpd, or policy changed to allow the file outside of /var/run/proftpd?

Comment 8 Paul Howarth 2010-02-15 09:33:45 UTC
When I was looking at my own system prior to making Comment #5 I ran "strings" on /usr/sbin/proftpd and found /var/run/proftpd/proftpd.pid. However, I'm running a build of proftpd 1.3.3rc3, not 1.3.2c as in Fedora, and it seems upstream has moved the PID file location between those releases.

I think that either /var/run/proftpd/proftpd.pid or /var/run/proftpd.pid are both sane places for the PID file though, and IMHO policy should support both. There are plenty of existing examples of daemons that have their own directory in /var/run but write their PID files directly under /var/run.

Comment 9 Paul Howarth 2010-02-15 10:27:37 UTC
Just updated to 1.3.3rc4 and got this AVC:

time->Mon Feb 15 10:22:23 2010
type=SYSCALL msg=audit(1266229343.222:225193): arch=c000003e syscall=121 success=no exit=-13 a0=37ea a1=0 a2=37ea a3=7fffddeb8f80 items=0 ppid=1 pid=14091 auid=0 uid=0 gid=99 euid=0 suid=0 fsuid=0 egid=0 sgid=99 fsgid=0 tty=(none) ses=20978 comm="proftpd" exe="/usr/sbin/proftpd" subj=unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1266229343.222:225193): avc:  denied  { getpgid } for  pid=14091 comm="proftpd" scontext=unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 tcontext=unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 tclass=process

It originates from the scoreboard code again:

int pr_scoreboard_entry_kill(pr_scoreboard_entry_t *sce, int signo) {
  int res;

  if (sce == NULL) {
    errno = EINVAL;
    return -1;
  }

  if (ServerType == SERVER_STANDALONE) {
#ifdef HAVE_GETPGID
    pid_t curr_pgrp;

# ifdef HAVE_GETPGRP
    curr_pgrp = getpgrp();
# else
    curr_pgrp = getpgid(0);
# endif /* HAVE_GETPGRP */

    if (getpgid(sce->sce_pid) != curr_pgrp) {
      pr_trace_msg(trace_channel, 1, "scoreboard entry PID %lu process group "
        "does not match current process group, refusing to send signal",
        (unsigned long) sce->sce_pid);
      errno = EPERM;
      return -1;
    }
#endif /* HAVE_GETPGID */
  }

  res = kill(sce->sce_pid, signo);
  return res;
}

So it would seem proftpd needs this permission.

Comment 10 Daniel Walsh 2010-02-16 15:00:21 UTC
Miroslav, also add this access.

Comment 11 Paul Howarth 2010-02-16 15:08:06 UTC
I'll be updating proftpd in Fedora to 1.3.2d soon.

Can the EL-5 policy be updated too as it would be good to update EPEL as well?

Comment 12 Miroslav Grepl 2010-02-16 17:00:11 UTC
Fixed in selinux-policy-3.6.32-91.fc12

Comment 13 Paul Howarth 2010-02-23 15:07:35 UTC
proftpd-1.3.2d-1.fc12 is in updates-testing now.

This, in conjunction with selinux-policy-3.6.32-91.fc12, should work without needing PidFile or ScoreboardFile directives in proftpd.conf.

Comment 14 Matt Castelein 2010-02-23 15:38:13 UTC
I have installed the updated proftpd but yum still cannot find the new selinux-policy.  I will retest when yum can see it.

Comment 15 Miroslav Grepl 2010-02-23 15:46:44 UTC
I am going to push out F-12 update today.

Comment 16 Fedora Update System 2010-02-23 20:55:47 UTC
selinux-policy-3.6.32-92.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/selinux-policy-3.6.32-92.fc12

Comment 17 Fedora Update System 2010-02-26 03:42:25 UTC
selinux-policy-3.6.32-92.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 selinux-policy'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F12/FEDORA-2010-2953

Comment 18 Fedora Update System 2010-03-04 00:11:10 UTC
selinux-policy-3.6.32-92.fc12 has been pushed to the Fedora 12 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.