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

Crash: lib/posix-process/clone causes segmentation fault during pthread_create on Linuxu #1281

Open
Julius1991 opened this issue Jan 25, 2024 · 0 comments
Labels
kind/bug Something isn't working

Comments

@Julius1991
Copy link

Julius1991 commented Jan 25, 2024

Describe the bug

The following code causes a segmentation fault when executing pthread_create on Linuxu and entering clone function in lib/posix-process/clone:

#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void *thread1_func(void *args)
{
	printf("Enter thread1 function.\n");
	sleep(5);
	printf("Leave thread1 function.\n");
	pthread_exit(NULL);
}

int main(void)
{	
	pthread_t thread1;

	printf("Starting threads.\n");
	pthread_create(&thread1, NULL, thread1_func, NULL);


	pthread_join(thread1, NULL);
	printf("Thread joined.\n");

	return 0;
}

Steps to reproduce

See description.

Expected behavior

No crash.

Which architectures were you using or does this bug affect?

linuxu

Which platforms were you using or does this bug affect?

x86_64

Relevant log output

./build/app-pthreads_linuxu-x86_64.dbg
[53553.328498] Info: [liblinuxuplat] <setup.c @   66> Allocate memory for heap (4 MiB)
[53553.328555] dbg:  [liblinuxuplat] <setup.c @  103> No initrd present.
[53553.328588] Info: [libukboot] <boot.c @  283> Unikraft constructor table at 0x48f000 - 0x48f010
[53553.328615] dbg:  [libukboot] <boot.c @  287> Call constructor: 0x48dc00())...
[53553.328632] dbg:  [libcontext] <ectx.c @   73> Load/store of extended CPU state: XSAVEOPT
[53553.328642] dbg:  [libukboot] <boot.c @  287> Call constructor: 0x431710())...
[53553.328657] Info: [libukboot] <boot.c @  320> Initialize memory allocator...
[53553.328664] dbg:  [libukboot] <boot.c @  213> Trying 0x7fc2b1864000-0x7fc2b1c64000 0x23
[53553.328673] Info: [libukallocbbuddy] <bbuddy.c @  584> Initialize binary buddy allocator 7fc2b1864000
[53553.328692] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1866000 - 7fc2b1868000 (order 1)
[53553.328719] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1868000 - 7fc2b1870000 (order 3)
[53553.328730] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1870000 - 7fc2b1880000 (order 4)
[53553.328744] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1880000 - 7fc2b1900000 (order 7)
[53553.328772] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1900000 - 7fc2b1a00000 (order 8)
[53553.328801] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1a00000 - 7fc2b1c00000 (order 9)
[53553.328829] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1c00000 - 7fc2b1c40000 (order 6)
[53553.328840] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1c40000 - 7fc2b1c60000 (order 5)
[53553.328853] dbg:  [libukallocbbuddy] <bbuddy.c @  539> 7fc2b1864000: Add allocate unit 7fc2b1c60000 - 7fc2b1c64000 (order 2)
[53553.328881] dbg:  [libcontext] <tls.c @  173> tls_area_init: target: 0x7fc2b1866020 (536 bytes)
[53553.328889] dbg:  [libcontext] <tls.c @  175> tls_area_init: copy (.tdata): 4 bytes
[53553.328898] dbg:  [libcontext] <tls.c @  177> tls_area_init: uninitialized (.tbss): 332 bytes
[53553.328907] dbg:  [libcontext] <tls.c @  179> tls_area_init: pad: 0 bytes
[53553.328918] dbg:  [libcontext] <tls.c @  181> tls_area_init: tcb: 200 bytes
[53553.328925] dbg:  [libcontext] <tls.c @  183> tls_area_init: tcb self ptr: 0x7fc2b1866170
[53553.328950] dbg:  [libmuslglue] <__uk_init_tls.c @  245> ukarch_tls_tcb_init tcb 0x7fc2b1866170
[53553.328963] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866020  0d f0 b0 b0 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329010] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329079] dbg:  [libcontext] <tls.c @  204> *
[53553.329086] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866170  70 61 86 b1 c2 7f 00 00  00 00 00 00 00 00 00 00  |pa..............|
[53553.329172] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866180  70 61 86 b1 c2 7f 00 00  70 61 86 b1 c2 7f 00 00  |pa......pa......|
[53553.329263] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329338] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18661a0  00 00 00 00 00 00 00 00  02 00 00 00 00 00 00 00  |................|
[53553.329426] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18661b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329504] dbg:  [libcontext] <tls.c @  204> *
[53553.329512] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18661f0  00 10 c6 b1 c2 7f 00 00  f8 61 86 b1 c2 7f 00 00  |.........a......|
[53553.329602] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329677] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866210  00 00 00 00 00 00 00 00  d8 36 4e 00 00 00 00 00  |.........6N.....|
[53553.329778] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1866220  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.329874] dbg:  [libcontext] <tls.c @  204> *
[53553.329905] Info: [libukboot] <boot.c @  360> Initialize platform time...
[53553.329984] Info: [libukboot] <boot.c @  364> Initialize scheduling...
[53553.330054] Info: [libukschedcoop] <schedcoop.c @  263> Initializing cooperative scheduler
[53553.330067] dbg:  [libuksched] <thread.c @  265> uk_thread 0x7fc2b18670d0 (idle): ctx:0x7fc2b18670d0, ectx:0x7fc2b1c62240, tlsp:0x7fc2b1c62170
[53553.330074] dbg:  [libcontext] <tls.c @  173> tls_area_init: target: 0x7fc2b1c62020 (536 bytes)
[53553.330098] dbg:  [libcontext] <tls.c @  175> tls_area_init: copy (.tdata): 4 bytes
[53553.330105] dbg:  [libcontext] <tls.c @  177> tls_area_init: uninitialized (.tbss): 332 bytes
[53553.330116] dbg:  [libcontext] <tls.c @  179> tls_area_init: pad: 0 bytes
[53553.330144] dbg:  [libcontext] <tls.c @  181> tls_area_init: tcb: 200 bytes
[53553.330167] dbg:  [libcontext] <tls.c @  183> tls_area_init: tcb self ptr: 0x7fc2b1c62170
[53553.330198] dbg:  [libmuslglue] <__uk_init_tls.c @  245> ukarch_tls_tcb_init tcb 0x7fc2b1c62170
[53553.330228] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1c62020  0d f0 b0 b0 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.330378] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1c62030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.330509] dbg:  [libcontext] <tls.c @  204> *
[53553.330519] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1c62170  70 21 c6 b1 c2 7f 00 00  00 00 00 00 00 00 00 00  |p!..............|
[53553.330653] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b1c62180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.330726] dbg:  [libcontext] <tls.c @  204> *
[53553.330739] dbg:  [libmuslglue] <__uk_init_tls.c @  206> uk_thread_uktcb_init uk_thread 0x7fc2b18670d0, tcb 0x7fc2b1c62170
[53553.330774] dbg:  [libcontext] <ctx.c @  133> ukarch_ctx 0x7fc2b18670d0: entry:0x428fc0(7fc2b1867020), sp:0x7fc2b1c10018
[53553.330782] dbg:  [libuksched] <thread.c @  129> uk_thread 0x7fc2b18670d0 (idle) init cb: Skip 0x40d0c0() due to feature mismatch: ET required (has ET)
[53553.330791] dbg:  [libuksched] <thread.c @  265> uk_thread 0x7fc2b1c63020 (init): ctx:0x7fc2b1c63020, ectx:0x7fc2b1c63100, tlsp:0x7fc2b1866170
[53553.330797] dbg:  [libuksched] <thread.c @  145> uk_thread 0x7fc2b1c63020 (init) init: Call initialization 0x40d0c0()...
[53553.330804] dbg:  [libposix_process] <process.c @  415> thread 0x7fc2b1c63020 (init): Parent 0 (<n/a>) without process context, skipping...
[53553.330813] Info: [libukboot] <boot.c @  382> Init Table @ 0x48f010 - 0x48f050
[53553.330843] dbg:  [libukboot] <boot.c @  390> Call init function: 0x403bd0(0x7ffc2f909a40)...
[53553.330857] dbg:  [libukboot] <boot.c @  390> Call init function: 0x42b150(0x7ffc2f909a40)...
[53553.330865] dbg:  [libposix_fdtab] <fdtab.c @  502> (int) uk_syscall_r_dup3((int) 0x0, (int) 0x1, (int) 0x0)
[53553.330890] dbg:  [libposix_fdtab] <fdtab.c @  502> (int) uk_syscall_r_dup3((int) 0x0, (int) 0x2, (int) 0x0)
[53553.330897] dbg:  [libukboot] <boot.c @  390> Call init function: 0x40d980(0x7ffc2f909a40)...
[53553.330905] dbg:  [libposix_process] <process.c @  175> Process PID 0: New thread TID 1
[53553.330919] dbg:  [libposix_process] <process.c @  283> Process PID 1 created (parent PID: 0)
[53553.330932] dbg:  [libposix_fdio] <fd-shim.c @  359> (int) uk_syscall_r_ioctl((int) 0x1, (unsigned int) 0x5413, (void *) 0x7ffc2f909938)
[53553.330961] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f9098d0, (int) 0x2)
Powered by
[53553.330982] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909910, (int) 0x2)
o.   .o       _ _               __ _
[53553.331006] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909910, (int) 0x2)
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
[53553.331015] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909910, (int) 0x2)
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
[53553.331027] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909910, (int) 0x2)
oOo oOO| | | | |   (| | | (_) |  _) :_
[53553.331034] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909910, (int) 0x2)
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
[53553.331064] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909630, (int) 0x2)
         Telesto 0.16.1~30540358-custom
[53553.331074] Info: [libukboot] <boot.c @  469> Pre-init table at 0x4da130 - 0x4da130
[53553.331081] Info: [libukboot] <boot.c @  480> Constructor table at 0x4da130 - 0x4da130
[53553.331087] Info: [libukboot] <boot.c @  495> Environment variables:
[53553.331093] Info: [libukboot] <boot.c @  497>        PATH=/bin
[53553.331100] Info: [libukboot] <boot.c @  503> Calling main(1, ['./build/app-pthreads_linuxu-x86_64.dbg'])
[53553.331113] dbg:  [libposix_fdio] <fd-shim.c @  219> (ssize_t) uk_syscall_r_writev((int) 0x1, (const struct iovec *) 0x7ffc2f909950, (int) 0x2)
Starting threads.
[53553.331139] dbg:  [libuksignal] <signal.c @  118> (int) uk_syscall_r_rt_sigprocmask((int __attribute__((unused))) 0x1, (const sigset_t *__attribute__((unused))) 0x7ffc2f909940, (sigset_t *__attribute__((unused))) 0x0, (size_t __attribute__(( 1183.331139](void*) uk_syscall_e_mmap((void*) 0x0, (size_t) 0x23000, (int) 0x0, (int) 0x22, (int) 0xffffffffffffffff, (off_t) 0x0)
[53553.331233] dbg:  [libukmmap] <mmap.c @  194> (int) uk_syscall_r_mprotect((void*) 0x7fc2b1883000, (size_t) 0x21000, (int) 0x3)
[53553.331257] Warn: [libukmmap] <mmap.c @  196> __uk_syscall_r_mprotect() stubbed
[53553.331264] dbg:  [libcontext] <tls.c @  173> tls_area_init: target: 0x7fc2b18a39e0 (536 bytes)
[53553.331270] dbg:  [libcontext] <tls.c @  175> tls_area_init: copy (.tdata): 4 bytes
[53553.331276] dbg:  [libcontext] <tls.c @  177> tls_area_init: uninitialized (.tbss): 332 bytes
[53553.331282] dbg:  [libcontext] <tls.c @  179> tls_area_init: pad: 0 bytes
[53553.331305] dbg:  [libcontext] <tls.c @  181> tls_area_init: tcb: 200 bytes
[53553.331313] dbg:  [libcontext] <tls.c @  183> tls_area_init: tcb self ptr: 0x7fc2b18a3b30
[53553.331320] dbg:  [libmuslglue] <__uk_init_tls.c @  245> ukarch_tls_tcb_init tcb 0x7fc2b18a3b30
[53553.331327] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18a39e0  0d f0 b0 b0 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.331416] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18a39f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.331487] dbg:  [libcontext] <tls.c @  204> *
[53553.331497] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18a3b30  30 3b 8a b1 c2 7f 00 00  00 00 00 00 00 00 00 00  |0;..............|
[53553.331550] dbg:  [libcontext] <tls.c @  204> (tls_area): 7fc2b18a3b40  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
[53553.331598] dbg:  [libcontext] <tls.c @  204> *
[53553.331611] dbg:  [libuksignal] <signal.c @  118> (int) uk_syscall_r_rt_sigprocmask((int __attribute__((unused))) 0x0, (const sigset_t *__attribute__((unused))) 0x4a9b60, (sigset_t *__attribute__((unused))) 0x7ffc2f909940, (size_t __attribut 1183.331611] ��MSegmentation fault
@Julius1991 Julius1991 added the kind/bug Something isn't working label Jan 25, 2024
@Julius1991 Julius1991 changed the title Crash: lib/posix-process/clone causes segmentation fault during pthread_create on Linuxu Crash: lib/posix-process/clone causes segmentation fault during pthread_create Jan 25, 2024
@Julius1991 Julius1991 changed the title Crash: lib/posix-process/clone causes segmentation fault during pthread_create Crash: lib/posix-process/clone causes segmentation fault during pthread_create on Linuxu Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant