[syzbot] [usb?] memory leak in class_create

11 views
Skip to first unread message

syzbot

unread,
May 1, 2023, 12:53:46ā€ÆPM5/1/23
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 22b8cc3e78f5 Merge tag 'x86_mm_for_6.4' of git://git.kerne..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16fc7958280000
kernel config: https://syzkaller.appspot.com/x/.config?x=5046ebeca744dd40
dashboard link: https://syzkaller.appspot.com/bug?extid=e7afd76ad060fa0d2605
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1599a2b4280000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14eb395fc80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/3ad2088c196b/disk-22b8cc3e.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/61919a5b89c6/vmlinux-22b8cc3e.xz
kernel image: https://storage.googleapis.com/syzbot-assets/a7adb5503ac8/bzImage-22b8cc3e.xz

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

BUG: memory leak
unreferenced object 0xffff88810af67080 (size 96):
comm "kworker/0:2", pid 4402, jiffies 4294950769 (age 14.190s)
hex dump (first 32 bytes):
bf 03 9b 85 ff ff ff ff 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff81544e14>] kmalloc_trace+0x24/0x90 mm/slab_common.c:1057
[<ffffffff82b65445>] kmalloc include/linux/slab.h:559 [inline]
[<ffffffff82b65445>] kzalloc include/linux/slab.h:680 [inline]
[<ffffffff82b65445>] class_create+0x25/0x90 drivers/base/class.c:261
[<ffffffff831f7a80>] init_usb_class drivers/usb/core/file.c:91 [inline]
[<ffffffff831f7a80>] usb_register_dev+0x290/0x3d0 drivers/usb/core/file.c:179
[<ffffffff832cffc4>] usblp_probe+0x4e4/0x750 drivers/usb/class/usblp.c:1208
[<ffffffff831f39a9>] usb_probe_interface+0x179/0x3c0 drivers/usb/core/driver.c:396
[<ffffffff82b62d7d>] call_driver_probe drivers/base/dd.c:579 [inline]
[<ffffffff82b62d7d>] really_probe+0x12d/0x430 drivers/base/dd.c:658
[<ffffffff82b63141>] __driver_probe_device+0xc1/0x1a0 drivers/base/dd.c:800
[<ffffffff82b6324a>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:830
[<ffffffff82b6343b>] __device_attach_driver+0xfb/0x150 drivers/base/dd.c:958
[<ffffffff82b60191>] bus_for_each_drv+0xc1/0x110 drivers/base/bus.c:457
[<ffffffff82b63962>] __device_attach+0x102/0x2a0 drivers/base/dd.c:1030
[<ffffffff82b618fa>] bus_probe_device+0xca/0xd0 drivers/base/bus.c:532
[<ffffffff82b5def3>] device_add+0x993/0xc60 drivers/base/core.c:3625
[<ffffffff831f0a89>] usb_set_configuration+0x9a9/0xc90 drivers/usb/core/message.c:2211
[<ffffffff832033a1>] usb_generic_driver_probe+0xa1/0x100 drivers/usb/core/generic.c:238
[<ffffffff831f3080>] usb_probe_device+0x60/0x140 drivers/usb/core/driver.c:293

BUG: memory leak
unreferenced object 0xffff8881051f1a00 (size 512):
comm "kworker/0:2", pid 4402, jiffies 4294950769 (age 14.190s)
hex dump (first 32 bytes):
00 1a 1f 05 81 88 ff ff 00 1a 1f 05 81 88 ff ff ................
00 00 00 00 00 00 00 00 bf 03 9b 85 ff ff ff ff ................
backtrace:
[<ffffffff81544e14>] kmalloc_trace+0x24/0x90 mm/slab_common.c:1057
[<ffffffff82b65308>] kmalloc include/linux/slab.h:559 [inline]
[<ffffffff82b65308>] kzalloc include/linux/slab.h:680 [inline]
[<ffffffff82b65308>] class_register+0x28/0x140 drivers/base/class.c:186
[<ffffffff82b65467>] class_create+0x47/0x90 drivers/base/class.c:270
[<ffffffff831f7a80>] init_usb_class drivers/usb/core/file.c:91 [inline]
[<ffffffff831f7a80>] usb_register_dev+0x290/0x3d0 drivers/usb/core/file.c:179
[<ffffffff832cffc4>] usblp_probe+0x4e4/0x750 drivers/usb/class/usblp.c:1208
[<ffffffff831f39a9>] usb_probe_interface+0x179/0x3c0 drivers/usb/core/driver.c:396
[<ffffffff82b62d7d>] call_driver_probe drivers/base/dd.c:579 [inline]
[<ffffffff82b62d7d>] really_probe+0x12d/0x430 drivers/base/dd.c:658
[<ffffffff82b63141>] __driver_probe_device+0xc1/0x1a0 drivers/base/dd.c:800
[<ffffffff82b6324a>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:830
[<ffffffff82b6343b>] __device_attach_driver+0xfb/0x150 drivers/base/dd.c:958
[<ffffffff82b60191>] bus_for_each_drv+0xc1/0x110 drivers/base/bus.c:457
[<ffffffff82b63962>] __device_attach+0x102/0x2a0 drivers/base/dd.c:1030
[<ffffffff82b618fa>] bus_probe_device+0xca/0xd0 drivers/base/bus.c:532
[<ffffffff82b5def3>] device_add+0x993/0xc60 drivers/base/core.c:3625
[<ffffffff831f0a89>] usb_set_configuration+0x9a9/0xc90 drivers/usb/core/message.c:2211
[<ffffffff832033a1>] usb_generic_driver_probe+0xa1/0x100 drivers/usb/core/generic.c:238



---
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 syzk...@googlegroups.com.

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

If the bug is already fixed, 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 change bug's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

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

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

Alan Stern

unread,
May 1, 2023, 3:16:47ā€ÆPM5/1/23
to syzbot, gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
There is definitely a memory leak in usb_register_dev()'s error pathways
-- it doesn't call destroy_usb_class() -- but I don't think that is the
cause of this bug. Let's try some diagnostics.

Alan Stern

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ 22b8cc3e78f5

Index: usb-devel/drivers/usb/core/file.c
===================================================================
--- usb-devel.orig/drivers/usb/core/file.c
+++ usb-devel/drivers/usb/core/file.c
@@ -209,6 +209,8 @@ int usb_register_dev(struct usb_interfac
retval = PTR_ERR(intf->usb_dev);
}
up_write(&minor_rwsem);
+ dev_info(&intf->dev, "Post class create: refcount %d\n",
+ atomic_read(&usb_class->kref.refcount.refs));
return retval;
}
EXPORT_SYMBOL_GPL(usb_register_dev);
@@ -242,6 +244,8 @@ void usb_deregister_dev(struct usb_inter

intf->usb_dev = NULL;
intf->minor = -1;
+ dev_info(&intf->dev, "Pre class destroy: refcount %d\n",
+ atomic_read(&usb_class->kref.refcount.refs));
destroy_usb_class();
}
EXPORT_SYMBOL_GPL(usb_deregister_dev);

syzbot

unread,
May 1, 2023, 3:37:25ā€ÆPM5/1/23
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, raf...@kernel.org, st...@rowland.harvard.edu, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in class_create

BUG: memory leak
unreferenced object 0xffff88810a6af480 (size 96):
comm "kworker/0:2", pid 1755, jiffies 4294944661 (age 9.520s)
hex dump (first 32 bytes):
c7 03 9b 85 ff ff ff ff 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff81544e14>] kmalloc_trace+0x24/0x90 mm/slab_common.c:1057
[<ffffffff82b65445>] kmalloc include/linux/slab.h:559 [inline]
[<ffffffff82b65445>] kzalloc include/linux/slab.h:680 [inline]
[<ffffffff82b65445>] class_create+0x25/0x90 drivers/base/class.c:261
[<ffffffff831f7a9b>] init_usb_class drivers/usb/core/file.c:91 [inline]
[<ffffffff831f7a9b>] usb_register_dev+0x2ab/0x3e0 drivers/usb/core/file.c:179
[<ffffffff832cfff4>] usblp_probe+0x4e4/0x750 drivers/usb/class/usblp.c:1208
[<ffffffff831f39a9>] usb_probe_interface+0x179/0x3c0 drivers/usb/core/driver.c:396
[<ffffffff82b62d7d>] call_driver_probe drivers/base/dd.c:579 [inline]
[<ffffffff82b62d7d>] really_probe+0x12d/0x430 drivers/base/dd.c:658
[<ffffffff82b63141>] __driver_probe_device+0xc1/0x1a0 drivers/base/dd.c:800
[<ffffffff82b6324a>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:830
[<ffffffff82b6343b>] __device_attach_driver+0xfb/0x150 drivers/base/dd.c:958
[<ffffffff82b60191>] bus_for_each_drv+0xc1/0x110 drivers/base/bus.c:457
[<ffffffff82b63962>] __device_attach+0x102/0x2a0 drivers/base/dd.c:1030
[<ffffffff82b618fa>] bus_probe_device+0xca/0xd0 drivers/base/bus.c:532
[<ffffffff82b5def3>] device_add+0x993/0xc60 drivers/base/core.c:3625
[<ffffffff831f0a89>] usb_set_configuration+0x9a9/0xc90 drivers/usb/core/message.c:2211
[<ffffffff832033d1>] usb_generic_driver_probe+0xa1/0x100 drivers/usb/core/generic.c:238
[<ffffffff831f3080>] usb_probe_device+0x60/0x140 drivers/usb/core/driver.c:293

BUG: memory leak
unreferenced object 0xffff888114088c00 (size 512):
comm "kworker/0:2", pid 1755, jiffies 4294944661 (age 9.520s)
hex dump (first 32 bytes):
00 8c 08 14 81 88 ff ff 00 8c 08 14 81 88 ff ff ................
00 00 00 00 00 00 00 00 c7 03 9b 85 ff ff ff ff ................
backtrace:
[<ffffffff81544e14>] kmalloc_trace+0x24/0x90 mm/slab_common.c:1057
[<ffffffff82b65308>] kmalloc include/linux/slab.h:559 [inline]
[<ffffffff82b65308>] kzalloc include/linux/slab.h:680 [inline]
[<ffffffff82b65308>] class_register+0x28/0x140 drivers/base/class.c:186
[<ffffffff82b65467>] class_create+0x47/0x90 drivers/base/class.c:270
[<ffffffff831f7a9b>] init_usb_class drivers/usb/core/file.c:91 [inline]
[<ffffffff831f7a9b>] usb_register_dev+0x2ab/0x3e0 drivers/usb/core/file.c:179
[<ffffffff832cfff4>] usblp_probe+0x4e4/0x750 drivers/usb/class/usblp.c:1208
[<ffffffff831f39a9>] usb_probe_interface+0x179/0x3c0 drivers/usb/core/driver.c:396
[<ffffffff82b62d7d>] call_driver_probe drivers/base/dd.c:579 [inline]
[<ffffffff82b62d7d>] really_probe+0x12d/0x430 drivers/base/dd.c:658
[<ffffffff82b63141>] __driver_probe_device+0xc1/0x1a0 drivers/base/dd.c:800
[<ffffffff82b6324a>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:830
[<ffffffff82b6343b>] __device_attach_driver+0xfb/0x150 drivers/base/dd.c:958
[<ffffffff82b60191>] bus_for_each_drv+0xc1/0x110 drivers/base/bus.c:457
[<ffffffff82b63962>] __device_attach+0x102/0x2a0 drivers/base/dd.c:1030
[<ffffffff82b618fa>] bus_probe_device+0xca/0xd0 drivers/base/bus.c:532
[<ffffffff82b5def3>] device_add+0x993/0xc60 drivers/base/core.c:3625
[<ffffffff831f0a89>] usb_set_configuration+0x9a9/0xc90 drivers/usb/core/message.c:2211
[<ffffffff832033d1>] usb_generic_driver_probe+0xa1/0x100 drivers/usb/core/generic.c:238



Tested on:

commit: 22b8cc3e Merge tag 'x86_mm_for_6.4' of git://git.kerne..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=14569d94280000
kernel config: https://syzkaller.appspot.com/x/.config?x=5046ebeca744dd40
dashboard link: https://syzkaller.appspot.com/bug?extid=e7afd76ad060fa0d2605
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=138259d7c80000

Greg KH

unread,
May 16, 2023, 9:54:51ā€ÆAM5/16/23
to syzbot, linux-...@vger.kernel.org, linu...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
On Mon, May 01, 2023 at 09:53:45AM -0700, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 22b8cc3e78f5 Merge tag 'x86_mm_for_6.4' of git://git.kerne..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=16fc7958280000
> kernel config: https://syzkaller.appspot.com/x/.config?x=5046ebeca744dd40
> dashboard link: https://syzkaller.appspot.com/bug?extid=e7afd76ad060fa0d2605
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1599a2b4280000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14eb395fc80000
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/3ad2088c196b/disk-22b8cc3e.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/61919a5b89c6/vmlinux-22b8cc3e.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/a7adb5503ac8/bzImage-22b8cc3e.xz

diff --git a/drivers/base/class.c b/drivers/base/class.c
index ac1808d1a2e8..9b44edc8416f 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -320,6 +322,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class,
start_knode = &start->p->knode_class;
klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode);
iter->type = type;
+ iter->sp = sp;
}
EXPORT_SYMBOL_GPL(class_dev_iter_init);

@@ -361,6 +364,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_next);
void class_dev_iter_exit(struct class_dev_iter *iter)
{
klist_iter_exit(&iter->ki);
+ subsys_put(iter->sp);
}
EXPORT_SYMBOL_GPL(class_dev_iter_exit);

diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 9deeaeb457bb..abf3d3bfb6fe 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -74,6 +74,7 @@ struct class {
struct class_dev_iter {
struct klist_iter ki;
const struct device_type *type;
+ struct subsys_private *sp;
};

int __must_check class_register(const struct class *class);

syzbot

unread,
May 16, 2023, 10:27:21ā€ÆAM5/16/23
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-and-tested-by: syzbot+e7afd7...@syzkaller.appspotmail.com

Tested on:

commit: 22b8cc3e Merge tag 'x86_mm_for_6.4' of git://git.kerne..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
console output: https://syzkaller.appspot.com/x/log.txt?x=16eedb6e280000
kernel config: https://syzkaller.appspot.com/x/.config?x=c317b48f2c445e87
dashboard link: https://syzkaller.appspot.com/bug?extid=e7afd76ad060fa0d2605
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=17ed8b21280000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages