public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [mtd?] WARNING in release_mtd_partition
@ 2025-01-31 13:54 syzbot
  2025-02-02  0:45 ` Edward Adam Davis
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: syzbot @ 2025-01-31 13:54 UTC (permalink / raw)
  To: linux-kernel, linux-mtd, miquel.raynal, richard, syzkaller-bugs,
	vigneshr

Hello,

syzbot found the following issue on:

HEAD commit:    2a9f04bde07a Merge tag 'rtc-6.14' of git://git.kernel.org/..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11fe5ddf980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=98d83cc1742b7377
dashboard link: https://syzkaller.appspot.com/bug?extid=074732af3fc6c528f8a0
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14590b24580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=15fe5ddf980000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/89ef40be688f/disk-2a9f04bd.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/7471856a382f/vmlinux-2a9f04bd.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d694ab107faf/bzImage-2a9f04bd.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com

RDX: 0000000000000008 RSI: 0000000000001269 RDI: 0000000000000003
RBP: 0000000000000001 R08: 00007fff4fe6dbf7 R09: 0000000000000007
R10: 0000000000000001 R11: 0000000000000246 R12: 00007f0fdafc421c
R13: 00007f0fdafc4184 R14: 00007f0fdafc4077 R15: 00007f0fdafef570
 </TASK>
------------[ cut here ]------------
WARNING: CPU: 0 PID: 5826 at drivers/mtd/mtdpart.c:37 release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Modules linked in:
CPU: 0 UID: 0 PID: 5826 Comm: syz-executor397 Not tainted 6.13.0-syzkaller-09734-g2a9f04bde07a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
RIP: 0010:release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Code: 00 fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 75 1e 48 8b 7b 38 e8 ef 84 cd fb 48 89 df 5b 5d e9 e5 84 cd fb e8 70 4a 75 fb 90 <0f> 0b 90 eb c2 e8 a5 29 d8 fb eb db 48 89 ef e8 9b 29 d8 fb eb a5
RSP: 0018:ffffc90003e1f828 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffff88802c1d1000 RCX: ffffffff8b417995
RDX: ffff8880310c3c00 RSI: ffffffff86439150 RDI: ffff88802c1d1000
RBP: ffff88802c1d1648 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000004 R11: ffffffff81000130 R12: 0000000000000000
R13: dffffc0000000000 R14: 0000000000000000 R15: 0000000000000000
FS:  000055558b9cd480(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000008 CR3: 0000000034aca000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 mtd_release+0xa0/0xd0 drivers/mtd/mtdcore.c:101
 device_release+0xa1/0x240 drivers/base/core.c:2567
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1e4/0x5a0 lib/kobject.c:737
 put_device+0x1f/0x30 drivers/base/core.c:3773
 add_mtd_device+0xbb3/0x1700 drivers/mtd/mtdcore.c:750
 mtd_add_partition+0x300/0x650 drivers/mtd/mtdpart.c:279
 mtdchar_blkpg_ioctl+0x20d/0x250 drivers/mtd/mtdchar.c:562
 mtdchar_ioctl+0xbbe/0x2050 drivers/mtd/mtdchar.c:1216
 mtdchar_unlocked_ioctl+0xb0/0xf0 drivers/mtd/mtdchar.c:1239
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl fs/ioctl.c:892 [inline]
 __x64_sys_ioctl+0x190/0x200 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0fdaf83199
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff4fe6de58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fff4fe6de70 RCX: 00007f0fdaf83199
RDX: 0000000000000008 RSI: 0000000000001269 RDI: 0000000000000003
RBP: 0000000000000001 R08: 00007fff4fe6dbf7 R09: 0000000000000007
R10: 0000000000000001 R11: 0000000000000246 R12: 00007f0fdafc421c
R13: 00007f0fdafc4184 R14: 00007f0fdafc4077 R15: 00007f0fdafef570
 </TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [syzbot] [mtd?] WARNING in release_mtd_partition
  2025-01-31 13:54 [syzbot] [mtd?] WARNING in release_mtd_partition syzbot
@ 2025-02-02  0:45 ` Edward Adam Davis
  2025-02-02  1:01   ` syzbot
  2025-02-02  1:10 ` Edward Adam Davis
  2025-02-02  1:31 ` [PATCH] mtd: capture device name setting failure when adding mtd Edward Adam Davis
  2 siblings, 1 reply; 9+ messages in thread
From: Edward Adam Davis @ 2025-02-02  0:45 UTC (permalink / raw)
  To: syzbot+074732af3fc6c528f8a0; +Cc: linux-kernel, syzkaller-bugs

#syz test

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 724f917f91ba..a71cd75858e4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -741,7 +741,8 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->dev.type = &mtd_devtype;
 	mtd->dev.class = &mtd_class;
 	mtd->dev.devt = MTD_DEVT(i);
-	dev_set_name(&mtd->dev, "mtd%d", i);
+	if (dev_set_name(&mtd->dev, "mtd%d", i))
+		goto fail_devname;
 	dev_set_drvdata(&mtd->dev, mtd);
 	mtd_check_of_node(mtd);
 	of_node_get(mtd_get_of_node(mtd));
@@ -790,6 +791,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	device_unregister(&mtd->dev);
 fail_added:
 	of_node_put(mtd_get_of_node(mtd));
+fail_devname:
 	idr_remove(&mtd_idr, i);
 fail_locked:
 	mutex_unlock(&mtd_table_mutex);


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [syzbot] [mtd?] WARNING in release_mtd_partition
  2025-02-02  0:45 ` Edward Adam Davis
@ 2025-02-02  1:01   ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2025-02-02  1:01 UTC (permalink / raw)
  To: eadavis, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in sysfs_create_file_ns

R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000000 R14: 00007fb7345a5fa0 R15: 00007fffd549f308
 </TASK>
------------[ cut here ]------------
WARNING: CPU: 1 PID: 6732 at fs/sysfs/file.c:376 sysfs_create_file_ns+0x148/0x1d0 fs/sysfs/file.c:376
Modules linked in:
CPU: 1 UID: 0 PID: 6732 Comm: syz.0.16 Not tainted 6.13.0-syzkaller-ga86bf2283d2c-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
RIP: 0010:sysfs_create_file_ns+0x148/0x1d0 fs/sysfs/file.c:376
Code: e9 03 80 3c 01 00 75 7f 48 8b 7d 30 4d 89 e9 4c 89 e6 8b 4c 24 38 44 8b 44 24 48 e8 02 fb ff ff 89 c5 eb 0e e8 a9 4a 5f ff 90 <0f> 0b 90 bd ea ff ff ff e8 9b 4a 5f ff 48 b8 00 00 00 00 00 fc ff
RSP: 0018:ffffc900031678b0 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 1ffff9200062cf17 RCX: ffffffff8643ddcb
RDX: ffff888031e29e00 RSI: ffffffff82599ea7 RDI: ffff8880615d91a0
RBP: ffff8880615d91a0 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff8f24c880
R13: 0000000000000000 R14: dffffc0000000000 R15: ffff8880615d91d0
FS:  00007fb7352246c0(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055f98dcaf950 CR3: 000000001e686000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 sysfs_create_file include/linux/sysfs.h:788 [inline]
 sysfs_create_files+0x6c/0x1d0 fs/sysfs/file.c:390
 mtd_add_partition_attrs drivers/mtd/mtdpart.c:238 [inline]
 mtd_add_partition+0x32b/0x650 drivers/mtd/mtdpart.c:283
 mtdchar_blkpg_ioctl+0x20d/0x250 drivers/mtd/mtdchar.c:562
 mtdchar_ioctl+0xbbe/0x2050 drivers/mtd/mtdchar.c:1216
 mtdchar_unlocked_ioctl+0xb0/0xf0 drivers/mtd/mtdchar.c:1239
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl fs/ioctl.c:892 [inline]
 __x64_sys_ioctl+0x190/0x200 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb73438cda9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fb735224038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fb7345a5fa0 RCX: 00007fb73438cda9
RDX: 0000000000000008 RSI: 0000000000001269 RDI: 0000000000000003
RBP: 00007fb735224090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000000 R14: 00007fb7345a5fa0 R15: 00007fffd549f308
 </TASK>


Tested on:

commit:         a86bf228 Merge tag 'pull-misc' of git://git.kernel.org..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1451fddf980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=714e7008e8c086ea
dashboard link: https://syzkaller.appspot.com/bug?extid=074732af3fc6c528f8a0
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=17c1fddf980000


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [syzbot] [mtd?] WARNING in release_mtd_partition
  2025-01-31 13:54 [syzbot] [mtd?] WARNING in release_mtd_partition syzbot
  2025-02-02  0:45 ` Edward Adam Davis
@ 2025-02-02  1:10 ` Edward Adam Davis
  2025-02-02  1:32   ` syzbot
  2025-02-02  1:31 ` [PATCH] mtd: capture device name setting failure when adding mtd Edward Adam Davis
  2 siblings, 1 reply; 9+ messages in thread
From: Edward Adam Davis @ 2025-02-02  1:10 UTC (permalink / raw)
  To: syzbot+074732af3fc6c528f8a0; +Cc: linux-kernel, syzkaller-bugs

#syz test

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 724f917f91ba..a71cd75858e4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -741,7 +741,8 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->dev.type = &mtd_devtype;
 	mtd->dev.class = &mtd_class;
 	mtd->dev.devt = MTD_DEVT(i);
-	dev_set_name(&mtd->dev, "mtd%d", i);
+	if (error = dev_set_name(&mtd->dev, "mtd%d", i))
+		goto fail_devname;
 	dev_set_drvdata(&mtd->dev, mtd);
 	mtd_check_of_node(mtd);
 	of_node_get(mtd_get_of_node(mtd));
@@ -790,6 +791,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	device_unregister(&mtd->dev);
 fail_added:
 	of_node_put(mtd_get_of_node(mtd));
+fail_devname:
 	idr_remove(&mtd_idr, i);
 fail_locked:
 	mutex_unlock(&mtd_table_mutex);


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] mtd: capture device name setting failure when adding mtd
  2025-01-31 13:54 [syzbot] [mtd?] WARNING in release_mtd_partition syzbot
  2025-02-02  0:45 ` Edward Adam Davis
  2025-02-02  1:10 ` Edward Adam Davis
@ 2025-02-02  1:31 ` Edward Adam Davis
  2025-02-06 16:58   ` Miquel Raynal
  2 siblings, 1 reply; 9+ messages in thread
From: Edward Adam Davis @ 2025-02-02  1:31 UTC (permalink / raw)
  To: syzbot+074732af3fc6c528f8a0
  Cc: linux-kernel, linux-mtd, miquel.raynal, richard, syzkaller-bugs,
	vigneshr

syzbot reported a WARNING in release_mtd_partition. [1]

The reproducer uses "/proc/thread-self/fail-nth" to trigger the failure
of memory allocation when executing dev_set_name() in add_mtd_device(),
which eventually causes device_register() to fail because the device name
is not set, and finally triggers a warning in put_device().

[1]
WARNING: CPU: 0 PID: 5826 at drivers/mtd/mtdpart.c:37 release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Modules linked in:
CPU: 0 UID: 0 PID: 5826 Comm: syz-executor397 Not tainted 6.13.0-syzkaller-09734-g2a9f04bde07a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
RIP: 0010:release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Code: 00 fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 75 1e 48 8b 7b 38 e8 ef 84 cd fb 48 89 df 5b 5d e9 e5 84 cd fb e8 70 4a 75 fb 90 <0f> 0b 90 eb c2 e8 a5 29 d8 fb eb db 48 89 ef e8 9b 29 d8 fb eb a5
RSP: 0018:ffffc90003e1f828 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffff88802c1d1000 RCX: ffffffff8b417995
RDX: ffff8880310c3c00 RSI: ffffffff86439150 RDI: ffff88802c1d1000
RBP: ffff88802c1d1648 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000004 R11: ffffffff81000130 R12: 0000000000000000
R13: dffffc0000000000 R14: 0000000000000000 R15: 0000000000000000
FS:  000055558b9cd480(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000008 CR3: 0000000034aca000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 mtd_release+0xa0/0xd0 drivers/mtd/mtdcore.c:101
 device_release+0xa1/0x240 drivers/base/core.c:2567
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1e4/0x5a0 lib/kobject.c:737
 put_device+0x1f/0x30 drivers/base/core.c:3773
 add_mtd_device+0xbb3/0x1700 drivers/mtd/mtdcore.c:750
 mtd_add_partition+0x300/0x650 drivers/mtd/mtdpart.c:279
 mtdchar_blkpg_ioctl+0x20d/0x250 drivers/mtd/mtdchar.c:562
 mtdchar_ioctl+0xbbe/0x2050 drivers/mtd/mtdchar.c:1216
 mtdchar_unlocked_ioctl+0xb0/0xf0 drivers/mtd/mtdchar.c:1239
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl fs/ioctl.c:892 [inline]
 __x64_sys_ioctl+0x190/0x200 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=074732af3fc6c528f8a0
Tested-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 drivers/mtd/mtdcore.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 724f917f91ba..a71cd75858e4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -741,7 +741,8 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->dev.type = &mtd_devtype;
 	mtd->dev.class = &mtd_class;
 	mtd->dev.devt = MTD_DEVT(i);
-	dev_set_name(&mtd->dev, "mtd%d", i);
+	if (error = dev_set_name(&mtd->dev, "mtd%d", i))
+		goto fail_devname;
 	dev_set_drvdata(&mtd->dev, mtd);
 	mtd_check_of_node(mtd);
 	of_node_get(mtd_get_of_node(mtd));
@@ -790,6 +791,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	device_unregister(&mtd->dev);
 fail_added:
 	of_node_put(mtd_get_of_node(mtd));
+fail_devname:
 	idr_remove(&mtd_idr, i);
 fail_locked:
 	mutex_unlock(&mtd_table_mutex);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [syzbot] [mtd?] WARNING in release_mtd_partition
  2025-02-02  1:10 ` Edward Adam Davis
@ 2025-02-02  1:32   ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2025-02-02  1:32 UTC (permalink / raw)
  To: eadavis, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com
Tested-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com

Tested on:

commit:         a86bf228 Merge tag 'pull-misc' of git://git.kernel.org..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14bfcb24580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=714e7008e8c086ea
dashboard link: https://syzkaller.appspot.com/bug?extid=074732af3fc6c528f8a0
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=115cd5f8580000

Note: testing is done by a robot and is best-effort only.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mtd: capture device name setting failure when adding mtd
  2025-02-02  1:31 ` [PATCH] mtd: capture device name setting failure when adding mtd Edward Adam Davis
@ 2025-02-06 16:58   ` Miquel Raynal
  2025-02-07 12:10     ` [PATCH V2] " Edward Adam Davis
  0 siblings, 1 reply; 9+ messages in thread
From: Miquel Raynal @ 2025-02-06 16:58 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: syzbot+074732af3fc6c528f8a0, linux-kernel, linux-mtd, richard,
	syzkaller-bugs, vigneshr

Hello Edward,

> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 724f917f91ba..a71cd75858e4 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -741,7 +741,8 @@ int add_mtd_device(struct mtd_info *mtd)
>  	mtd->dev.type = &mtd_devtype;
>  	mtd->dev.class = &mtd_class;
>  	mtd->dev.devt = MTD_DEVT(i);
> -	dev_set_name(&mtd->dev, "mtd%d", i);
> +	if (error = dev_set_name(&mtd->dev, "mtd%d", i))

Thanks a lot for the analyse and for fixing this. May I ask however to
follow a more common pattern for error checking that is:

       error = dev_set_name(...);
       if (error)
                goto...

This way it is closer to the usual error handling and also aligned with
the rest of the file.

Otherwise LGTM.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V2] mtd: capture device name setting failure when adding mtd
  2025-02-06 16:58   ` Miquel Raynal
@ 2025-02-07 12:10     ` Edward Adam Davis
  2025-02-07 14:46       ` Miquel Raynal
  0 siblings, 1 reply; 9+ messages in thread
From: Edward Adam Davis @ 2025-02-07 12:10 UTC (permalink / raw)
  To: miquel.raynal
  Cc: eadavis, linux-kernel, linux-mtd, richard, syzkaller-bugs,
	vigneshr

syzbot reported a WARNING in release_mtd_partition. [1]

The reproducer uses "/proc/thread-self/fail-nth" to trigger the failure
of memory allocation when executing dev_set_name() in add_mtd_device(),
which eventually causes device_register() to fail because the device name
is not set, and finally triggers a warning in put_device().

[1]
WARNING: CPU: 0 PID: 5826 at drivers/mtd/mtdpart.c:37 release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Modules linked in:
CPU: 0 UID: 0 PID: 5826 Comm: syz-executor397 Not tainted 6.13.0-syzkaller-09734-g2a9f04bde07a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
RIP: 0010:release_mtd_partition+0x71/0x90 drivers/mtd/mtdpart.c:37
Code: 00 fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 75 1e 48 8b 7b 38 e8 ef 84 cd fb 48 89 df 5b 5d e9 e5 84 cd fb e8 70 4a 75 fb 90 <0f> 0b 90 eb c2 e8 a5 29 d8 fb eb db 48 89 ef e8 9b 29 d8 fb eb a5
RSP: 0018:ffffc90003e1f828 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffff88802c1d1000 RCX: ffffffff8b417995
RDX: ffff8880310c3c00 RSI: ffffffff86439150 RDI: ffff88802c1d1000
RBP: ffff88802c1d1648 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000004 R11: ffffffff81000130 R12: 0000000000000000
R13: dffffc0000000000 R14: 0000000000000000 R15: 0000000000000000
FS:  000055558b9cd480(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000008 CR3: 0000000034aca000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 mtd_release+0xa0/0xd0 drivers/mtd/mtdcore.c:101
 device_release+0xa1/0x240 drivers/base/core.c:2567
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1e4/0x5a0 lib/kobject.c:737
 put_device+0x1f/0x30 drivers/base/core.c:3773
 add_mtd_device+0xbb3/0x1700 drivers/mtd/mtdcore.c:750
 mtd_add_partition+0x300/0x650 drivers/mtd/mtdpart.c:279
 mtdchar_blkpg_ioctl+0x20d/0x250 drivers/mtd/mtdchar.c:562
 mtdchar_ioctl+0xbbe/0x2050 drivers/mtd/mtdchar.c:1216
 mtdchar_unlocked_ioctl+0xb0/0xf0 drivers/mtd/mtdchar.c:1239
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl fs/ioctl.c:892 [inline]
 __x64_sys_ioctl+0x190/0x200 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=074732af3fc6c528f8a0
Tested-by: syzbot+074732af3fc6c528f8a0@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
V1 -> V2: adjust "common pattern for error checking"

 drivers/mtd/mtdcore.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 724f917f91ba..b80d5098d276 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -741,7 +741,9 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->dev.type = &mtd_devtype;
 	mtd->dev.class = &mtd_class;
 	mtd->dev.devt = MTD_DEVT(i);
-	dev_set_name(&mtd->dev, "mtd%d", i);
+	error = dev_set_name(&mtd->dev, "mtd%d", i);
+	if (error)
+		goto fail_devname;
 	dev_set_drvdata(&mtd->dev, mtd);
 	mtd_check_of_node(mtd);
 	of_node_get(mtd_get_of_node(mtd));
@@ -790,6 +792,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	device_unregister(&mtd->dev);
 fail_added:
 	of_node_put(mtd_get_of_node(mtd));
+fail_devname:
 	idr_remove(&mtd_idr, i);
 fail_locked:
 	mutex_unlock(&mtd_table_mutex);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V2] mtd: capture device name setting failure when adding mtd
  2025-02-07 12:10     ` [PATCH V2] " Edward Adam Davis
@ 2025-02-07 14:46       ` Miquel Raynal
  0 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2025-02-07 14:46 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: linux-kernel, linux-mtd, richard, syzkaller-bugs, vigneshr

On Fri, 07 Feb 2025 20:10:35 +0800, Edward Adam Davis wrote:
> syzbot reported a WARNING in release_mtd_partition. [1]
> 
> The reproducer uses "/proc/thread-self/fail-nth" to trigger the failure
> of memory allocation when executing dev_set_name() in add_mtd_device(),
> which eventually causes device_register() to fail because the device name
> is not set, and finally triggers a warning in put_device().
> 
> [...]

Applied to mtd/next, thanks!

[1/1] mtd: capture device name setting failure when adding mtd
      commit: 3f930a52d7151addefa6d5ba9f7f2c17dc52db1d

Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-07 14:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-31 13:54 [syzbot] [mtd?] WARNING in release_mtd_partition syzbot
2025-02-02  0:45 ` Edward Adam Davis
2025-02-02  1:01   ` syzbot
2025-02-02  1:10 ` Edward Adam Davis
2025-02-02  1:32   ` syzbot
2025-02-02  1:31 ` [PATCH] mtd: capture device name setting failure when adding mtd Edward Adam Davis
2025-02-06 16:58   ` Miquel Raynal
2025-02-07 12:10     ` [PATCH V2] " Edward Adam Davis
2025-02-07 14:46       ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox