From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935180AbcA0SZZ (ORCPT ); Wed, 27 Jan 2016 13:25:25 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:36815 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934462AbcA0SZV (ORCPT ); Wed, 27 Jan 2016 13:25:21 -0500 From: Alexander Potapenko To: adech.fo@gmail.com, cl@linux.com, dvyukov@google.com, akpm@linux-foundation.org, ryabinin.a.a@gmail.com, rostedt@goodmis.org Cc: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 1/8] kasan: Change the behavior of kmalloc_large_oob_right test Date: Wed, 27 Jan 2016 19:25:06 +0100 Message-Id: <35b553cafcd5b77838aeaf5548b457dfa09e30cf.1453918525.git.glider@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org depending on which allocator (SLAB or SLUB) is being used Signed-off-by: Alexander Potapenko --- lib/test_kasan.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index c32f3b0..66dd92f 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -68,7 +68,22 @@ static noinline void __init kmalloc_node_oob_right(void) static noinline void __init kmalloc_large_oob_right(void) { char *ptr; - size_t size = KMALLOC_MAX_CACHE_SIZE + 10; + size_t size; + + if (KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE) { + /* + * We're using the SLAB allocator. Allocate a chunk that fits + * into a slab. + */ + size = KMALLOC_MAX_CACHE_SIZE - 256; + } else { + /* + * KMALLOC_MAX_SIZE > KMALLOC_MAX_CACHE_SIZE. + * We're using the SLUB allocator. Allocate a chunk that does + * not fit into a slab to trigger the page allocator. + */ + size = KMALLOC_MAX_CACHE_SIZE + 10; + } pr_info("kmalloc large allocation: out-of-bounds to right\n"); ptr = kmalloc(size, GFP_KERNEL); -- 2.7.0.rc3.207.g0ac5344