Re: tty: memory leak in tty_register_driver

From: Dmitry Vyukov
Date: Sun Feb 28 2016 - 11:42:55 EST


On Mon, Feb 15, 2016 at 11:42 AM, Dmitry Vyukov <dvyukov@xxxxxxxxxx> wrote:
> Hello,
>
> When I am running the following program in a parallel loop, kmemleak
> starts reporting memory leaks of objects allocated in
> tty_register_driver during boot. These leaks start popping up
> chaotically and as you can see they originate in different drivers
> (synclinkmp_init, isdn_init, chr_dev_init, sysfs_init).
>
> On commit 388f7b1d6e8ca06762e2454d28d6c3c55ad0fe95 (4.5-rc3).
>
> // autogenerated by syzkaller (http://github.com/google/syzkaller)
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <sys/ioctl.h>
>
> int main()
> {
> int fd, val;
>
> fd = open("/dev/ptmx", O_RDWR);
> val = 21;
> ioctl(fd, TIOCSETD, &val);
> return 0;
> }
>
> unreferenced object 0xffff88006708dc20 (size 8):
> comm "swapper/0", pid 1, jiffies 4294672590 (age 930.839s)
> hex dump (first 8 bytes):
> 74 74 79 53 4c 4d 38 00 ttySLM8.
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff88006709b330 (size 152):
> comm "swapper/0", pid 1, jiffies 4294672590 (age 930.839s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> [<ffffffff866617af>] ret_from_fork+0x3f/0x70 arch/x86/entry/entry_64.S:468
> unreferenced object 0xffff88006708d860 (size 8):
> comm "swapper/0", pid 1, jiffies 4294672591 (age 930.838s)
> hex dump (first 8 bytes):
> 74 74 79 53 4c 4d 39 00 ttySLM9.
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff88006709a490 (size 152):
> comm "swapper/0", pid 1, jiffies 4294672591 (age 930.853s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> [<ffffffff866617af>] ret_from_fork+0x3f/0x70 arch/x86/entry/entry_64.S:468
> unreferenced object 0xffff880064f3c960 (size 8):
> comm "swapper/0", pid 1, jiffies 4294674404 (age 929.065s)
> hex dump (first 8 bytes):
> 74 74 79 49 31 30 00 ff ttyI10..
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff848b4ef8>] isdn_tty_modem_init+0x3a8/0x1220
> drivers/isdn/i4l/isdn_tty.c:1785
> [<ffffffff889ed622>] isdn_init+0x2c3/0x505
> drivers/isdn/i4l/isdn_common.c:2334
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> unreferenced object 0xffff880064f41380 (size 152):
> comm "swapper/0", pid 1, jiffies 4294674404 (age 929.066s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff848b4ef8>] isdn_tty_modem_init+0x3a8/0x1220
> drivers/isdn/i4l/isdn_tty.c:1785
> [<ffffffff889ed622>] isdn_init+0x2c3/0x505
> drivers/isdn/i4l/isdn_common.c:2334
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> unreferenced object 0xffff88006717e960 (size 8):
> comm "swapper/0", pid 1, jiffies 4294672708 (age 973.931s)
> hex dump (first 8 bytes):
> 32 33 37 3a 31 38 39 00 237:189.
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff880067169ad0 (size 152):
> comm "swapper/0", pid 1, jiffies 4294672708 (age 973.931s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> [<ffffffff866617af>] ret_from_fork+0x3f/0x70 arch/x86/entry/entry_64.S:468
> unreferenced object 0xffff88006717eb40 (size 8):
> comm "swapper/0", pid 1, jiffies 4294672709 (age 973.930s)
> hex dump (first 8 bytes):
> 32 33 37 3a 31 39 30 00 237:190.
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff8800363ffa80 (size 152):
> comm "swapper/0", pid 1, jiffies 4294672709 (age 973.962s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> [<ffffffff866617af>] ret_from_fork+0x3f/0x70 arch/x86/entry/entry_64.S:468
> unreferenced object 0xffff88006717ed20 (size 8):
> comm "swapper/0", pid 1, jiffies 4294672711 (age 973.960s)
> hex dump (first 8 bytes):
> 32 33 37 3a 31 39 31 00 237:191.
> backtrace:
> [<ffffffff81765d10>] __kmalloc_track_caller+0x1b0/0x320 mm/slub.c:4068
> [<ffffffff816b37a9>] kstrdup+0x39/0x70 mm/util.c:53
> [<ffffffff816b3826>] kstrdup_const+0x46/0x60 mm/util.c:74
> [<ffffffff8194e5bb>] __kernfs_new_node+0x2b/0x2b0 fs/kernfs/dir.c:536
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff8800671c3cf0 (size 152):
> comm "swapper/0", pid 1, jiffies 4294672711 (age 973.960s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_create_sys_dev_entry drivers/base/core.c:974
> [<ffffffff8358a05c>] device_add+0xf9c/0x1480 drivers/base/core.c:1105
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889babcb>] synclinkmp_init+0x35a/0x40e
> drivers/tty/synclinkmp.c:3992
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> [<ffffffff8663ca33>] kernel_init+0x13/0x150 init/main.c:936
> [<ffffffff866617af>] ret_from_fork+0x3f/0x70 arch/x86/entry/entry_64.S:468
> unreferenced object 0xffff88006ca7f5a0 (size 152):
> comm "swapper/0", pid 1, jiffies 4294670068 (age 267.578s)
> hex dump (first 32 bytes):
> 01 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [<ffffffff8194e5fc>] __kernfs_new_node+0x6c/0x2b0 fs/kernfs/dir.c:540
> [<ffffffff81951c70>] kernfs_new_node+0x80/0xe0 fs/kernfs/dir.c:572
> [<ffffffff81957223>] kernfs_create_link+0x33/0x150 fs/kernfs/symlink.c:32
> [<ffffffff81959c4b>] sysfs_do_create_link_sd.isra.2+0x8b/0x120
> fs/sysfs/symlink.c:44
> [< inline >] sysfs_do_create_link fs/sysfs/symlink.c:80
> [<ffffffff81959d45>] sysfs_create_link+0x65/0xc0 fs/sysfs/symlink.c:92
> [< inline >] device_add_class_symlinks drivers/base/core.c:891
> [<ffffffff835897fc>] device_add+0x73c/0x1480 drivers/base/core.c:1086
> [<ffffffff8358a55d>] device_register+0x1d/0x20 drivers/base/core.c:1189
> [<ffffffff82f80b50>] tty_register_device_attr+0x320/0x760
> drivers/tty/tty_io.c:3312
> [< inline >] tty_register_device drivers/tty/tty_io.c:3239
> [<ffffffff82f8133b>] tty_register_driver+0x36b/0x670
> drivers/tty/tty_io.c:3504
> [<ffffffff889b171c>] vty_init+0x366/0x398 drivers/tty/vt/vt.c:3093
> [<ffffffff889af3f6>] tty_init+0x146/0x14a drivers/tty/tty_io.c:3686
> [<ffffffff889bb4e8>] chr_dev_init+0x12a/0x13c drivers/char/mem.c:869
> [<ffffffff81002259>] do_one_initcall+0x159/0x380 init/main.c:794
> [< inline >] do_initcall_level init/main.c:859
> [< inline >] do_initcalls init/main.c:867
> [< inline >] do_basic_setup init/main.c:885
> [<ffffffff888fcc29>] kernel_init_freeable+0x474/0x52d init/main.c:1010
> unreferenced object 0xffff88003de48000 (size 2096):
> comm "swapper/0", pid 0, jiffies 4294667421 (age 186.244s)
> hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 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:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [< inline >] __idr_pre_get lib/idr.c:196
> [<ffffffff82be9253>] ida_pre_get+0x123/0x270 lib/idr.c:899
> [<ffffffff82be9471>] ida_simple_get+0xd1/0x1d0 lib/idr.c:1096
> [<ffffffff8194e622>] __kernfs_new_node+0x92/0x2b0 fs/kernfs/dir.c:544
> [<ffffffff81952906>] kernfs_create_root+0xe6/0x2a0 fs/kernfs/dir.c:782
> [<ffffffff88972422>] sysfs_init+0x18/0x8c fs/sysfs/mount.c:69
> [<ffffffff8896d670>] mnt_init+0x1e0/0x42e fs/namespace.c:3143
> [<ffffffff8896cfdc>] vfs_caches_init+0xaa/0x156 fs/dcache.c:3461
> [<ffffffff888fc718>] start_kernel+0x60c/0x6a9 init/main.c:659
> [<ffffffff888fb350>] x86_64_start_reservations+0x38/0x3a
> arch/x86/kernel/head64.c:203
> [<ffffffff888fb4aa>] x86_64_start_kernel+0x158/0x167
> arch/x86/kernel/head64.c:184
> [<ffffffffffffffff>] 0xffffffffffffffff
> unreferenced object 0xffff88003de4ee58 (size 2096):
> comm "swapper/0", pid 0, jiffies 4294667421 (age 186.244s)
> hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 00 80 e4 3d 00 88 ff ff ...........=....
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace:
> [<ffffffff81761ba3>] kmem_cache_alloc+0x153/0x2e0 mm/slub.c:2609
> [< inline >] kmem_cache_zalloc include/linux/slab.h:597
> [< inline >] __idr_pre_get lib/idr.c:196
> [<ffffffff82be9253>] ida_pre_get+0x123/0x270 lib/idr.c:899
> [<ffffffff82be9471>] ida_simple_get+0xd1/0x1d0 lib/idr.c:1096
> [<ffffffff8194e622>] __kernfs_new_node+0x92/0x2b0 fs/kernfs/dir.c:544
> [<ffffffff81952906>] kernfs_create_root+0xe6/0x2a0 fs/kernfs/dir.c:782
> [<ffffffff88972422>] sysfs_init+0x18/0x8c fs/sysfs/mount.c:69
> [<ffffffff8896d670>] mnt_init+0x1e0/0x42e fs/namespace.c:3143
> [<ffffffff8896cfdc>] vfs_caches_init+0xaa/0x156 fs/dcache.c:3461
> [<ffffffff888fc718>] start_kernel+0x60c/0x6a9 init/main.c:659
> [<ffffffff888fb350>] x86_64_start_reservations+0x38/0x3a
> arch/x86/kernel/head64.c:203
> [<ffffffff888fb4aa>] x86_64_start_kernel+0x158/0x167
> arch/x86/kernel/head64.c:184
> [<ffffffffffffffff>] 0xffffffffffffffff


+Catalin (kmemleak maintainer)

I am noticed a weird thing. I am not 100% sure but it seems that the
leaks are reported iff I run leak checking concurrently with the
programs running. And if I run the program several thousand times and
then run leak checking, then no leaks reported.

Catalin, it is possible that it is a kmemleak false positive?

I see that kmemleak just scans thread stacks one-by-one. I would
expect that kmemleak should stop all threads, then scan all stacks and
all registers of all threads, and then restart threads. If it does not
scan registers or does not stop threads, then I think it should be
possible that a pointer value can sneak off kmemleak. Does it make
sense?