From patchwork Tue Feb 15 18:39:38 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: 12747498 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 7F5DBC433EF for ; Tue, 15 Feb 2022 18:39:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EECD56B0078; Tue, 15 Feb 2022 13:39:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C7C6B007B; Tue, 15 Feb 2022 13:39:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8C066B007D; Tue, 15 Feb 2022 13:39:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id C8E106B0078 for ; Tue, 15 Feb 2022 13:39:43 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 919388249980 for ; Tue, 15 Feb 2022 18:39:43 +0000 (UTC) X-FDA: 79145877846.06.128D12E Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf06.hostedemail.com (Postfix) with ESMTP id D913D180005 for ; Tue, 15 Feb 2022 18:39:42 +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=1644950380; 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=pwV+5NwZYvQrQ1JgfEXwuJfZqiKqAoxKp8Wr6tUObj4=; b=tWXktW8oDUS1MhFseJtb3CLIKZuWLrPDlv2sQlq+eyNkoNG1e/ZPG6PDlwMn2tYaAx5EW6 9UtA67ZGSmseXId+wLFPydBzmgeXSAb/AdIjZo9BxnBvVkt5eJSjVaeN/RrpBRQIffZ97l +19DsKFp5Hnxmwaped+jsGsDYi/30LE= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm] fix for "kasan: improve vmalloc tests" Date: Tue, 15 Feb 2022 19:39:38 +0100 Message-Id: <865c91ba49b90623ab50c7526b79ccb955f544f0.1644950160.git.andreyknvl@google.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D913D180005 X-Stat-Signature: 4fxj4txyuiroaccgy6goorxq8ipewbjo Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tWXktW8o; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-HE-Tag: 1644950382-368531 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 vmap_tags() and vm_map_ram_tags() pass invalid page array size to vm_map_ram() and vm_unmap_ram(). It's supposed to be 1, but it's 1 << order == 2 currently. Remove order variable (it can only be 0 with the current code) and hardcode the number of pages in these tests. Signed-off-by: Andrey Konovalov Acked-by: Marco Elver --- lib/test_kasan.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 491a82006f06..8416161d5177 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -1149,7 +1149,6 @@ static void vmap_tags(struct kunit *test) { char *p_ptr, *v_ptr; struct page *p_page, *v_page; - size_t order = 1; /* * This test is specifically crafted for the software tag-based mode, @@ -1159,12 +1158,12 @@ static void vmap_tags(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); - p_page = alloc_pages(GFP_KERNEL, order); + p_page = alloc_pages(GFP_KERNEL, 1); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); p_ptr = page_address(p_page); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); - v_ptr = vmap(&p_page, 1 << order, VM_MAP, PAGE_KERNEL); + v_ptr = vmap(&p_page, 1, VM_MAP, PAGE_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); /* @@ -1186,14 +1185,13 @@ static void vmap_tags(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, p_page, v_page); vunmap(v_ptr); - free_pages((unsigned long)p_ptr, order); + free_pages((unsigned long)p_ptr, 1); } static void vm_map_ram_tags(struct kunit *test) { char *p_ptr, *v_ptr; struct page *page; - size_t order = 1; /* * This test is specifically crafted for the software tag-based mode, @@ -1201,12 +1199,12 @@ static void vm_map_ram_tags(struct kunit *test) */ KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); - page = alloc_pages(GFP_KERNEL, order); + page = alloc_pages(GFP_KERNEL, 1); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); p_ptr = page_address(page); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); - v_ptr = vm_map_ram(&page, 1 << order, -1); + v_ptr = vm_map_ram(&page, 1, -1); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); @@ -1216,8 +1214,8 @@ static void vm_map_ram_tags(struct kunit *test) *p_ptr = 0; *v_ptr = 0; - vm_unmap_ram(v_ptr, 1 << order); - free_pages((unsigned long)p_ptr, order); + vm_unmap_ram(v_ptr, 1); + free_pages((unsigned long)p_ptr, 1); } static void vmalloc_percpu(struct kunit *test)