Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 27079 - dhcpd crashes because it doesn't have write permission on lease file.
Summary: dhcpd crashes because it doesn't have write permission on lease file.
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: High critical (vote)
Assignee: Max Kalika (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 31840
  Show dependency tree
 
Reported: 2003-08-21 14:41 UTC by Danny Dowlearn
Modified: 2004-01-20 15:43 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
updated dhcpd init file (dhcp,1.08 KB, text/plain)
2004-01-01 15:39 UTC, Lars Kneschke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Danny Dowlearn 2003-08-21 14:41:39 UTC
On my system, dhcpd is run as the 'dhcp' user (non-root).  But, the
'/var/lib/dhcp' directory (and its contents) were owned by root:root with 644
permissions.  So here's what would happen:

dhcpd would run for a while (having been started at boot-time or explicitly
restarted after it crashed) and would renew a few leases on my network (1
server, 3 workstations ; 3 static ip's, the rest from a pool.)  I would see a
few of the leases in my '/var/log/everything'.

Then, dhcpd would want to write the leases to '/var/lib/dhcp/dhcpd.leases'. 
Since it didn't have permission, it put an entry in syslog saying, "Can't create
new lease file: Permission denied", and it would crash.

The obvious workaround was to:

# cd /var/lib
# chown -R dhcp:dhcp dhcp/

leaving me to wonder why those permissions weren't set up in the first place. 
Since fixing that, dhcpd has been running for longer than the usual "time to
crash", so assume it's working now.

Originally I had tried to remerge dhcp, but that didn't fix the problem.  (Maybe
a remerge wouldn't replace the '/var/lib/dhcp' directory structure?)

Reproducible: Always
Steps to Reproduce:
1.emerge dhcp
2.look at how '/var/lib/dhcp' is owned by root:root, but dhcpd is run by user 'dhcp'
3.try to let dhcpd renew some leases, and watch it crash?

Actual Results:  
I watched it crash.

Expected Results:  
Not crash.

Moo.
Comment 1 Martin Holzer (RETIRED) gentoo-dev 2003-08-21 23:49:02 UTC
running in chroot is not an option for you ?
Comment 2 Danny Dowlearn 2003-08-22 11:05:37 UTC
> running in chroot is not an option for you ?

you'll have to excuse my ignorance, but chroot to where?  i can't find any directories or files where user 'dhcp' has write access (besides the ones i manually switched).  i thought the 'standard' default behavior was to have the lease file in /var/lib/dhcp/ anyway.
Comment 3 Martin Holzer (RETIRED) gentoo-dev 2003-08-28 00:41:42 UTC
*** Bug 27460 has been marked as a duplicate of this bug. ***
Comment 4 Eric Pretorious 2003-08-29 13:45:00 UTC
Is dhcpd pre-configured to run as the user dhcp? No 'dhcp' user is created during installation or post-installation.

I only run dhcpcd (the client daemon) and  - even though it runs as root - It still doesn't create the /var/lib/dhcp/dhclient.leases file.  :^(
Comment 5 Danny Dowlearn 2003-08-29 15:55:50 UTC
> Is dhcpd pre-configured to run as the user dhcp? No 'dhcp' user is created during installation or post-installation.
>
>I only run dhcpcd (the client daemon) and  - even though it runs as root - It still doesn't create the /var/lib/dhcp/dhclient.leases file.  :^(

I did nothing special after the emerging dhcp utilities, and I run both dhcpcd and dhcpd on my router.  dhcpd runs as the 'dhcp' user, but dhcpcd runs as 'root'.  This seems reasonable, given the functions that they perform.  I know why my dhcpd was having problems (see the bug desc.), but I dunno why your dhcpcd isn't writing lease files.  Although I'll note that my 'dhclient.leases' is empty and owned by dhcp:dhcp, even though it does have a lease right now.  No errors anywhere, though.
Comment 6 Andreas Vinsander 2003-09-06 16:25:21 UTC
Actually dhcpd manage to write some leases to the file, I think it crashes when it is about to cleanup the file and create a new one containing the valid leases. Since it just adds leases to the end of the original lease file it needs to clean it up once in a while. At least that is my observation. I did the same thing 'chown dhcp.dhcp /var/lib/dhcp' to fix it and its running flawlessly since.
Comment 7 Max Kalika (RETIRED) gentoo-dev 2003-09-16 19:00:06 UTC
Ok, reassigning this bug to myself because I maintain this ebuild. Let me
follow up on some things here so we can get this into stable.

Danny: I checked in a new version which is supposed to set proper perms.
Please try it and report back.  To chroot, you need to change
/etc/conf.d/dhcp to point to the dhcp directory.  This directory must be
set up properly. To do that you must first make sure dhcp works correctly
without chroot, and then you need to run:

  ebuild /var/db/pkg/net-misc/dhcp*/dhcp*.ebuild config

Eric: version 3.0_p2-r1 (currently ~x86) uses the paranoia patch which
changes the daemon to run as dhcp.  The user is added to the system
during the install procedure.
Comment 8 Danny Dowlearn 2003-09-17 17:16:30 UTC
Okay, I'm trying it w/o chroot for now.  I'll have to run it for 24-48hrs. to make sure it's working (give it enough time to need to update the file).

I completely unmerged both dhcpcd and dhcp(d) since they shared the offending directory (could this have been the problem?).  I backedup'd/removed /etc/dhcp/, /etc/dhcpcd/, and /var/lib/dhcp/.  Then, I remerged each package, and re-copied by old /etc/dhcp/ and /etc/dhpcd/ _only_ (not /var/lib/dhcp/).  I'll keep y'all posted.

(Btw, since remerging, they now have separate directories in /var/lib/, namely /var/lib/dhcp/ and /var/lib/dhcpc/.  Is that what this is all about or is it just 'cleaner' that way?  The latter, I'm thinking.)
Comment 9 Danny Dowlearn 2003-09-19 01:17:10 UTC
(I just realized bugzilla/mozilla doesn't wrap text lines.  My bad.)

Okay.  It's been running for about 36hrs.  Have some info:

dannyd@alpha /var/lib $ ls -la dhcp/ dhcpc/
dhcp/:
total 9
drwxr-xr-x    2 dhcp     dhcp          136 Sep 18 21:52 .
drwxr-xr-x   15 root     root          368 Sep 17 18:58 ..
-rw-r--r--    1 root     root            0 Sep 17 18:58 .keep
-rw-r--r--    1 dhcp     dhcp          704 Sep 18 21:52 dhcpd.leases
-rw-r--r--    1 dhcp     dhcp          941 Sep 18 21:52 dhcpd.leases~

dhcpc/:
total 5
drwxr-xr-x    2 root     root           80 Sep 17 18:53 .
drwxr-xr-x   15 root     root          368 Sep 17 18:58 ..
-rw-r--r--    1 root     root          469 Sep 17 18:53 dhcpcd-eth1.info

dannyd@alpha /var/lib $ ps axuf | grep dhcp
root  3669  0.0  0.1  1340  316 ?  S  Sep17  0:00 /sbin/dhcpcd -R eth1
dhcp  6092  0.0  0.4  2572  992 ?  S  Sep17  0:00 [dhcpd]

So I guess it's going to work now.  I have just executed the 'ebuild config'
thing to set up the chroot.  '/etc/init.d/dhcp restart' looks good with:

"Starting chrooted dhcp...    [OK]"

All permissions/ownerships look the same as before chroot.  Rad.
Comment 10 JG 2003-09-19 02:38:25 UTC
hi,
is it possible that there is a bug in the init-script of dhcpd or somewhere else?
i just installed dhcp 3.0_p2-r1 on a new server and used my config from the old server which i should replace, but it just died after 1 hour running.

first i thought it was grsecurity because of those messages:
grsec: From 10.x.x.x: denied hardlink of /var/lib/dhcp/dhcpd.leases (owned by 0.0) to /var/lib/dhcp/dhcpd.leases~ for (dhcpd:3098) UID(1000) EUID(1000), parent (init:1) UID(0) EUID(0)
grsec: From 10.x.x.x: signal 11 sent to (dhcpd:3098) UID(1000) EUID(1000), parent (init:1) UID(0) EUID(0)

if i manually "chown dhcp:dhcp /var/lib/dhcp/dhcpd.leases" it seems to be fine (though i can only tell in a few hours).
if i then restart dhcpd with "/etc/init.d/dhcp restart" the ownership of the dhcpd.leases file is set to root:root again...and then when dhcpd wants to write to it => crash
at the moment i'm using a kernel without grsecurity for testing.

i'm not using chrooted environment (commented out the CHROOT line in /etc/conf.d/dhcp) because i got problems with logging when chrooted.

JG
Comment 11 Max Kalika (RETIRED) gentoo-dev 2003-09-19 08:37:41 UTC
Danny, thanks for confirming. I'll close this as fixed. 
 
JG, it seems entirely a problem with the grsec patch.  You may need to 
relax/adjust your ACLs.  If problems persist, open another bug because 
that is a completely separate issue.  Thanks. 
Comment 12 Eric Pretorious 2003-10-02 15:26:29 UTC
Max: My bug relates specically to dhcpcd-1.3.2* (not dhcpd-3.0). (I had originally
opened bug 27460 to report this but it was marked as a duplicate of this
bug.) 

I'm still experiencing the same failure to utilize /var/lib/dhcp/client.leases.
Comment 13 Lars Kneschke 2003-12-31 05:12:49 UTC
I do still have this problem! I'm using net-misc/dhcp-3.0_p2-r2 and my dhcpd is still crashing regulary. 

I do also have this root:root problem.

ProxyLK root # ls -l /var/lib/dhcp/
total 8
-rw-r--r--    1 root     root         1211 Dec 31 14:06 dhcpd.leases
-rw-r--r--    1 dhcp     dhcp         1211 Dec 31 13:48 dhcpd.leases~

Comment 14 Max Kalika (RETIRED) gentoo-dev 2003-12-31 08:02:31 UTC
Reopening.. I'm really lost as to what is happening here.  Mine works just fine without any crashes.
Comment 15 ari edelkind 2003-12-31 12:54:49 UTC
I'm the author of the isc-dhcpd paranoia patch (max contacted me).  I'm not in charge of the gentoo package.

The fact that the dhcpd.leases file is originally created as root is not a problem; these permissions affect file/inode content only, and should not affect directory actions, such as renaming or deleting the file.  This is standard unix behavior, and if the grsecurity patch breaks this, it's a problem with the grsecurity patch.

Anyone currently experiencing a server lease-write problem should update this ticket with the following:

  - permissions of /var/lib/dhcp (ls -ld /var/lib/dhcp)
  - permissions of <chroot>/var/lib/dhcp if you're using chroot
  - if the owner of either of these directories is root, that's your problem, and you should list the gentoo package revision you're using.
  - if the owner of these directories is your dhcp user, i'll need the output of strace, detailing the events leading to program abort.  You can use:
      # strace -o <file> -f dhcpd <options>

You can attach the entire strace output to this ticket, though you probably shouldn't include it all in the body of your report.

If you're experiencing a client (dhcpcd) lease problem, you have a separate issue, and this ticket is not for you.
Comment 16 Lars Kneschke 2004-01-01 15:34:11 UTC
ProxyLK root # ls -ld /var/lib/dhcp
drwxr-xr-x    2 dhcp     dhcp          136 Jan  1 23:37 /var/lib/dhcp

This is from syslog:

Jan  1 14:23:07 ProxyLK grsec: denied hardlink of /var/lib/dhcp/dhcpd.leases (owned by 0.0) to /var/lib/dhcp/dhcpd.leases~ for (dhcpd:6787) UID(1002) EUID(1002), parent (init:1) UID(0) EUID(0)

The dhcpd is starting up and is creating the dhcpd.leases as root. After that it switches to user dhcp. After is trys to create the hardlink, which gets denied by grsecurity. Why can't the dhcpd.leases get created as the dhcp user?

Anyways, i attached my new init script, which seems to fix the problem. I change the ownership of dhcpd.leases after dhcpd gets started.

Cu
Comment 17 Lars Kneschke 2004-01-01 15:39:18 UTC
Created attachment 22983 [details]
updated dhcpd init file
Comment 18 ari edelkind 2004-01-02 12:14:25 UTC
The script you attached introduces a race condition, in which the lease file may not have been created by the time chown is called.

As i mentioned, your issue can be considered a problem with the grsecurity patch, or at least its restrictive settings.  However, if you wish to account for this behavior in dhcpd anyway, i know that max had been writing an additional patch to change ownership of the original lease file after creation.
Comment 19 Max Kalika (RETIRED) gentoo-dev 2004-01-02 12:21:30 UTC
Thank you for clearing this Ari, I completely ignored the fact that grsecurity might be the culprit, but now it makes a lot of sense.  Do you see any problems with the patch you mention?  If not, I'll put it back for folks with grsec.  Thanks again.
Comment 20 Danny Dowlearn 2004-01-08 14:08:23 UTC
Hello again.  I'm the original reporter from back in the day.  While recently upgrading my system (via emerge world), a new version of dhcpd was installed.  The original fix worked for a while (i.e. putting "Setting permissions on dhcpd leases file" in the init script).  However, after upgrading the (original) problem came back.  Right after the server would start.  (I'm fairly sure that) the problem is that the permissions on the leases file are being set (via the init script) _before_ the server starts.  The server re-chown's it to root:root.  My kludge was to stick an additional "Setting permissions on dhcpd leases file . . . again" ebegin right after the server starts in the start() functions (rather than in the check_config() function where it currently resides.  Also, I'm not using any grsecurity stuff or chroot stuff.

Back when this issue first came up, I can't remember if the fixed init script put the "Setting permissions..." in check_config() or in start().  However, putting it in the latter has worked for me.

dannyd
Comment 21 Max Kalika (RETIRED) gentoo-dev 2004-01-14 17:05:51 UTC
I went ahead and re-added the ebuild with the chown patch. Give it a try please.
Comment 22 Lars Kneschke 2004-01-14 23:45:38 UTC
Looks good now. No problems so far.
Comment 23 Martin Holzer (RETIRED) gentoo-dev 2004-01-20 15:43:01 UTC
closing the last time, hope so