4.16-stable review patch. If anyone has any objections, please let me know.
------------------ From: Andrey Konovalov <andreyk...@google.com> [ Upstream commit 91c93ed07f04f5b32a30321d522d8ca9504745bf ] When an invalid-free is triggered by one of the KASAN tests, the object doesn't actually get freed. This later leads to a BUG failure in kmem_cache_destroy that checks that there are no allocated objects in the cache that is being destroyed. Fix this by calling kmem_cache_free with the proper object address after the call that triggers invalid-free. Link: http://lkml.kernel.org/r/286eaefc0a6c3fa9b83b87e7d6dc0fbb5b5c9926.1519924383.git.andreyk...@google.com Signed-off-by: Andrey Konovalov <andreyk...@google.com> Acked-by: Andrey Ryabinin <aryabi...@virtuozzo.com> Cc: Alexander Potapenko <gli...@google.com> Cc: Dmitry Vyukov <dvyu...@google.com> Cc: Geert Uytterhoeven <ge...@linux-m68k.org> Cc: Nick Terrell <terre...@fb.com> Cc: Chris Mason <c...@fb.com> Cc: Yury Norov <yno...@caviumnetworks.com> Cc: Al Viro <v...@zeniv.linux.org.uk> Cc: "Luis R . Rodriguez" <mcg...@kernel.org> Cc: Palmer Dabbelt <pal...@dabbelt.com> Cc: "Paul E . McKenney" <paul...@linux.vnet.ibm.com> Cc: Jeff Layton <jlay...@redhat.com> Cc: "Jason A . Donenfeld" <ja...@zx2c4.com> Cc: Kostya Serebryany <k...@google.com> Signed-off-by: Andrew Morton <a...@linux-foundation.org> Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> Signed-off-by: Sasha Levin <alexander.le...@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org> --- lib/test_kasan.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -567,7 +567,15 @@ static noinline void __init kmem_cache_i return; } + /* Trigger invalid free, the object doesn't get freed */ kmem_cache_free(cache, p + 1); + + /* + * Properly free the object to prevent the "Objects remaining in + * test_cache on __kmem_cache_shutdown" BUG failure. + */ + kmem_cache_free(cache, p); + kmem_cache_destroy(cache); }