Closed RoyWFHuang closed 1 year ago
At present, CI pipeline was not set, and there is no automated procedure to validate the changes proposed by each pull request.
@RoyWFHuang, could you run make check
and ensure that all tests are passing?
In 5.4 kernel (multipass environment)
Check if exist: drwxr-xr-x 3 dir...Success
Check if exist: -rw-r--r-- 2 file...Success
Check if exist: -rw-r--r-- 2 hdlink...Success
Check if exist: drwxr-xr-x 2 dir...Success
Check if exist: lrwxrwxrwx 1 symlink...Success
but in 5.15 kernel has some problem with
[ 1242.539714] usercopy: Kernel memory exposure attempt detected from SLUB object 'simplefs_cache' (offset 4, size 4)!
[ 1242.549642] ------------[ cut here ]------------
[ 1242.549648] kernel BUG at mm/usercopy.c:99!
[ 1242.552914] invalid opcode: 0000 [#1] SMP PTI
[ 1242.556949] CPU: 0 PID: 1812 Comm: ls Tainted: G OE 5.15.0-78-generic #85-Ubuntu
[ 1242.567873] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015
[ 1242.574281] RIP: 0010:usercopy_abort+0x7b/0x7d
even if I revert my code, it is the same error. So I believe that this is existing problem in kernel 5.15 (upgrade from 5.4)
this seems the same issue with "Random kernel BUG at mm/usercopy.c:99 from SLUB object ", because my environment is the same with the ticket, Ubuntu 20.04 from kernel 5.4 upgrade to 5.15.
So, need more time to validation what's different in kernel 5.4 and 5.15
I see there is a Hardware name: QEMU Standard PC in your trace. Do you use virtual environment to test or the PC ?
Yes, I use multipass environment for test, and the multipass runs on ubuntu host 22.04 kernel 5.15 phyical pc host.
but in 5.15 kernel has some problem with
[ 1242.539714] usercopy: Kernel memory exposure attempt detected from SLUB object 'simplefs_cache' (offset 4, size 4)! [ 1242.549642] ------------[ cut here ]------------ [ 1242.549648] kernel BUG at mm/usercopy.c:99! [ 1242.552914] invalid opcode: 0000 [#1] SMP PTI [ 1242.556949] CPU: 0 PID: 1812 Comm: ls Tainted: G OE 5.15.0-78-generic #85-Ubuntu [ 1242.567873] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 [ 1242.574281] RIP: 0010:usercopy_abort+0x7b/0x7d
even if I revert my code, it is the same error. So I believe that this is existing problem in kernel 5.15 (upgrade from 5.4)
I tend to merge the proposed changes. @fewletter, can you check this patch?
@RoyWFHuang, please file a new issue for the above.
Ok, I can check this commit later.
Create a new issue #30
I write a simple script file which includes creating a directory named temp and mount the file system on this directory.
SIMPLEFS_MOD=simplefs.ko
IMAGE=$1
mkdir -p temp
lsmod && \
make test.img
sudo mount -t simplefs -o loop $IMAGE temp && \
pushd temp >/dev/null
The original code shows the directory can't be correctly read.
fewletter@fewletter-Veriton-M4665G:~/linux_kernel/simplefs$ make simple_check
...
mount: /home/fewletter/linux_kernel/simplefs/temp: mount(2) system call failed: 並不是一個目錄
The new code shows the directory can be correctly read and the file system can mount on the directory correctly.
fewletter@fewletter-Veriton-M4665G:~/linux_kernel/simplefs$ make simple_check
fewletter@fewletter-Veriton-M4665G:~/linux_kernel/simplefs$ df -Th
檔案系統 類型 容量 已用 可用 已用% 掛載點
...
/dev/loop13 simplefs 200M 3.6M 197M 2% /home/fewletter/linux_kernel/simplefs/temp
The results above are been test in 5.15 kernel pc. As for the make check command, I have the same result as RoyWFHuang.
Thank @RoyWFHuang for contributing! I have amended the git commit messages.
Description: In previous linux kernel version (e.g 5.8), ls -la will not show . and .. in root directory
Root cause : In Linux system, there are different way to implement "ls" command. Like Ubuntu system, using glibc. Embedded system using busybox. glibc/ busybox code show in reference
And you can see that the ext2/ ext3/ ext4/ system all skip inode number 0. In kernel document ext4 also say that "There is no inode 0"
In "patchwork - vfs: avoid creation of inode number 0 in get_next_ino" add code to avoid to provide the 0 inode so in 6.3 kernel source code, we can see these patch code
Fix solution: By following ext4 rule, skip inode number 0. When creating image layout in inode section, we skip first block and use next inode (inode number 1) with the root inode. And we also modify the d_make_root, we use inode number 1 for the root inode.
How has this been tested: In kernel 5.15 here is original source code: ubuntu@primary:/home/roy/src-code/github/roy/simplefs/test15$ uname -a Linux primary 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:18:26 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ubuntu@primary:/home/roy/src-code/github/roy/simplefs/test15$ ls -la total 0 In kernel 5.15 here is patch code ubuntu@primary:/home/roy/src-code/github/roy/simplefs/test15$ uname -a Linux primary 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:18:26 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ubuntu@primary:/home/roy/src-code/github/roy/simplefs/test15$ ls -la total 5 drwxrwxr-x 2 root root 4096 Jan 1 1970 . drwxrwxr-x 1 ubuntu ubuntu 4096 Jul 22 22:10 .. In kernel 5.4 here is original source code: ubuntu@vcluster101-vxm:/home/roy/src-code/github/roy/simplefs$ uname -a Linux vcluster101-vxm 5.4.0-153-generic #170-Ubuntu SMP Fri Jun 16 13:43:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ubuntu@vcluster101-vxm:/home/roy/src-code/github/roy/simplefs/test4$ ls -la total 0 In kernel 5.4 here is patch code ubuntu@vcluster101-vxm:/home/roy/src-code/github/roy/simplefs/test4$ uname -a Linux vcluster101-vxm 5.4.0-153-generic #170-Ubuntu SMP Fri Jun 16 13:43:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ubuntu@vcluster101-vxm:/home/roy/src-code/github/roy/simplefs/test4$ ls -la total 5 drwxrwxr-x 2 root root 4096 Jan 1 1970 . drwxrwxr-x 1 ubuntu ubuntu 4096 Jul 22 22:42 ..
references: Glibc may have a patch to fix readdir?, https://sourceware.org/bugzilla/show_bug.cgi?id=19970
glibc implement readdir, https://elixir.bootlin.com/glibc/glibc-2.35.9000/source/sysdeps/unix/sysv/linux/readdir64.c#L31
busybox implement ls, https://github.com/mirror/busybox/blob/2d4a3d9e6c1493a9520b907e07a41aca90cdfd94/coreutils/ls.c#L924
ext2, ext3 ,ext4 file system don't use 0 for root inode, https://stackoverflow.com/questions/2099121/why-do-inode-numbers-start-from-1-and-not-0
Linux kernel document in ext4 file system, https://www.kernel.org/doc/html/latest/filesystems/ext4/inodes.html?highlight=inode
vfs: avoid inode 0, https://patchwork.kernel.org/project/linux-fsdevel/patch/1435245958-4507-1-git-send-email-cmaiolino@redhat.com/
Linux kernel in inode, 6.3 https://elixir.bootlin.com/linux/v6.3.13/source/fs/inode.c#L983
Close #12