Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault in ModSecurity 2.9 for Apache #3300

Open
vizovitin opened this issue Nov 13, 2024 · 22 comments
Open

Segmentation fault in ModSecurity 2.9 for Apache #3300

vizovitin opened this issue Nov 13, 2024 · 22 comments
Assignees
Labels
2.x Related to ModSecurity version 2.x

Comments

@vizovitin
Copy link

Describe the bug

Segmentation fault in ModSecurity 2.9.7 for Apache on very specific POST requests.

Logs and dumps

I cannot provide full core dump or request parameters due to potential inclusion of information from a production server. However, here's the stack trace:

(gdb) where
#0  0x00007f33133b507f in modsecurity_request_body_end_raw (msr=0x7f33030f7ba8, error_msg=0x7ffc207520e8)
    at apache2/msc_reqbody.c:572
#1  0x00007f33133aa748 in modsecurity_request_body_end_urlencoded (error_msg=0x7ffc207520e8, msr=0x7f33030f7ba8)
    at apache2/msc_reqbody.c:622
#2  modsecurity_request_body_end (error_msg=0x7ffc207520e8, msr=0x7f33030f7ba8)
    at apache2/msc_reqbody.c:730
#3  read_request_body (error_msg=0x7ffc207520e8, msr=<optimized out>)
    at apache2/apache2_io.c:350
#4  hook_request_late (r=0x7f33114960a0)
    at apache2/mod_security2.c:1026
#5  0x0000564a3d81b9a8 in ap_run_fixups ()
#6  0x0000564a3d82e553 in ap_process_request_internal ()
#7  0x0000564a3d84f8e5 in ap_process_async_request ()
#8  0x0000564a3d84fb33 in ap_process_request ()
#9  0x0000564a3d84fe77 in ?? ()
#10 0x0000564a3d83be88 in ap_run_process_connection ()
#11 0x00007f3313eed128 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#12 0x00007f3313eed4a1 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#13 0x00007f3313eedda7 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#14 0x0000564a3d8070e8 in ap_run_mpm ()
#15 0x0000564a3d806609 in main ()
(gdb) bt full
#0  0x00007f33133b507f in modsecurity_request_body_end_raw (msr=0x7f33030f7ba8, error_msg=0x7ffc207520e8)
    at apache2/msc_reqbody.c:572
        chunks = <optimized out>
        one_chunk = <optimized out>
        d = 0x564a3f7dc390 "\340s}\027\003\003\b@alswitch\",\"from\":\"meta\",\"options\":{\"H\":\"DISABLE\",\"S\":\"ENABLE\"},\"default\":\"H\",\"children\":[\"vibe_partial_units\"],\"hide_nodes\":[\"vibe_partial_units\"],\"value\":\"H\"},{\"label\":\"Select items for parti"...
        i = <optimized out>
        sofar = 0
#1  0x00007f33133aa748 in modsecurity_request_body_end_urlencoded (error_msg=0x7ffc207520e8, msr=0x7f33030f7ba8)
    at apache2/msc_reqbody.c:622
        invalid_count = 0
        invalid_count = <optimized out>
#2  modsecurity_request_body_end (error_msg=0x7ffc207520e8, msr=0x7f33030f7ba8)
    at apache2/msc_reqbody.c:730
        my_error_msg = 0x0
        metadata = <optimized out>
...
(gdb) print msr->msc_reqbody_length
$5 = 128070
(gdb) print msr->msc_reqbody_buffer
$4 = 0x564a3f7dc390 "\340s}\027\003\003\b@alswitch\",\"from\":\"meta\",\"options\":{\"H\":\"DISABLE\",\"S\":\"ENABLE\"},\"default\":\"H\",\"children\":[\"vibe_partial_units\"],\"hide_nodes\":[\"vibe_partial_units\"],\"value\":\"H\"},{\"label\":\"Select items for parti"...
(gdb) print i
$1 = <optimized out>
(gdb) print msr->msc_reqbody_chunks
$2 = (apr_array_header_t *) 0x0
(gdb) print sofar
$6 = 0
 543 static apr_status_t modsecurity_request_body_end_raw(modsec_rec *msr, char **error_msg) {
 ...
 567     /* Copy the data we keep in chunks into the new buffer. */
 568
 569     sofar = 0;
 570     d = msr->msc_reqbody_buffer;
 571     chunks = (msc_data_chunk **)msr->msc_reqbody_chunks->elts;
 572     for(i = 0; i < msr->msc_reqbody_chunks->nelts; i++) {
 573         if (sofar + chunks[i]->length <= msr->msc_reqbody_length) {
 574             memcpy(d, chunks[i]->data, chunks[i]->length);
 575             d += chunks[i]->length;
 576             sofar += chunks[i]->length;
 577         } else {
 578             *error_msg = apr_psprintf(msr->mp, "Internal error, request body buffer overflow.");
 579             return -1;
 580         }
 581     }

To Reproduce

N/A

Reproduced only on production server with very specific steps in a very customized WordPress.
ModSecurity for Apache, blocking, with Comodo (free) ruleset, in Fast mode, with 210710 and 222212 security rule IDs switched off.

Actual behavior

Request fails with 502 Bad Gateway served by nginx (reverse proxy before Apache). In the backend the following is logged:

==> /var/www/vhosts/system/example.net/logs/proxy_error_log <==
2024/11/13 08:59:28 [error] 3413043#0: *178721 upstream prematurely closed connection while reading response header from upstream, client: 123.45.123.45, server: example.net, request: "POST /wp-json/wplms/v2/saveDraft/?post HTTP/2.0", upstream: "https://127.0.0.1:7081/wp-json/wplms/v2/saveDraft/?post", host: "example.net", referrer: "https://example.net/"

==> /var/log/apache2/error.log <==
[Wed Nov 13 08:59:29.122617 2024] [core:notice] [pid 1141769] AH00051: child pid 3437845 exit signal Segmentation fault (11), possible coredump in /etc/apache2

Expected behavior

Apache children should not crash due to ModSecurity.

Server (please complete the following information):

  • ModSecurity version (and connector): 2.9.7
  • WebServer: apache2 2.4.52-1ubuntu4.12 (OS vendor packages)
  • OS (and distro): Ubuntu 22.04 x86_64 (likely ANY Linux)

Rule Set (please complete the following information):

  • Running any public or commercial rule set? Comodo (free)
  • What is the version number? 1.241

Additional context

Unfortunately, I cannot test the issue on 2.9.8 (as it is production server I don't own).

The following patch alleviates the issue, although it is most certainly "incorrect":

--- apache2/msc_reqbody.c.orig  2024-11-13 14:52:48.728063792 +0000
+++ apache2/msc_reqbody.c       2024-11-13 14:56:58.774675155 +0000
@@ -547,6 +547,11 @@

     *error_msg = NULL;

+    if (msr->msc_reqbody_chunks == NULL) {
+       *error_msg = apr_psprintf(msr->mp, "Internal error, request body chunks are NULL.");
+       return -1;
+    }
+
     /* Allocate a buffer large enough to hold the request body. */

     if (msr->msc_reqbody_length + 1 == 0) {
@vizovitin vizovitin added the 2.x Related to ModSecurity version 2.x label Nov 13, 2024
@airween
Copy link
Member

airween commented Nov 13, 2024

Hi @vizovitin,

thanks for provided info. We try to investigate the root cause soon, but probably the given patch would be enough at first.

@marcstern what do you think?

@vizovitin
Copy link
Author

vizovitin commented Nov 13, 2024

JFYI: There might be a few other places in the same file with similar issue, but since I'm not acquainted with the code and they don't seem to trigger any issues, I chose to keep the patch to a minimum (i.e. patch only one usage).

@marcstern
Copy link

I wonder if the cause is not that modsecurity_request_body_end_raw() is called with a body that's not chunked-encoded.
Why is it called inside modsecurity_request_body_end_urlencoded(), thus when body is url-encoded, and not when multipart-encoding is used?
Shouldn't we solve the problem at a higher level (and add assert() all over the place)?

@vizovitin: can you show us an example of problematic request?

@vizovitin
Copy link
Author

Unfortunately, I don't think I can. It is from a production server I don't control. The request itself is rather large and includes various authentication and other potentially private data.

If you need to check something specific I may still be able to check it.

@marcstern
Copy link

Can we have the request headers (you can remove any specific one, like cookies)?

@vizovitin
Copy link
Author

Sure. I've redacted some stuff (mostly marked as REDACTED). Also POST data is a lot larger. I've also changed the domain address.

curl 'https://abcde.example.net/wp-json/wplms/v2/create/13377?post' \
  -H 'accept: */*' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'content-type: text/plain;charset=UTF-8' \
  -H 'cookie: wordpress_test_cookie=WP%20Cookie%20check; wp_lang=en_US; other_cookies=REDACTED' \
  -H 'origin: https://abcde.example.net' \
  -H 'priority: u=1, i' \
  -H 'referer: https://abcde.example.net/' \
  -H 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="123", "Google Chrome";v="123"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/512.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/512.36' \
  --data-raw '{"course":"REDACTED","object":["REDACTED"],"token":"REDACTED","course_id":13377}'

@marcstern
Copy link

Can we have the headers "Content-Type" and "Transfer-Encoding" from the original request?

@vizovitin
Copy link
Author

Content-Type is listed above. There was no Transfer-Encoding, apparently.

@marcstern
Copy link

Sorry, I meant Content-Length.
As there was no Transfer-Encoding, I assume Content-Length was present.
Can you check with curl -v?
Also, what are the values of SecRequestBodyLimitAction, SecRequestBodyLimit, SecRequestBodyNoFilesLimit in your config?
Is the body bigger than SecRequestBodyLimit/SecRequestBodyNoFilesLimit?

@vizovitin
Copy link
Author

I just copied the request data from a browser developer console. So if the header is not there - I suppose it wasn't present.

There are no specified directives in the configuration:

# egrep -R '^\s*SecRequestBody' /etc/apache2/
/etc/apache2/plesk.conf.d/server.conf:  SecRequestBodyAccess Off
/etc/apache2/plesk.conf.d/server.conf.bak:      SecRequestBodyAccess Off
/etc/apache2/conf-available/modsec2.imunify.conf:  SecRequestBodyAccess On
/etc/apache2/conf-enabled/zz999_modsec2.imunify.conf:  SecRequestBodyAccess On

Can you check with curl -v?

content-length: 70888

You can also see above in the issue, which might be useful:

(gdb) print msr->msc_reqbody_length
$5 = 128070

@Orgoth
Copy link

Orgoth commented Nov 25, 2024

I can confirm the issue on a production server with thousands of requests per minute.

Unfortunately, because there are so many requests, I can't assign the segmentation faults to specific calls.

I had to disable modsecurity until the version is fixed.

The current Version is not usable for large production servers with thousands of requests.

[Mon Nov 25 09:37:01.995450 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1296571 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:02.999260 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1297516 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:03.002419 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1297532 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:04.006397 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1298803 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:04.008661 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1298804 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:05.011671 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1299902 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:05.014133 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1299909 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:06.017114 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1300280 exit signal Segmentation fault (11)
[Mon Nov 25 09:37:51.068692 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1300404 exit signal Segmentation fault (11)
[Mon Nov 25 09:38:05.092304 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1300306 exit signal Segmentation fault (11)
[Mon Nov 25 09:38:40.129827 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1303257 exit signal Segmentation fault (11)
[Mon Nov 25 09:38:51.143493 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1305905 exit signal Segmentation fault (11)
[Mon Nov 25 09:38:52.147886 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1303039 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:05.163310 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1306418 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:11.175904 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1306351 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:12.180060 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308069 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:16.187294 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308195 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:17.191438 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308257 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:18.195594 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308327 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:26.206429 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308383 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:35.218895 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1309729 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:38.225267 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1308442 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:39.229238 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1310375 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:42.234334 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1310515 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:42.237375 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1310955 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:56.253240 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1312449 exit signal Segmentation fault (11)
[Mon Nov 25 09:39:58.258255 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1312453 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:04.267694 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1312997 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:06.272934 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1313743 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:09.279215 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1313880 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:13.286491 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1312846 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:21.300287 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1314087 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:23.305024 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1314517 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:24.309225 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1315174 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:31.318245 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1315581 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:36.326550 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1316327 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:37.330654 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1317363 exit signal Segmentation fault (11)
[Mon Nov 25 09:40:40.336886 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1317421 exit signal Segmentation fault (11)
[Mon Nov 25 09:41:11.382405 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1317688 exit signal Segmentation fault (11)
[Mon Nov 25 09:41:21.396147 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1319806 exit signal Segmentation fault (11)
[Mon Nov 25 09:41:35.412682 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1315020 exit signal Segmentation fault (11)
[Mon Nov 25 09:41:54.433534 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1321364 exit signal Segmentation fault (11)
[Mon Nov 25 09:41:56.438380 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1320054 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:03.448785 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1322453 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:09.457454 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1322619 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:10.461227 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1323617 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:28.482029 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1324587 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:33.490618 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1324459 exit signal Segmentation fault (11)
[Mon Nov 25 09:42:55.518387 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1326537 exit signal Segmentation fault (11)
[Mon Nov 25 09:43:13.540013 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1326441 exit signal Segmentation fault (11)
[Mon Nov 25 09:43:41.571937 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1329180 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:03.597222 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1330000 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:16.612640 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1328355 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:17.615771 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1331776 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:18.622308 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1334293 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:19.627812 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1334748 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:20.632505 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1335707 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:50.663430 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1336984 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:56.672892 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1336454 exit signal Segmentation fault (11)
[Mon Nov 25 09:44:57.677060 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1340865 exit signal Segmentation fault (11)
[Mon Nov 25 09:45:04.685608 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1341668 exit signal Segmentation fault (11)
[Mon Nov 25 09:45:13.697578 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1341430 exit signal Segmentation fault (11)
[Mon Nov 25 09:45:17.703361 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1342831 exit signal Segmentation fault (11)
[Mon Nov 25 09:45:29.717492 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1344679 exit signal Segmentation fault (11)
[Mon Nov 25 09:45:43.738665 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1343473 exit signal Segmentation fault (11)
[Mon Nov 25 09:46:34.793013 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1346324 exit signal Segmentation fault (11)
[Mon Nov 25 09:46:51.814064 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1345210 exit signal Segmentation fault (11)
[Mon Nov 25 09:47:03.829621 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1351357 exit signal Segmentation fault (11)
[Mon Nov 25 09:47:42.882122 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1352990 exit signal Segmentation fault (11)
[Mon Nov 25 09:47:59.903261 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1354638 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:00.907544 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1352860 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:03.912798 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1356073 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:04.916249 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1355932 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:04.919250 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1357329 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:05.922442 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1357478 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:07.927825 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1357490 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:08.931850 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1357742 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:12.938273 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1358362 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:21.950400 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1359074 exit signal Segmentation fault (11)
[Mon Nov 25 09:48:56.981754 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1360246 exit signal Segmentation fault (11)
[Mon Nov 25 09:49:41.028920 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1360882 exit signal Segmentation fault (11)
[Mon Nov 25 09:50:03.055555 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1369424 exit signal Segmentation fault (11)
[Mon Nov 25 09:50:25.080647 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1371419 exit signal Segmentation fault (11)
[Mon Nov 25 09:50:31.089015 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1366997 exit signal Segmentation fault (11)
[Mon Nov 25 09:50:50.112240 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1375304 exit signal Segmentation fault (11)
[Mon Nov 25 09:51:19.145072 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1377457 exit signal Segmentation fault (11)
[Mon Nov 25 09:51:28.157422 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1381316 exit signal Segmentation fault (11)
[Mon Nov 25 09:51:39.172513 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1374861 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:01.197218 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1381645 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:03.201218 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1385765 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:07.207868 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1383396 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:12.240182 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387656 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:12.243288 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387682 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:13.247274 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387768 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:13.250342 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387795 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:19.259548 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387882 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:19.261961 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1387909 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:21.265294 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1389066 exit signal Segmentation fault (11)
[Mon Nov 25 09:52:52.299803 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1389077 exit signal Segmentation fault (11)
[Mon Nov 25 09:53:07.326457 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1394107 exit signal Segmentation fault (11)
[Mon Nov 25 09:53:43.366800 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1394742 exit signal Segmentation fault (11)
[Mon Nov 25 09:53:57.386452 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1397929 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:06.398812 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1398430 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:08.402418 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1390472 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:09.405228 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1398866 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:13.411467 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1400464 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:16.418164 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1400591 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:18.431961 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1401142 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:29.446633 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1401238 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:29.449639 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1401321 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:37.459730 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1402327 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:42.467522 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1402300 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:42.470295 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1403472 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:43.473227 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1404892 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:47.479576 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1404918 exit signal Segmentation fault (11)
[Mon Nov 25 09:54:51.486906 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1405350 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:11.508903 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1406464 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:21.522048 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1406978 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:27.530547 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1411138 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:29.535287 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1410132 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:42.551274 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1412054 exit signal Segmentation fault (11)
[Mon Nov 25 09:55:49.561052 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1413581 exit signal Segmentation fault (11)
[Mon Nov 25 09:56:34.611847 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1415321 exit signal Segmentation fault (11)
[Mon Nov 25 09:56:54.636302 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1412377 exit signal Segmentation fault (11)
[Mon Nov 25 09:56:56.641215 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1421011 exit signal Segmentation fault (11)
[Mon Nov 25 09:56:57.644574 2024] [core:notice] [pid 552344:tid 552344] AH00052: child pid 1423207 exit signal Segmentation fault (11)

@dune73
Copy link
Member

dune73 commented Nov 26, 2024

I feel your pain @Orgoth, but ModSec 2.9 is definitely suitable for production.

Which does not mean it's free from bugs. What you are encountering is tough. Have not seen such a bad behavior in years.

On Apache, you have mod_forensic that writes a request to disk the moment it starts - and when it finishes. When you get a segfault, the culprit is in the log, in the delta to be precise.

Maybe you can enable that together with ModSec in the off hours for a couple of minutes. Or if you have a loadbalancer in front of multiple instances, you direct but a small portion of the traffic to a server with mod_forensic + ModSec so the impact is lower.

@Orgoth
Copy link

Orgoth commented Nov 26, 2024

I feel your pain @Orgoth, but ModSec 2.9 is definitely suitable for production.

Which does not mean it's free from bugs. What you are encountering is tough. Have not seen such a bad behavior in years.

On Apache, you have mod_forensic that writes a request to disk the moment it starts - and when it finishes. When you get a segfault, the culprit is in the log, in the delta to be precise.

Maybe you can enable that together with ModSec in the off hours for a couple of minutes. Or if you have a loadbalancer in front of multiple instances, you direct but a small portion of the traffic to a server with mod_forensic + ModSec so the impact is lower.

Thank you for the hint with mod_forensic, I will test it when the load is not this high.
Sadly, there is no loadbalancer to redirect the traffic.

@dune73
Copy link
Member

dune73 commented Nov 26, 2024

Very good.

Unfortunately, I can not help you fix the code - @marcstern is in the best position to do that. But I can help you dig down on this. Which will ideally bring up a minimal config and a minimal curl call to trigger the segfault. Which will apparently support a fast solution for your problem.

So mod_forensic should help you isolate the request. The next step is putting it under the microscope.

Identify the request via URI, IP address or some other pattern.

Then create a rule that disables ModSec for everybody else (ctl rule engine off). Ideally very few SegFaults going forward now and you can run this in prod under normal load.

Then you remove all the rules outside the ctl statement rule and hope there is no more segfault. Now you add a rule that triggers the full audit log for the request in question.

You now have a full dump of the request. Reproduce it with curl and try to trigger the segfault (reenable ModSec and the rules for your client apparently). If that works, try to reproduce in the lab.

If that works, gradually reduce the rules and the config until you have a minimal config and the individual rule that triggers the problem.

I am not ruling out a situation where it's a combination of rules and requests interfering with one another. But I suggest you try out the recipe above. If this does not work, we need to brainstorm based on your findings.

@marcstern
Copy link

content-length: 70888
(gdb) print msr->msc_reqbody_length
$5 = 128070

This is strange no?
I expect both values to be equal (real body length = content-length

@dune73
Copy link
Member

dune73 commented Nov 27, 2024

Yes. Strange but while I have seen application servers segfault on this, ModSec is usually coping. Or am I wrong?

@marcstern
Copy link

Can you give at least the exception from the core dump?
We fixed a lot of pointers problems in 2.9.8. Can you try it?

@vizovitin
Copy link
Author

This is strange no?

These values are technically from 2 different requests (although I imagine they should be pretty close) - one from initial gdb session over a core dump triggered by browser request, another one from a curl -v manual one, so I don't think the difference is that suspicious.

We fixed a lot of pointers problems in 2.9.8. Can you try it?

If you're asking me, no, I cannot. This was a production server and I don't have access to it anymore.

@Orgoth
Copy link

Orgoth commented Nov 27, 2024

In my Case, the segmentation faults did not happen again since the restart this morning with forensic and security2 enabled.
I will monitor it, if it happens again.

I have another 7 servers on which ModSecurity will also be used in the near future.
If there are any problems, it will be easier for me to trace them, as they are not so extremely busy.

Thanks again for the tip with log_forensic and how I can best proceed.

Have a nice week.

@dune73
Copy link
Member

dune73 commented Nov 27, 2024

Ah no, a Heisenbug!

But good luck, keeping my fingers crossed for you!

@marcstern
Copy link

@vizovitin / @Orgoth, can you give the exact exception from the core dump?

@Orgoth
Copy link

Orgoth commented Nov 27, 2024

@vizovitin / @Orgoth, can you give the exact exception from the core dump?

It is a large production server, and core dumps are not enabled by default.
So unfortunately I have to disappoint you, I cannot provide a CoreDump.
Also because there have been no new segmentation faults so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to ModSecurity version 2.x
Projects
None yet
Development

No branches or pull requests

5 participants