Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1089040pxb; Wed, 16 Feb 2022 10:42:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBWERToNNhvCCESLk0zMYt4DidoNP+nRUcKd/BkmGStg3Jg1C9VTYHTkKCe6zDarpEaheJ X-Received: by 2002:a62:754d:0:b0:4c7:f5db:5bd7 with SMTP id q74-20020a62754d000000b004c7f5db5bd7mr4708661pfc.46.1645036943411; Wed, 16 Feb 2022 10:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645036943; cv=none; d=google.com; s=arc-20160816; b=m6c7aRm2JeFTm0Yab9ByY25dJGJEK0A8IPocHu299XNvy4wBGhreqSng7whScVvtP9 EV0o8662PhSQIYA9OIivyj1CGNx4t1/PFRMl+jLv87EaD4JL6HoIPqKAFrOoa6eVWz8+ NoC2xiHsnock7T16dM2Z+OR7365LLqJBuwbm6NP4Cbb2EzCyq/TgMJHTX8TuQpVvBzRu AIx9MxDb/rZulKX9ECwvZmm0zTHYCbkWBTBYqPKT/9As0bvdK6nfiXMjBkdPF5I7mdRU lAEkBjHQCBLKTuJR80flzS/L7wlWPFH/PDFFOQW19fd8tamMPPEbtQ+n/2DZHrbkea/8 RcCg== 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=RX1MiZpwQpJ0b3L1gArX38pH7r/Ihc4JwK8Scpn15pk=; b=mpPUgPwYL/0Mx8btV7EM7ylLaiQ28LAOgZpoXXkUK/StL/tW1f1FnscvbK5/PYSyAd bG6cXVmsoXkVxS6f/m3uwNjQwr8V1L7xYC+uVU5Kl8uRm50YBnTZaRVfUH39yjL6hXoo /Agtpfr4chYnUv4zVrDIiORrhGXT/0eb0piSCWqrrFgjhX27IR7ebUNQ10gwTYOtaZFz ZlU2awcc1TInoj5xIfjzxdqhv3Z5KXw7vUbSLg5ASKJ8K5/NR1K+SElDk3GYg8fj4gnI KJuYm3GliORJblSQsnvRFze/XLqtVtZCeaVubHllJ3lavt3tw4OrNzEOy+B3rkZluAdo s+5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=auojpY6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1si8213607pju.52.2022.02.16.10.42.07; Wed, 16 Feb 2022 10:42:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=auojpY6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233958AbiBPP1K (ORCPT + 99 others); Wed, 16 Feb 2022 10:27:10 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbiBPP1K (ORCPT ); Wed, 16 Feb 2022 10:27:10 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C1B13E8B; Wed, 16 Feb 2022 07:26:57 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id e79so3858iof.13; Wed, 16 Feb 2022 07:26:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RX1MiZpwQpJ0b3L1gArX38pH7r/Ihc4JwK8Scpn15pk=; b=auojpY6RZCoHWJ/4x2YOYeUUljS7wYk8WlNj5MCi2Yk/KzSIFHoNm/87wPuSd0oqbe iJhtQiMeFb+7xvUz0w4kI4PqXtGvU9htbgYVPND8XCCyezl9w0x85UyIHLEBlZCl9KJw iWG2+M44RCTTaJvE7+4tO7lINSWQKYgcDSDFv7g7WlQ+yIWdcsU65tExMMc7VK7JqTbg ZTWvPF3f6lMqbvSlee1fpte4I9BFlwlUiq7IsVzjYxOdzJwIbYhh6vgT/Np0nXvfjxeB cF+WXuLW1ExDd2N28sxc/dUQXc+AmGd1F2lQysPP2VdwiuyuZpSvKEoDLO742sa0jeAj vpFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RX1MiZpwQpJ0b3L1gArX38pH7r/Ihc4JwK8Scpn15pk=; b=dgocvxsfOOcWOjl5bEHxk64tpMEHFWyB3TMjt21D1493eFiCerSVoPDHRLYt6EbPZl mNSWAjiIFYJ1oh47b7YrvrwvHbhepmusv8h7YrxJJTsWA73txhSQ3X8hEEv2PAiVvWVQ MdUDbrqlEavmcCClrRer/27j6UbvB++rxPmIUrvlI1HjrvjT43QsPJ/nDd+gs0ITQVwQ DJr/DLXWBZ/PnY3sRJrvirDoJ/Zfzsi5vwaaWX4bmwmhL3SQtA45x7EYLAqJB6rpM02l 1t9Jt50VFAhz+FOxvBWv00cX9WiQ1SPuVxdDzs0ohS6k9aemaJjlXsm4ydVNmisHBHk5 W9Gg== X-Gm-Message-State: AOAM531qrF8Y+RR7GfyFgWnrKNC6xHButljM57LW1EBOliCrMeEtXVEl 0EahX2BQoN//+UC5r8dRukqXQOSgUNo6zgSafPU= X-Received: by 2002:a05:6638:3799:b0:30f:cc82:ebc4 with SMTP id w25-20020a056638379900b0030fcc82ebc4mr2090155jal.117.1645025216948; Wed, 16 Feb 2022 07:26:56 -0800 (PST) MIME-Version: 1.0 References: <20220213183232.4038718-1-keescook@chromium.org> In-Reply-To: <20220213183232.4038718-1-keescook@chromium.org> From: Andrey Konovalov Date: Wed, 16 Feb 2022 16:26:46 +0100 Message-ID: Subject: Re: [PATCH] kasan: test: Silence allocation warnings from GCC 12 To: Kees Cook Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev , LKML , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 13, 2022 at 7:32 PM Kees Cook wrote: > > GCC 12 is able to see more problems with allocation sizes at compile > time, so these must be silenced so the runtime checks will still be > available. Use OPTIMIZER_HIDE_VAR() to silence the new warnings: > > lib/test_kasan.c: In function 'ksize_uaf': Hm, the warning mentions ksize_uaf, but none of the changes touch it. > lib/test_kasan.c:781:61: warning: array subscript 120 is outside array bounds of 'void[120]' [-Warray-bounds] > 781 | KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); > | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~ > lib/test_kasan.c:96:9: note: in definition of macro 'KUNIT_EXPECT_KASAN_FAIL' > 96 | expression; \ > | ^~~~~~~~~~ > In function 'kmalloc', > inlined from 'ksize_uaf' at lib/test_kasan.c:775:8: > ./include/linux/slab.h:581:24: note: at offset 120 into object of size 120 allocated by 'kmem_cache_alloc_trace' > 581 | return kmem_cache_alloc_trace( > | ^~~~~~~~~~~~~~~~~~~~~~~ > 582 | kmalloc_caches[kmalloc_type(flags)][index], > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 583 | flags, size); > | ~~~~~~~~~~~~ > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Andrey Konovalov > Cc: Dmitry Vyukov > Cc: kasan-dev@googlegroups.com > Signed-off-by: Kees Cook > --- > lib/test_kasan.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 26a5c9007653..a19b3d608e3e 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -124,6 +124,7 @@ static void kmalloc_oob_right(struct kunit *test) > > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > + OPTIMIZER_HIDE_VAR(ptr); > > /* > * An unaligned access past the requested kmalloc size. > @@ -185,6 +186,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > > + OPTIMIZER_HIDE_VAR(ptr); > KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0); > > kfree(ptr); > @@ -265,6 +267,7 @@ static void kmalloc_large_oob_right(struct kunit *test) > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > > + OPTIMIZER_HIDE_VAR(ptr); > KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0); > kfree(ptr); > } > @@ -748,6 +751,7 @@ static void ksize_unpoisons_memory(struct kunit *test) > > ptr = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > + OPTIMIZER_HIDE_VAR(ptr); > real_size = ksize(ptr); > > /* This access shouldn't trigger a KASAN report. */ > -- > 2.30.2 >