Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2704015rwb; Sat, 24 Sep 2022 13:26:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qlFr/m9I8P5ilbA7vrvdft/mHeEFqXuLnarMi9G5vES2PbYG+9gLdfD0/Av7wChLVwytB X-Received: by 2002:a17:90b:30d0:b0:200:22a4:bfcf with SMTP id hi16-20020a17090b30d000b0020022a4bfcfmr27864991pjb.181.1664051186367; Sat, 24 Sep 2022 13:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664051186; cv=none; d=google.com; s=arc-20160816; b=hukzujvOGmTnYDc2bboLP5+5gAYK6GmzNdX8IATumwvsAae16YlofpZggZ24AOM8zh 65l8K06SdFSwJN9WadoEsSd6i7opZiKjkm8lO2HTJg+8Fs13rXFGvUbqP5jNoLYEnQfb YIu6vrWZqlnl21zgAv6LqNamhkh9ElgJW0haAHSMGVUyP/T4jYES4/gSNsGYOybgWfD4 9GPcA99seD5AdWlV14L3dLYlpCNadxB+1WoGWfXkYnc0O7v5dZrZpM6af823v5Ldngij NQZYWFu2Oi8pVAvlSMsWVfSfbWubYIfWR07RbVsJVW4b+E/8ekFZRDjuhDvbVVeW+uCi Km1A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=EcbtpHcwl1Nm1cXUQncscydMAW3SGpJ+fUyDvKUD0nQ=; b=dmcacIHtQtv/0D8My9GVri+92nYtF/sCwr2rtcMaxSR4OPOykHrGmjcEDD9Fm2Jjrk GTjG31IpRiOzefLPEODOt4gJAXxf+Rw1qBLvwkj+pGIOY5cf1FyxvmK3JwXVt7/jx+P2 LGBSu0Scz0EtDe+NrYiQ7BkDDFG+k3y450ifskrc3U1ATUE9BxZCI75oxJc4MC+U2qBT M5u6vo3yOd7uO9KrFIVPbv/Fp4MoMuIK/1+KNIP713gPzeXZ6d4DBfT1YZS2dtOAppA4 IBt3OQRu2/N3fr5LX1BAq70rvmgTemhA36hCn6+Vc2wPTM0uYsaX4PhqiZX6jBH4P6pl R9zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CcFOjNnK; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a63af55000000b0043c7b0510d9si2928664pgo.556.2022.09.24.13.26.14; Sat, 24 Sep 2022 13:26:26 -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=@linux.dev header.s=key1 header.b=CcFOjNnK; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbiIXUNg (ORCPT + 99 others); Sat, 24 Sep 2022 16:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiIXUNd (ORCPT ); Sat, 24 Sep 2022 16:13:33 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B13D25467B for ; Sat, 24 Sep 2022 13:13:31 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1664050408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EcbtpHcwl1Nm1cXUQncscydMAW3SGpJ+fUyDvKUD0nQ=; b=CcFOjNnKphgG+wY7I/0DvqEcGZ5n7WzssWBxwk/AvymIZh5IV2os3XuTWymxLHwrVXKk4M V6UC2WdeIHc53aLIVcygXEoXq/zKzE9dIU7sW0+RmU85ZR+0UrSI0NaEuFbZt4fLsi2GZB nKTzhjVfnhH3j/5Cb/JapNV49ktpch8= From: andrey.konovalov@linux.dev To: Marco Elver , Andrew Morton Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Kees Cook , linux-kernel@vger.kernel.org, Andrey Konovalov , kernel test robot Subject: [PATCH mm] kasan: fix array-bounds warnings in tests Date: Sat, 24 Sep 2022 22:13:27 +0200 Message-Id: <288e31a608ba707ea6de47fc6b43d8d79bb2d252.1664050397.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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: Andrey Konovalov GCC's -Warray-bounds option detects out-of-bounds accesses to statically-sized allocations in krealloc out-of-bounds tests. Use OPTIMIZER_HIDE_VAR to suppress the warning. Also change kmalloc_memmove_invalid_size to use OPTIMIZER_HIDE_VAR instead of a volatile variable. Reported-by: kernel test robot Signed-off-by: Andrey Konovalov --- mm/kasan/kasan_test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 71cb402c404f..1d51efe131db 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -324,6 +324,9 @@ static void krealloc_more_oob_helper(struct kunit *test, char *ptr1, *ptr2; size_t middle; + OPTIMIZER_HIDE_VAR(size1); + OPTIMIZER_HIDE_VAR(size2); + KUNIT_ASSERT_LT(test, size1, size2); middle = size1 + (size2 - size1) / 2; @@ -356,6 +359,9 @@ static void krealloc_less_oob_helper(struct kunit *test, char *ptr1, *ptr2; size_t middle; + OPTIMIZER_HIDE_VAR(size1); + OPTIMIZER_HIDE_VAR(size2); + KUNIT_ASSERT_LT(test, size2, size1); middle = size2 + (size1 - size2) / 2; @@ -578,13 +584,14 @@ static void kmalloc_memmove_invalid_size(struct kunit *test) { char *ptr; size_t size = 64; - volatile size_t invalid_size = size; + size_t invalid_size = size; ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); memset((char *)ptr, 0, 64); OPTIMIZER_HIDE_VAR(ptr); + OPTIMIZER_HIDE_VAR(invalid_size); KUNIT_EXPECT_KASAN_FAIL(test, memmove((char *)ptr, (char *)ptr + 4, invalid_size)); kfree(ptr); -- 2.25.1