Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp355911pxb; Thu, 14 Jan 2021 07:35:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvmGdiRTLYuVIsaXA3/mLZo1eZQ4VgiiZw4R2EzLM1ZpPKPXLcDQjcA7RrDzgR76LMa30v X-Received: by 2002:a17:906:3401:: with SMTP id c1mr5829504ejb.156.1610638501594; Thu, 14 Jan 2021 07:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610638501; cv=none; d=google.com; s=arc-20160816; b=TinEtcGHdhNNxyXaKSHRXc2PxLRHPigNXTDWTWcOGrW9x28BAcGsrOFOh8JScj73Lg zK8mchdlNM/Y2YQs7D8IwtRGVNgpgFWYhZPPiA75rH7Ip0Giy5V3GPUlUaAQxbXVCzrC BvLxPnrM0PnEmny83y7iiBgiNzASlsmbITTa/JfP+GunxKt+l9PUd3nyAI2td+kNiode zmePIaH/VDtxHO/RfV3j0fmPzhuMQ337TYxh+lF+djtaDXQiFJb6tyI3rC/j6HRQlOTG zu8mVThJBkAmxpiCbp26sfzsoz59pRm4sCTDExRN9zARZkkC+Wmw/1Igg/Un/YC3Q15L caDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rZ/Nqkyz1NzBbC9d12mdlvYcjVEDi+jgRuueCoXzbVA=; b=PcHXDJhoiuMBhLYjQCeY0HJB8HZpm4IpwC8SwaFeFGHjN/cLkiZXE8Pjc1/UdulI00 IU9zHfJOrshTef0RQnLzpu6VMzfS4k3G900MSFaU/SRd7jXISFJbOpnX86FVCloCnFjK 5S6n0uN5RQK7NFZwF0FtbZzSq00EL8ZKqVCnCeTgmYasdEavbCSQpKEKrOkD2BjEXkFa 4vlkJI384DeorGGzcdzsLndL6dcvsFoJOoqJyMuO/WHgnWn48pOwDOuViSnjfYOMOd4H 4YrRNnKKGUpWxkkQoHbsF7GWNfZ+zfPuIPcpMlV0gpsD+c51Cg6XwkWb1C9EW2bZED9k ojZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eBy7cKZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh14si2641566ejb.45.2021.01.14.07.34.36; Thu, 14 Jan 2021 07:35:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eBy7cKZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729216AbhANPdq (ORCPT + 99 others); Thu, 14 Jan 2021 10:33:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728967AbhANPdp (ORCPT ); Thu, 14 Jan 2021 10:33:45 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89184C0613C1 for ; Thu, 14 Jan 2021 07:33:05 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id b5so3389906pjk.2 for ; Thu, 14 Jan 2021 07:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rZ/Nqkyz1NzBbC9d12mdlvYcjVEDi+jgRuueCoXzbVA=; b=eBy7cKZ3wJTClUI2m4kVw3DQiatogxgxrOB9kFInZXzWgT9o1em7B0C8OJhCIexOzK +/sswB2OtP1hVYCA6xofoubvfW34RgqeFLiuf5UkQGIPiAhQtzpaWbz4ue1rGh+9R7uA k9smac70hwrCG8+H4aGrdKpV/OvylmT1FyiSQd9QOmzCkhseRJLHb2OxUrZkKP/spyNS iIF06rNO5kiuxn1nYtwL8r0cKIP85jC+AX+xefTiUHFco4CR6a7vcKK63aY4cH2+k28Y 7c9hN9hUdwZqAQcswUVPvI+hkmFcpjTyS0hwWiAdcD5EYm3nQSuN8AzuUGdeT1G/Sd1L N5WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rZ/Nqkyz1NzBbC9d12mdlvYcjVEDi+jgRuueCoXzbVA=; b=K+8pdxLwvIUkBjbDuQCcpuC9Mn26XdhvNxw8itgVrRZFDbmEwfkC8K0xSVDY9Bf/hP MAVhq8fjP+5DIorlfMf9ezqbmdvtCGCwwqd0n5qC9U0eDAXRwO/BocPPmVwl4rs5ajg8 Ivt/cSd/ulIZuyvSCz3c2qGSuSLTd3v+yzEMjb70fAxHJC9BAai9OQV6wgyX7RW2XWzd jPUq0YZ00wH9CfkbmE+TXGaNySgQxX4Rejy5q2SN1ro9v+4/dCAk8ESgUDdfcCn5VsKH hzDFyqOtRzIg8LIZkpuufzK7w8dSPi1n68H8LUlgXbnIkvqjScfshFfTTOES8ueI4TEw TgoQ== X-Gm-Message-State: AOAM530aj4NClGhZVH4zQwievvJ9lpsyfq62LSjLvo7DvKPc0IJvBuEV CWGhrp2qg9BcieQ+tqTy2KwfS4CPyT8Ac4sGlmyNfA== X-Received: by 2002:a17:90b:350b:: with SMTP id ls11mr5447639pjb.166.1610638384902; Thu, 14 Jan 2021 07:33:04 -0800 (PST) MIME-Version: 1.0 References: <0e994d67a05cbf23b3c6186a862b5d22cad2ca7b.1610554432.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Thu, 14 Jan 2021 16:32:53 +0100 Message-ID: Subject: Re: [PATCH v2 13/14] kasan: add a test for kmem_cache_alloc/free_bulk To: Marco Elver Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 13, 2021 at 5:38 PM Marco Elver wrote: > > On Wed, 13 Jan 2021 at 17:22, Andrey Konovalov wrote: > > > > Add a test for kmem_cache_alloc/free_bulk to make sure there are now > > false-positives when these functions are used. > > s/now/no/ (but by itself doesn't necessarily demand a v3) > > > Link: https://linux-review.googlesource.com/id/I2a8bf797aecf81baeac61380c567308f319e263d > > Signed-off-by: Andrey Konovalov > > --- > > lib/test_kasan.c | 39 ++++++++++++++++++++++++++++++++++----- > > 1 file changed, 34 insertions(+), 5 deletions(-) > > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > > index 5e3d054e5b8c..d9f9a93922d5 100644 > > --- a/lib/test_kasan.c > > +++ b/lib/test_kasan.c > > @@ -479,10 +479,11 @@ static void kmem_cache_oob(struct kunit *test) > > { > > char *p; > > size_t size = 200; > > - struct kmem_cache *cache = kmem_cache_create("test_cache", > > - size, 0, > > - 0, NULL); > > + struct kmem_cache *cache; > > + > > + cache = kmem_cache_create("test_cache", size, 0, 0, NULL); > > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); > > + > > p = kmem_cache_alloc(cache, GFP_KERNEL); > > if (!p) { > > kunit_err(test, "Allocation failed: %s\n", __func__); > > @@ -491,11 +492,12 @@ static void kmem_cache_oob(struct kunit *test) > > } > > > > KUNIT_EXPECT_KASAN_FAIL(test, *p = p[size + OOB_TAG_OFF]); > > + > > kmem_cache_free(cache, p); > > kmem_cache_destroy(cache); > > } > > > > -static void memcg_accounted_kmem_cache(struct kunit *test) > > +static void kmem_cache_accounted(struct kunit *test) > > { > > int i; > > char *p; > > @@ -522,6 +524,32 @@ static void memcg_accounted_kmem_cache(struct kunit *test) > > kmem_cache_destroy(cache); > > } > > > > +static void kmem_cache_bulk(struct kunit *test) > > +{ > > + struct kmem_cache *cache; > > + size_t size = 200; > > + size_t p_size = 10; > > s/p_size/ARRAY_SIZE(p)/ > ? > > > + char *p[10]; > > + bool ret; > > + int i; > > + > > + cache = kmem_cache_create("test_cache", size, 0, 0, NULL); > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); > > + > > + ret = kmem_cache_alloc_bulk(cache, GFP_KERNEL, p_size, (void **)&p); > > + if (!ret) { > > + kunit_err(test, "Allocation failed: %s\n", __func__); > > + kmem_cache_destroy(cache); > > + return; > > + } > > + > > + for (i = 0; i < p_size; i++) > > + p[i][0] = p[i][size - 1] = 42; > > + > > + kmem_cache_free_bulk(cache, p_size, (void **)&p); > > + kmem_cache_destroy(cache); > > +} > > + > > static char global_array[10]; > > > > static void kasan_global_oob(struct kunit *test) > > @@ -961,7 +989,8 @@ static struct kunit_case kasan_kunit_test_cases[] = { > > KUNIT_CASE(kfree_via_page), > > KUNIT_CASE(kfree_via_phys), > > KUNIT_CASE(kmem_cache_oob), > > - KUNIT_CASE(memcg_accounted_kmem_cache), > > + KUNIT_CASE(kmem_cache_accounted), > > + KUNIT_CASE(kmem_cache_bulk), > > KUNIT_CASE(kasan_global_oob), > > KUNIT_CASE(kasan_stack_oob), > > KUNIT_CASE(kasan_alloca_oob_left), > > -- > > 2.30.0.284.gd98b1dd5eaa7-goog > > Will fix all in v3, thanks!