From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 215E8C54EE9 for ; Sun, 25 Sep 2022 17:03:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AF2D8E001E; Sun, 25 Sep 2022 13:03:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45EE18E0007; Sun, 25 Sep 2022 13:03:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 327278E001E; Sun, 25 Sep 2022 13:03:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 205CD8E0007 for ; Sun, 25 Sep 2022 13:03:19 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DBB37AAA2E for ; Sun, 25 Sep 2022 17:03:18 +0000 (UTC) X-FDA: 79951228476.16.9F1A073 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf18.hostedemail.com (Postfix) with ESMTP id 680C41C000B for ; Sun, 25 Sep 2022 17:03:18 +0000 (UTC) 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 5F8E4B80BEC; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664125398; a=rsa-sha256; cv=none; b=4EkVZ6RL06xafqWSzopPCqRkwGzEMVYR5GLOUhCCU2Ewn50jnGRgK3nYkJzlhYNlEvC0TN q6WsMqNBJpsOQCK1vk1OLoaGWSwyTKU+Gec8sUC5Iz2lYI8vp+b2OlsQlchgBmdvUQ3dHM DnrBe+ihUCLfHfutENW5WFRdeCKXTKg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=hbIdH3Y6; dmarc=none; spf=pass (imf18.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664125398; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ET9jid1fFz41r3oSHHroP+XNjGjrtmMKMEMT1FtwlQg=; b=2AoECrvoC7ZeUABaz7bLtob+KZsgmtRtqJhk54/iCHgV+vp8qp8+ek07YEBqUrQdd3nSNX vKDEzYWQxiKY7y9GP0s5/4DYrFtlHmlv8tS/RwEX3ZrdvRiT5naXCFtkqB0+9lYtVAhtiI GyiL0nrfW/ilLh5GXe4nk0zNMT3lPQQ= X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 680C41C000B Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=hbIdH3Y6; dmarc=none; spf=pass (imf18.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: bbi7dgb1q79sqwczipa3bid4wk1wdzer X-HE-Tag: 1664125398-905765 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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