Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2704211rwb; Sat, 24 Sep 2022 13:26:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EiagqdAHSqTz7hs5Ta8SZKxlIB7KM1BbVFojpzpbnF+25gd2ItWh/A8WtAOkH0Dl0fY85 X-Received: by 2002:a17:902:d54d:b0:178:a62d:d4e6 with SMTP id z13-20020a170902d54d00b00178a62dd4e6mr15004353plf.73.1664051205931; Sat, 24 Sep 2022 13:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664051205; cv=none; d=google.com; s=arc-20160816; b=Hll14BZZ52TwCJ8T5ADfSVgwqb+ci22pbMyHVTqd8WBuZRcSef4uusAg/jS8p+HyBA 5fHxFdwxZXov7OO9Cnizktb/Qfqf9QmEbnaw4upvg2dTHSA8iJOmLBFOGONLBhWy9Ol3 0WzQiywNilDs4eATEP0gDNYvCGs/CxfRiNYnmLr0QHl0cFLeSiS2HhpyndAtNhXd0BbH dXni3I2Uglm96a5vzHaNcXplM6nbgja6ssDJtLWkrlhzZkJIGKyXNh1DVzcSMwhhXU7M hODjTLuFg0kkeZfMa1rW/0aI2vL8vhE6pOE6VOwCaNnLDKaFxDTFEM+oG+TCYIqyuTK4 bhFA== 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=nC3nuVqN+jtEUN74Nl68oDoRxZZaXpDu+Kubg+3Y4uE=; b=01ojPn0ws7FAHMu8AIeUIHa/a/KHP+iX6SsuqWTk8voNLwhnyYsw7VFhPxPFbD7GDC B8V+xR0XggrEJFdiU4g/HvLuI4kfCSzLnP3iaKXY55kHa1+qKc+j9d7L1+QohzpJnP8K epVkDiPPztHS/n9xgDunkx4S2jraxfd3fM4bFYEHKdCPQ0+Sc1rT4e5qepjIJP9MYpj9 rkMmPR+ikEnkBmMIo/yKKQvethnNj/+Gy8WpQWkDSYMHdFdZhpFi/RVKEtkinK+GJexc EOS7h/Sc2KED4tGnUGDAt8StVf2axGly/1u+Ndhly6PAWq6qZZWBj14wQeD6ijN76SVJ Iqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="K5b/cTkQ"; 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 l12-20020a63da4c000000b00438a4023e2dsi12771474pgj.574.2022.09.24.13.26.34; Sat, 24 Sep 2022 13:26:45 -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="K5b/cTkQ"; 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 S233463AbiIXUX2 (ORCPT + 99 others); Sat, 24 Sep 2022 16:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiIXUX1 (ORCPT ); Sat, 24 Sep 2022 16:23:27 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 175E140BDB for ; Sat, 24 Sep 2022 13:23:25 -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=1664051004; 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=nC3nuVqN+jtEUN74Nl68oDoRxZZaXpDu+Kubg+3Y4uE=; b=K5b/cTkQVPZHrmVwC5a5EZ6fbHafwPdgOTRisgbxnFrlDyFsNV8EppN8s8pwk3WvoYaKMh 2jMjRVOcQmLC7gpvopmtr3Sjin8ubOEGUnRny9AGIWZGq0fj7LCCb784kCWrUGCCFlpiDQ mFqrQzCTdUdXXfuIweR95PiUh6ngdA4= 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 v2] kasan: fix array-bounds warnings in tests Date: Sat, 24 Sep 2022 22:23:21 +0200 Message-Id: <9c0210393a8da6fb6887a111a986eb50dfc1b895.1664050880.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 --- Changes v1->v2: - Hide ptr2 instead of size1 and size2 to be consistent with other uses of OPTIMIZER_HIDE_VAR in KASAN tests. --- mm/kasan/kasan_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 71cb402c404f..dbb0a672380f 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -333,6 +333,8 @@ static void krealloc_more_oob_helper(struct kunit *test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); + OPTIMIZER_HIDE_VAR(ptr2); + /* All offsets up to size2 must be accessible. */ ptr2[size1 - 1] = 'x'; ptr2[size1] = 'x'; @@ -365,6 +367,8 @@ static void krealloc_less_oob_helper(struct kunit *test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); + OPTIMIZER_HIDE_VAR(ptr2); + /* Must be accessible for all modes. */ ptr2[size2 - 1] = 'x'; @@ -578,13 +582,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