[security] scene_manager/loader_xmt.c:750 Use-After-Free in xmt_find_node

Open
#4,078 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
40/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
security

Research direction

Reproduce with the linked .xmt sample under the ASan build, then read xmt_find_node at scene_manager/loader_xmt.c:750 together with its caller xmt_parse_route (:1221) and xmt_parse_element (:1739). Trace how nodes are registered and released during parsing, starting from gf_node_unregister in scenegraph/base_scenegraph.c:827, to see why a route can still resolve a node that was already freed. Done means the sample parses without an ASan heap-use-after-free report and node ownership during route resolution is clearly defined.

Written by the indexing model from the issue text.

Description

scene_manager/loader_xmt.c:750 Use-After-Free in xmt_find_node

Description:

While parsing a crafted XMT scene, xmt_parse_element (scene_manager/loader_xmt.c:1739) calls xmt_parse_route (scene_manager/loader_xmt.c:1221), which resolves a route endpoint through xmt_find_node (scene_manager/loader_xmt.c:750). A node referenced by the route has already been released earlier during parsing, so xmt_find_node reads memory that was freed. AddressSanitizer reports a heap-use-after-free at scene_manager/loader_xmt.c:750. The vanilla build is nondeterministic (the freed memory is sometimes still readable), which is expected for a use-after-free; the ASan report is the authoritative evidence.

To Reproduce

Steps to reproduce the behavior:

./MP4Box -add ./231_xmt_find_node_scene_manager_loader_xmt_c_750.xmt -new /dev/null
Output:

asan-build:

==403906==ERROR: AddressSanitizer: heap-use-after-free on address 0x7c47fefe7400 at pc 0x7fe8012231ef bp 0x7ffccde04b90 sp 0x7ffccde04b88
READ of size 8 at 0x7c47fefe7400 thread T0
    #0 0x7fe8012231ee in xmt_find_node scene_manager/loader_xmt.c:750
    #1 0x7fe80122358e in xmt_parse_route scene_manager/loader_xmt.c:1221
    #2 0x7fe80122bcfd in xmt_parse_element scene_manager/loader_xmt.c:1739
    #3 0x7fe801232ded in xmt_node_start scene_manager/loader_xmt.c:2984
    #4 0x7fe80099e4dc in xml_sax_node_start utils/xml_parser.c:308
    #5 0x7fe8009a32c3 in xml_sax_parse_attribute utils/xml_parser.c:357
    #6 0x7fe8009a32c3 in xml_sax_parse utils/xml_parser.c:940
    #7 0x7fe80099ef80 in gf_xml_sax_parse_intern utils/xml_parser.c:1110
    #8 0x7fe8009a40b7 in gf_xml_sax_parse utils/xml_parser.c:1138
    #9 0x7fe8009a4462 in xml_sax_read_file utils/xml_parser.c:1225
    #10 0x7fe8009a4ffb in gf_xml_sax_parse_file utils/xml_parser.c:1354
    #11 0x7fe801221644 in load_xmt_run scene_manager/loader_xmt.c:3712
    #12 0x7fe8019375e0 in ctxload_process filters/load_bt_xmt.c:544
    #13 0x7fe801676169 in gf_filter_process_task filter_core/filter.c:3257
    #14 0x7fe801646f03 in gf_fs_thread_proc filter_core/filter_session.c:2420
    #15 0x7fe80164bf7c in gf_fs_run filter_core/filter_session.c:2728
    #16 0x7fe8010c64fb in gf_media_import media_tools/media_import.c:1639
    #17 0x55b5684b3efd in import_file /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/fileimport.c:1733
    #18 0x55b56846eb5c in do_add_cat /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/mp4box.c:4679
    #19 0x55b56847123b in mp4box_main /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/mp4box.c:6447
    #20 0x7fe800433fb9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:59
    #21 0x7fe8004340d6 in __libc_start_main_impl ../csu/libc-start.c:360
    #22 0x55b56844f0c0 in _start (/run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/bin/gcc/MP4Box+0x4e0c0) (BuildId: d055c5484f27068a8903997f49222289a37b0af7)

0x7c47fefe7400 is located 0 bytes inside of 64-byte region [0x7c47fefe7400,0x7c47fefe7440)
freed by thread T0 here:
    #0 0x7fe80272340f in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:51
    #1 0x7fe800a78a37 in gf_node_unregister scenegraph/base_scenegraph.c:827

previously allocated by thread T0 here:
    #0 0x7fe80272435f in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:67
    #1 0x7fe800af1d08 in VisibilitySensor_Create scenegraph/mpeg4_nodes.c:15769
    #2 0x7fe800af1d08 in gf_sg_mpeg4_node_new scenegraph/mpeg4_nodes.c:36902

SUMMARY: AddressSanitizer: heap-use-after-free scene_manager/loader_xmt.c:750 in xmt_find_node
Environment
OS: tested at 7.1.5+kali-amd64 x86_64 GNU/Linux ;
Compiler version: GCC 15.3.0-2 ;
CPU type: x86_64 ;
MP4Box - GPAC commit hash 425ef34eecf4583cf1163baca1df772e91a0ce35 ;
MP4Box - GPAC version 26.08-DEV-rev397-g425ef34ee-master ;
Additional context

link to the sample (github-url):

231_xmt_find_node_scene_manager_loader_xmt_c_750.xmt

Screenshots

screen

screen

Dominant language
C
Stars
3.3k
Forks
601
Avg merge
3d 17h
Merged PRs (30d)
22

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from gpac/gpac

All issues in gpac/gpac

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.