Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
description of repo status
Open Source
>
Other
>
Operation System
&&
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
458
Star
1.7K
Fork
1.9K
GVP
openEuler
/
kernel
Closed
Code
Issues
1271
Pull Requests
991
Wiki
Insights
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
【OLK 5.10】并发创建md设备触发uaf
Done
#I8O6NL
Task
Li Lingfeng
Opened this issue
2023-12-13 20:06
# 问题现象 ``` ================================================================== BUG: KASAN: use-after-free in md_alloc+0xb0/0x660 drivers/md/md.c:5772 Read of size 8 at addr ffff8880927f1048 by task syz-executor.3/11266 CPU: 2 PID: 11266 Comm: syz-executor.3 Tainted: G W 5.10.0-10135-g9ab9d9e426bc-dirty #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:82 [inline] dump_stack+0xbe/0xfd lib/dump_stack.c:123 print_address_description.constprop.0+0x19/0x170 mm/kasan/report.c:400 __kasan_report.cold+0x6c/0x84 mm/kasan/report.c:560 kasan_report+0x3a/0x50 mm/kasan/report.c:585 md_alloc+0xb0/0x660 drivers/md/md.c:5772 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 RIP: 0033:0x45513d Code: 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fee384de058 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 000000000058c050 RCX: 000000000045513d RDX: 0000000000000200 RSI: 0000000020000040 RDI: ffffffffffffff9c RBP: 000000000058c050 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 000000000000006e R14: 0000000000425470 R15: 00007fff476992c0 Allocated by task 11264: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48 kasan_set_track mm/kasan/common.c:56 [inline] set_alloc_info mm/kasan/common.c:512 [inline] __kasan_kmalloc mm/kasan/common.c:544 [inline] __kasan_kmalloc.constprop.0+0xf0/0x130 mm/kasan/common.c:515 kmalloc include/linux/slab.h:563 [inline] kzalloc include/linux/slab.h:675 [inline] mddev_find_or_alloc+0x1d6/0x510 drivers/md/md.c:795 md_alloc+0x26/0x660 drivers/md/md.c:5750 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 Freed by task 11264: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48 kasan_set_track+0x1c/0x30 mm/kasan/common.c:56 kasan_set_free_info+0x20/0x40 mm/kasan/generic.c:384 __kasan_slab_free.part.0+0x13f/0x1b0 mm/kasan/common.c:496 slab_free_hook mm/slub.c:1569 [inline] slab_free_freelist_hook mm/slub.c:1608 [inline] slab_free mm/slub.c:3179 [inline] kfree+0xce/0x860 mm/slub.c:4179 mddev_free drivers/md/md.c:5735 [inline] md_alloc+0x4f6/0x660 drivers/md/md.c:5850 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 The buggy address belongs to the object at ffff8880927f1000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 72 bytes inside of 4096-byte region [ffff8880927f1000, ffff8880927f2000) The buggy address belongs to the page: page:ffffea000249fc00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x927f0 head:ffffea000249fc00 order:3 compound_mapcount:0 compound_pincount:0 flags: 0xfffffc0010200(slab|head|node=0|zone=1|lastcpupid=0x1fffff) raw: 000fffffc0010200 ffffea000240c408 ffffea0002798408 ffff88810004f500 raw: 0000000000000000 0000000000020002 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8880927f0f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff8880927f0f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff8880927f1000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff8880927f1080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff8880927f1100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== ``` # 复现补丁: ``` diff --git a/drivers/md/md.c b/drivers/md/md.c index b0007e936b0f..f2c87061a153 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5753,10 +5753,15 @@ static int md_alloc(dev_t dev, char *name) int shift; int unit; int error; + static int alloc_seq = 1; + + printk("delay in %d alloc\n", alloc_seq++); + mdelay(3000); if (!mddev) return -ENODEV; + printk("use mddev %d\n", alloc_seq); partitioned = (MAJOR(mddev->unit) != MD_MAJOR); shift = partitioned ? MdpMinorShift : 0; unit = MINOR(mddev->unit) >> shift; @@ -5819,9 +5824,11 @@ static int md_alloc(dev_t dev, char *name) disk->flags |= GENHD_FL_EXT_DEVT; disk->events |= DISK_EVENT_MEDIA_CHANGE; mddev->gendisk = disk; - error = add_disk_safe(disk); - if (error) +// error = add_disk_safe(disk); + if (error) { + printk("add disk fail\n"); goto out_put_disk; + } kobject_init(&mddev->kobj, &md_ktype); error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md"); @@ -5848,6 +5855,7 @@ static int md_alloc(dev_t dev, char *name) blk_cleanup_disk(disk); out_free_mddev: mddev_free(mddev); + printk("freed mddev\n"); mutex_unlock(&disks_mutex); return error; } ``` # 复现步骤: ``` echo md0 > /sys/module/md_mod/parameters/new_array & mdadm --create /dev/md0 -l1 -n2 /dev/sda /dev/sdb ```
# 问题现象 ``` ================================================================== BUG: KASAN: use-after-free in md_alloc+0xb0/0x660 drivers/md/md.c:5772 Read of size 8 at addr ffff8880927f1048 by task syz-executor.3/11266 CPU: 2 PID: 11266 Comm: syz-executor.3 Tainted: G W 5.10.0-10135-g9ab9d9e426bc-dirty #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:82 [inline] dump_stack+0xbe/0xfd lib/dump_stack.c:123 print_address_description.constprop.0+0x19/0x170 mm/kasan/report.c:400 __kasan_report.cold+0x6c/0x84 mm/kasan/report.c:560 kasan_report+0x3a/0x50 mm/kasan/report.c:585 md_alloc+0xb0/0x660 drivers/md/md.c:5772 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 RIP: 0033:0x45513d Code: 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fee384de058 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 000000000058c050 RCX: 000000000045513d RDX: 0000000000000200 RSI: 0000000020000040 RDI: ffffffffffffff9c RBP: 000000000058c050 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 000000000000006e R14: 0000000000425470 R15: 00007fff476992c0 Allocated by task 11264: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48 kasan_set_track mm/kasan/common.c:56 [inline] set_alloc_info mm/kasan/common.c:512 [inline] __kasan_kmalloc mm/kasan/common.c:544 [inline] __kasan_kmalloc.constprop.0+0xf0/0x130 mm/kasan/common.c:515 kmalloc include/linux/slab.h:563 [inline] kzalloc include/linux/slab.h:675 [inline] mddev_find_or_alloc+0x1d6/0x510 drivers/md/md.c:795 md_alloc+0x26/0x660 drivers/md/md.c:5750 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 Freed by task 11264: kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48 kasan_set_track+0x1c/0x30 mm/kasan/common.c:56 kasan_set_free_info+0x20/0x40 mm/kasan/generic.c:384 __kasan_slab_free.part.0+0x13f/0x1b0 mm/kasan/common.c:496 slab_free_hook mm/slub.c:1569 [inline] slab_free_freelist_hook mm/slub.c:1608 [inline] slab_free mm/slub.c:3179 [inline] kfree+0xce/0x860 mm/slub.c:4179 mddev_free drivers/md/md.c:5735 [inline] md_alloc+0x4f6/0x660 drivers/md/md.c:5850 md_probe+0x5b/0x70 drivers/md/md.c:5858 kobj_lookup+0x1d3/0x2e0 drivers/base/map.c:152 get_gendisk+0x60/0x260 block/genhd.c:1127 bdev_get_gendisk fs/block_dev.c:1140 [inline] __blkdev_get+0xb5/0x1170 fs/block_dev.c:1567 blkdev_get+0x9b/0x1c0 fs/block_dev.c:1784 blkdev_open+0x14e/0x190 fs/block_dev.c:1901 do_dentry_open+0x310/0x8b0 fs/open.c:817 do_open+0x5b0/0x800 fs/namei.c:3320 path_openat+0x1c2/0x3b0 fs/namei.c:3438 do_filp_open+0x134/0x280 fs/namei.c:3465 do_sys_openat2+0x579/0x790 fs/open.c:1186 do_sys_open fs/open.c:1202 [inline] __do_sys_openat fs/open.c:1218 [inline] __se_sys_openat fs/open.c:1213 [inline] __x64_sys_openat+0xf3/0x180 fs/open.c:1213 do_syscall_64+0x30/0x40 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x62/0xc7 The buggy address belongs to the object at ffff8880927f1000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 72 bytes inside of 4096-byte region [ffff8880927f1000, ffff8880927f2000) The buggy address belongs to the page: page:ffffea000249fc00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x927f0 head:ffffea000249fc00 order:3 compound_mapcount:0 compound_pincount:0 flags: 0xfffffc0010200(slab|head|node=0|zone=1|lastcpupid=0x1fffff) raw: 000fffffc0010200 ffffea000240c408 ffffea0002798408 ffff88810004f500 raw: 0000000000000000 0000000000020002 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8880927f0f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff8880927f0f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff8880927f1000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff8880927f1080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff8880927f1100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== ``` # 复现补丁: ``` diff --git a/drivers/md/md.c b/drivers/md/md.c index b0007e936b0f..f2c87061a153 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5753,10 +5753,15 @@ static int md_alloc(dev_t dev, char *name) int shift; int unit; int error; + static int alloc_seq = 1; + + printk("delay in %d alloc\n", alloc_seq++); + mdelay(3000); if (!mddev) return -ENODEV; + printk("use mddev %d\n", alloc_seq); partitioned = (MAJOR(mddev->unit) != MD_MAJOR); shift = partitioned ? MdpMinorShift : 0; unit = MINOR(mddev->unit) >> shift; @@ -5819,9 +5824,11 @@ static int md_alloc(dev_t dev, char *name) disk->flags |= GENHD_FL_EXT_DEVT; disk->events |= DISK_EVENT_MEDIA_CHANGE; mddev->gendisk = disk; - error = add_disk_safe(disk); - if (error) +// error = add_disk_safe(disk); + if (error) { + printk("add disk fail\n"); goto out_put_disk; + } kobject_init(&mddev->kobj, &md_ktype); error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md"); @@ -5848,6 +5855,7 @@ static int md_alloc(dev_t dev, char *name) blk_cleanup_disk(disk); out_free_mddev: mddev_free(mddev); + printk("freed mddev\n"); mutex_unlock(&disks_mutex); return error; } ``` # 复现步骤: ``` echo md0 > /sys/module/md_mod/parameters/new_array & mdadm --create /dev/md0 -l1 -n2 /dev/sda /dev/sdb ```
Comments (
1
)
Sign in
to comment
Status
Done
Backlog
Doing
Done
Declined
Assignees
Not set
Labels
sig/Kernel
Not set
Projects
Unprojected
Unprojected
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
Duration
(hours)
参与者(2)
C
1
https://gitee.com/openeuler/kernel.git
git@gitee.com:openeuler/kernel.git
openeuler
kernel
kernel
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register