[libdl] dlmodule: 32-bit section-size sum overflow in dlmodule_load_relocated_object() -> heap overflow (follow-up to #11898)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
- 領域
- embedded-iot, security
調査の方向性
Start with components/libc/posix/libdl/dlelf.c, especially dlmodule_load_relocated_object() around the section-size accumulation and copy loop; then read dlmodule.c around dlmodule_load() to trace how the file buffer is sized. Use the three malformed ELF inputs described in the issue to check the overflow and bounds cases, and verify benign ARM ET_REL and ET_DYN modules still load. Done means malformed inputs are rejected without sanitizer errors.
索引モデルが issue の本文から書いたものです。
説明
Summary
dlmodule_load_relocated_object() sizes the module image by adding the sh_size of every loadable
section into an rt_ubase_t (32 bits on ARM/RISC-V32/i386) without an overflow check, allocates that
many bytes, and then copies or zero-fills every section with its full sh_size. A relocatable module
whose section sizes sum past 2^32 gets a small allocation and the loader writes far past it. Section
offsets/sizes are also never compared with the file length, so rt_memcpy() reads past the file buffer.
The writes happen inside dlmodule_load(), before the relocation-target checks of PR #12016 run and
before any module code is executed.
Tested commit: master fbdb9711db8be41fe84f92a2f983c048c11f9a47 (2026-12-01). The loader files are
byte-identical to 332ac026 and contain PR #12016 (df2e0bffec).
Root cause (components/libc/posix/libdl/dlelf.c, master)
437 for (index = 0; index < elf_module->e_shnum; index ++)
440 if (IS_PROG(shdr[index]) && IS_AX(shdr[index])) module_size += shdr[index].sh_size; /* text /
446 if (IS_PROG(shdr[index]) && IS_ALLOC(shdr[index])) module_size += shdr[index].sh_size; / rodata /
451 if (IS_PROG(shdr[index]) && IS_AW(shdr[index])) module_size += shdr[index].sh_size; / data /
456 if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index])) module_size += shdr[index].sh_size; / bss /
483 module_size += RT_ALIGN(dlmodule_common_block(...), sizeof(rt_ubase_t)); / also unchecked /
491 module_size += common_align - 1; / also unchecked /
500 module->mem_space = rt_malloc(module_size); / wrapped, small */
518 rt_memset(ptr, 0, module_size);
527 rt_memcpy(ptr, (rt_uint8_t )elf_module + shdr[index].sh_offset, shdr[index].sh_size); / text /
538 rt_memcpy(ptr, ... , shdr[index].sh_size); / rodata /
549 rt_memcpy(ptr, ... , shdr[index].sh_size); / data /
560 rt_memset(ptr, 0, shdr[index].sh_size); / bss */
module_ptr is the whole file read into a heap buffer of exactly the file length (dlmodule.c:513-516),
and sh_offset + sh_size is never checked against that length.
Affected versions
The unchecked sum has existed since the module loader was added: 5211e7ff8f "add module feature"
(2010-04-11, src/module.c, first tag v1.2.0), moved to components/libc/libdl/dlelf.c by efe452313
(2018-08-30, v3.1.0) and later to components/libc/posix/libdl/. Present in v5.3.0 (99428a1e7f,
2026-09-10) and master fbdb971. PR #12016 does not cover it: its checks run after the copy loop.
Reproduction
Harness: the unmodified dlelf.c dlmodule.c dlsym.c dlopen.c dlclose.c arch/arm.c compiled for ARM32
with arm-linux-gnueabihf-gcc -fsanitize=address,undefined; a shim maps rt_malloc/rt_free/rt_memcpy/
rt_memset/... and the module symbol table to host functions; main() calls
dlopen(argv[1]) -> dlsym("main") -> dlclose(). Run under qemu-arm (user mode). Inputs are made from a
benign ARM relocatable module (m1_arm.o) by changing one field:
bss_memset_write.o a .rodata section with sh_size = 0xffffffff -> 32-bit sum wraps to 203 bytes
negative_size_memset.o .bss sh_size = 0xfffffffe
memcpy_huge_sh_size.o a .data section with sh_size = 0x1000000 (16 MiB, larger than the 1.5 KiB file)
=== bss_memset_write.o
ERROR: AddressSanitizer: heap-buffer-overflow on address 0x43503f8b
WRITE of size 128 at 0x43503f8b thread T0
#1 rt_memset harness/shim.c:25
#2 dlmodule_load_relocated_object rtt/components/libc/posix/libdl/dlelf.c:560
#3 dlmodule_load rtt/components/libc/posix/libdl/dlmodule.c:556
#4 rt_dlopen rtt/components/libc/posix/libdl/dlopen.c:74
0x43503f8b is located 0 bytes after 203-byte region [0x43503ec0,0x43503f8b)
#2 dlmodule_load_relocated_object rtt/components/libc/posix/libdl/dlelf.c:500
=== negative_size_memset.o
ERROR: AddressSanitizer: negative-size-param: (size=-2)
#2 dlmodule_load_relocated_object rtt/components/libc/posix/libdl/dlelf.c:560
=== memcpy_huge_sh_size.o
ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x4350186c,0x4450186c) and [0x43303720, 0x44303720) overlap
#2 dlmodule_load_relocated_object rtt/components/libc/posix/libdl/dlelf.c:549
0x43303bf0 is located 0 bytes after 1392-byte region [0x43303680,0x43303bf0) <- the file buffer (dlmodule.c:513)
No loader error message is printed before the crash. 8 benign modules (ARM ET_REL and ET_DYN) load
without any sanitizer report.
Impact
- Kernel heap overflow of attacker-chosen length with zero bytes or attacker-controlled file contents
at module-load time, in the context of the thread calling dlopen() / dlmodule_exec() (msh executes
*.mo files found on the filesystem, components/finsh/msh.c:312). This may allow arbitrary code
execution in the kernel. - Out-of-bounds read of the file buffer (sh_offset + sh_size unchecked), up to 4 GiB.
- The corruption happens during dlopen() of a malformed or truncated module, before its constructors
run and before any check of the loaded image can take place; it is in the input validation that
#12016 started to add (its review asked for sh_offset/sh_size validation against the file size as a
follow-up).
Suggested fix (3 files, +89/-16; I can open a PR)
- dlmodule_size_add(): overflow-checked accumulation of every term of module_size (section sizes,
counted once per copy exactly as the copy loop does, the common block and its alignment padding). - dlmodule_in_image(): [sh_offset, sh_offset + sh_size) of every section that is copied, and of symbol
tables, must lie inside the file; same for the section/program header tables and for PT_LOAD
[p_offset, p_offset + p_filesz) in dlmodule_load_shared_object(). - dlmodule_load() / dlmodule_load_custom() pass the file length to the two loaders (0 = unknown for a
custom ops->load() that does not report a length; the size-overflow checks still apply there).
With this change all three inputs are rejected ("Module: section 6 out of image", "Module: section 5
size overflow", "Module: section 3 out of image") with no sanitizer report, and all benign modules
load. On a 3,000-file sample of a 42,460-file mutation corpus, 63 files that crashed no longer crash,
no file gains a sanitizer report, and 11 files that were accepted are now rejected (all have a
segment, section or header table outside the file, or a common-block alignment that overflows).
Not addressed (read-only): unterminated string tables reaching strcmp/strlen, symbol/relocation table
reads at dlelf.c:250/337/469/689.
Classification: CWE-190 leading to CWE-122/CWE-787; CWE-125 for the file-buffer read.
Suggested CVSS 3.1: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H = 7.1 (a user or operator loads a
crafted module file).
Reporter: Jeongwon Jang (SWSEC Lab, Chungnam National University), [email protected]
Discovery and analysis: this issue was found with automated tools: a structure-aware ELF fuzzer
(Exefuzzer, an AFL++ custom mutator), AFL++, and LLM-assisted source review and target-specific
mutation scripts. The results above were reproduced by re-running the attached reproducers; the
analysis and this write-up were prepared with the assistance of these tools, and I reviewed them.
Disclosure: I have not shared this issue with anyone else. Please let me know your preferred
disclosure timeline; I am happy to test a fix.
- 主要言語
- C
- スター
- 12.4k
- フォーク
- 5.5k
- 平均マージ
- 3日 13時間
- マージ済み PR(30日)
- 73
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
RT-Thread/rt-thread のほかの issue
-
[Bug] Out-of-bounds stack read and callback signature mismatch in TM4C123 ADC driver (drv_adc.c)オープンbug Component component: drivers
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
RT-Thread/rt-thread#12118 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
BSP BSP: NXP bug Component component: drivers
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
RT-Thread/rt-thread#12117 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
BSP BSP: GD32 bug Component component: drivers
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
RT-Thread/rt-thread#12115 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Arch: ARM/AArch64 BSP BSP: GD32 bug Component component: drivers
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
RT-Thread/rt-thread#12109 · コメント 5 件 ·
メンテナーはふだん 2 日以内に返信
-
action bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
RT-Thread/rt-thread#12106 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
RT-Thread/rt-thread の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
signalwire/freeswitch#3329 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Status: Opened
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
espressif/esp-protocols#1224 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
bot-triaged module: bfloat16 module: cuda module: half module: numerical-stability triage review
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信