openresty / openresty/lua-nginx-module

ngx_log use a free request pointer

Open
#2,133 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

I don't any idea about this issues, maybe the Heap-use-after-free is safe
I use ngx.log when cdata's __gc function are called


nginx version: openresty/1.21.4.1 (no pool)
built by clang 14.0.0 (clang-1400.0.29.202)
built with OpenSSL 3.0.7 1 Nov 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2 -DAPISIX_BASE_VER=0.0.0 -g -fsanitize=address -O0 -fno-inline-functions -fno-omit-frame-pointer -I/opt/homebrew/opt/pcre/include -I/opt/homebrew/opt/openssl/include -g' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/wasmtime-c-api/lib -g -fsanitize=address -O0 -fno-inline-functions -fno-omit-frame-pointer -L/opt/homebrew/opt/pcre/lib -L/opt/homebrew/opt/openssl/lib -g' --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../mod_dubbo --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../ngx_multi_upstream_module --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../apisix-nginx-module --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../apisix-nginx-module/src/stream --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../apisix-nginx-module/src/meta --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../wasm-nginx-module --add-module=/Users/apple/apisix-build-tools/download/openresty-1.21.4.1/../lua-var-nginx-module --with-poll_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module


Heap-use-after-free on address 0x000105018188 at pc 0x00010107cb88 bp 0x00016f2fd4c0 sp 0x00016f2fd4b8
READ of size 8 at 0x000105018188 thread T0
at 0x10107cb84 ngx_http_lua_ngx_log (ngx_http_lua_log.c:44)
at 0x101e3ddf8 lj_BC_FUNCC
at 0x101e4387c gc_call_finalizer (lj_gc.c:520)
at 0x101e45f5c gc_onestep (lj_gc.c:705)
at 0x10110a0d8 ngx_http_lua_access_by_chunk (ngx_http_lua_accessby.c:248)
at 0x101109cc4 ngx_http_lua_access_handler_inline (ngx_http_lua_accessby.c:185)
at 0x101108c94 ngx_http_lua_access_handler (ngx_http_lua_accessby.c:158)
at 0x100c778e8 ngx_http_core_access_phase (ngx_http_core_module.c:1118)
at 0x100c7306c ngx_http_core_run_phases (ngx_http_core_module.c:888)
at 0x100c72e18 ngx_http_handler (ngx_http_core_module.c:871)
at 0x100cb51f8 ngx_http_process_request (ngx_http_request.c:2120)
at 0x100cbddb0 ngx_http_process_request_headers (ngx_http_request.c:1498)
at 0x100cbb270 ngx_http_process_request_line (ngx_http_request.c:1165)
at 0x100ca6754 ngx_http_wait_request_handler (ngx_http_request.c:503)
at 0x100c15d98 ngx_kqueue_process_events (ngx_kqueue_module.c:669)
at 0x100bc8c54 ngx_process_events_and_timers (ngx_event.c:257)
at 0x100c0b0c8 ngx_single_process_cycle (ngx_process_cycle.c:329)
at 0x100aff758 main (nginx.c:383)
at 0x196f8fe4c
Freed by thread T0 here:
at 0x1035e2de4 wrap_free
at 0x100b0ba30 ngx_destroy_pool (ngx_palloc.c:76)
at 0x1011635bc ngx_http_lua_init_worker (ngx_http_lua_initworkerby.c:299)
at 0x100c0acc8 ngx_single_process_cycle (ngx_process_cycle.c:305)
at 0x100aff758 main (nginx.c:383)
at 0x196f8fe4c
Previously allocated by thread T0 here:
at 0x1035e2ca8 wrap_malloc
at 0x100beaa0c ngx_alloc (ngx_alloc.c:22)
at 0x100b0be40 ngx_malloc (ngx_palloc.c:137)
at 0x100b0bdcc ngx_palloc (ngx_palloc.c:120)
at 0x100b0c5fc ngx_pcalloc (ngx_palloc.c:215)
at 0x1010fa74c ngx_http_lua_create_fake_request (ngx_http_lua_util.c:4075)
at 0x101162b38 ngx_http_lua_init_worker (ngx_http_lua_initworkerby.c:267)
at 0x100c0acc8 ngx_single_process_cycle (ngx_process_cycle.c:305)
at 0x100aff758 main (nginx.c:383)
at 0x196f8fe4c

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ngx_http_lua_ngx_log in ngx_http_lua_log.c:44 and trace the fake request allocation in ngx_http_lua_util.c:4075 through ngx_http_lua_init_worker in ngx_http_lua_initworkerby.c:267-299. Reproduce the cdata __gc call to ngx.log with the shown AddressSanitizer configuration; done means the reported heap-use-after-free no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.