owasp-modsecurity / ModSecurity-apache

ModSecurity v3 Apache Connector
Apache License 2.0
87 stars 51 forks source link

Segmentation fault #46

Closed cyberblackhole closed 5 years ago

cyberblackhole commented 5 years ago

I'm using ModSecurity v3.0.3 (Linux)

I pulled latest commit for modsecurity-apache just to test whether post data is accessible by _ARGSPOST.

I'm getting the below error in apache error logs.

[Thu Nov 22 11:57:20.005976 2018] [core:notice] [pid 3768] AH00051: child pid 3823 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Nov 22 11:57:20.015739 2018] [watchdog:debug] [pid 3832] mod_watchdog.c(565): AH02980: Watchdog: nothing configured?
[Thu Nov 22 11:57:20.016621 2018] [proxy:debug] [pid 3832] proxy_util.c(1785): AH00925: initializing worker proxy:reverse shared
[Thu Nov 22 11:57:20.016965 2018] [proxy:debug] [pid 3832] proxy_util.c(1827): AH00927: initializing worker proxy:reverse local
[Thu Nov 22 11:57:20.017503 2018] [proxy:debug] [pid 3832] proxy_util.c(1878): AH00931: initialized single connection worker in child 3832 for (*)

Please let me know what is going wrong.

Originally posted by @Goron1606 in https://github.com/SpiderLabs/ModSecurity-apache/pull/22#issuecomment-440927889

c0deguard commented 5 years ago

I'm also facing similar issue. I guess this is because of some bug in "Proposed fix for msc_process_request_body call too early" Here it shows building failed because of this https://travis-ci.org/SpiderLabs/ModSecurity-apache

victorhora commented 5 years ago

Hi all

I think there's an issue there indeed, but i'm not sure its related with the fact that the tests from Travis are failing. This is what Travis says about the build:

image

So Apache is failing to start (or the script is believes is the case) and unless the issue is happening right at the start of Apache/ModSecurity, it might be something wrong with the tests.

Could you please provide a full backtrace/stacktraces of this issue for further investigation?

Thanks

cyberblackhole commented 5 years ago

@victorhora Can you please specify the logs which you require and their file paths?

victorhora commented 5 years ago

I would recommend recompiling everything (ModSecurity, Apache, Apache-connector) with debug symbols. This is usually accomplished by appending CFLAGS/CPPFLAGS like so:

$ export CFLAGS="-g -O0"

After that you can collect the stack traces by following these steps: https://httpd.apache.org/dev/debugging.html

You should also check the debugging section in the README of libModSecurity and the Apache connector

Thanks for your support :)

cyberblackhole commented 5 years ago

@victorhora Please find below the attached stacktrace of apache server

(gdb) run
Starting program: /usr/sbin/apache2 -X -d /etc/apache2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
warning: Temporarily disabling breakpoints for unloaded shared library "/opt/ModSecurity-apache/src/.libs/mod_security3.so"

Breakpoint 1, 0x00005555555c5ee0 in ap_process_request ()
(gdb) n
Single stepping until exit from function ap_process_request,
which has no line number information.

Breakpoint 2, create_tx_context (r=0x7fffe8c2a0a0) at src/mod_security3.c:135
135     msc_t *msr = NULL;
(gdb) n
136     msc_conf_t *z = NULL;
(gdb) n
137     char *unique_id = NULL;
(gdb) n
139     z = (msc_conf_t *)ap_get_module_config(r->per_dir_config,
(gdb) n
142     msr = (msc_t *)apr_pcalloc(r->pool, sizeof(msc_t));
(gdb) n
143     if (msr == NULL) {
(gdb) n
147     msr->r = r;
(gdb) n
148     unique_id = getenv("UNIQUE_ID");
(gdb) n
149     if (unique_id != NULL || strlen(unique_id) > 0) {
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x00007fffe8c45222 in create_tx_context (r=0x7fffe8c2a0a0) at src/mod_security3.c:149
149     if (unique_id != NULL || strlen(unique_id) > 0) {
(gdb) where
#0  0x00007fffe8c45222 in create_tx_context (r=0x7fffe8c2a0a0) at src/mod_security3.c:149
#1  0x00007fffe8c456b1 in hook_request_late (r=0x7fffe8c2a0a0) at src/mod_security3.c:371
#2  0x00005555555a3f00 in ap_run_fixups ()
#3  0x00005555555a661d in ap_process_request_internal ()
#4  0x00005555555c5d08 in ap_process_async_request ()
#5  0x00005555555c5ef0 in ap_process_request ()
#6  0x00005555555c213d in ?? ()
#7  0x00005555555b79f0 in ap_run_process_connection ()
#8  0x00007ffff4819831 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#9  0x00007ffff4819ae3 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#10 0x00007ffff481acad in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#11 0x000055555559119e in ap_run_mpm ()
#12 0x0000555555589a7b in main ()
(gdb) 
zimmerle commented 5 years ago

Hi @Goron1606,

Do you happens to have mod_unique_id loaded?

cyberblackhole commented 5 years ago

Hi @zimmerle ,

I confirm the module is enabled.

zimmerle commented 5 years ago

Fixed at: 61f2ff14f690da6c05f0e7053bb41b430ae8b732

Thanks @Goron1606

cyberblackhole commented 5 years ago

@zimmerle , @victorhora

Thanks for the support and quick fix.