Bug 55787 - Chroot fails with "Cannot chroot when not started as root" error
Summary: Chroot fails with "Cannot chroot when not started as root" error
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.4.6
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2013-11-16 17:03 UTC by Arul Selvan
Modified: 2019-01-06 15:32 UTC (History)
1 user (show)



Attachments
strace output (803.37 KB, text/x-log)
2013-11-16 19:57 UTC, Arul Selvan
Details
error log (1.23 KB, text/x-log)
2013-11-16 19:58 UTC, Arul Selvan
Details
minimal apache.conf (474 bytes, text/plain)
2013-11-16 19:58 UTC, Arul Selvan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arul Selvan 2013-11-16 17:03:49 UTC
I have set my chroot directory as shown below. 

ChrootDir /var/www

When started with the above chroot setting, apache2 exits with the following error

[Sat Nov 16 10:20:54.241556 2013] [unixd:alert] [pid 12802] (2)No such file or directory: AH02158: Cannot chroot when not started as root

NOTE: apache2 is started as 'root' user. It looks like the call to check geteuid() is made after apache2 lowers its privilege to APACHE_RUN_USER?

I am not sure this is a bug or configuration issue. This directory (/var/www) mentioned above was setup with everything needed for chroot'ed environment with libapache2-mod-chroot and was working fine for many years running under apache 2.2. Recently, I upgraded to 2.4.6 and wanted to switch to apache2's native Chroot since mod_chroot is no longer maintained and I am now stuck with the above error.
Comment 1 Eric Covener 2013-11-16 19:38:28 UTC
Dropping userid happens later in the same function.   Also, works for me.

Can you demonstrate with a minimal configuration and include it w/ an strace -f of startup?
Comment 2 Arul Selvan 2013-11-16 19:57:49 UTC
Created attachment 31048 [details]
strace output

Here you go...

root@gorilla:/etc/apache2# rm /var/log/apache2/error.log
root@gorilla:/etc/apache2# apachectl start >/tmp/apache2_strace.log 2>&1

I am attaching apache.conf and apache2.strace.log
Comment 3 Arul Selvan 2013-11-16 19:58:05 UTC
Created attachment 31049 [details]
error log
Comment 4 Arul Selvan 2013-11-16 19:58:25 UTC
Created attachment 31050 [details]
minimal apache.conf
Comment 5 Eric Covener 2013-11-16 20:21:09 UTC
Pretty weird, the trace shows geteuid(), chdir(), chroot() which are all after the message you say was issued (assuming it hasn't changed recently) but those all follow the error.

It's almost like you have a 2nd copy of the mod_unixd code loaded.

can you add apachectl -l and -M output w/ the same conf from the strace?
Comment 6 Arul Selvan 2013-11-16 20:27:34 UTC
Very interesting.... I do see it loaded twice!, how do I get rid of one?

root@gorilla:/etc/apache2# apachectl -l -M 
Compiled in modules:
  core.c
  mod_so.c
  mod_watchdog.c
  http_core.c
  mod_log_config.c
  mod_logio.c
  mod_version.c
  mod_unixd.c
  mod_unixd.c
root@gorilla:/etc/apache2#
Comment 7 Eric Covener 2013-11-16 20:59:39 UTC
(In reply to Arul from comment #6)
> Very interesting.... I do see it loaded twice!, how do I get rid of one?
> 
> root@gorilla:/etc/apache2# apachectl -l -M 
>   mod_unixd.c
>   mod_unixd.c
> root@gorilla:/etc/apache2#

That is an impressive bug.  Can you open a bug against ubuntu/debian/wherever the build comes from?
Comment 8 Stefan Fritsch 2013-11-16 23:53:11 UTC
Trunk fix: r1542615 .

This will fixed in Debian in the next upload. If you use an already released version of Ubuntu that includes 2.4, you need to file a bug report with Ubuntu.
Comment 9 Arul Selvan 2013-11-17 00:57:52 UTC
Yes, I am using the latest Ubuntu 13.10 that includes the 2.4.6 version. 

root@gorilla:~# apache2ctl -v
Server version: Apache/2.4.6 (Ubuntu)
Server built:   Aug  9 2013 14:31:04
root@gorilla:~# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=13.10
DISTRIB_CODENAME=saucy
DISTRIB_DESCRIPTION="Ubuntu 13.10"

I will file a bug report w/ Ubuntu referencing this. 

Thank you for your help.
Comment 10 Arul Selvan 2013-11-17 13:52:50 UTC
(In reply to Arul Selvan from comment #9)
> Yes, I am using the latest Ubuntu 13.10 that includes the 2.4.6 version. 
> 
> root@gorilla:~# apache2ctl -v
> Server version: Apache/2.4.6 (Ubuntu)
> Server built:   Aug  9 2013 14:31:04
> root@gorilla:~# cat /etc/lsb-release 
> DISTRIB_ID=Ubuntu
> DISTRIB_RELEASE=13.10
> DISTRIB_CODENAME=saucy
> DISTRIB_DESCRIPTION="Ubuntu 13.10"
> 
> I will file a bug report w/ Ubuntu referencing this. 
> 
> Thank you for your help.

Bug report filed in Ubuntu: 
https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/1251939
Comment 11 Christophe JAILLET 2019-01-06 15:32:53 UTC
This has been backported in 2.4.x in r1555792 and is part of 2.4.7.

The ubuntu launchpad issue in comment #10 is also marked as "Fix Released"