Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 278335 - net-misc/dhcp-3.1.2_p1 init.d/dhcpd test incompatible with chroot
Summary: net-misc/dhcp-3.1.2_p1 init.d/dhcpd test incompatible with chroot
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-19 16:46 UTC by Arthur Hagen
Modified: 2012-10-10 03:48 UTC (History)
1 user (show)

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


Attachments
dhcpd-init2-fix.patch (dhcpd-init2-fix.patch,712 bytes, patch)
2009-08-19 16:37 UTC, Lance Albertson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur Hagen 2009-07-19 16:46:05 UTC
The new init.d script for dhcpd runs a "/usr/sbin/dhcpd -cf ${DHCPD_CHROOT}/${DHCPD_CONF} -t" and checks the result before allowing dhcpd to start.

However, this fails when using chroot and include files.
Example:

DCHPD_CHROOT is set to /var/chroot/dhcp
/var/chroot/dhcp/etc/dhcp/dhcpd.conf is valid, and contains:
include "/var/nfs/master/dhcpd.master"

This causes the init.d script to execute the following:

/usr/sbin/dhcpd -cf /var/chroot/dhcp/etc/dhcpd.conf -t

However, when not run from within the chroot jail, the include line is likely not valid, and an error is the result:

Internet Systems Consortium DHCP Server V3.1.2p1-Gentoo
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Can't open /var/nfs/master/dhcpd.master: No such file or directory

... because it didn't look for /var/chroot/dhcp/var/nfs/master/dhcpd.master which is the correct include name when run in a chroot jail.

It doesn't have to point to an nfs directory, of course, includes like these will fail as well:
include "/etc/dhcp/dhcpd.master"
include "../intranet1/dhcpd.include"

To summarize, /etc/init.d/dhcpd has outsmarted itself.  It should not call -t at all unless it can do so from within a chroot context.  Else, the test will not be valid.

What added value does inserting the -t test give?  I mean, if there's an error in the config files, dhcpd won't start anyhow.  If the init.d script ran a -t test IF AND ONLY IF dhcpd failed to start, I could understand, but to run it BEFORE starting adds no value.
Comment 1 Lance Albertson 2009-08-19 16:37:31 UTC
Created attachment 201716 [details, diff]
dhcpd-init2-fix.patch

We encountered the same problem at the OSL when we upgraded dhcpd for the latest GLSA. It looks like the new init script incorrectly deals with chroot'd dhcp setups. I used the same logic from the start section of the script and applied it to the configtest section.

I tested it on both chroot and non-chrooted dhcpd setups and it appears to work properly now. You should fix this ASAP before other people encounter this problem.

Cheers-
Comment 2 Arthur Hagen 2009-08-19 23:05:45 UTC
While the patch deals with the chroot situation, it still won't work when the master file is on an NFS mount with root_squash (recommended), unless the file is world readable (not recommended).
The test runs as root, unlike the dhcpd process which runs as a user, and thus the test fails when root is disallowed from reading the include file.  Similar for selinux or file systems with ACLs, I should think.

Yeah, you can patch that too by adding -user and -group as appropriate, but what's the point?  It doesn't add any value whatsoever, because any errors -t catches are also caught by attempting to start the daemon.
If the daemon doesn't start, THEN the script can run -t to (try) to find out why, but if it DOES start, -t only adds to the startup time without giving any benefit.  Most distros try to reduce startup time, not increase it.
Comment 3 Lance Albertson 2009-08-19 23:42:20 UTC
(In reply to comment #2)
> While the patch deals with the chroot situation, it still won't work when the
> master file is on an NFS mount with root_squash (recommended), unless the
> file is world readable (not recommended).  The test runs as root, unlike the
> dhcpd process which runs as a user, and thus the test fails when root is
> disallowed from reading the include file.  Similar for selinux or file
> systems with ACLs, I should think.
> 
> Yeah, you can patch that too by adding -user and -group as appropriate, but
> what's the point?  It doesn't add any value whatsoever, because any errors -t
> catches are also caught by attempting to start the daemon.  If the daemon
> doesn't start, THEN the script can run -t to (try) to find out why, but if it
> DOES start, -t only adds to the startup time without giving any benefit.
> Most distros try to reduce startup time, not increase it.

The point is, you don't want to stop a critical service if there's a config
syntax error. DHCPD will *not* start if there's a syntax error, so if you test
it afterwards your service will be broken. Testing it afterwards is pointless
since you would have stopped the process at that point. Doing the check before
allows you to keep the service running while you fix the config error.

We probably should add -user/-group to the check so that its the same, but I
don't know many people who are running DHCP via NFS ;-)
Comment 4 SpanKY gentoo-dev 2011-03-05 23:54:08 UTC
ive included this in dhcp-4.2.1.  i'll leave open in case someone wants to also add to dhcp-3.x.
Comment 5 SpanKY gentoo-dev 2012-10-10 03:48:37 UTC
dhcp-4.x is stable now.  dhcp-3.x is dead.