Skip to content

filters/f_decoder_wrapper: fix use-after-free#17553

Closed
N-R-K wants to merge 1 commit intompv-player:masterfrom
N-R-K:uaf-fix2
Closed

filters/f_decoder_wrapper: fix use-after-free#17553
N-R-K wants to merge 1 commit intompv-player:masterfrom
N-R-K:uaf-fix2

Conversation

@N-R-K
Copy link
Contributor

@N-R-K N-R-K commented Mar 10, 2026

to trigger it, run any video with mutliple audio tracks and click on the audio track icon in default osc.

this used to be guarded by locks but was changed in a569c3c with no explaination as to why. reverting back to old way fixes the UAF, so do that.

ASan stacktrace (notably, the allocation happens in one thread and the free on another):

==29382==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ba2add5cc70 at pc 0x7f22b71f0ddf bp 0x7ffe01061990 sp 0x7ffe01061150 READ of size 5 at 0x7ba2add5cc70 thread T0
    #0 0x7f22b71f0dde  (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x88dde)
    #1 0x000000b6b875 in ta_strdup ../ta/ta_utils.c:114
    #2 0x000000b6ca63 in ta_xstrdup ../ta/ta_utils.c:285
    #3 0x00000072b39e in str_get ../options/m_option.c:1289
    #4 0x00000075240b in m_option_get_node ../options/m_option.h:604
    #5 0x0000007571d5 in m_property_read_sub ../options/m_property.c:486
    #6 0x0000007b4a76 in get_track_entry ../player/command.c:2132
    #7 0x000000758ca4 in m_property_read_list ../options/m_property.c:577
    #8 0x0000007b6001 in mp_property_list_tracks ../player/command.c:2239
    #9 0x000000752ef7 in do_action ../options/m_property.c:94
    #10 0x000000753b75 in m_property_do ../options/m_property.c:175
    #11 0x0000007d965b in mp_property_do ../player/command.c:4734
    #12 0x0000007868d2 in getproperty_fn ../player/client.c:1422
    #13 0x00000078c8ea in send_client_property_changes ../player/client.c:1699
    #14 0x00000078e364 in mp_client_send_property_changes ../player/client.c:1770
    #15 0x0000008610e1 in mp_wait_events ../player/playloop.c:56
    #16 0x000000875e39 in run_playloop ../player/playloop.c:1313
    #17 0x000000842b74 in play_current_file ../player/loadfile.c:1952
    #18 0x000000846816 in mp_play_files ../player/loadfile.c:2144
    #19 0x00000084cbde in mpv_main ../player/main.c:457
    #20 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    #21 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)
    #22 0x7f22b2a760f4 in __libc_start_main (/lib64/libc.so.6+0x260f4)
    #23 0x000000418160 in _start (/home/nrk/src/core/mpv/build-debug/mpv+0x418160)

0x7ba2add5cc70 is located 80 bytes inside of 85-byte region [0x7ba2add5cc20,0x7ba2add5cc75) freed by thread T2 here:
    #0 0x7f22b72aeaeb  (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x146aeb)
    #1 0x000000b68bca in ta_free ../ta/ta.c:246
    #2 0x000000b689ff in ta_free_children ../ta/ta.c:231
    #3 0x000000b68ba1 in ta_free ../ta/ta.c:243
    #4 0x000000b689ff in ta_free_children ../ta/ta.c:231
    #5 0x000000b68ba1 in ta_free ../ta/ta.c:243
    #6 0x000000765060 in ao_chain_uninit ../player/audio.c:275
    #7 0x000000765410 in uninit_audio_chain ../player/audio.c:290
    #8 0x000000827f7c in mp_switch_track_n ../player/loadfile.c:733
    #9 0x0000007ae477 in mp_property_switch_track ../player/command.c:1982
    #10 0x000000752ef7 in do_action ../options/m_property.c:94
    #11 0x000000753680 in m_property_do ../options/m_property.c:142
    #12 0x0000007d965b in mp_property_do ../player/command.c:4734
    #13 0x0000007cf713 in mp_property_alias ../player/command.c:3788
    #14 0x000000752ef7 in do_action ../options/m_property.c:94
    #15 0x000000753680 in m_property_do ../options/m_property.c:142
    #16 0x0000007d965b in mp_property_do ../player/command.c:4734
    #17 0x0000007e42f9 in change_property_cmd ../player/command.c:5367
    #18 0x0000007ed67e in cmd_add_cycle ../player/command.c:5870
    #19 0x0000007e9617 in run_command ../player/command.c:5643
    #20 0x000000782aa7 in run_client_command ../player/client.c:1134
    #21 0x000000783284 in mpv_command_string ../player/client.c:1169
    #22 0x000000bac63c in script_command ../player/lua.c:610
    #23 0x7f22b370945a  (/usr/lib64/libluajit-5.1.so.2+0x645a)

previously allocated by thread T0 here:
    #0 0x7f22b72afc9b in malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x147c9b)
    #1 0x000000b67ee4 in ta_alloc_size ../ta/ta.c:139
    #2 0x000000b68241 in ta_realloc_size ../ta/ta.c:187
    #3 0x000000b6b5dd in strndup_append_at ../ta/ta_utils.c:93
    #4 0x000000b6b96b in ta_strndup ../ta/ta_utils.c:127
    #5 0x000000b6b892 in ta_strdup ../ta/ta_utils.c:114
    #6 0x000000b6ca63 in ta_xstrdup ../ta/ta_utils.c:285
    #7 0x000000625be3 in reinit_decoder ../filters/f_decoder_wrapper.c:458
    #8 0x000000626bf5 in mp_decoder_wrapper_reinit ../filters/f_decoder_wrapper.c:491
    #9 0x0000007698bc in init_audio_decoder ../player/audio.c:533
    #10 0x00000076a9dc in reinit_audio_chain_src ../player/audio.c:592
    #11 0x000000769c49 in reinit_audio_chain ../player/audio.c:556
    #12 0x0000008411e8 in play_current_file ../player/loadfile.c:1871
    #13 0x000000846816 in mp_play_files ../player/loadfile.c:2144
    #14 0x00000084cbde in mpv_main ../player/main.c:457
    #15 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    #16 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)

Thread T2 created by T0 here:
    #0 0x7f22b72a5efd in pthread_create (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x13defd)
    #1 0x000000881a9a in mp_load_script ../player/scripting.c:192
    #2 0x000000882827 in load_builtin_script ../player/scripting.c:252
    #3 0x000000882bd7 in mp_load_builtin_scripts ../player/scripting.c:264
    #4 0x00000080bfaf in mp_option_run_callback ../player/command.c:7989
    #5 0x000000861b4b in handle_option_callbacks ../player/playloop.c:130
    #6 0x00000084bd41 in mp_initialize ../player/main.c:389
    #7 0x00000084cbc9 in mpv_main ../player/main.c:455
    #8 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    #9 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)

to trigger it, run any video with mutliple audio tracks and
click on the audio track icon in default osc.

this used to be guarded by locks but was changed in
a569c3c with no explaination as to why.
reverting back to old way fixes the UAF, so do that.

ASan stacktrace (notably, the allocation happens in one thread
and the free on another):

==29382==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ba2add5cc70 at pc 0x7f22b71f0ddf bp 0x7ffe01061990 sp 0x7ffe01061150
READ of size 5 at 0x7ba2add5cc70 thread T0
    #0 0x7f22b71f0dde  (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x88dde)
    mpv-player#1 0x000000b6b875 in ta_strdup ../ta/ta_utils.c:114
    mpv-player#2 0x000000b6ca63 in ta_xstrdup ../ta/ta_utils.c:285
    mpv-player#3 0x00000072b39e in str_get ../options/m_option.c:1289
    mpv-player#4 0x00000075240b in m_option_get_node ../options/m_option.h:604
    mpv-player#5 0x0000007571d5 in m_property_read_sub ../options/m_property.c:486
    mpv-player#6 0x0000007b4a76 in get_track_entry ../player/command.c:2132
    mpv-player#7 0x000000758ca4 in m_property_read_list ../options/m_property.c:577
    mpv-player#8 0x0000007b6001 in mp_property_list_tracks ../player/command.c:2239
    mpv-player#9 0x000000752ef7 in do_action ../options/m_property.c:94
    mpv-player#10 0x000000753b75 in m_property_do ../options/m_property.c:175
    mpv-player#11 0x0000007d965b in mp_property_do ../player/command.c:4734
    mpv-player#12 0x0000007868d2 in getproperty_fn ../player/client.c:1422
    mpv-player#13 0x00000078c8ea in send_client_property_changes ../player/client.c:1699
    mpv-player#14 0x00000078e364 in mp_client_send_property_changes ../player/client.c:1770
    mpv-player#15 0x0000008610e1 in mp_wait_events ../player/playloop.c:56
    mpv-player#16 0x000000875e39 in run_playloop ../player/playloop.c:1313
    mpv-player#17 0x000000842b74 in play_current_file ../player/loadfile.c:1952
    mpv-player#18 0x000000846816 in mp_play_files ../player/loadfile.c:2144
    mpv-player#19 0x00000084cbde in mpv_main ../player/main.c:457
    mpv-player#20 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    mpv-player#21 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)
    mpv-player#22 0x7f22b2a760f4 in __libc_start_main (/lib64/libc.so.6+0x260f4)
    mpv-player#23 0x000000418160 in _start (/home/nrk/src/core/mpv/build-debug/mpv+0x418160)

0x7ba2add5cc70 is located 80 bytes inside of 85-byte region [0x7ba2add5cc20,0x7ba2add5cc75)
freed by thread T2 here:
    #0 0x7f22b72aeaeb  (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x146aeb)
    mpv-player#1 0x000000b68bca in ta_free ../ta/ta.c:246
    mpv-player#2 0x000000b689ff in ta_free_children ../ta/ta.c:231
    mpv-player#3 0x000000b68ba1 in ta_free ../ta/ta.c:243
    mpv-player#4 0x000000b689ff in ta_free_children ../ta/ta.c:231
    mpv-player#5 0x000000b68ba1 in ta_free ../ta/ta.c:243
    mpv-player#6 0x000000765060 in ao_chain_uninit ../player/audio.c:275
    mpv-player#7 0x000000765410 in uninit_audio_chain ../player/audio.c:290
    mpv-player#8 0x000000827f7c in mp_switch_track_n ../player/loadfile.c:733
    mpv-player#9 0x0000007ae477 in mp_property_switch_track ../player/command.c:1982
    mpv-player#10 0x000000752ef7 in do_action ../options/m_property.c:94
    mpv-player#11 0x000000753680 in m_property_do ../options/m_property.c:142
    mpv-player#12 0x0000007d965b in mp_property_do ../player/command.c:4734
    mpv-player#13 0x0000007cf713 in mp_property_alias ../player/command.c:3788
    mpv-player#14 0x000000752ef7 in do_action ../options/m_property.c:94
    mpv-player#15 0x000000753680 in m_property_do ../options/m_property.c:142
    mpv-player#16 0x0000007d965b in mp_property_do ../player/command.c:4734
    mpv-player#17 0x0000007e42f9 in change_property_cmd ../player/command.c:5367
    mpv-player#18 0x0000007ed67e in cmd_add_cycle ../player/command.c:5870
    mpv-player#19 0x0000007e9617 in run_command ../player/command.c:5643
    mpv-player#20 0x000000782aa7 in run_client_command ../player/client.c:1134
    mpv-player#21 0x000000783284 in mpv_command_string ../player/client.c:1169
    mpv-player#22 0x000000bac63c in script_command ../player/lua.c:610
    mpv-player#23 0x7f22b370945a  (/usr/lib64/libluajit-5.1.so.2+0x645a)

previously allocated by thread T0 here:
    #0 0x7f22b72afc9b in malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x147c9b)
    mpv-player#1 0x000000b67ee4 in ta_alloc_size ../ta/ta.c:139
    mpv-player#2 0x000000b68241 in ta_realloc_size ../ta/ta.c:187
    mpv-player#3 0x000000b6b5dd in strndup_append_at ../ta/ta_utils.c:93
    mpv-player#4 0x000000b6b96b in ta_strndup ../ta/ta_utils.c:127
    mpv-player#5 0x000000b6b892 in ta_strdup ../ta/ta_utils.c:114
    mpv-player#6 0x000000b6ca63 in ta_xstrdup ../ta/ta_utils.c:285
    mpv-player#7 0x000000625be3 in reinit_decoder ../filters/f_decoder_wrapper.c:458
    mpv-player#8 0x000000626bf5 in mp_decoder_wrapper_reinit ../filters/f_decoder_wrapper.c:491
    mpv-player#9 0x0000007698bc in init_audio_decoder ../player/audio.c:533
    mpv-player#10 0x00000076a9dc in reinit_audio_chain_src ../player/audio.c:592
    mpv-player#11 0x000000769c49 in reinit_audio_chain ../player/audio.c:556
    mpv-player#12 0x0000008411e8 in play_current_file ../player/loadfile.c:1871
    mpv-player#13 0x000000846816 in mp_play_files ../player/loadfile.c:2144
    mpv-player#14 0x00000084cbde in mpv_main ../player/main.c:457
    mpv-player#15 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    mpv-player#16 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)

Thread T2 created by T0 here:
    #0 0x7f22b72a5efd in pthread_create (/usr/lib/gcc/x86_64-pc-linux-gnu/15/libasan.so.8+0x13defd)
    mpv-player#1 0x000000881a9a in mp_load_script ../player/scripting.c:192
    mpv-player#2 0x000000882827 in load_builtin_script ../player/scripting.c:252
    mpv-player#3 0x000000882bd7 in mp_load_builtin_scripts ../player/scripting.c:264
    mpv-player#4 0x00000080bfaf in mp_option_run_callback ../player/command.c:7989
    mpv-player#5 0x000000861b4b in handle_option_callbacks ../player/playloop.c:130
    mpv-player#6 0x00000084bd41 in mp_initialize ../player/main.c:389
    mpv-player#7 0x00000084cbc9 in mpv_main ../player/main.c:455
    mpv-player#8 0x000000d0bb9a in main ../osdep/main-fn-unix.c:5
    mpv-player#9 0x7f22b2a76038  (/lib64/libc.so.6+0x26038)
@N-R-K
Copy link
Contributor Author

N-R-K commented Mar 10, 2026

Closing in favor of: #17554

@N-R-K N-R-K closed this Mar 10, 2026
@N-R-K N-R-K deleted the uaf-fix2 branch March 10, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant