MentOS icon indicating copy to clipboard operation
MentOS copied to clipboard

Function `__kmem_cache_alloc_slab` causes crash during boot.

Open Galfurian opened this issue 7 months ago • 2 comments

The function __kmem_cache_alloc_slab is currently causing a crash during boot.

The problem seems to be related to managing the slab_freelist.

The full backtrace for the bug is:

#0  list_head_pop (head=0xc0530408)
    at libc/inc/sys/list_head.h:151
#1  0xc0027ec7 in __kmem_cache_alloc_slab (cachep=0xc12c0a20, slab_page=0xc05303e0)
    at mentos/src/mem/slab.c:134
#2  0xc0028331 in kmem_cache_alloc (cachep=0xc12c0a20, flags=3264)
    at mentos/src/mem/slab.c:261
#3  0xc000fcfe in ext2_alloc_cache (fs=0xc12d0800)
    at mentos/src/fs/ext2.c:674
#4  0xc0011890 in ext2_get_real_block_index (fs=0xc12d0800, inode=0xf791cdf8, block_index=1)
    at mentos/src/fs/ext2.c:1496
#5  0xc0011c16 in ext2_read_inode_block (fs=0xc12d0800, inode=0xf791cdf8, block_index=1, buffer=0xc13f6000 "...")
    at mentos/src/fs/ext2.c:1597
#6  0xc0011e23 in ext2_read_inode_data (fs=0xc12d0800, inode=0xf791cdf8, inode_index=25, offset=0, nbyte=114624, buffer=0xc1460000 "...")
    at mentos/src/fs/ext2.c:1662
#7  0xc001556a in ext2_read (file=0xc13ec540, buffer=0xc1460000 "...", offset=0, nbyte=114624)
    at mentos/src/fs/ext2.c:2870
#8  0xc000b139 in vfs_read (file=0xc13ec540, buf=0xc1460000, offset=0, nbytes=114624)
    at mentos/src/fs/vfs.c:188
#9  0xc0032fe0 in elf_load_file (task=0xc1408000, file=0xc13ec540, entry=0xc1408088)
    at mentos/src/elf/elf.c:308
#10 0xc002c5be in __load_executable (path=0xc0035a39 "/bin/init", task=0xc1408000, entry=0xc1408088)
    at mentos/src/process/process.c:206
#11 0xc002cc60 in process_create_init (path=0xc0035a39 "/bin/init")
    at mentos/src/process/process.c:373
#12 0xc0000faf in kmain (boot_informations=0x2e0000 <boot_info>)
    at mentos/src/kernel.c:423

Apparently, at some point, the slab_page->slab_freelist->next becomes NULL. Consequently, when it tries to remove list_head_remove(head->next);, we have an error.

Galfurian avatar Jul 18 '24 18:07 Galfurian