Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3663771rwb; Sun, 25 Sep 2022 10:17:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WsNyyj0olwTFK5TDaJH8UPWuKBZxMmG+9A3fZCuCgtKlvNacknU+xNJRvwfxWb9FC/RJm X-Received: by 2002:a17:907:961e:b0:782:670d:9ff9 with SMTP id gb30-20020a170907961e00b00782670d9ff9mr14234585ejc.387.1664126260535; Sun, 25 Sep 2022 10:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664126260; cv=none; d=google.com; s=arc-20160816; b=QInNc95oBO2jlxMCTeoFCezAETr7/m8osyj3n4fy48Xy8aCrW0ATzalDGX/jJ9v9vt Ba8GrqJEVtv3TELGQzQHy/0Sr0x2WrhkZc8Zv00YcEcIxZ9KZrjyuTS4cnLVPL1RI9r0 MnoXlNbOGfEGAzGjfO5idyorQiGvewYglVqIAXd35/bEOJvzFeeV9AXr/vI1NXX7pTgJ EzoHYP2BYW60NQW3v+xaOr1u3GorYUWGpYzk15q8ZsoaTbqq3jxwaM7zsKnmBSLJKsIQ ljJMr3u78HQx1obXHDQnpBxVIR4I7G9KHobq890PvAG1xbc0FzSn5fPvkCIP2w5WdHkY j/Kw== 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:subject:cc:to:from:date :dkim-signature; bh=ET9jid1fFz41r3oSHHroP+XNjGjrtmMKMEMT1FtwlQg=; b=g2UjLtCb/HokOEi/vhJdSb4yCOcYw9+VY54rx2fH054Q2k54cAPnaLxOZLil7aDKA8 CdJqKzkHVqx7oA/iWqh06pX1i5ChVrIuWu6nzhN0WIKqU7fUfMwSdJfda+dJsosUG4uH huzJqOd4kxuESsT+RwRYgQA9qd1V/RwH6ZXYjLNRUhTElD11kmp06kJGvvFSgOogGMyT V5EPraeExD717kByT2vNzXt7gXlpzl6tsZ3uKdUYH/fdbazYvgrH+VUubLhXmXgD+wIf 3TjZPa3jdbCSYsQxjfTa7YDFOOcIBaLJGvuaIvteeIG8v/iZcSd/mRy5Mce0zU4Czggt llJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=hbIdH3Y6; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he36-20020a1709073da400b007804f3dafbesi450744ejc.587.2022.09.25.10.17.15; Sun, 25 Sep 2022 10:17:40 -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-foundation.org header.s=korg header.b=hbIdH3Y6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232732AbiIYRDX (ORCPT + 99 others); Sun, 25 Sep 2022 13:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231770AbiIYRDT (ORCPT ); Sun, 25 Sep 2022 13:03:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2FA2D1D7 for ; Sun, 25 Sep 2022 10:03:17 -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 68A7EB81261 for ; Sun, 25 Sep 2022 17:03:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F534C433D6; Sun, 25 Sep 2022 17:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1664125395; bh=wt+mZDy4YvA8gmtHTDKqy0I4i4iX1GwGHxWqk6D/Uak=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hbIdH3Y6FUgeCxQPNbi72CVz9puHGeo+av3JO16m3Ce+0rhIjrV8W4FKB2VFqIcrj /gz0gAnJeKOqtbDyFfnKG7x/Pg8jVw8tDkHAeOiqKW2wKehK8qXlSfBrpIf4rr4wJu lG62pIRFUowy8mSLre9DwM+PENnHf3wRazvhUF00= Date: Sun, 25 Sep 2022 10:03:12 -0700 From: Andrew Morton To: andrey.konovalov@linux.dev Cc: Marco Elver , 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: Re: [PATCH mm v2] kasan: fix array-bounds warnings in tests Message-Id: <20220925100312.6bfecb122b314862ad7b2dd4@linux-foundation.org> In-Reply-To: <9c0210393a8da6fb6887a111a986eb50dfc1b895.1664050880.git.andreyknvl@google.com> References: <9c0210393a8da6fb6887a111a986eb50dfc1b895.1664050880.git.andreyknvl@google.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 On Sat, 24 Sep 2022 22:23:21 +0200 andrey.konovalov@linux.dev wrote: > 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. > > ... > > --- 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); What chance does a reader have of working out why this is here? If "little" then a code comment would be a nice way of saving that poor person for having to dive into the git history. > /* 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