Boundary check for atoi() in bionic/libc. #1

merged 1 commit into from Feb 3, 2012


None yet
2 participants

michaelwu added a commit that referenced this pull request Feb 3, 2012

Merge pull request #1 from jaoo/atoipatch
Boundary check for atoi() in bionic/libc.

@michaelwu michaelwu merged commit 02c1d6a into mozilla-b2g:gingerbread Feb 3, 2012

michaelwu pushed a commit that referenced this pull request Sep 11, 2014

Handle pthread-related changes (mutex/atfork)
CRs-fixed: 345913
First commit:

Revert "Revert "am be741d4: am 2f460fb: am 73b5cad: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"""

This reverts commit 06823da.

Second commit:

bionic: fix atfork hanlder_mutex deadlock

This cherry-picks commit 34e89c2

After applying the kernel_id fix, the system refused to boot up and we
got following crash log:
I/DEBUG   (  113): pid: 618, tid: 618  >>> org.simalliance.openmobileapi.service:remote <<<
I/DEBUG   (  113): signal 16 (SIGSTKFLT), code -6 (?), fault addr --------
I/DEBUG   (  113):  eax fffffe00  ebx b77de994  ecx 00000080  edx 00724002
I/DEBUG   (  113):  esi 00000000  edi 00004000
I/DEBUG   (  113):  xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000 xss 0000007b
I/DEBUG   (  113):  eip b7761351  ebp bfdf3de8  esp bfdf3dc4  flags 00000202
I/DEBUG   (  113):     #00  eip: 00015351  /system/lib/
I/DEBUG   (  113):     #1  eip: 0000d13c  /system/lib/ (pthread_mutex_lock)
I/DEBUG   (  113):     #2  eip: 00077b48  /system/lib/ (__bionic_atfork_run_prepare)
I/DEBUG   (  113):     #3  eip: 00052cdb  /system/lib/ (fork)
I/DEBUG   (  113):     #4  eip: 0009ae91  /system/lib/ (_Z18dvmOptimizeDexFileillPKcjjb)
I/DEBUG   (  113):     #5  eip: 000819d6  /system/lib/ (_Z14dvmJarFileOpenPKcS0_PP7JarFileb)
I/DEBUG   (  113):     #6  eip: 000b175e  /system/lib/ (_ZL40Dalvik_dalvik_system_DexFile_openDexFilePKjP6JValue)
I/DEBUG   (  113):     #7  eip: 0011fb94  /system/lib/

Root cause:
The atfork uses the mutex handler_mutex to protect the atfork_head. The
parent will call __bionic_atfork_run_prepare() to lock the handler_mutex,
and need both the parent and child to unlock their own copy of handler_mutex
after fork. At that time, the owner of hanlder_mutex is set as the parent.
If we apply the kernel_id fix, then the child's kernel_id will be set as
child's tid.
The handler_mutex is a recursive lock, and pthread_mutex_unlock(&hander_mutex)
will fail because the mutex owner is the parent, while the current tid
(__get_thread()->kernel_id) is child, not matched with the mutex owner.
At that time, the handler_mutex is left in lock state.If the child wants to
fork other process after than, then it will try to lock handler_mutex, and
then be deadlocked.

Since the child has its own copy of vm space from the the parent, the
child space's handler_mutex should be reset to the initialized state.

Change-Id: I994e84201e29a32f088ad4a76f314d978c4b142d
Signed-off-by: Jack Ren <>
Signed-off-by: Chenyang Du <>
Signed-off-by: Bruce Beare <>
(cherry picked from commit c6d42edc8a4d28ff71ff2a0cc061ce5fa15e8247)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment