BACKPORT: mm/kmemleak: fix UAF bug in kmemleak_scan()
Commit 6edda04c ("mm/kmemleak: prevent soft lockup in first object iteration loop of kmemleak_scan()") fixes soft lockup problem in kmemleak_scan() by periodically doing a cond_resched(). It does take a reference of the current object before doing it. Unfortunately, if the object has been deleted from the object_list, the next object pointed to by its next pointer may no longer be valid after coming back from cond_resched(). This can result in use-after-free and other nasty problem. Fix this problem by adding a del_state flag into kmemleak_object structure to synchronize the object deletion process between kmemleak_cond_resched() and __remove_object() to make sure that the object remained in the object_list in the duration of the cond_resched() call. Link: https://lkml.kernel.org/r/20230119040111.350923-3-longman@redhat.com Fixes: 6edda04c ("mm/kmemleak: prevent soft lockup in first object iteration loop of kmemleak_scan()") Change-Id: I7d44a56d2943e7140d9bcad56c6b1a20236f3827 Signed-off-by:Waiman Long <longman@redhat.com> Reviewed-by:
Catalin Marinas <catalin.marinas@arm.com> Cc: Muchun Song <songmuchun@bytedance.com> Signed-off-by:
Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 782e4179) [surenb: resolve trivial merge conflict due to the new pinned parameter in kmemleak_cond_resched] Bug: 280352049 Change-Id: Id1b794a3f22053141a0e86269a3316da1da317db Signed-off-by:
Suren Baghdasaryan <surenb@google.com>
Loading
Please sign in to comment