You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2024/01/24 05:10:27 UTC
[Bug 68527] New: NULL dereference in mod_dir:fixup_dir
https://bz.apache.org/bugzilla/show_bug.cgi?id=68527
Bug ID: 68527
Summary: NULL dereference in mod_dir:fixup_dir
Product: Apache httpd-2
Version: 2.5-HEAD
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: mod_dir
Assignee: bugs@httpd.apache.org
Reporter: benjamin.p.kallus.gr@dartmouth.edu
Target Milestone: ---
- Platform: Linux 6.7.0 x86_64
- Build: gcc 12.2.0, apache httpd trunk default build configuration
- httpd_config:
> ServerRoot "/usr/local/apache2"
> Listen 80
> LoadModule authz_core_module modules/mod_authz_core.so
> LoadModule unixd_module modules/mod_unixd.so
> LoadModule http2_module modules/mod_http2.so
> LoadModule proxy_module modules/mod_proxy.so
> LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
> LoadModule rewrite_module modules/mod_rewrite.so
> LoadModule dir_module modules/mod_dir.so
> User daemon
> Group daemon
> ServerName apache
> <VirtualHost *:80>
> DocumentRoot /var/www
> <Directory /var/www>
> DirectoryIndex index.php
> SetHandler "proxy:fcgi://127.0.0.1:9000/"
> RewriteEngine On
> RewriteBase /
> RewriteRule ^(.*)$ /index.php [L,QSA]
> </Directory>
> </VirtualHost>
- php-fpm version: 8.2.7 (from Debian Bookworm repos)
- php-fpm config: The default from the Debian Bookworm repos, except with the
listen directive modified to use a TCP socket instead of a UDS
- /var/www/index.php:
> <?php
> echo "hello world";
> ?>
To reproduce the crash,
1. build apache with the configuration described above
2. run the server in gdb:
> gdb /usr/local/apache2/bin/httpd
> (gdb) r -X
3. In another terminal, send a simple request using nc:
> printf 'GET / HTTP/1.1\r\nHost: whatever\r\n\r\n | nc localhost 80'
4. Watch the server segfault and crash:
> Thread 28 "httpd" received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7fffe76006c0 (LWP 64658)]
> __strcmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283
5. Take a backtrace and see what's wrong:
> (gdb) bt
> #0 __strcmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283
> #1 0x00007ffff7c22804 in fixup_dir (r=0x7fffd8004c30) at mod_dir.c:306
> #2 dir_fixups (r=0x7fffd8004c30) at mod_dir.c:422
> #3 0x00005555555d1ee0 in ap_run_fixups (r=r@entry=0x7fffd8004c30) at request.c:87
> #4 0x00005555555d46ba in ap_process_request_internal (r=r@entry=0x7fffd8004c30) at request.c:435
> #5 0x0000555555598b25 in ap_process_async_request (r=r@entry=0x7fffd8004c30) at http_request.c:448
> #6 0x000055555559453c in ap_process_http_async_connection (c=0x7fff10000fa0) at http_core.c:159
> #7 ap_process_http_connection (c=0x7fff10000fa0) at http_core.c:250
> #8 0x00005555555b7a00 in ap_run_process_connection (c=c@entry=0x7fff10000fa0) at connection.c:43
> #9 0x00005555555a6b86 in process_socket (thd=thd@entry=0x7fffe0000d10, p=<optimized out>,
> sock=<optimized out>, cs=<optimized out>, my_child_num=my_child_num@entry=0,
> my_thread_num=my_thread_num@entry=0) at event.c:1129
> #10 0x00005555555a73b2 in worker_thread (thd=0x7fffe0000d10, dummy=<optimized out>) at event.c:2488
> #11 0x00007ffff7f07f7f in dummy_worker (opaque=0x7fffe0000d10) at threadproc/unix/thread.c:165
> #12 0x00007ffff7d5d044 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
> #13 0x00007ffff7ddc880 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100
6. Check the first argument register and notice that it's NULL:
> (gdb) print $rdi
> $1 = 0
The offending revision is this one, which passes r->content_type to strcmp
without making sure it's not NULL:
> https://svn.apache.org/viewvc?view=revision&revision=1695583
I tried adding in a check for NULL on line 306, and the server still segfaults
on line 315, which is another unchecked strcmp added in the same revision.
Adding in another check for NULL on line 315 prevents the segfault, but the
server still 500s, which is probably an indication that something about my
config is wrong. I wrote this config from scratch, so it's very likely that
it's doing something unorthodox :)
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org
[Bug 68527] NULL dereference in mod_dir:fixup_dir
Posted by "bugzilla.apache.org via bugs" <bu...@httpd.apache.org>.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68527
--- Comment #3 from abernal <ab...@apache.org> ---
Reproduced with a real build and gdb. The crash is confirmed as reported:
strcmp(r->handler, ...) in fixup_dir() dereferences a NULL r->handler. That
happens once mod_rewrite's internal-redirect loop protection
(LimitInternalRecursion, default 10) kicks in on a self-matching RewriteRule --
each internal redirect gets a fresh request_rec, and by the time the loop is
cut off, r->handler is no longer the one set earlier in the chain by
SetHandler. No working FastCGI backend is needed to reproduce: the crash
happens during the fixups phase, before any handler runs.
Fix and a regression test are available as a pull request:
https://github.com/apache/httpd/pull/915
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org
[Bug 68527] NULL dereference in mod_dir:fixup_dir
Posted by "bugzilla.apache.org via bugs" <bu...@httpd.apache.org>.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68527
abernal <ab...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #4 from abernal <ab...@apache.org> ---
Correction to my previous comment: I misidentified the NULL pointer.
fixup_dir() unconditionally does "if (!r->handler) r->handler =
DIR_MAGIC_TYPE;" at the top of the function, so r->handler can never be NULL at
either strcmp() site -- the crash I reproduced was actually hitting the
r->content_type dereference, i.e. the same bug already described in this report
and fixed by Eric Covener's commit (r1936401 "PR68527: fixup_dir segfault with
no content-type"), already on trunk and backported to 2.4.x (r1937718). There
is no remaining defect here. Closed https://github.com/apache/httpd/pull/915,
which incorrectly guarded r->handler instead. Marking RESOLVED/FIXED since both
trunk and 2.4.x already have the real fix.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org
[Bug 68527] NULL dereference in mod_dir:fixup_dir
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68527
--- Comment #1 from SamCo DWS <in...@samco-dev.net> ---
I can independently confirm this crash on a completely different setup, which
shows the bug is not specific to a particular rewrite/config style but a
general collision between mod_rewrite (per-directory context) and mod_dir's
fixup handler whenever a directory request gets rewritten to a handler-bound
target.
Environment:
- Debian 13 (Trixie), Apache/2.4.67
- PHP-FPM 8.4, connected via mod_proxy_fcgi (SetHandler
"proxy:unix:/run/php/php8.4-fpm.sock|fcgi://localhost/")
- Trigger: per-directory .htaccess (AllowOverride), NOT a vhost-level
RewriteRule as in the original report:
RewriteEngine On
RewriteRule ^$ index.php?_route[controller]=index [L,QSA]
- Request: GET / (i.e. the exact directory root, matching ^$)
Backtrace (with debug symbols via debuginfod, Apache 2.4.67):
#0 __strcmp_avx2 () at ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283
#1 fixup_dir (r=...) at ./modules/mappers/mod_dir.c:280
#2 dir_fixups (r=...) at ./modules/mappers/mod_dir.c:395
#3 ap_run_fixups (r=...) at ./server/request.c:86
#4 ap_process_request_internal (r=...) at ./server/request.c:416
#5 ap_process_async_request (r=...) at ./modules/http/http_request.c:450
...
Identical root cause as already identified in this report: both unguarded
strcmp(r->content_type, DIR_MAGIC_TYPE)
calls in fixup_dir() (the DirectoryCheckHandler==On branch AND the
REWRITE_REDIRECT_HANDLER_NAME "step aside" branch) dereference r->content_type
without a NULL check. In our case r->content_type was NULL because the
type_checker phase runs before the per-directory mod_rewrite fixup sets the
proxy handler, so mod_mime never assigns a content type for the directory
request before mod_dir's fixup runs.
We reproduced this consistently with BOTH DirectoryCheckHandler On and Off -
each setting simply routes through a different one of the two unguarded
strcmp() calls, so toggling the directive is not a usable workaround.
Workaround that does prevent the crash (confirms the NULL r->content_type
theory): forcing a non-NULL content type before the fixup phase runs, e.g.
<Directory /path/to/app>
ForceType text/html
</Directory>
Given:
1. This has now been independently reproduced on two different Apache
versions, two different OS/package bases, two different PHP-FPM
versions, and two different rewrite trigger styles (vhost-level vs.
.htaccess) - it is clearly a general, easily-triggered defect, not a
one-off config quirk.
2. The trigger config (mod_rewrite + mod_proxy_fcgi + PHP-FPM, rewriting a
directory root to an index script) is an extremely common real-world
pattern for PHP front-controller frameworks.
3. Any unauthenticated client request matching the vulnerable pattern
crashes the worker process handling it - this is a trivially triggerable
remote DoS vector, not just a functional bug.
Given the report has been sitting at NEW since 2024 with a clearly identified
root cause and a proposed two-line fix, could this please be reprioritized?
The fix suggested in this report (adding `r->content_type &&` before both
strcmp() calls in fixup_dir()) is minimal and low-risk.
Happy to provide our full core dump / additional backtraces if useful.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org
[Bug 68527] NULL dereference in mod_dir:fixup_dir
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68527
--- Comment #2 from Eric Covener <co...@gmail.com> ---
thanks for resurrecting. committed to trunk and proposed for 2.4.x
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org