Skip to contentSkip to conversation

"Fix spurious sanity check failures in destroy_workqueue()" introduced memory leaks

PATCH New Qian Cai 2 participants 2 messages Sep 20, 2019 Workqueue

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

The linux-next commit [1] introduced a lot of memory leaks while running LTP fs tests (/opt/ltp/runltp -f fs). Reverted the commit fixed the problem. It seems the new code wq->rescuer to NULL without free it first, so later rcu_free_wq() is unable to free it.

unreferenced object 0xffff8f822e7c8428 (size 192):
  comm "fs_fill", pid 8310, jiffies 4294965449 (age 494.720s) hex dump (first 32 bytes):
    28 84 7c 2e 82 8f ff ff 28 84 7c 2e 82 8f ff ff  (.|.....(.|..... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................ backtrace:

    [<0000000030795d2f>] kmem_cache_alloc_node_trace+0x153/0x470
    [<000000000398512e>] alloc_worker+0x21/0x50
    [<000000001934cb3a>] init_rescuer.part.4+0x1d/0xb0
    [<00000000f36417e5>] alloc_workqueue+0x336/0x5f3
    [<0000000011066bf3>] ext4_fill_super+0x1eec/0x2f70 [ext4]
    [<000000001fdee6fd>] mount_bdev+0x191/0x1c0
    [<00000000e2d3e265>] ext4_mount+0x15/0x20 [ext4]
    [<00000000631fe1d9>] legacy_get_tree+0x34/0x60
    [<00000000ee947c38>] vfs_get_tree+0x27/0xb0
    [<00000000f4bcb594>] do_mount+0x8a0/0xae0
    [<0000000005dd5056>] ksys_mount+0xb6/0xd0
    [<00000000fb14e10a>] __x64_sys_mount+0x25/0x30
    [<000000009fb1dd3e>] do_syscall_64+0x6d/0x488
    [<00000000a822a6c4>] entry_SYSCALL_64_after_hwframe+0x49/0xbe

unreferenced object 0xffff8f824c314218 (size 192):
  comm "fs_fill", pid 8310, jiffies 4294966011 (age 489.100s) hex dump (first 32 bytes):
    18 42 31 4c 82 8f ff ff 18 42 31 4c 82 8f ff ff  .B1L.....B1L.... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................ backtrace:

    [<0000000030795d2f>] kmem_cache_alloc_node_trace+0x153/0x470
    [<000000000398512e>] alloc_worker+0x21/0x50
    [<000000001934cb3a>] init_rescuer.part.4+0x1d/0xb0
    [<00000000f36417e5>] alloc_workqueue+0x336/0x5f3
    [<000000000b6d2e88>] xfs_init_mount_workqueues+0x2a/0x150 [xfs]
    [<0000000014c756cd>] xfs_fs_fill_super+0x311/0x760 [xfs]
    [<000000001fdee6fd>] mount_bdev+0x191/0x1c0
    [<00000000d0aa6706>] xfs_fs_mount+0x15/0x20 [xfs]
    [<00000000631fe1d9>] legacy_get_tree+0x34/0x60
    [<00000000ee947c38>] vfs_get_tree+0x27/0xb0
    [<00000000f4bcb594>] do_mount+0x8a0/0xae0
    [<0000000005dd5056>] ksys_mount+0xb6/0xd0
    [<00000000fb14e10a>] __x64_sys_mount+0x25/0x30
    [<000000009fb1dd3e>] do_syscall_64+0x6d/0x488
    [<00000000a822a6c4>] entry_SYSCALL_64_after_hwframe+0x49/0xbe

[1] https://lore.kernel.org/lkml/[email protected]
k.com/

maintainer
#1 lore raw

PATCH 1/1 workqueue: Fix missing kfree(rescuer) in destroy_workqueue()

From 8efe1223d73c218ce7e8b2e0e9aadb974b582d7f Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Fri, 20 Sep 2019 13:39:57 -0700

Fixes def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()")

---
Applied to wq/for-5.4-fixes.

Thanks.

 kernel/workqueue.c | 1 +
 1 file changed, 1 insertion(+)
kernel/workqueue.c +1 -0
index 93e20f5330fc..3f067f1d72e3 100644
@@ -4345,6 +4345,7 @@ void destroy_workqueue(struct workqueue_struct *wq)
 
 		/* rescuer will empty maydays list before exiting */
 		kthread_stop(rescuer->task);
+		kfree(rescuer);
 	}
 
 	/* sanity checks */
Signature · 1 line
2.17.1