Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3004490rwb; Mon, 15 Aug 2022 15:59:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR5DMjmSev1jYnsd1TgYKH/kh370mUq0lpI7mrFMcXdN6m086+GbUOzsMAKiNZ7JHQxCgdaK X-Received: by 2002:a05:6a00:1950:b0:534:ebea:546d with SMTP id s16-20020a056a00195000b00534ebea546dmr6108763pfk.77.1660604376488; Mon, 15 Aug 2022 15:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660604376; cv=none; d=google.com; s=arc-20160816; b=gapoCUSCJ0R3vBCZ5P3fpDW1IsuOcuRWnaEF4u+gRki3pxeaeUjkVGi6hsMie2o81o GBqf3UC/pmuEg+atHDxmYFPnAXIpKx/GaTri4diLE+MRlX94S8ziVSJpq143d45Fz2Qt ZJwVckFmJbSkTmHcpVoMzzhixoLrCPzc1iHF2X3CZR9h5qfC9j9BHMYSOUwlnacG/byc Yx3BrE14u+m7sQoeR2lI57BFlngx0AsDSZ5TXaLEZZhHg7plgMycR7G7yNLiOOeLj8lS eGbSsmpHs7YiNHyLOCYZeYDrhmR+42MUrXuOlxi6pvuZ/JoZgB7c0OV1e97ExRA9+/De EU6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NbVc0Vo1sLqcgfTOm2iqMSV26EFs3rA276g9CXnCZk0=; b=mdCVO1zG5u+VtDKnZxgR9hBtRc08g7iPY7rvMX/4rGlEZsW95Tc/YA6bIZEmnpIGDT rgJ5PV0GWqPQMAXI6s+aUsUGjj3GqpC7x8YaaMr9zfQu9IlXIxVmTv6TKc5fQe9gbpFn R2YK0+xXa65sIyMyNf+kFqsbJ/f1sP1mtEDrvzDqAaGnZe1Kn343zFEMxyHd1HNW7zwr hzjaagCXQg4PJLwBXx3BXTSljfIGBa1u7D2N3OtfAT5u54VtJe9YaUkHWR3GwSSEWocZ JF10N86rhDGaR1bjem0jdVwfcUvoxoVFA7RHUg1qDXakEWpgG+k7kmPAGfOqn8uJDFnI rpKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nnJPVBeZ; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a63ea0d000000b0041ccd457e9dsi12114404pgi.664.2022.08.15.15.59.25; Mon, 15 Aug 2022 15:59:36 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=nnJPVBeZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344562AbiHOUc6 (ORCPT + 99 others); Mon, 15 Aug 2022 16:32:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347526AbiHOUZz (ORCPT ); Mon, 15 Aug 2022 16:25:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36FDD9C51A; Mon, 15 Aug 2022 12:03:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9D775B81107; Mon, 15 Aug 2022 19:03:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB140C433C1; Mon, 15 Aug 2022 19:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590186; bh=9JSTDmXy453rHTFb12rtKlZSkrD3HQt1RpXe4eSj4RY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnJPVBeZJ6xFKtUGeAGIgu2k1lK/i4utPti+u5sE0Qgjhoyu/MrqHvLPSSn+6ubjb Wziy1iE+PpOcBk/k+9ngmCNMUYN/ggKf/niWfd2jDmQ2EHLznuF8C2RsABLK83eCBF BvLeAXYXGhU28b9/kP7tj8ZJ1gza0GpyskqPKlEg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, Kees Cook , Sasha Levin Subject: [PATCH 5.18 0180/1095] kasan: test: Silence GCC 12 warnings Date: Mon, 15 Aug 2022 19:52:59 +0200 Message-Id: <20220815180437.088934858@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Kees Cook [ Upstream commit aaf50b1969d7933a51ea421b11432a7fb90974e3 ] GCC 12 continues to get smarter about array accesses. The KASAN tests are expecting to explicitly test out-of-bounds conditions at run-time, so hide the variable from GCC, to avoid warnings like: ../lib/test_kasan.c: In function 'ksize_uaf': ../lib/test_kasan.c:790:61: warning: array subscript 120 is outside array bounds of 'void[120]' [-Warray-bounds] 790 | KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~ ../lib/test_kasan.c:97:9: note: in definition of macro 'KUNIT_EXPECT_KASAN_FAIL' 97 | expression; \ | ^~~~~~~~~~ Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Vincenzo Frascino Cc: kasan-dev@googlegroups.com Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20220608214024.1068451-1-keescook@chromium.org Signed-off-by: Sasha Levin --- lib/test_kasan.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index ad880231dfa8..630e0c31d7c2 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -131,6 +131,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. * Only generic KASAN can precisely detect these. @@ -159,6 +160,7 @@ static void kmalloc_oob_left(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 = *(ptr - 1)); kfree(ptr); } @@ -171,6 +173,7 @@ static void kmalloc_node_oob_right(struct kunit *test) ptr = kmalloc_node(size, GFP_KERNEL, 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); + OPTIMIZER_HIDE_VAR(ptr); KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = ptr[size]); kfree(ptr); } @@ -191,6 +194,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); @@ -271,6 +275,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); } @@ -410,6 +415,8 @@ static void kmalloc_oob_16(struct kunit *test) ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); + OPTIMIZER_HIDE_VAR(ptr1); + OPTIMIZER_HIDE_VAR(ptr2); KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); kfree(ptr1); kfree(ptr2); @@ -756,6 +763,8 @@ static void ksize_unpoisons_memory(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); real_size = ksize(ptr); + OPTIMIZER_HIDE_VAR(ptr); + /* This access shouldn't trigger a KASAN report. */ ptr[size] = 'x'; @@ -778,6 +787,7 @@ static void ksize_uaf(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); kfree(ptr); + OPTIMIZER_HIDE_VAR(ptr); KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr)); KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); -- 2.35.1