Bug 17206 - Filehandles of logs not closed before exec of cgi scripts
Summary: Filehandles of logs not closed before exec of cgi scripts
Status: CLOSED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.0.44
Hardware: All FreeBSD
: P1 critical (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-19 15:46 UTC by Christian Kratzer
Modified: 2004-11-16 19:05 UTC (History)
1 user (show)



Attachments
disables inheriting of access and error logs (684 bytes, patch)
2003-02-21 11:32 UTC, Christian Kratzer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Kratzer 2003-02-19 15:46:29 UTC
We updated one of our servers from apache-2.0.39 to 
apache-2.0.44 and noticed that 2.0.44 fails to close 
the file handles of the logfiles before executing cgi 
scripts.

We test by running a php script via the cgi interface and 
using lsof to list the open file handles. (See below)

This enables cgi's to access the logs of other virtual hosts.

We can reproduce this under FreeBSD 4-STBALE and 5.0 RELEASE
using the preforked mpm and apache-2.0.40, 2.0.43 and 2.0.44.
The problem does not occur on apache-2.0.39.  

We think this bug might be related to Bug 12774 which was closed
due to lack of response from the original poster.  This was also 
oing from 2.0.39 to 2.0.40.

This could also be related to the changes in apr/file_io/src/unix/file_dup.c
from 1.48 to 1.49 and the introduction of apr_file_setaside().   
These changes were after 2.0.39 and before 2.0.40.

Greetings
Christian Kratzer
CK Software GmbH

--snipp--
COMMAND  PID    USER   FD   TYPE     DEVICE SIZE/OFF    NODE NAME
php     3308 webmail  cwd   VDIR 151,131079      512 1474242
/u1/jails/jail-webmail/www/servers/webmail/htdocs
php     3308 webmail  rtd   VDIR 151,131079      512 1291924 /u1/jails/jail-webmail
php     3308 webmail  txt   VREG 151,131079  1343042 1473554
/u1/jails/jail-webmail/www/cgi-php/php
php     3308 webmail  txt   VREG 151,131079    80080 1293805
/u1/jails/jail-webmail/usr/libexec/ld-elf.so.1
php     3308 webmail  txt   VREG 151,131079   749398 1473486
/u1/jails/jail-webmail/usr/local/lib/libc-client4.so.8
php     3308 webmail  txt   VREG 151,131079   126427 1452224
/u1/jails/jail-webmail/usr/local/lib/libexpat.so.4
php     3308 webmail  txt   VREG 151,131079    19544 1292898
/u1/jails/jail-webmail/usr/lib/libhistory.so.4
php     3308 webmail  txt   VREG 151,131079   147000 1292903
/u1/jails/jail-webmail/usr/lib/libreadline.so.4
php     3308 webmail  txt   VREG 151,131079   258872 1292446
/u1/jails/jail-webmail/usr/lib/libncurses.so.5
php     3308 webmail  txt   VREG 151,131079    85712 1473115
/u1/jails/jail-webmail/usr/local/lib/libpq.so.3
php     3308 webmail  txt   VREG 151,131079   132379 1473270
/u1/jails/jail-webmail/usr/local/lib/mysql/libmysqlclient.so.10
php     3308 webmail  txt   VREG 151,131079    51156 1292749
/u1/jails/jail-webmail/usr/lib/libz.so.2
php     3308 webmail  txt   VREG 151,131079    28480 1292428
/u1/jails/jail-webmail/usr/lib/libcrypt.so.2
php     3308 webmail  txt   VREG 151,131079   192724 1452773
/u1/jails/jail-webmail/usr/local/lib/libldap.so.2
php     3308 webmail  txt   VREG 151,131079    47937 1452770
/u1/jails/jail-webmail/usr/local/lib/liblber.so.2
php     3308 webmail  txt   VREG 151,131079    38500 1292702
/u1/jails/jail-webmail/usr/lib/libpam.so.1
php     3308 webmail  txt   VREG 151,131079   908698 1473181
/u1/jails/jail-webmail/usr/local/lib/libiconv.so.3
php     3308 webmail  txt   VREG 151,131079   211156 1473420
/u1/jails/jail-webmail/usr/local/lib/libgd.so.4
php     3308 webmail  txt   VREG 151,131079   340310 1473287
/u1/jails/jail-webmail/usr/local/lib/libfreetype.so.9
php     3308 webmail  txt   VREG 151,131079   139364 1472995
/u1/jails/jail-webmail/usr/local/lib/libpng.so.5
php     3308 webmail  txt   VREG 151,131079   135696 1473155
/u1/jails/jail-webmail/usr/local/lib/libjpeg.so.9
php     3308 webmail  txt   VREG 151,131079   117736 1292433
/u1/jails/jail-webmail/usr/lib/libm.so.2
php     3308 webmail  txt   VREG 151,131079   762896 1293883
/u1/jails/jail-webmail/usr/lib/libcrypto.so.2
php     3308 webmail  txt   VREG 151,131079   181720 1293903
/u1/jails/jail-webmail/usr/lib/libssl.so.2
php     3308 webmail  txt   VREG 151,131079   575584 1292596
/u1/jails/jail-webmail/usr/lib/libc.so.4
php     3308 webmail    0u  PIPE 0xf08bb4e0    16384
php     3308 webmail    1u  PIPE 0xeba05bc0    16384         ->0xf08bb760
php     3308 webmail    2u  PIPE 0xebcb63a0    16384         ->0xeba03960
php     3308 webmail    4u  PIPE 0xeba03a00    16384         ->0xeb666a00
php     3308 webmail    5u  PIPE 0xeb666a00    16384         ->0xeba03a00
php     3308 webmail    6u  VREG 151,131079     4519 1474234
/u1/jails/jail-webmail/www/logs/httpd-error.log
php     3308 webmail    7u  VREG 151,131079        0 1474628
/u1/jails/jail-webmail/www/servers/webmail109/logs/httpd-error.log
php     3308 webmail    8u  VREG 151,131079        0 1474629
/u1/jails/jail-webmail/www/servers/webmail108/logs/httpd-error.log
php     3308 webmail    9u  VREG 151,131079        0 1474630
/u1/jails/jail-webmail/www/servers/webmail107/logs/httpd-error.log
php     3308 webmail   10u  VREG 151,131079        0 1474631
/u1/jails/jail-webmail/www/servers/webmail106/logs/httpd-error.log
php     3308 webmail   11u  VREG 151,131079        0 1474632
/u1/jails/jail-webmail/www/servers/webmail105/logs/httpd-error.log
php     3308 webmail   12u  VREG 151,131079        0 1474633
/u1/jails/jail-webmail/www/servers/webmail104/logs/httpd-error.log
php     3308 webmail   13u  VREG 151,131079        0 1474634
/u1/jails/jail-webmail/www/servers/webmail103/logs/httpd-error.log
php     3308 webmail   14u  VREG 151,131079        0 1474635
/u1/jails/jail-webmail/www/servers/webmail102/logs/httpd-error.log
php     3308 webmail   15u  VREG 151,131079        0 1474636
/u1/jails/jail-webmail/www/servers/webmail101/logs/httpd-error.log
php     3308 webmail   16u  VREG 151,131079        0 1474637
/u1/jails/jail-webmail/www/servers/webmail100/logs/httpd-error.log
php     3308 webmail   17u  VREG 151,131079     2109 1474254
/u1/jails/jail-webmail/www/servers/webmail/logs/httpd-error.log
php     3308 webmail   18w  VREG 151,131079      675 1474236
/u1/jails/jail-webmail/www/logs/httpd-access.log
php     3308 webmail   19w  VREG 151,131079        0 1474638
/u1/jails/jail-webmail/www/servers/webmail109/logs/httpd-access.log
php     3308 webmail   20w  VREG 151,131079        0 1474639
/u1/jails/jail-webmail/www/servers/webmail108/logs/httpd-access.log
php     3308 webmail   21w  VREG 151,131079        0 1474640
/u1/jails/jail-webmail/www/servers/webmail107/logs/httpd-access.log
php     3308 webmail   22w  VREG 151,131079        0 1474641
/u1/jails/jail-webmail/www/servers/webmail106/logs/httpd-access.log
php     3308 webmail   23w  VREG 151,131079        0 1474642
/u1/jails/jail-webmail/www/servers/webmail105/logs/httpd-access.log
php     3308 webmail   24w  VREG 151,131079        0 1474643
/u1/jails/jail-webmail/www/servers/webmail104/logs/httpd-access.log
php     3308 webmail   25w  VREG 151,131079        0 1474644
/u1/jails/jail-webmail/www/servers/webmail103/logs/httpd-access.log
php     3308 webmail   26w  VREG 151,131079        0 1474645
/u1/jails/jail-webmail/www/servers/webmail102/logs/httpd-access.log
php     3308 webmail   27w  VREG 151,131079        0 1474646
/u1/jails/jail-webmail/www/servers/webmail101/logs/httpd-access.log
php     3308 webmail   28w  VREG 151,131079        0 1474647
/u1/jails/jail-webmail/www/servers/webmail100/logs/httpd-access.log
php     3308 webmail   29w  VREG 151,131079     7821 1474255
/u1/jails/jail-webmail/www/servers/webmail/logs/httpd-access.log
--snipp--
Comment 1 Christian Kratzer 2003-02-21 11:32:14 UTC
Created attachment 4966 [details]
disables inheriting of access and error logs
Comment 2 Christian Kratzer 2003-02-21 12:02:32 UTC
Apache httpd fails to close access and error logs when it forks and 
execs cgi scripts.  From our preliminary understanding of the code
the fix is to call apr_file_inherit_unset() in place of 
apr_file_inherit_set() in both server/log.c and loggers/mod_log_config.c.

The bug first appeared going from 2.0.39 to 2.0.40 because a typo in the
definition of the APR_INHERIT flag had reversed the effect of
apr_file_inherit_set().  For this please see cvs diff of
/apr/include/arch/unix/Attic/inherit.h between 1.10 and 1.11.

The attached patch forces cleanup of logfiles on fork/exec of cgi's.

All calls of *_inherit_set() and *_inherit_unset() should be validated 
for correct behavior in their respective contexts.

Credit for digging through the sources and finding the fix goes
Bjoern Zeeb <bzeeb@zabbadoz.net>.

In case of questions we have more detailed information available.
Please email.



Comment 3 Bjoern A. Zeeb 2003-02-22 21:50:31 UTC
the fix does not help with all mpms.
People who need to know more got 2nd mail.
Comment 4 Bjoern A. Zeeb 2003-03-07 07:14:47 UTC
further public discussions on patches are here
(apr) http://marc.theaimsgroup.com/?t=104688218100008&r=1&w=2
and here
(httpd) http://marc.theaimsgroup.com/?t=104696493400002&r=1&w=2

Also pointed wrowe to his commit
http://cvs.apache.org/viewcvs.cgi/httpd-2.0/server/log.c.diff?r1=1.94&r2=1.95&di
ff_format=h
Comment 5 William A. Rowe Jr. 2003-03-20 22:08:40 UTC
  Thanks to you, Christian, Bjoern and Joe I believe we have this licked.
  Fixes are applied to the forthcoming 2.0.45 release and the 2.1.0-dev tree.
Comment 6 Bjoern A. Zeeb 2003-04-02 20:19:31 UTC
Many thanks back to you, William Rowe, for your great work
solving even more problems in apr/httpd related to this. Thanks.