You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is that with the config enabled, the address of the sem will be added to a global list obj_type_sem, ref: https://github.com/zephyrproject-rtos/zephyr/blob/8e5e9922c5c428d457568e317256894efccce078/kernel/sem.c#L68-L73. We essentially caused a use-after-free once the function getaddrinfo returns. This also reveals a potential larger problem where we need to treat each sem's lifecycle as infinite, as I don't see a zephyr interface to "destroy" a semaphore. Thus, rather than recreating a new sem each time we enters getaddrinfo function, we'll probably need a global one. Moreover, it seems the semaphore is really not needed in this function, and we can just do without -- dns_resolve_cb is called synchronously, right?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In the following code,
k_sem_init
is called on memory allocated on stack:micropython/ports/zephyr/modsocket.c
Lines 436 to 442 in 255d74b
This will cause memory corruption if
CONFIG_OBJ_CORE_SEM=y
. I can consistently reproduce it on olimex_stm32_e407 board:The issue is that with the config enabled, the address of the sem will be added to a global list
obj_type_sem
, ref:https://github.com/zephyrproject-rtos/zephyr/blob/8e5e9922c5c428d457568e317256894efccce078/kernel/sem.c#L68-L73. We essentially caused a use-after-free once the function
getaddrinfo
returns. This also reveals a potential larger problem where we need to treat each sem's lifecycle as infinite, as I don't see a zephyr interface to "destroy" a semaphore. Thus, rather than recreating a new sem each time we entersgetaddrinfo
function, we'll probably need a global one. Moreover, it seems the semaphore is really not needed in this function, and we can just do without -- dns_resolve_cb is called synchronously, right?micropython/ports/zephyr/modsocket.c
Lines 443 to 451 in 255d74b
Please let me know your thoughts. If my theory is correct, maybe we should also review other semaphore usage in port/zephyr? Thanks!
Bo
Beta Was this translation helpful? Give feedback.
All reactions