Patch "mm/kmemleak.c: wait for scan completion before disabling free" has been added to the 3.18-stable tree
Quoted 76 lines · On 5/3/2018 2:13 AM, [email protected] wrote:
This is a note to let you know that I've just added the patch titled
mm/kmemleak.c: wait for scan completion before disabling freeto the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summaryThe filename of the patch is:
mm-kmemleak.c-wait-for-scan-completion-before-disabling-free.patch
and it can be found in the queue-3.18 subdirectory.If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From foo@baz Wed May 2 13:21:44 PDT 2018
From: Vinayak Menon <[email protected]>
Date: Wed, 28 Mar 2018 16:01:16 -0700
Subject:mm/kmemleak.c: wait for scan completion before disabling freeFrom: Vinayak Menon <[email protected]>
[ Upstream commit
914b6dfff790544d9b77dfd1723adb3745ec9700]A crash is observed when
kmemleak_scanaccesses theobject->pointer, likely due to the following race.TASK A TASK B TASK C
kmemleak_write
(with "scan" and
NOT "scan=on")
kmemleak_scan()
create_object
kmem_cache_allocfails
kmemleak_disable
kmemleak_do_cleanup
kmemleak_free_enabled= 0
kfreekmemleak_freebails out
(kmemleak_free_enabledis 0)
slub freesobject->pointer
update_checksum
crash -object->pointer
freed (DEBUG_PAGEALLOC)
kmemleak_do_cleanupwaits for the scan thread to complete, but not for direct call tokmemleak_scanviakmemleak_write. So add a wait forkmemleak_scancompletion before disablingkmemleak_free, and while at it fix the comment onstop_scan_thread.[[email protected]: fix stop_scan_thread comment]Signed-off-by Vinayak Menon <[email protected]>Reviewed-by Catalin Marinas <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- mm/kmemleak.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/kmemleak.c +1
-2@@ -1481,8 +1481,7 @@ static void start_scan_thread(void) }/* -* Stop the automatic memory scanning thread. This function must be called -* with the scan_mutex held. +* Stop the automatic memory scanning thread. */ static void stop_scan_thread (void ) {
mm/kmemleak.c static void kmemleak_do_cleanup(struct w · line 1748
Quoted 4 lines
mm/kmemleak.c +1
-0@@ -1746,12 +1745,15 @@ static void kmemleak_do_cleanup(struct wmutex_lock (&scan_mutex);stop_scan_thread (); +mutex_lock (&scan_mutex);
The lock is taken once above� stop_scan_thread() and can result in a deadlock.
The lock was removed from kmemleak_do_cleanup by following commit which is not present on 3.18
commit 5f369f374ba4889fe3c17883402db5ee8d254216
Author: Catalin Marinas <[email protected]>
Date:�� Wed Jun 24 16:58:31 2015 -0700
��� mm: kmemleak: do not acquire scan_mutex in kmemleak_do_cleanup()
So we may have to pick the above patch too.
Quoted 19 lines
mm/kmemleak.c +5
-3/* -* Once the scan thread has stopped, it is safe to no longer track -* object freeing. Ordering of the scan thread stopping and the memory -* accesses below is guaranteed by the kthread_stop() function. +* Once it is made sure that kmemleak_scan has stopped, it is safe to no +* longer track object freeing. Ordering of the scan thread stopping and +* the memory accesses below is guaranteed by the kthread_stop() +* function. */ kmemleak_free_enabled =0 ; +mutex_unlock (&scan_mutex);if (!kmemleak_found_leaks)__kmemleak_do_cleanup ();Patches currently in stable-queue which might be from [email protected] are
queue-3.18/mm-kmemleak.c-wait-for-scan-completion-before-disabling-free.patch
Greg KH
maintainerQuoted 87 lines · Vinayak Menon
Quoted 76 lines · On 5/3/2018 2:13 AM, [email protected] wrote:
This is a note to let you know that I've just added the patch titled
mm/kmemleak.c: wait for scan completion before disabling freeto the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summaryThe filename of the patch is:
mm-kmemleak.c-wait-for-scan-completion-before-disabling-free.patch
and it can be found in the queue-3.18 subdirectory.If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From foo@baz Wed May 2 13:21:44 PDT 2018
From: Vinayak Menon <[email protected]>
Date: Wed, 28 Mar 2018 16:01:16 -0700
Subject:mm/kmemleak.c: wait for scan completion before disabling freeFrom: Vinayak Menon <[email protected]>
[ Upstream commit
914b6dfff790544d9b77dfd1723adb3745ec9700]A crash is observed when
kmemleak_scanaccesses theobject->pointer, likely due to the following race.TASK A TASK B TASK C
kmemleak_write
(with "scan" and
NOT "scan=on")
kmemleak_scan()
create_object
kmem_cache_allocfails
kmemleak_disable
kmemleak_do_cleanup
kmemleak_free_enabled= 0
kfreekmemleak_freebails out
(kmemleak_free_enabledis 0)
slub freesobject->pointer
update_checksum
crash -object->pointer
freed (DEBUG_PAGEALLOC)
kmemleak_do_cleanupwaits for the scan thread to complete, but not for direct call tokmemleak_scanviakmemleak_write. So add a wait forkmemleak_scancompletion before disablingkmemleak_free, and while at it fix the comment onstop_scan_thread.[[email protected]: fix stop_scan_thread comment]Signed-off-by Vinayak Menon <[email protected]>Reviewed-by Catalin Marinas <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- mm/kmemleak.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/kmemleak.c +1
-2@@ -1481,8 +1481,7 @@ static void start_scan_thread(void) }/* -* Stop the automatic memory scanning thread. This function must be called -* with the scan_mutex held. +* Stop the automatic memory scanning thread. */ static void stop_scan_thread (void ) {mm/kmemleak.c static void kmemleak_do_cleanup(struct w · line 1748
Quoted 4 lines
mm/kmemleak.c +1
-0@@ -1746,12 +1745,15 @@ static void kmemleak_do_cleanup(struct wmutex_lock (&scan_mutex);stop_scan_thread (); +mutex_lock (&scan_mutex);The lock is taken once above�
stop_scan_thread()and can result in a deadlock.The lock was removed from
kmemleak_do_cleanupby following commit which is not present on 3.18
Quoted 7 lines
commit
5f369f374ba4889fe3c17883402db5ee8d254216
Author: Catalin Marinas <[email protected]>
Date:�� Wed Jun 24 16:58:31 2015 -0700��� mm: kmemleak: do not acquire
scan_mutexinkmemleak_do_cleanup()So we may have to pick the above patch too.
All was dropped, so no worries anymore :)
thanks,
greg k-h