Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4254058rwb; Sun, 7 Aug 2022 19:26:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6J9Xnfff18HArM+2M167Y3ZyL6pag0D/WL9AUPkaJ/iSLpJcgiIUfQCvZbiyoexGNWSolt X-Received: by 2002:a17:90b:3586:b0:1f4:d507:783e with SMTP id mm6-20020a17090b358600b001f4d507783emr26473345pjb.171.1659925612323; Sun, 07 Aug 2022 19:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659925612; cv=none; d=google.com; s=arc-20160816; b=H26gIs4d7aflyXlIe0Vf3seI0aDII7lrZVmaZ43tQdo/wb5dq+sN1oNZnJ1pGQj70m rEAMktazYoNV2/9XTl/S0fCjcJ8r9peY9J8jXJCgtwAYvZI5r1x07jEeFX+lE84nIe6U b2wsNWA0pcXxe+B74jYe1weFWNxl7bcGKnoHfiazao7G/9hTuUSl+cVYqueVu8kWIsC8 jlkYU+vI9qlDT+6IyjQeR2ozmFi8qL8wWND62KbQdDjG5QBvp2NapqLKgwes9N2O87vN 0j72cCVPTZuc5PQV0sOZYciZ79lmtXGYt4D/jZoNa0xPu4+nxiBklHBzlbjz1Wkf6mxj VGQA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gEsiCc1uHZf2iIl1jS/mS/QK/9xcwoIBVTzboVIh2IQ=; b=emy3XDzJuF+Th5CZRfMGYpTA/+SpgLx8KAWnTyX6uBWd6omJiH+xwRRGuurHpLIjEX ILmw2qsgifTivyt6stucvlYAYFiJ4bZnyE3/AjV9rO12DQu15SbBVKCLIN0bXMQnsKiE vHmGdOBQ+AfA/PMgQHVuhhHaHiRu48tsTnjy9hjyIXWqXjJ+5VbcHcQmwJyl+9rA0J+a rw4YwRIM+82F/lMtup/TZhGIDroSY8vKW/0gQePHtxH+vvG0eehJ39q1RsgwXYTWwAMr HyZSvVfiMqT22dowbWGoagbsB7bIlcbiT6Mw/EvOlY+W9x3/LUHErqBkUxdFhN7+o2um v+gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VYhjA4VU; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a170902bd9300b0016d43e38858si9279602pls.605.2022.08.07.19.26.38; Sun, 07 Aug 2022 19:26:52 -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=@kernel.org header.s=k20201202 header.b=VYhjA4VU; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242358AbiHHBij (ORCPT + 99 others); Sun, 7 Aug 2022 21:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiHHBha (ORCPT ); Sun, 7 Aug 2022 21:37:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6B1DE88; Sun, 7 Aug 2022 18:33:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C351060DE1; Mon, 8 Aug 2022 01:33:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04E9AC4314A; Mon, 8 Aug 2022 01:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659922426; bh=rL2JjXrFDpp4+lMDb3vqOvN1N3q+hens8UpckDx4+5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYhjA4VUCMNqJFtIlXcpKsH7G3spkZ5Y3/Bvi7J/QbiKXgjPsKaaOEmFMwxbIf5c0 YokhOZ+cYYDtWep/W0DGuxw/tKtwLvWluYIp0JNALFx7yhjHHZe9Pf24lEgVgBcLnA H9tFWWxiZe8EJN4p5n0WYsJ/wuEpUS5aYhDu7v9T8NowiIrIXxasmxrG+YSUzfaBIx QnR4bxc6kuYUCXz+sjOiFx4hMFVNxNF1BBn5fJAtdT+Dlv+i7+IgBemi314X1JyeMH KvNM8NHkbTJRjxZoZKfH1BLLitamJ1RSSp6QSIBpej3egZZvk5j0srU4DutIodLb6c CidA7fPPSVXqg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, Sasha Levin Subject: [PATCH AUTOSEL 5.19 57/58] kasan: test: Silence GCC 12 warnings Date: Sun, 7 Aug 2022 21:31:15 -0400 Message-Id: <20220808013118.313965-57-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220808013118.313965-1-sashal@kernel.org> References: <20220808013118.313965-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 c233b1a4e984..58c1b01ccfe2 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