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

udp: fix double free in udp_destroy #380

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

jalalmostafa
Copy link
Contributor

There is double free in the UDP stack.
The elements in stk->udp->udp_hd.vec are freed twice. Once in pcb_destroy by mempool_destroy and another time in udp_destroy by iterating the vector elements.

First time:

mempool_destroy(stk->pcb_objs);

Second time:

valgrind report:

==317618== Invalid free() / delete / delete[] / realloc()
==317618==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==317618==    by 0x4918D1F: udp_destroy (cnet_udp.c:65)
==317618==    by 0x491A033: __do_calls (cnet_reg.c:71)
==317618==    by 0x491A033: cnet_do_instance_calls (cnet_reg.c:87)
==317618==    by 0x115F0B: tcpecho_exit (main.c:39)
==317618==    by 0x49E351F: ??? (in /usr/lib/x86_64-linux-gnu/libc.so.6)
==317618==    by 0x487CBCF: ??? (cne.c:240)
==317618==    by 0x48C3E3B: cne_timer_manage (cne_timer.c:439)
==317618==    by 0x114ED4: tcpecho_timer (main.c:325)
==317618==    by 0x48BE9AE: __thread_init (cne_thread.c:121)
==317618==    by 0x4A35AC2: start_thread (pthread_create.c:442)
==317618==    by 0x4AC6A03: clone (clone.S:100)
==317618==  Address 0x1fcc3080 is 0 bytes inside a block of size 65,536 free'd
==317618==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==317618==    by 0x48936F8: mempool_destroy (mempool.c:115)
==317618==    by 0x491A973: pcb_destroy (cnet_pcb.c:174)
==317618==    by 0x491A033: __do_calls (cnet_reg.c:71)
==317618==    by 0x491A033: cnet_do_instance_calls (cnet_reg.c:87)
==317618==    by 0x115F0B: tcpecho_exit (main.c:39)
==317618==    by 0x49E351F: ??? (in /usr/lib/x86_64-linux-gnu/libc.so.6)
==317618==    by 0x487CBCF: ??? (cne.c:240)
==317618==    by 0x48C3E3B: cne_timer_manage (cne_timer.c:439)
==317618==    by 0x114ED4: tcpecho_timer (main.c:325)
==317618==    by 0x48BE9AE: __thread_init (cne_thread.c:121)
==317618==    by 0x4A35AC2: start_thread (pthread_create.c:442)
==317618==    by 0x4AC6A03: clone (clone.S:100)
==317618==  Block was alloc'd at
==317618==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==317618==    by 0x489367C: mempool_populate (mempool.c:72)
==317618==    by 0x4893A53: mempool_create (mempool.c:200)
==317618==    by 0x491A9E0: pcb_create (cnet_pcb.c:191)
==317618==    by 0x491A05F: __do_calls (cnet_reg.c:71)
==317618==    by 0x491A05F: cnet_do_instance_calls (cnet_reg.c:87)
==317618==    by 0x491A6D2: cnet_stk_initialize (cnet_stk.c:82)
==317618==    by 0x115A9A: tcpecho_worker (main.c:282)
==317618==    by 0x48BE9AE: __thread_init (cne_thread.c:121)
==317618==    by 0x4A35AC2: start_thread (pthread_create.c:442)
==317618==    by 0x4AC6A03: clone (clone.S:100)

Copy link
Contributor

@KeithWiles KeithWiles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@KeithWiles KeithWiles merged commit be70669 into CloudNativeDataPlane:main Jul 24, 2024
6 checks passed
@jalalmostafa jalalmostafa deleted the double-free branch August 6, 2024 15:41
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.

2 participants