[GH-ISSUE #68] 日志轮转时出错 #46

Closed
opened 2026-03-04 12:18:21 +03:00 by kerem · 12 comments
Owner

Originally created by @purplegrape on GitHub (Oct 9, 2021).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/68

nginx 版本 1.20.1
ngx_waf 版本 6.1.5 (6.1.4也存在类似问题)

通过dmesg -T 命令发现,ngx_http_waf 模块有如下类似报错

[Sat Oct 9 03:20:15 2021] nginx[3355]: segfault at 18 ip 00007fa9f6493659 sp 00007ffe2a3c0600 error 4 in ngx_http_waf_module.so[7fa9f6453000+6b000]

开debug之后,error.log部分日志如下

2021/10/09 03:22:01 [debug] 3355#3355: *345447 ngx_waf_debug: The module context has been obtained.
2021/10/09 03:22:01 [debug] 3355#3355: *345447 ngx_waf_debug: The configuration of the module has been obtained.
2021/10/09 03:22:01 [notice] 25988#25988: signal 17 (SIGCHLD) received from 3355
2021/10/09 03:22:01 [alert] 25988#25988: worker process 3355 exited on signal 11
2021/10/09 03:22:01 [notice] 25988#25988: start worker process 4887
2021/10/09 03:22:01 [notice] 25988#25988: signal 29 (SIGIO) received
2021/10/09 03:22:01 [notice] 4887#4887: sched_setaffinity(): using cpu #2
2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The scheduler has been started.
2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The module context has been obtained.
2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The configuration of the module has been obtained.

此次问题大概发生在logrotate 时,其它时间也偶有触发,手动 logrotate -f /etc/logrotate.d/nginx 无法重现,请求大神分析。

Originally created by @purplegrape on GitHub (Oct 9, 2021). Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/68 nginx 版本 1.20.1 ngx_waf 版本 6.1.5 (6.1.4也存在类似问题) 通过dmesg -T 命令发现,ngx_http_waf 模块有如下类似报错 [Sat Oct 9 03:20:15 2021] nginx[3355]: segfault at 18 ip 00007fa9f6493659 sp 00007ffe2a3c0600 error 4 in ngx_http_waf_module.so[7fa9f6453000+6b000] 开debug之后,error.log部分日志如下 2021/10/09 03:22:01 [debug] 3355#3355: *345447 ngx_waf_debug: The module context has been obtained. 2021/10/09 03:22:01 [debug] 3355#3355: *345447 ngx_waf_debug: The configuration of the module has been obtained. 2021/10/09 03:22:01 [notice] 25988#25988: signal 17 (SIGCHLD) received from 3355 2021/10/09 03:22:01 [alert] 25988#25988: worker process 3355 exited on signal 11 2021/10/09 03:22:01 [notice] 25988#25988: start worker process 4887 2021/10/09 03:22:01 [notice] 25988#25988: signal 29 (SIGIO) received 2021/10/09 03:22:01 [notice] 4887#4887: sched_setaffinity(): using cpu #2 2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The scheduler has been started. 2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The module context has been obtained. 2021/10/09 03:22:01 [debug] 4887#4887: *346468 ngx_waf_debug: The configuration of the module has been obtained. 此次问题大概发生在logrotate 时,其它时间也偶有触发,手动 logrotate -f /etc/logrotate.d/nginx 无法重现,请求大神分析。
kerem closed this issue 2026-03-04 12:18:21 +03:00
Author
Owner

@ADD-SP commented on GitHub (Oct 9, 2021):

检查一下 nginx 日志目录下是否有名为 core 的文件。

<!-- gh-comment-id:939232932 --> @ADD-SP commented on GitHub (Oct 9, 2021): 检查一下 nginx 日志目录下是否有名为 `core` 的文件。
Author
Owner

@purplegrape commented on GitHub (Oct 9, 2021):

没有

<!-- gh-comment-id:939260264 --> @purplegrape commented on GitHub (Oct 9, 2021): 没有
Author
Owner

@ADD-SP commented on GitHub (Oct 9, 2021):

先完成链接内所示的前五步,然后等待错误出现,错误出现后按链接内所示的第七步开始完成后续的所有步骤。

https://github.com/ADD-SP/ngx_waf/issues/18#issuecomment-760785975

<!-- gh-comment-id:939261064 --> @ADD-SP commented on GitHub (Oct 9, 2021): 先完成链接内所示的前五步,然后等待错误出现,错误出现后按链接内所示的第七步开始完成后续的所有步骤。 https://github.com/ADD-SP/ngx_waf/issues/18#issuecomment-760785975
Author
Owner

@purplegrape commented on GitHub (Oct 9, 2021):

补充一点,nginx和动态模块的二进制文件均是在centos7+gcc 4.8 下编译,实际运行环境为amaozn linux 2
在闲置服务器上运行正常,生产环境出现worker异常退出

<!-- gh-comment-id:939266588 --> @purplegrape commented on GitHub (Oct 9, 2021): 补充一点,nginx和动态模块的二进制文件均是在centos7+gcc 4.8 下编译,实际运行环境为amaozn linux 2 在闲置服务器上运行正常,生产环境出现worker异常退出
Author
Owner

@purplegrape commented on GitHub (Oct 12, 2021):

由于是生产环境,没敢大动作调试,经过摸索,将waf_mode 从STD 改为 STATIC ,worker异常退出已消失。
另外一个开发测试环境,流量小,异常一直未被触发,问题症结推测应该是某个动态逻辑或规则。

<!-- gh-comment-id:940749062 --> @purplegrape commented on GitHub (Oct 12, 2021): 由于是生产环境,没敢大动作调试,经过摸索,将waf_mode 从STD 改为 STATIC ,worker异常退出已消失。 另外一个开发测试环境,流量小,异常一直未被触发,问题症结推测应该是某个动态逻辑或规则。
Author
Owner

@ADD-SP commented on GitHub (Oct 12, 2021):

尝试设置 waf_mode STD !POST;,有可能是 v6.1.5 版本存在的一个读取 POST 请求的 Bug 导致的。如果按此设置后问题消失可以尝试升级到 v6.1.6

尝试设置 waf_mode STD !LIB-INJECTION-SQLI;,有可能是依赖库 libinjection 导致的。如果按此设置后问题消失则可以保持这个设置,即 !LIB-INJECTION-SQLI。如果需要检测 SQL 注入建议升级到最新的 Current 版本,此版本集成了 ModSecurity,可以使用 ModSecurity CRS

虽然是废话,但是鉴于生产环境十分重要,升级后最好特别关注服务状态。

<!-- gh-comment-id:940759058 --> @ADD-SP commented on GitHub (Oct 12, 2021): 尝试设置 `waf_mode STD !POST;`,有可能是 v6.1.5 版本存在的一个读取 POST 请求的 Bug 导致的。如果按此设置后问题消失可以尝试升级到 [v6.1.6](https://github.com/ADD-SP/ngx_waf/releases/tag/v6.1.6)。 尝试设置 `waf_mode STD !LIB-INJECTION-SQLI;`,有可能是依赖库 [libinjection](https://github.com/libinjection/libinjection) 导致的。如果按此设置后问题消失则可以保持这个设置,即 `!LIB-INJECTION-SQLI`。如果需要检测 SQL 注入建议升级到最新的 Current 版本,此版本集成了 ModSecurity,可以使用 [ModSecurity CRS](https://owasp.org/www-project-modsecurity-core-rule-set/)。 虽然是废话,但是鉴于生产环境十分重要,升级后最好特别关注服务状态。
Author
Owner

@purplegrape commented on GitHub (Oct 19, 2021):

与日志轮转无关,但暂时难以定位问题根源,上文临时方法确认有效,故关闭issue 。

<!-- gh-comment-id:946403590 --> @purplegrape commented on GitHub (Oct 19, 2021): 与日志轮转无关,但暂时难以定位问题根源,上文临时方法确认有效,故关闭issue 。
Author
Owner

@ADD-SP commented on GitHub (Oct 19, 2021):

是哪个临时方法有效?或许能借此推测根源。是否更新了模块版本?

<!-- gh-comment-id:946620106 --> @ADD-SP commented on GitHub (Oct 19, 2021): 是哪个临时方法有效?或许能借此推测根源。是否更新了模块版本?
Author
Owner

@purplegrape commented on GitHub (Oct 20, 2021):

waf_mode STATIC;
waf_mode STD !LIB-INJECTION-SQLI;
以上临时方法在生产环境实测有效,可规避worker异常退出
PS:模块更新到了6.1.6

<!-- gh-comment-id:947228998 --> @purplegrape commented on GitHub (Oct 20, 2021): waf_mode STATIC; waf_mode STD !LIB-INJECTION-SQLI; 以上临时方法在生产环境实测有效,可规避worker异常退出 PS:模块更新到了6.1.6
Author
Owner

@ADD-SP commented on GitHub (Oct 20, 2021):

编译模块的时候是否添加了 gcc-fstack-protector-strong 参数?

<!-- gh-comment-id:947297410 --> @ADD-SP commented on GitHub (Oct 20, 2021): 编译模块的时候是否添加了 `gcc` 的 `-fstack-protector-strong` 参数?
Author
Owner

@purplegrape commented on GitHub (Oct 20, 2021):

使用rpmbuild 自动化编译,只是按照文档指示加了参数-std=gnu99
--with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -std=gnu99

<!-- gh-comment-id:947344059 --> @purplegrape commented on GitHub (Oct 20, 2021): 使用rpmbuild 自动化编译,只是按照文档指示加了参数-std=gnu99 --with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -std=gnu99
Author
Owner

@ADD-SP commented on GitHub (Oct 26, 2021):

错误一时难以定位,暂时关闭,必要时再打开。

<!-- gh-comment-id:951549872 --> @ADD-SP commented on GitHub (Oct 26, 2021): 错误一时难以定位,暂时关闭,必要时再打开。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ngx_waf#46
No description provided.