Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3027979rwb; Mon, 15 Aug 2022 16:26:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dAriiINhwkZ08GsXIBtmKU77H6alaVicazlXchw6UqMn20cGrv9TMmikj58a/nCCXB9Uz X-Received: by 2002:a05:6402:84d:b0:435:a764:9aad with SMTP id b13-20020a056402084d00b00435a7649aadmr17387290edz.332.1660605984112; Mon, 15 Aug 2022 16:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605984; cv=none; d=google.com; s=arc-20160816; b=svReUZdQoBrpkChAE2ab8/Fm8HkAuZPLiRSt3tLb5TBEApKisW+b7bMY4oid7+3w0y nJnFY6JMgOYeEuzXuqjTtK64LN+k3QPrVy+oneCcJmiGZ63evOmk4Z4ALYCmsflLMXkI USX9A96Nr4ZCZaZ5y9p/ozGizcAnwfSyA5qwgMJBXXMmHWQvo7DdIZ6/6EJsCFPpHonS KqcvGwuKfY1UVTJZy1eCcXLBvE6ZqzQGR3fHIL7Xgh3YF3FQRG66dHEOQ363TOFDj51h W3u5J0fJ9KI6fGT/59ogLLnGCF3XzLYV3lNqBUxC46x5GJglXxmOsaANZGkApeFFUbxa paPg== 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=gEsiCc1uHZf2iIl1jS/mS/QK/9xcwoIBVTzboVIh2IQ=; b=YbZUePyZzO5STzq9mrjQV5FUgwrDEH85Ro+ECzLIur7/L41hXzh9gi3vwg7fVQ7LTa 16/Yrc6LE6E0E90w4l2FwuvG5nYdRkSwlIPSVUYIkvnIw74bD1GXDdj17Dg+4xIu0tpl p1TGXfCU9mibZbVYCrqDdDmIMfELh5t04VemHBNzkAcgCqJGRmDoQbtLpOTzsUTlOATs vYoA/MvKlscFOBfg3ta0kpoJ/j+52+1uF+VJBOnWV76epC1eUAsx6V5CzHsPBdlBiNHe kdRYAfqn9ANlhDEi0P6rtRe943WgEZKOugSoMSld2WnWhHTP6ZUNzNDxkXYPKQr4Bzeh UpTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dbiLDWCW; 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 qf6-20020a1709077f0600b00730babc11e3si11148460ejc.640.2022.08.15.16.25.58; Mon, 15 Aug 2022 16:26:24 -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=dbiLDWCW; 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 S1350785AbiHOWkn (ORCPT + 99 others); Mon, 15 Aug 2022 18:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350407AbiHOWgd (ORCPT ); Mon, 15 Aug 2022 18:36:33 -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 3C3A212F715; Mon, 15 Aug 2022 12:50:13 -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 3173861089; Mon, 15 Aug 2022 19:49:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CCE2C433C1; Mon, 15 Aug 2022 19:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592984; bh=rL2JjXrFDpp4+lMDb3vqOvN1N3q+hens8UpckDx4+5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dbiLDWCWvCSiLB1tYrEG1mohupS7QCz1H+APT4cyiHPPneWhmflKkUNln+hp7FOgy rQNTbLP4OowMS385R0kr0nl8FfSg54IaigiyYqCNLE4g2fQkY4Nm4RFt1wKUG/sziv DYsH8iMn+5hXdL0KUwdzedJ/H04lQ3hd+hHd9o4I= 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.19 0196/1157] kasan: test: Silence GCC 12 warnings Date: Mon, 15 Aug 2022 19:52:32 +0200 Message-Id: <20220815180447.555804762@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 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