Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed TURN session use after free #3814

Merged
merged 3 commits into from
Jan 5, 2024
Merged

Fixed TURN session use after free #3814

merged 3 commits into from
Jan 5, 2024

Conversation

sauwming
Copy link
Member

@sauwming sauwming commented Dec 26, 2023

To fix #3776.

=================================================================
==15049==ERROR: AddressSanitizer: heap-use-after-free on address 0x0002b00b5648 at pc 0x0001056f5610 bp 0x00029dd327b0 sp 0x00029dd327a8
    #0 0x1056f560c in stun_on_request_complete+0xc8c (Jami:arm64+0x102a8560c)
    #1 0x1056ea7f4 in stun_tsx_on_complete+0x2a8 (Jami:arm64+0x102a7a7f4)
    #2 0x1056f2498 in retransmit_timer_callback+0x12c (Jami:arm64+0x102a82498)
    #3 0x105685fec in pj_timer_heap_poll+0x468 (Jami:arm64+0x102a15fec)

0x0002b00b5648 is located 200 bytes inside of 256-byte region [0x0002b00b5580,0x0002b00b5680)
freed by thread T1102 here:
    #2 0x105674788 in cpool_release_pool+0xec (Jami:arm64+0x102a04788)
    #3 0x105704130 in dataconn_on_data_read+0x180 (Jami:arm64+0x102a94130)
    #4 0x105663b48 in ioqueue_on_read_complete+0x39c (Jami:arm64+0x1029f3b48)
    #5 0x1056537a4 in ioqueue_dispatch_read_event+0x700 (Jami:arm64+0x1029e37a4)

In turn_session.c stun_on_request_complete(pj_stun_session *stun, ..., void *token, ...), we will access the token passed in the parameter, but in this case, the token has become invalid since the pool has been released in turn_sock.c dataconn_on_data_read().

The issue seems to be caused because the token used (conn_bind) is allocated from the dataconn's pool.

dataconn_on_connect_complete() -> pj_turn_session_connection_bind(turn_sock->sess, conn->pool, ...):

    conn_bind = PJ_POOL_ZALLOC_T(pool, struct conn_bind_t);
...
    status = pj_stun_session_send_msg(sess->stun, conn_bind, PJ_FALSE,

@sauwming sauwming merged commit ca0c440 into master Jan 5, 2024
35 checks passed
@sauwming sauwming deleted the turn-sess-token branch January 5, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

heap-use-after-free in turn_sock (TCP)
2 participants