LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-27-2014, 09:11 PM   #1
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Rep: Reputation: 31
Gentoo SELinux permission denied error when starting dhcpd


I have recently set up a Gentoo server to serve as a network router. Though it will serve on a semi-trusted network, I have nevertheless attempted to put together a secure server. Accordingly, I installed gentoo-hardened and have installed and configured SELinux. This is only my second time playing with SELinux and my first time getting it to work (for the most part). While for the most part everything seems to work fine, I have discovered that, when in SELinux enforcing mode, I cannot start dhcpd without errors:

Code:
root@server# run_init /etc/init.d/dhcpd start
Authenticating root.
Password:
 * /var/lib/dhcp: creating directory
sed: can't read /etc/dhcp/dhcpd.conf: Permission denied
 * /var/lib/dhcp/dhcpd.leases: creating file
 * checkpath: open: Permission denied
sed: can't read /etc/dhcp/dhcpd.conf: Permission denied
 * Starting dhcpd ... * start-stop-daemon: did not create a valid pid in `//var/run/dhcp/dhcpd.pid'
 [ !! ]
 * ERROR: dhcpd failed to start
I am running this from the following context:
Code:
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),26(tape),27(video) context=staff_u:sysadm_r:sysadm_t
Permissions on the requisite files/directories are thus:
Code:
root@server# ls -lZ /etc/dhcp
total 8
-rw-r--r--. 1 root root system_u:object_r:dhcp_etc_t  914 Nov 25 15:57 dhclient.conf
-rw-r--r--. 1 root root system_u:object_r:dhcp_etc_t 3305 Nov 26 15:27 dhcpd.conf

root@server# ls -ldZ /var/lib/dhcp
drwxr-xr-x. 2 dhcp dhcp system_u:object_r:dhcp_state_t 4096 Nov 27 20:15 /var/lib/dhcp
And the dhcpd process spawned looks like this:
Code:
LABEL                           UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
system_u:system_r:dhcpd_t       dhcp     11114     1  0  2597  5716   0 20:36 ?        00:00:00 /usr/sbin/dhcpd -cf /etc/dhcp/dhcpd.conf -q -pf /var/run/dhcp/dhcpd.pid -lf /var/lib/dhcp/dhcpd.leases -user dhcp -group dhcp
As far as I can tell, the files and directories are labeled correctly, and for good measure I ran "rlpkg dhcp" with no change. I also tried reemerging the selinux-dhcp policy to no avail. Can anyone enlighten me on this behavior? Does this indicate a bug in the policy? A mistake in my configuration? Or am I simply not running the init.d script properly? As I said, I am fairly new to SELinux and anything that can shed light on its inner workings would be appreciated.

edit: To clarify, dhcpd starts normally if SELinux is set to permissive.

Last edited by hda7; 11-28-2014 at 11:01 AM.
 
Old 11-29-2014, 06:40 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Hmm. First thing I'd do is run 'grep dhc /var/log/audit/audit.log|audit2allow;' and see if there's any clues.
 
Old 11-29-2014, 08:52 PM   #3
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by unSpawn View Post
Hmm. First thing I'd do is run 'grep dhc /var/log/audit/audit.log|audit2allow;' and see if there's any clues.
Even after attempting to start dhcpd, audit.log appears to be empty. I even ran "semodule -DB" in an attempt to have more verbose logging with the same result. Does SELinux's logging need configuring/enabling?
 
Old 11-30-2014, 03:18 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by hda7 View Post
Does SELinux's logging need configuring/enabling?
Check if the audit service (auditd) is running. If it isn't then AVC messages should appear in /var/log/messages or equivalent. The configuration requirements for the audit service are minimal and AFAIK it should work with a minimal conf (prolly has sane defaults) right out of the box.
 
Old 11-30-2014, 09:22 AM   #5
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by unSpawn View Post
Check if the audit service (auditd) is running.
Well, it wasn't. It was already installed though, with a nearly-sane default config (there was a line for 64-bit systems even though this is a 32-bit machine/install). Auditd now added to default runlevel.

Quote:
Originally Posted by unSpawn
Hmm. First thing I'd do is run 'grep dhc /var/log/audit/audit.log|audit2allow;' and see if there's any clues.
Now that auditd is running, that gives

Code:
#============= dhcpd_t ==============
allow dhcpd_t tmpfs_t:file { read write };

#============= initrc_t ==============
allow initrc_t dhcp_etc_t:file read;
allow initrc_t dhcpd_t:process { siginh rlimitinh noatsecure };
allow initrc_t tmpfs_t:file { read unlink };
The thing which grabs my attention is "noatsecure." Does this mean that starting dhcpd is only allowed from one of the "secure terminals" listed in /etc/securetty? Currently I'm running inside a screen session over ssh.
 
Old 11-30-2014, 02:58 PM   #6
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by hda7 View Post
The thing which grabs my attention is "noatsecure." Does this mean that starting dhcpd is only allowed from one of the "secure terminals" listed in /etc/securetty? Currently I'm running inside a screen session over ssh.
Apparently not. Logging in via the serial port (ttyS0, which is in "/etc/securetty") and trying to start dhcpd still fails. I did, however, catch this additional audit section:
Code:
#============= tmpfiles_t ==============

#!!!! This avc can be allowed using the boolean 'tmpfiles_manage_all_non_security'
allow tmpfiles_t dhcp_state_t:dir { getattr search };
 
Old 11-30-2014, 02:59 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by hda7 View Post
The thing which grabs my attention is "noatsecure." Does this mean that starting dhcpd is only allowed from one of the "secure terminals" listed in /etc/securetty?
No, it's Something Completely Different: noatsecure disables environment sanitation. See AT_SECURE in 'man getauxval' or other Glibc documentation.
 
Old 11-30-2014, 04:18 PM   #8
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Original Poster
Rep: Reputation: 31
OK, this is what I've gathered so far from the audit log:

1) The SELinux boolean "tmpfiles_manage_all_non_security" probably ought to be tripped on
2) /etc/init.d/dhcpd itself attempts to read the configuration file (apparently to find the lease file name), but it runs in the system_u:system_r:initrc_t context, which is not permitted access.

It seems to me, then, that allowing initrc_t read access to dhcp_etc_t files would be the most straightforward solution. Time to learn how to add policy rules...

Last edited by hda7; 11-30-2014 at 04:20 PM.
 
Old 11-30-2014, 04:33 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by hda7 View Post
It seems to me, then, that allowing initrc_t read access to dhcp_etc_t files would be the most straightforward solution.
Yes, that's quite common for transitions from the calling init domain to another one on runlevel change.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kubuntu 12.04 Permission Denied errors when starting up Predictability Ubuntu 11 11-26-2012 11:13 PM
mkdir throws Permission Denied error in a directoy even with root ownership and 777 permission surajchalukya Linux - Security 14 09-03-2012 08:34 AM
Apache starting error after installing PHP (reloc: Permission denied) bilal_mld Linux - Newbie 3 01-05-2011 03:13 AM
Starting Tomcat from Eclipse - Permission denied robbbert Programming 1 06-30-2006 04:23 AM
Selinux, ./INSTALL: /bin/sh: bad interpreter: Permission denied TomF Linux - Security 2 12-08-2004 11:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration