From patchwork Sat Sep 24 20:13:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12987823 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 469A7C32771 for ; Sat, 24 Sep 2022 20:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3756D8E0014; Sat, 24 Sep 2022 16:13:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FDF58E0007; Sat, 24 Sep 2022 16:13:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19E968E0014; Sat, 24 Sep 2022 16:13:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0685D8E0007 for ; Sat, 24 Sep 2022 16:13:32 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9B8991205CE for ; Sat, 24 Sep 2022 20:13:31 +0000 (UTC) X-FDA: 79948079022.22.496351E Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf25.hostedemail.com (Postfix) with ESMTP id 15A27A0002 for ; Sat, 24 Sep 2022 20:13:30 +0000 (UTC) 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 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CcFOjNnK; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664050411; a=rsa-sha256; cv=none; b=TdFCv7msjsbpSNEvSqxEcAInYesV8sWQY+AaNKx4qdborUQ3agRavmJRkx2pOpJHwg/ORP yTpQJPMZQYU7NlSo6q8CD3oLLv1TakEm86k2cgRn2KFUWbRh2mUrgM+jcwL8DBnubwWT7U 75JCvizDahE7YtgHmfnwuQfulgf3k6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664050411; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=EcbtpHcwl1Nm1cXUQncscydMAW3SGpJ+fUyDvKUD0nQ=; b=AdQl9G+e2TvWgPWJzniY2O733+HY38uyqYIwivuHUUDFJo7QUj18wWt4YTUYse+CShipE0 C0nvAKSJDjPNIEG6XDvjXf3QW2hMbgw1ibc99odFmovVZy2yBebqPqjAsMLuFn71yhVWlz GUoFRh+KtHTnXX9H31KxQxMbXarbSUk= X-Stat-Signature: i3po8cmfo5oc7a8ow8hzgodytqepwqzs X-Rspamd-Queue-Id: 15A27A0002 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CcFOjNnK; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1664050410-328017 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: 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);