Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 830748 - sys-apps/sandbox: deadlock with sys-devel/mold using dev-libs/mimalloc-2.0.3-r1
Summary: sys-apps/sandbox: deadlock with sys-devel/mold using dev-libs/mimalloc-2.0.3-r1
Status: RESOLVED OBSOLETE
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Sandbox (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Sandbox Maintainers
URL:
Whiteboard:
Keywords:
: 830458 (view as bug list)
Depends on:
Blocks: systemwide-mold
  Show dependency tree
 
Reported: 2022-01-07 22:56 UTC by Михаил
Modified: 2023-11-09 21:08 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Михаил 2022-01-07 22:56:09 UTC
Portage unable to build package with sys-devel/mold-1.0.1 linker.

mold use mimalloc for memory allocation.
sandbox can't handle mimalloc initialization because of using implicit allocation by self via dlsym().

Reproducible: Always

Steps to Reproduce:
1. Install sys-devel/mold-1.0.1

2. Set package environment to use mold:
LD=mold
CFLAGS="${CFLAGS} -fuse-ld=mold"
CXXFLAGS="${CXXFLAGS} -fuse-ld=mold"
LDFLAGS="${LDFLAGS} -fuse-ld=mold"

 
3. emerge -1 <package>
Actual Results:  
deadlock in linker process

checking whether the C compiler works...

Expected Results:  
sandbox does not change linker behaviour. 

#0  futex_wait (private=0, expected=2, futex_word=0x7f3d04531340 <lock>) at ../sysdeps/nptl/futex-internal.h:146
#1  __lll_lock_wait (futex=futex@entry=0x7f3d04531340 <lock>, private=0) at lowlevellock.c:52
#2  0x00007f3d03bc7fa3 in __GI___pthread_mutex_lock (mutex=mutex@entry=0x7f3d04531340 <lock>) at ../nptl/pthread_mutex_lock.c:80
#3  0x00007f3d045199b2 in sb_lock () at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/lock.c:16
#4  0x00007f3d04518f15 in before_syscall (dirfd=<optimized out>, sb_nr=-1, func=0x7f3d04522435 "access_rd", file=0x7ffc81c79350 "/sys/devices/system/node/node1", flags=4)
    at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:1060
#5  0x00007f3d04518fe0 in before_syscall_access (dirfd=dirfd@entry=-100, sb_nr=<optimized out>, sb_nr@entry=24, func=func@entry=0x7f3d04522f11 "access", file=file@entry=0x7ffc81c79350 "/sys/devices/system/node/node1", 
    flags=flags@entry=4) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:1094
#6  0x00007f3d0451c5ec in access_DEFAULT (pathname=pathname@entry=0x7ffc81c79350 "/sys/devices/system/node/node1", mode=mode@entry=4)
    at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/wrapper-funcs/__wrapper_simple.c:52
#7  0x00007f3d04477a30 in mi_os_numa_node_countx () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1307
#8  0x00007f3d04478df1 in _mi_os_numa_node_count_get () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1359
#9  0x00007f3d04478e31 in _mi_os_numa_node_count () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/include/mimalloc-internal.h:781
#10 _mi_os_numa_node_get (tld=tld@entry=0x7f3d0449c6e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1370
#11 0x00007f3d0447b937 in _mi_os_numa_node (tld=0x7f3d0449c6e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/include/mimalloc-internal.h:776
#12 _mi_segment_cache_pop (size=size@entry=67108864, commit_mask=commit_mask@entry=0x7ffc81c794e0, decommit_mask=decommit_mask@entry=0x7ffc81c79560, large=large@entry=0x7ffc81c794c6, is_pinned=is_pinned@entry=0x7ffc81c794c7, 
    is_zero=is_zero@entry=0x7ffc81c794c5, memid=0x7ffc81c794d8, tld=0x7f3d0449c6e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment-cache.c:53
#13 0x00007f3d0447e9d4 in mi_segment_init (segment=segment@entry=0x0, required=required@entry=0, tld=tld@entry=0x7f3d0449c340 <tld_main+32>, os_tld=os_tld@entry=0x7f3d0449c6e8 <tld_main+968>, huge_page=huge_page@entry=0x0)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:836
#14 0x00007f3d0447ef99 in mi_segment_alloc (required=required@entry=0, tld=tld@entry=0x7f3d0449c340 <tld_main+32>, os_tld=os_tld@entry=0x7f3d0449c6e8 <tld_main+968>, huge_page=huge_page@entry=0x0)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:950
#15 0x00007f3d044803d5 in mi_segment_reclaim_or_alloc (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, needed_slices=needed_slices@entry=1, block_size=block_size@entry=48, tld=tld@entry=0x7f3d0449c340 <tld_main+32>, 
    os_tld=os_tld@entry=0x7f3d0449c6e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1469
#16 0x00007f3d04480577 in mi_segments_page_alloc (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, page_kind=page_kind@entry=MI_PAGE_SMALL, required=required@entry=48, block_size=block_size@entry=48, tld=0x7f3d0449c340 <tld_main+32>, 
    os_tld=0x7f3d0449c6e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1488
#17 0x00007f3d044809b1 in _mi_segment_page_alloc (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, block_size=block_size@entry=48, tld=<optimized out>, os_tld=<optimized out>)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1553
#18 0x00007f3d044821e5 in mi_page_fresh_alloc (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, pq=pq@entry=0x7f3d0449bbc8 <_mi_heap_main+1192>, block_size=48)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:248
#19 0x00007f3d04482318 in mi_page_fresh (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, pq=pq@entry=0x7f3d0449bbc8 <_mi_heap_main+1192>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:264
#20 0x00007f3d044844a0 in mi_page_queue_find_free_ex (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, pq=pq@entry=0x7f3d0449bbc8 <_mi_heap_main+1192>, first_try=first_try@entry=true)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:705
#21 0x00007f3d04484697 in mi_find_free_page (size=40, heap=0x7f3d0449b720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:742
#22 mi_find_page (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:831
#23 0x00007f3d044847cb in _mi_malloc_generic (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:856
#24 0x00007f3d04485975 in _mi_page_malloc (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, page=0x7f3d044928c0 <_mi_page_empty>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:32
#25 0x00007f3d044860f3 in mi_heap_malloc_small (heap=0x7f3d0449b720 <_mi_heap_main>, size=32) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:83
#26 0x00007f3d04487001 in mi_heap_malloc (size=32, heap=0x7f3d0449b720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:101
#27 _mi_heap_malloc_zero (heap=heap@entry=0x7f3d0449b720 <_mi_heap_main>, size=32, zero=zero@entry=true) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:151
#28 0x00007f3d04487370 in mi_heap_zalloc (size=<optimized out>, heap=0x7f3d0449b720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:159
#29 mi_heap_calloc (size=32, count=1, heap=0x7f3d0449b720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:597
#30 mi_calloc (count=count@entry=1, size=size@entry=32) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:601
#31 0x00007f3d039ffaf8 in _dlerror_run (operate=operate@entry=0x7f3d039ff390 <dlsym_doit>, args=args@entry=0x7ffc81c79980) at dlerror.c:148
#32 0x00007f3d039ff410 in __dlsym (handle=<optimized out>, name=name@entry=0x7f3d04522561 "mmap") at dlsym.c:70
#33 0x00007f3d0451aeee in get_dlsym (symname=symname@entry=0x7f3d04522561 "mmap", symver=symver@entry=0x0) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/wrappers.c:51
#34 0x00007f3d04519a2e in sb_mmap (addr=addr@entry=0x0, length=length@entry=32, prot=prot@entry=3, flags=flags@entry=34, fd=fd@entry=-1, offset=offset@entry=0)
    at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/memory.c:28
#35 0x00007f3d04519aa2 in malloc (size=32) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/memory.c:50
#36 0x00007f3d0452043d in __xmalloc (size=16, file=file@entry=0x7f3d04522050 "/var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c", func=func@entry=0x7f3d04522540 <__func__.6> "init_env_entries", 
    line=line@entry=555) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsbutil/sb_memory.c:34
#37 0x00007f3d04518681 in init_env_entries (prefixes_array=prefixes_array@entry=0x7f3d0452f2f0 <sbcontext+16>, prefixes_num=prefixes_num@entry=0x7f3d0452f318 <sbcontext+56>, env=env@entry=0x7f3d04522496 "SANDBOX_DENY", 
    prefixes_env=prefixes_env@entry=0x7ffc81c81893 "", warn=warn@entry=1) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:555
#38 0x00007f3d045187fd in sb_process_env_settings () at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:627
#39 0x00007f3d04518e23 in libsb_init () at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:92
#40 0x00007f3d04518f9c in before_syscall (dirfd=<optimized out>, sb_nr=-3, func=0x7f3d04522440 "open_rd", file=0x7f3d0448d438 "/proc/sys/vm/overcommit_memory", flags=0)
    at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:1063
--Type <RET> for more, q to quit, c to continue without paging--
#41 0x00007f3d0451900e in before_syscall_open_int (dirfd=dirfd@entry=-100, sb_nr=<optimized out>, sb_nr@entry=5, func=func@entry=0x7f3d04522ea8 "open", file=file@entry=0x7f3d0448d438 "/proc/sys/vm/overcommit_memory", 
    flags=flags@entry=0) at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/libsandbox.c:1104
#42 0x00007f3d0451e103 in open_DEFAULT (pathname=pathname@entry=0x7f3d0448d438 "/proc/sys/vm/overcommit_memory", flags=flags@entry=0)
    at /var/tmp/portage/sys-apps/sandbox-2.25/work/sandbox-2.25/libsandbox/wrapper-funcs/__wrapper_simple.c:52
#43 0x00007f3d0447763b in open (__oflag=0, __path=0x7f3d0448d438 "/proc/sys/vm/overcommit_memory") at /usr/include/bits/fcntl2.h:53
#44 os_detect_overcommit () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:231
#45 0x00007f3d044787a3 in _mi_os_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:260
#46 0x00007f3d0448c7ab in mi_process_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/init.c:523
#47 0x00007f3d0448c87a in mi_thread_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/init.c:372
#48 0x00007f3d0448488e in _mi_malloc_generic (heap=heap@entry=0x7f3d0449a1c0 <_mi_heap_empty>, size=size@entry=72712) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:843
#49 0x00007f3d04486ef5 in mi_heap_malloc (size=72704, heap=0x7f3d0449a1c0 <_mi_heap_empty>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:106
#50 mi_malloc (size=72704) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:119
#51 0x00007f3d03de75a4 in ?? () from target:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libstdc++.so.6
#52 0x00007f3d0456f04e in call_init (env=0x7ffc81c7bf38, argv=0x7ffc81c7be28, argc=33, l=<optimized out>) at dl-init.c:74
#53 call_init (l=<optimized out>, argc=33, argv=0x7ffc81c7be28, env=0x7ffc81c7bf38) at dl-init.c:30
#54 0x00007f3d0456f134 in _dl_init (main_map=0x7f3d045911e0, argc=33, argv=0x7ffc81c7be28, env=0x7ffc81c7bf38) at dl-init.c:121
#55 0x00007f3d0456008a in _dl_start_user () from target:/lib64/ld-linux-x86-64.so.2
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-01-08 01:35:44 UTC
Sounds similar to some of the issues vapier has linked to before, I think, with e.g. jemalloc?
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-01-08 09:31:39 UTC
Wait, didn't we fix this? Please try latest (masked) sandbox?
Comment 3 Михаил 2022-01-08 10:10:08 UTC
(In reply to Sam James from comment #2)
> Wait, didn't we fix this? Please try latest (masked) sandbox?

Latest masked with same result.

Reason for deadlock.

1. mimalloc try to open "/proc/sys/vm/overcommit_memory"
2. sandbox hook open() syscall while holdind mutex.
3. sandbox check want to use mmap() and call dlsym for lazy loading address.
4. dlsym use calloc from mimalloc.
5. mimalloc do second open() syscall for "/sys/devices/system/node/node1".
6. sandbox handle second open() and can't lock mutex already locked at step 2. (deadlock)




#0  futex_wait (private=0, expected=2, futex_word=0x7f0bb4930360 <lock>) at ../sysdeps/nptl/futex-internal.h:146
#1  __lll_lock_wait (futex=futex@entry=0x7f0bb4930360 <lock>, private=0) at lowlevellock.c:52
#2  0x00007f0bb3fc4fa3 in __GI___pthread_mutex_lock (mutex=mutex@entry=0x7f0bb4930360 <lock>) at ../nptl/pthread_mutex_lock.c:80
#3  0x00007f0bb4916971 in sb_lock () at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/lock.c:16
#4  0x00007f0bb4915e8d in before_syscall (dirfd=<optimized out>, sb_nr=-1, func=0x7f0bb4920435 "access_rd", file=0x7ffceb5d0ef0 "/sys/devices/system/node/node1", flags=4)
    at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:1057
#5  0x00007f0bb4915f58 in before_syscall_access (dirfd=dirfd@entry=-100, sb_nr=<optimized out>, sb_nr@entry=24, func=func@entry=0x7f0bb492106d "access", file=file@entry=0x7ffceb5d0ef0 "/sys/devices/system/node/node1", 
    flags=flags@entry=4) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:1091
#6  0x00007f0bb491a3a6 in access_DEFAULT (pathname=pathname@entry=0x7ffceb5d0ef0 "/sys/devices/system/node/node1", mode=mode@entry=4)
    at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/wrapper-funcs/__wrapper_simple.c:52
#7  0x00007f0bb4874a30 in mi_os_numa_node_countx () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1307
#8  0x00007f0bb4875df1 in _mi_os_numa_node_count_get () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1359
#9  0x00007f0bb4875e31 in _mi_os_numa_node_count () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/include/mimalloc-internal.h:781
#10 _mi_os_numa_node_get (tld=tld@entry=0x7f0bb48996e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:1370
#11 0x00007f0bb4878937 in _mi_os_numa_node (tld=0x7f0bb48996e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/include/mimalloc-internal.h:776
#12 _mi_segment_cache_pop (size=size@entry=67108864, commit_mask=commit_mask@entry=0x7ffceb5d1080, decommit_mask=decommit_mask@entry=0x7ffceb5d1100, large=large@entry=0x7ffceb5d1066, is_pinned=is_pinned@entry=0x7ffceb5d1067, 
    is_zero=is_zero@entry=0x7ffceb5d1065, memid=0x7ffceb5d1078, tld=0x7f0bb48996e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment-cache.c:53
#13 0x00007f0bb487b9d4 in mi_segment_init (segment=segment@entry=0x0, required=required@entry=0, tld=tld@entry=0x7f0bb4899340 <tld_main+32>, os_tld=os_tld@entry=0x7f0bb48996e8 <tld_main+968>, huge_page=huge_page@entry=0x0)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:836
#14 0x00007f0bb487bf99 in mi_segment_alloc (required=required@entry=0, tld=tld@entry=0x7f0bb4899340 <tld_main+32>, os_tld=os_tld@entry=0x7f0bb48996e8 <tld_main+968>, huge_page=huge_page@entry=0x0)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:950
#15 0x00007f0bb487d3d5 in mi_segment_reclaim_or_alloc (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, needed_slices=needed_slices@entry=1, block_size=block_size@entry=48, tld=tld@entry=0x7f0bb4899340 <tld_main+32>, 
    os_tld=os_tld@entry=0x7f0bb48996e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1469
#16 0x00007f0bb487d577 in mi_segments_page_alloc (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, page_kind=page_kind@entry=MI_PAGE_SMALL, required=required@entry=48, block_size=block_size@entry=48, tld=0x7f0bb4899340 <tld_main+32>, 
    os_tld=0x7f0bb48996e8 <tld_main+968>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1488
#17 0x00007f0bb487d9b1 in _mi_segment_page_alloc (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, block_size=block_size@entry=48, tld=<optimized out>, os_tld=<optimized out>)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/segment.c:1553
#18 0x00007f0bb487f1e5 in mi_page_fresh_alloc (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, pq=pq@entry=0x7f0bb4898bc8 <_mi_heap_main+1192>, block_size=48)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:248
#19 0x00007f0bb487f318 in mi_page_fresh (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, pq=pq@entry=0x7f0bb4898bc8 <_mi_heap_main+1192>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:264
#20 0x00007f0bb48814a0 in mi_page_queue_find_free_ex (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, pq=pq@entry=0x7f0bb4898bc8 <_mi_heap_main+1192>, first_try=first_try@entry=true)
    at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:705
#21 0x00007f0bb4881697 in mi_find_free_page (size=40, heap=0x7f0bb4898720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:742
#22 mi_find_page (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:831
#23 0x00007f0bb48817cb in _mi_malloc_generic (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:856
#24 0x00007f0bb4882975 in _mi_page_malloc (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, page=0x7f0bb488f8c0 <_mi_page_empty>, size=size@entry=40) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:32
#25 0x00007f0bb48830f3 in mi_heap_malloc_small (heap=0x7f0bb4898720 <_mi_heap_main>, size=32) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:83
#26 0x00007f0bb4884001 in mi_heap_malloc (size=32, heap=0x7f0bb4898720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:101
#27 _mi_heap_malloc_zero (heap=heap@entry=0x7f0bb4898720 <_mi_heap_main>, size=32, zero=zero@entry=true) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:151
#28 0x00007f0bb4884370 in mi_heap_zalloc (size=<optimized out>, heap=0x7f0bb4898720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:159
#29 mi_heap_calloc (size=32, count=1, heap=0x7f0bb4898720 <_mi_heap_main>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:597
#30 mi_calloc (count=count@entry=1, size=size@entry=32) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:601
#31 0x00007f0bb3dfcaf8 in _dlerror_run (operate=operate@entry=0x7f0bb3dfc390 <dlsym_doit>, args=args@entry=0x7ffceb5d1520) at dlerror.c:148
#32 0x00007f0bb3dfc410 in __dlsym (handle=<optimized out>, name=name@entry=0x7f0bb4920561 "mmap") at dlsym.c:70
#33 0x00007f0bb4918882 in get_dlsym (symname=symname@entry=0x7f0bb4920561 "mmap", symver=symver@entry=0x0) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/wrappers.c:51
#34 0x00007f0bb49169ed in sb_mmap (addr=addr@entry=0x0, length=length@entry=32, prot=prot@entry=3, flags=flags@entry=34, fd=fd@entry=-1, offset=offset@entry=0)
    at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/memory.c:28
#35 0x00007f0bb4916a61 in malloc (size=32) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/memory.c:50
#36 0x00007f0bb491df56 in __xmalloc (size=16, file=file@entry=0x7f0bb4920048 "/var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c", func=func@entry=0x7f0bb4920540 <__func__.6> "init_env_entries", 
    line=line@entry=563) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsbutil/sb_memory.c:34
#37 0x00007f0bb49155e4 in init_env_entries (prefixes_array=prefixes_array@entry=0x7f0bb492e318 <sbcontext+24>, prefixes_num=prefixes_num@entry=0x7f0bb492e340 <sbcontext+64>, env=env@entry=0x7f0bb4920496 "SANDBOX_DENY", 
    prefixes_env=prefixes_env@entry=0x7ffceb5d7893 "", warn=warn@entry=1) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:563
#38 0x00007f0bb4915760 in sb_process_env_settings () at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:635
#39 0x00007f0bb4915d83 in libsb_init () at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:93
#40 0x00007f0bb4915f14 in before_syscall (dirfd=<optimized out>, sb_nr=-3, func=0x7f0bb4920440 "open_rd", file=0x7f0bb488a438 "/proc/sys/vm/overcommit_memory", flags=0)
    at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:1060
--Type <RET> for more, q to quit, c to continue without paging--c
#41 0x00007f0bb4915f86 in before_syscall_open_int (dirfd=dirfd@entry=-100, sb_nr=<optimized out>, sb_nr@entry=5, func=func@entry=0x7f0bb492101c "open", file=file@entry=0x7f0bb488a438 "/proc/sys/vm/overcommit_memory", flags=flags@entry=0) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/libsandbox.c:1101
#42 0x00007f0bb4919626 in open_DEFAULT (pathname=pathname@entry=0x7f0bb488a438 "/proc/sys/vm/overcommit_memory", flags=flags@entry=0) at /var/tmp/portage/sys-apps/sandbox-3.1/work/sandbox-3.1/libsandbox/wrapper-funcs/__wrapper_simple.c:52
#43 0x00007f0bb487463b in open (__oflag=0, __path=0x7f0bb488a438 "/proc/sys/vm/overcommit_memory") at /usr/include/bits/fcntl2.h:53
#44 os_detect_overcommit () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:231
#45 0x00007f0bb48757a3 in _mi_os_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/os.c:260
#46 0x00007f0bb48897ab in mi_process_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/init.c:523
#47 0x00007f0bb488987a in mi_thread_init () at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/init.c:372
#48 0x00007f0bb488188e in _mi_malloc_generic (heap=heap@entry=0x7f0bb48971c0 <_mi_heap_empty>, size=size@entry=72712) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/page.c:843
#49 0x00007f0bb4883ef5 in mi_heap_malloc (size=72704, heap=0x7f0bb48971c0 <_mi_heap_empty>) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:106
#50 mi_malloc (size=72704) at /var/tmp/portage/dev-libs/mimalloc-2.0.3-r1/work/mimalloc-2.0.3/src/alloc.c:119
#51 0x00007f0bb41e45a4 in ?? () from target:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/libstdc++.so.6
#52 0x00007f0bb496e04e in call_init (env=0x7ffceb5d3ad8, argv=0x7ffceb5d39c8, argc=33, l=<optimized out>) at dl-init.c:74
#53 call_init (l=<optimized out>, argc=33, argv=0x7ffceb5d39c8, env=0x7ffceb5d3ad8) at dl-init.c:30
#54 0x00007f0bb496e134 in _dl_init (main_map=0x7f0bb49901e0, argc=33, argv=0x7ffceb5d39c8, env=0x7ffceb5d3ad8) at dl-init.c:121
#55 0x00007f0bb495f08a in _dl_start_user () from target:/lib64/ld-linux-x86-64.so.2
#56 0x0000000000000021 in ?? ()
Comment 4 Михаил 2022-01-08 11:39:13 UTC
May be libsb_init() must be called before sb_lock() and with disabled syscall handlers.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-01-08 23:37:16 UTC
*** Bug 830458 has been marked as a duplicate of this bug. ***
Comment 6 Михаил 2022-11-16 07:47:28 UTC
Looks like it is fixed. I could not reproduce is with

sys-devel/mold-1.7.0
dev-cpp/tbb-2021.7.0
dev-libs/mimalloc-2.0.7
Comment 7 Michael Gn. Gajda 2023-01-07 13:04:16 UTC
It might be due to other things wrong with my system, but I cannot confirm this working.

Current config:

sh bash 5.1_p16-r2                                                                                        
ld GNU ld (Gentoo 2.38 p4) 2.38 
sys-apps/sandbox:          2.29::gentoo                                                                                                                                                                        
sys-devel/autoconf:        2.71-r5::gentoo           
sys-devel/automake:        1.16.5::gentoo                                                                 
sys-devel/binutils:        2.38-r2::gentoo, 2.39-r4::gentoo                                               
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/clang:           14.0.6-r1::gentoo, 15.0.6::gentoo                                              
sys-devel/gcc:             11.3.1_p20221209::gentoo, 12.2.0::gentoo
sys-devel/gcc-config:      2.8::gentoo                                                                                                                                                                              
sys-devel/libtool:         2.4.7::gentoo                                                                  
sys-devel/llvm:            14.0.6-r2::gentoo, 15.0.6::gentoo                                                                                                                                                        
sys-devel/make:            4.3::gentoo                                                                                                                                                                              
sys-kernel/linux-headers:  5.15-r3::gentoo (virtual/os-headers)                                                                                                                                                     
sys-libs/glibc:            2.36-r5::gentoo    


mold 1.8.0-r1
dev-libs/mimalloc 2.0.7
tbb 2021.7.0-r1


I got the error:
> checking libc path... configure: error: Unable to determine LIBC PATH ()

Tried rebuilding glibc (without mold), did not help. Other packages build without issues.

Current workaround is to build sandbox and glibc without mold, this works.
Comment 8 Marco Scardovi (scardracs) 2023-11-09 21:08:00 UTC
I can confirm sandbox builds correctly with mold-2.3.2