Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1044304pxb; Wed, 16 Feb 2022 09:42:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOZzApRPotiELSQBBqMppEF0r7uKTMfVwLBgLR/lw9I2/dn+SEqQzTlk6KaAfwJabOj+TH X-Received: by 2002:aa7:d949:0:b0:40f:2aa1:1bd1 with SMTP id l9-20020aa7d949000000b0040f2aa11bd1mr4217000eds.284.1645033379037; Wed, 16 Feb 2022 09:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645033379; cv=none; d=google.com; s=arc-20160816; b=dU4fPlcMofhYhiJdztZsGdqXGDblkDeF5fhaW22eYOutTjGDd2y6VS8eIKdfWIXmKb iWDoI6GepzJyeHIo16PsW28mS0tV66D/pd+denrEgQ3UtBlCTekE8QCi+TGAYVZWdPBs chdT4faYeXxPv69JaysHUfoUa6ZJacRXI58mKA5gVFnls0fG3dPLhYRd7ZlBjODeCCfA W0p+BSqjWzknw51Qpm9qmv+3JUlJwP0sJsh2asPFHeVp8lOdDR/bRJnEgHMXWxwV9MJ/ q288sPiotIOGos6RSCkBXLkNrnufKnYcIoKI/AyITYsKdt2eqryuTk3JLK91y0ksEbgm U1UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iH8izYx1CVz5zaeZ+ywlrsYpOCO6qk+mt4vdLHF4sUs=; b=LGQT7x3qpA7N1ehwTRT1sZW0smCbRlvtPCEpde79qzdPkGyF2HSseEM6xENqrmANs7 8LS0cAod/X8T4QqM80HOFkXQXOHNEurysEkto/ph3Hw8afhFPTFc2vOYSiwfNvg2f8Lz /90DNdHihkPq2FvqT2rFN3LuytvXbr5M4jjD3UvDH3D6zCj97BGUDyJeh7y84BuXJsyc KN+2WRRlogO5qe+p1WxUr0kILI9AsILHZGxC21Kb0HFQUo8leS4Amu4ewoSol3FXsX1G MlEkExlQlLjZIFefGE24JPUpG8+MT7lrSYbhMp0qUkaL1FsOIZt4yyJCDv0FzEYndYop LHhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eSk+1+Gg; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5si2156879edu.254.2022.02.16.09.42.36; Wed, 16 Feb 2022 09:42:59 -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=@chromium.org header.s=google header.b=eSk+1+Gg; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236259AbiBPQWh (ORCPT + 99 others); Wed, 16 Feb 2022 11:22:37 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232378AbiBPQWf (ORCPT ); Wed, 16 Feb 2022 11:22:35 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1617BEBB9C for ; Wed, 16 Feb 2022 08:22:22 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d17so2581429pfl.0 for ; Wed, 16 Feb 2022 08:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iH8izYx1CVz5zaeZ+ywlrsYpOCO6qk+mt4vdLHF4sUs=; b=eSk+1+Ggbfk0AhU70cpJBicS0hA69s9vK1Bi7n96BbfWLI6zRs8x+KOsBbAI8mclXZ 3Zc8R9z9rkUEnkYWm55iGCZZ3nKpgsokl9S80sgZwB8Oh40iBMxq/oIobscYaTUl5IBA qh6yZLZLx4cteFegp47jDWPXBTBGtxZ10S+Yg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iH8izYx1CVz5zaeZ+ywlrsYpOCO6qk+mt4vdLHF4sUs=; b=CSITje5uFkUO6X6HYTZq1mEhGi99y957HjXaa+FhmZfVttioFBgbiupeA+KWw2lUxe NdjpVI/pwSSwxAXacKa1c61QSYWv1kvSC6zSckQWwa4FHrgk5zF/DXejL+wmXySfGXeA 0Mcam2Vt++Cumz+f21O+8y7k2beAPR1DhzAyptlVledPwTwAHt+5zodgnsPGxV3I9tmH dCx+mFmn0KOuttir2aHI6exUkcwgeuDpgG5Km5RZ1OCDTuLDis+gt8lgSTcdBkaTHeDk jt98uFHus3UWnNb+0iei4R1Ne+WvCfAuRG+F3if8R/WhbspJv1jD3D4B3/bYcC2fdKyu g1Xw== X-Gm-Message-State: AOAM531siF+iRvgqy6F3JT4sHUBqbzkjmMopbuAyGgHvCQv6uxpZyQfd YVBCnfTq+tB4cHxc+uNmkj02TA== X-Received: by 2002:a05:6a00:2387:b0:4e0:5414:da5c with SMTP id f7-20020a056a00238700b004e05414da5cmr3976133pfc.85.1645028541563; Wed, 16 Feb 2022 08:22:21 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h26sm5903093pgm.72.2022.02.16.08.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 08:22:21 -0800 (PST) Date: Wed, 16 Feb 2022 08:22:20 -0800 From: Kees Cook To: Andrey Konovalov Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev , LKML , linux-hardening@vger.kernel.org Subject: Re: [PATCH] kasan: test: Silence allocation warnings from GCC 12 Message-ID: <202202160821.AA9264A71@keescook> References: <20220213183232.4038718-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Wed, Feb 16, 2022 at 04:26:46PM +0100, Andrey Konovalov wrote: > 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. Excellent point -- let me go re-test this. -Kees > > > 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 > > -- Kees Cook