From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF549C433E0 for ; Tue, 12 Jan 2021 13:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 656F82311C for ; Tue, 12 Jan 2021 13:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730375AbhALNIP (ORCPT ); Tue, 12 Jan 2021 08:08:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728669AbhALNIH (ORCPT ); Tue, 12 Jan 2021 08:08:07 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5749AC061575 for ; Tue, 12 Jan 2021 05:07:27 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id q18so2452928wrn.1 for ; Tue, 12 Jan 2021 05:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GnsdLE8z7GKqgdEkPWmktkSWY9f1wcAcGK6xh9iY7ow=; b=Wv7K70rB+SEKqbws4zM/pkhyra65viIyckmvHfFq2ReRrTGzNhD7fX0n9rug0ViROJ hfPf4k+DkkXH9fsbsNe5vi8IR1aRGZOO0ggzQG86ea/+FDAZSDKLRQkqtamdkxHtIWgy 49eO9eIojEcm/0B5HmsRhbO42h2PBk9MCINAcHhmXpr8dKNFhj5uvPC2NywBs9anVlhT vx7NUbKALZCWqV9UfU/qsXDrq34YIRBYKWkkKWlIAHjZgMgljhlaIQ+t6J+W19d//aAP NKXDm08fh4lM5K/dCF/Tk9iaiIRTygAOKRSvnCCycqRWi2t9xdprKiR5dFzN/xuQtjHU 3phw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GnsdLE8z7GKqgdEkPWmktkSWY9f1wcAcGK6xh9iY7ow=; b=efp7YkI0QN6R+2UHL6d7kCZaZ839+UiLcorMFoEBtWnk0jkhRKCL6ziGxX8esq4CTp pkHNIUVeeVcE9sj2SLA/LPPX7edIri4RXhdRkOc8N8TRPyDIiyBz7lfdO62SFARVeUHk 0zjTtxoZewUfp1QfjvfYfSr6NLzTkuwjEgM0LAQ53AsYw94zaX26Pe/3TXmNaaynbYfl jy/FVIcUltNK+2ok4yLEbOP8/wfad2E/Zn5+3trW8CANsCXxwaG0UTHCCi9uZCk5xH8w iNdr94k6+ArxK/+FWL9qK2WX3BTbq9ZpG06yjT8c6uqMGXYacwopUNqrhW/yWqXJUzV9 L56A== X-Gm-Message-State: AOAM531iK0koJykHuvlbjwgnMnNdgDiF4Vk6b4TVepSE4DprGElMFa8y 8gg4snQclSJpcK91mE4ffYw0oQ== X-Google-Smtp-Source: ABdhPJyNJcJ+VXAmZB1PIycCUtop7P7TDEiXYuKJX7hmaQezI44o8GndzMSJnyA8AjY9AlU+wdupqQ== X-Received: by 2002:adf:b359:: with SMTP id k25mr4376621wrd.98.1610456845707; Tue, 12 Jan 2021 05:07:25 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) by smtp.gmail.com with ESMTPSA id b133sm3694353wme.33.2021.01.12.05.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 05:07:24 -0800 (PST) Date: Tue, 12 Jan 2021 14:07:19 +0100 From: Marco Elver To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/11] kasan: clean up comments in tests Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.2 (2020-11-20) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 05, 2021 at 07:27PM +0100, Andrey Konovalov wrote: > Clarify and update comments and info messages in KASAN tests. > > Signed-off-by: Andrey Konovalov > Link: https://linux-review.googlesource.com/id/I6c816c51fa1e0eb7aa3dead6bda1f339d2af46c8 Reviewed-by: Marco Elver > --- > lib/test_kasan.c | 94 +++++++++++++++++++++++------------------ > lib/test_kasan_module.c | 5 ++- > 2 files changed, 55 insertions(+), 44 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 2947274cc2d3..46e578c8e842 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -28,10 +28,9 @@ > #define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) > > /* > - * We assign some test results to these globals to make sure the tests > - * are not eliminated as dead code. > + * Some tests use these global variables to store return values from function > + * calls that could otherwise be eliminated by the compiler as dead code. > */ > - > void *kasan_ptr_result; > int kasan_int_result; > > @@ -39,14 +38,13 @@ static struct kunit_resource resource; > static struct kunit_kasan_expectation fail_data; > static bool multishot; > > +/* > + * Temporarily enable multi-shot mode. Otherwise, KASAN would only report the > + * first detected bug and panic the kernel if panic_on_warn is enabled. > + */ > static int kasan_test_init(struct kunit *test) > { > - /* > - * Temporarily enable multi-shot mode and set panic_on_warn=0. > - * Otherwise, we'd only get a report for the first case. > - */ > multishot = kasan_save_enable_multi_shot(); > - > return 0; > } > > @@ -56,12 +54,12 @@ static void kasan_test_exit(struct kunit *test) > } > > /** > - * KUNIT_EXPECT_KASAN_FAIL() - Causes a test failure when the expression does > - * not cause a KASAN error. This uses a KUnit resource named "kasan_data." Do > - * Do not use this name for a KUnit resource outside here. > - * > + * KUNIT_EXPECT_KASAN_FAIL() - check that the executed expression produces a > + * KASAN report; causes a test failure otherwise. This relies on a KUnit > + * resource named "kasan_data". Do not use this name for KUnit resources > + * outside of KASAN tests. > */ > -#define KUNIT_EXPECT_KASAN_FAIL(test, condition) do { \ > +#define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \ > fail_data.report_expected = true; \ > fail_data.report_found = false; \ > kunit_add_named_resource(test, \ > @@ -69,7 +67,7 @@ static void kasan_test_exit(struct kunit *test) > NULL, \ > &resource, \ > "kasan_data", &fail_data); \ > - condition; \ > + expression; \ > KUNIT_EXPECT_EQ(test, \ > fail_data.report_expected, \ > fail_data.report_found); \ > @@ -117,11 +115,12 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > - /* Allocate a chunk that does not fit into a SLUB cache to trigger > + /* > + * Allocate a chunk that does not fit into a SLUB cache to trigger > * the page allocator fallback. > */ > ptr = kmalloc(size, GFP_KERNEL); > @@ -137,7 +136,7 @@ static void kmalloc_pagealloc_uaf(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > @@ -154,7 +153,7 @@ static void kmalloc_pagealloc_invalid_free(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > @@ -168,7 +167,9 @@ static void kmalloc_large_oob_right(struct kunit *test) > { > char *ptr; > size_t size = KMALLOC_MAX_CACHE_SIZE - 256; > - /* Allocate a chunk that is large enough, but still fits into a slab > + > + /* > + * Allocate a chunk that is large enough, but still fits into a slab > * and does not trigger the page allocator fallback in SLUB. > */ > ptr = kmalloc(size, GFP_KERNEL); > @@ -218,7 +219,7 @@ static void kmalloc_oob_16(struct kunit *test) > > /* This test is specifically crafted for the generic mode. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > @@ -454,7 +455,7 @@ static void kasan_global_oob(struct kunit *test) > > /* Only generic mode instruments globals. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > @@ -469,10 +470,13 @@ static void ksize_unpoisons_memory(struct kunit *test) > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > real_size = ksize(ptr); > - /* This access doesn't trigger an error. */ > + > + /* This access shouldn't trigger a KASAN report. */ > ptr[size] = 'x'; > - /* This one does. */ > + > + /* This one must. */ > KUNIT_EXPECT_KASAN_FAIL(test, ptr[real_size] = 'y'); > + > kfree(ptr); > } > > @@ -483,7 +487,7 @@ static void kasan_stack_oob(struct kunit *test) > char *p = &stack_array[ARRAY_SIZE(stack_array) + i]; > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -498,12 +502,12 @@ static void kasan_alloca_oob_left(struct kunit *test) > > /* Only generic mode instruments dynamic allocas. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -518,12 +522,12 @@ static void kasan_alloca_oob_right(struct kunit *test) > > /* Only generic mode instruments dynamic allocas. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -568,7 +572,7 @@ static void kmem_cache_invalid_free(struct kunit *test) > return; > } > > - /* Trigger invalid free, the object doesn't get freed */ > + /* Trigger invalid free, the object doesn't get freed. */ > KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1)); > > /* > @@ -585,10 +589,12 @@ static void kasan_memchr(struct kunit *test) > char *ptr; > size_t size = 24; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -610,10 +616,12 @@ static void kasan_memcmp(struct kunit *test) > size_t size = 24; > int arr[9]; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -634,10 +642,12 @@ static void kasan_strings(struct kunit *test) > char *ptr; > size_t size = 24; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -701,12 +711,12 @@ static void kasan_bitops_generic(struct kunit *test) > > /* This test is specifically crafted for the generic mode. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > /* > - * Allocate 1 more byte, which causes kzalloc to round up to 16-bytes; > + * Allocate 1 more byte, which causes kzalloc to round up to 16 bytes; > * this way we do not actually corrupt other memory. > */ > bits = kzalloc(sizeof(*bits) + 1, GFP_KERNEL); > @@ -733,7 +743,7 @@ static void kasan_bitops_tags(struct kunit *test) > > /* This test is specifically crafted for the tag-based mode. */ > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_SW_TAGS required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_SW_TAGS required"); > return; > } > > @@ -765,7 +775,7 @@ static void vmalloc_oob(struct kunit *test) > void *area; > > if (!IS_ENABLED(CONFIG_KASAN_VMALLOC)) { > - kunit_info(test, "CONFIG_KASAN_VMALLOC is not enabled."); > + kunit_info(test, "skipping, CONFIG_KASAN_VMALLOC required"); > return; > } > > diff --git a/lib/test_kasan_module.c b/lib/test_kasan_module.c > index 3b4cc77992d2..eee017ff8980 100644 > --- a/lib/test_kasan_module.c > +++ b/lib/test_kasan_module.c > @@ -123,8 +123,9 @@ static noinline void __init kasan_workqueue_uaf(void) > static int __init test_kasan_module_init(void) > { > /* > - * Temporarily enable multi-shot mode. Otherwise, we'd only get a > - * report for the first case. > + * Temporarily enable multi-shot mode. Otherwise, KASAN would only > + * report the first detected bug and panic the kernel if panic_on_warn > + * is enabled. > */ > bool multishot = kasan_save_enable_multi_shot(); > > -- > 2.29.2.729.g45daf8777d-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 607B8C433E0 for ; Tue, 12 Jan 2021 13:09:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EEEED23125 for ; Tue, 12 Jan 2021 13:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEEED23125 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pVYGVF0CTJ0uZ/2+9NWwneOhBCZ5ET/e6rPhYm3yRjk=; b=hvk82i8YZlYAaR4WoDs3OVh4u e4+i3BYLmg1MzKFun7PZB6B/9I/Kg9DQbFANVidNHuqEe9adtcnTQleiCugkMQVRfqFX/Jr2kM4zV Cm8O/Op8L+27TkT4rAr5tAYp+6CzYfmwZb7oKro4x3tlhhtomh9YkSAPoi/5wX+A/xu9s5i8C6dGO JzPLPGiEeYyUJDflJi/sxTOe9NzMlXQziZ78k5BSHKEHN18KYCgYbw1+kgHPP1NrQMv4cNypzaCeN DJh6shfbYBgaN3LA+LWHSWqgSi2o9f56DM9Fbrm/NcHRhTdoKFUQseSSNOF1qvln1N0AsytCZ4/2j FSuMsQ5cw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzJOg-0005kr-As; Tue, 12 Jan 2021 13:07:42 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzJOR-0005fZ-8t for linux-arm-kernel@lists.infradead.org; Tue, 12 Jan 2021 13:07:30 +0000 Received: by mail-wr1-x432.google.com with SMTP id 91so2423124wrj.7 for ; Tue, 12 Jan 2021 05:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GnsdLE8z7GKqgdEkPWmktkSWY9f1wcAcGK6xh9iY7ow=; b=Wv7K70rB+SEKqbws4zM/pkhyra65viIyckmvHfFq2ReRrTGzNhD7fX0n9rug0ViROJ hfPf4k+DkkXH9fsbsNe5vi8IR1aRGZOO0ggzQG86ea/+FDAZSDKLRQkqtamdkxHtIWgy 49eO9eIojEcm/0B5HmsRhbO42h2PBk9MCINAcHhmXpr8dKNFhj5uvPC2NywBs9anVlhT vx7NUbKALZCWqV9UfU/qsXDrq34YIRBYKWkkKWlIAHjZgMgljhlaIQ+t6J+W19d//aAP NKXDm08fh4lM5K/dCF/Tk9iaiIRTygAOKRSvnCCycqRWi2t9xdprKiR5dFzN/xuQtjHU 3phw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GnsdLE8z7GKqgdEkPWmktkSWY9f1wcAcGK6xh9iY7ow=; b=BKIDQNuBXoWmFaiU0YxsWqK/BteCo5filKU/N+WQNiZo/y1+t8hL43BcCdWhjrAaJn JWb4T3DofGxT+cPhE6P6HSn5wEsrpS8vWahkG1l+7rIjwicPO5PpL3WALGMaA1nyAC4H U30e+ydyMbuA01pJk5LgzzoIHANq7XNy1T5jW0iJRSzBY2fQ/iJjEsQKtuiCR2OF91Se 3K/p5LW9Jv/hXGP1v3K5oNkOy/khrbQAr5V5C3sRyoTOcwgGeDJXfzlvht+cQnsYay0n tlUVNE0WfbGhgrKgRwlXdAqc0eUPjmiqxFcN3RDPuSkEOV0zXQF4ErzbV+A0EPN2YOuB xG9w== X-Gm-Message-State: AOAM532+w6GK0TBWsuO9jvoS5cQqvj6Y+RC418BB57Oh6Xl1mwQNKdKi E7Xg6egj5cNlmlerPN29dt+EJg== X-Google-Smtp-Source: ABdhPJyNJcJ+VXAmZB1PIycCUtop7P7TDEiXYuKJX7hmaQezI44o8GndzMSJnyA8AjY9AlU+wdupqQ== X-Received: by 2002:adf:b359:: with SMTP id k25mr4376621wrd.98.1610456845707; Tue, 12 Jan 2021 05:07:25 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) by smtp.gmail.com with ESMTPSA id b133sm3694353wme.33.2021.01.12.05.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 05:07:24 -0800 (PST) Date: Tue, 12 Jan 2021 14:07:19 +0100 From: Marco Elver To: Andrey Konovalov Subject: Re: [PATCH 03/11] kasan: clean up comments in tests Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.2 (2020-11-20) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210112_080727_492074_029EEFBD X-CRM114-Status: GOOD ( 34.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Branislav Rankov , Catalin Marinas , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 05, 2021 at 07:27PM +0100, Andrey Konovalov wrote: > Clarify and update comments and info messages in KASAN tests. > > Signed-off-by: Andrey Konovalov > Link: https://linux-review.googlesource.com/id/I6c816c51fa1e0eb7aa3dead6bda1f339d2af46c8 Reviewed-by: Marco Elver > --- > lib/test_kasan.c | 94 +++++++++++++++++++++++------------------ > lib/test_kasan_module.c | 5 ++- > 2 files changed, 55 insertions(+), 44 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 2947274cc2d3..46e578c8e842 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -28,10 +28,9 @@ > #define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) > > /* > - * We assign some test results to these globals to make sure the tests > - * are not eliminated as dead code. > + * Some tests use these global variables to store return values from function > + * calls that could otherwise be eliminated by the compiler as dead code. > */ > - > void *kasan_ptr_result; > int kasan_int_result; > > @@ -39,14 +38,13 @@ static struct kunit_resource resource; > static struct kunit_kasan_expectation fail_data; > static bool multishot; > > +/* > + * Temporarily enable multi-shot mode. Otherwise, KASAN would only report the > + * first detected bug and panic the kernel if panic_on_warn is enabled. > + */ > static int kasan_test_init(struct kunit *test) > { > - /* > - * Temporarily enable multi-shot mode and set panic_on_warn=0. > - * Otherwise, we'd only get a report for the first case. > - */ > multishot = kasan_save_enable_multi_shot(); > - > return 0; > } > > @@ -56,12 +54,12 @@ static void kasan_test_exit(struct kunit *test) > } > > /** > - * KUNIT_EXPECT_KASAN_FAIL() - Causes a test failure when the expression does > - * not cause a KASAN error. This uses a KUnit resource named "kasan_data." Do > - * Do not use this name for a KUnit resource outside here. > - * > + * KUNIT_EXPECT_KASAN_FAIL() - check that the executed expression produces a > + * KASAN report; causes a test failure otherwise. This relies on a KUnit > + * resource named "kasan_data". Do not use this name for KUnit resources > + * outside of KASAN tests. > */ > -#define KUNIT_EXPECT_KASAN_FAIL(test, condition) do { \ > +#define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \ > fail_data.report_expected = true; \ > fail_data.report_found = false; \ > kunit_add_named_resource(test, \ > @@ -69,7 +67,7 @@ static void kasan_test_exit(struct kunit *test) > NULL, \ > &resource, \ > "kasan_data", &fail_data); \ > - condition; \ > + expression; \ > KUNIT_EXPECT_EQ(test, \ > fail_data.report_expected, \ > fail_data.report_found); \ > @@ -117,11 +115,12 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > - /* Allocate a chunk that does not fit into a SLUB cache to trigger > + /* > + * Allocate a chunk that does not fit into a SLUB cache to trigger > * the page allocator fallback. > */ > ptr = kmalloc(size, GFP_KERNEL); > @@ -137,7 +136,7 @@ static void kmalloc_pagealloc_uaf(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > @@ -154,7 +153,7 @@ static void kmalloc_pagealloc_invalid_free(struct kunit *test) > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; > > if (!IS_ENABLED(CONFIG_SLUB)) { > - kunit_info(test, "CONFIG_SLUB is not enabled."); > + kunit_info(test, "skipping, CONFIG_SLUB required"); > return; > } > > @@ -168,7 +167,9 @@ static void kmalloc_large_oob_right(struct kunit *test) > { > char *ptr; > size_t size = KMALLOC_MAX_CACHE_SIZE - 256; > - /* Allocate a chunk that is large enough, but still fits into a slab > + > + /* > + * Allocate a chunk that is large enough, but still fits into a slab > * and does not trigger the page allocator fallback in SLUB. > */ > ptr = kmalloc(size, GFP_KERNEL); > @@ -218,7 +219,7 @@ static void kmalloc_oob_16(struct kunit *test) > > /* This test is specifically crafted for the generic mode. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > @@ -454,7 +455,7 @@ static void kasan_global_oob(struct kunit *test) > > /* Only generic mode instruments globals. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > @@ -469,10 +470,13 @@ static void ksize_unpoisons_memory(struct kunit *test) > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > real_size = ksize(ptr); > - /* This access doesn't trigger an error. */ > + > + /* This access shouldn't trigger a KASAN report. */ > ptr[size] = 'x'; > - /* This one does. */ > + > + /* This one must. */ > KUNIT_EXPECT_KASAN_FAIL(test, ptr[real_size] = 'y'); > + > kfree(ptr); > } > > @@ -483,7 +487,7 @@ static void kasan_stack_oob(struct kunit *test) > char *p = &stack_array[ARRAY_SIZE(stack_array) + i]; > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -498,12 +502,12 @@ static void kasan_alloca_oob_left(struct kunit *test) > > /* Only generic mode instruments dynamic allocas. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -518,12 +522,12 @@ static void kasan_alloca_oob_right(struct kunit *test) > > /* Only generic mode instruments dynamic allocas. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > if (!IS_ENABLED(CONFIG_KASAN_STACK)) { > - kunit_info(test, "CONFIG_KASAN_STACK is not enabled"); > + kunit_info(test, "skipping, CONFIG_KASAN_STACK required"); > return; > } > > @@ -568,7 +572,7 @@ static void kmem_cache_invalid_free(struct kunit *test) > return; > } > > - /* Trigger invalid free, the object doesn't get freed */ > + /* Trigger invalid free, the object doesn't get freed. */ > KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1)); > > /* > @@ -585,10 +589,12 @@ static void kasan_memchr(struct kunit *test) > char *ptr; > size_t size = 24; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -610,10 +616,12 @@ static void kasan_memcmp(struct kunit *test) > size_t size = 24; > int arr[9]; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -634,10 +642,12 @@ static void kasan_strings(struct kunit *test) > char *ptr; > size_t size = 24; > > - /* See https://bugzilla.kernel.org/show_bug.cgi?id=206337 */ > + /* > + * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT. > + * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details. > + */ > if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { > - kunit_info(test, > - "str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT"); > + kunit_info(test, "skipping, CONFIG_AMD_MEM_ENCRYPT enabled"); > return; > } > > @@ -701,12 +711,12 @@ static void kasan_bitops_generic(struct kunit *test) > > /* This test is specifically crafted for the generic mode. */ > if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_GENERIC required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_GENERIC required"); > return; > } > > /* > - * Allocate 1 more byte, which causes kzalloc to round up to 16-bytes; > + * Allocate 1 more byte, which causes kzalloc to round up to 16 bytes; > * this way we do not actually corrupt other memory. > */ > bits = kzalloc(sizeof(*bits) + 1, GFP_KERNEL); > @@ -733,7 +743,7 @@ static void kasan_bitops_tags(struct kunit *test) > > /* This test is specifically crafted for the tag-based mode. */ > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { > - kunit_info(test, "CONFIG_KASAN_SW_TAGS required\n"); > + kunit_info(test, "skipping, CONFIG_KASAN_SW_TAGS required"); > return; > } > > @@ -765,7 +775,7 @@ static void vmalloc_oob(struct kunit *test) > void *area; > > if (!IS_ENABLED(CONFIG_KASAN_VMALLOC)) { > - kunit_info(test, "CONFIG_KASAN_VMALLOC is not enabled."); > + kunit_info(test, "skipping, CONFIG_KASAN_VMALLOC required"); > return; > } > > diff --git a/lib/test_kasan_module.c b/lib/test_kasan_module.c > index 3b4cc77992d2..eee017ff8980 100644 > --- a/lib/test_kasan_module.c > +++ b/lib/test_kasan_module.c > @@ -123,8 +123,9 @@ static noinline void __init kasan_workqueue_uaf(void) > static int __init test_kasan_module_init(void) > { > /* > - * Temporarily enable multi-shot mode. Otherwise, we'd only get a > - * report for the first case. > + * Temporarily enable multi-shot mode. Otherwise, KASAN would only > + * report the first detected bug and panic the kernel if panic_on_warn > + * is enabled. > */ > bool multishot = kasan_save_enable_multi_shot(); > > -- > 2.29.2.729.g45daf8777d-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel