From patchwork Thu Dec 21 20:04:50 2023 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: 13502604 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 C0D9CC35274 for ; Thu, 21 Dec 2023 20:06:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A36D76B009A; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94AB76B009B; Thu, 21 Dec 2023 15:06:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 776DC6B009C; Thu, 21 Dec 2023 15:06:09 -0500 (EST) 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 5A7626B009A for ; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0C16F1C03B6 for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) X-FDA: 81591906858.12.35D9DC1 Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) by imf08.hostedemail.com (Postfix) with ESMTP id 34AA1160027 for ; Thu, 21 Dec 2023 20:06:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=USMsmCfc; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189167; 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:in-reply-to:references:references:dkim-signature; bh=ColijDwhDovJxdnzDPHxNzx5OycMVFqUSNs1GHs5mVk=; b=hJAbra9o+ECKGBW3UVm0njra0AZZEbk8qAr6asxIjbIkU9Mqhni/DtvVFcjbVcq93TNIJK uQT5ldTK7A+pLip0DseT+kOIDAyTCaHnaPcmB3wrGNkBjWOcoG/Sm9VSey3IYERIwtY67d ON3Gq9CP9RzwCP5Nzn2LDmClBZ5EX2M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=USMsmCfc; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189167; a=rsa-sha256; cv=none; b=ASaKPnPqZ7vdd70jbJHuaakgRssS77TcZUFAupq9Wy2x8/XvK1BC6lQUAv0K+W/Noh1lIY xM3QoGNo9mj/r4pbYMX6A6B2ZX2MDJ9qtbB6y6IMIcaM9tMYs3YW8Pay6qnGw85nOPFXzo 2jaZMwE9ul1aEP1bx/Y+1f/EmjmEaNY= 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=1703189165; 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: in-reply-to:in-reply-to:references:references; bh=ColijDwhDovJxdnzDPHxNzx5OycMVFqUSNs1GHs5mVk=; b=USMsmCfcfZYE03AC87Gmpyp9gmlr/kMJv0pWBUPw9nx0sHm6vrJx9MiJnMGDlRy1Np+vvg xVnk34bog6bJEXPpd1W0ZhX/6rrSohpzazwxYlJ0CsIiIqPW+tM023kd9Pj1/tI00TxpVr 7puIg/6gNeTx8rsKTuL0nS4IqNynK+s= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 08/11] kasan: check kasan_vmalloc_enabled in vmalloc tests Date: Thu, 21 Dec 2023 21:04:50 +0100 Message-Id: <954456e50ac98519910c3e24a479a18eae62f8dd.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 34AA1160027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fa7rft1kgnr5wu64yqyher6wrhqew3g1 X-HE-Tag: 1703189166-949720 X-HE-Meta: U2FsdGVkX1+1LWCgGkm43UmxYOvJQ4NBI1MFtafL1eGY1eLHtgjuxnsog9oUxq/IR/Al/0HLQJ+D1mEZ9qBBK6zppiiPvs717p3oMmxXTYKNVedJaVWevjpAyWiihHBslU70LzE0q5P26+uUBqz0uMfO3lMkcml+9Uf8BOC1W9GroKOlilcerG+Y++jVCfSC4aobXJDML/COOcn4o1sahexKXjPKEGxH0U8tHw0N946xSt6xeMPSks5h6lHoFvNTXUJ7yMcI/HAPotVpBU5Tq6FGeaT7gAcMGK1kryWCiocWklWVfS9/lKL9Uo3n0QfH+RmHB3DjgfbJZgewhRm3A0GZMcAQ+zZRZgLnD0CoUGnpd9buyMeJBJpp2CsK43jN7093oN4Jt20h02g130ze2314W/CKq2Y0MjeJo/XJogHnAEb0AZtUbMQtJdBKx5CVctaZ3DgEz2ITBnukaRgZZIKmwhFfowcfozFwHX6naXN76YxmR8do+i22eNztN2huQM9QZ1aMOAHH+30ptZCf1UD+WH44zsbUaLdnVwu3qqu/ePkly3FEqSJYn3M1MsZukmOUEep6HIDrYT2OQgRvmQzTm2dSccqSFHJyXwnuBN4NQVXyKRCcFjSrovFuBJ1GO/1JCnHii4q3r5X5Qwt/WgRtj5YW7MJEbFdK7Y29GZLM97879d0fVCgh2WMytX6AWYJqJEQFlB4XeqorYk+zCkAjT+RLylUqgMsPbj4zjf8qbSusmgHGSmzGoouJipqnY3+mfIDjFL7PGpgUHJdi2uwWJ54ALmBKO932Z0yWTxeTU2PADS8UDBGrfbIYcfg9XhL8bXE6jUOixvP+N9J7AGjyQMFy1Se+LmCIVCHAga46GHYQICyM1eai90Tq6YegDlRQBj04txg/a+I3VCrH189UK535+qSiN2shwjZcXyAmqIGiqzGEjaxemvI/mi7iHL29yxTClDEMCeYSELK QI1hOrgR C+r3HG6Fapk+HbdWzZCs3fPCCC/L0q0F28HZqIlP0kmPbvmbu5wDMlgNMacd1Ys00uOGK+Hr7XbtUDo31HEwjST984HXlP2MOQAWFuJps73p01IIPLK/Z0YM/bva6MzVraat4oKKSVt4Z6OtAAayhJgOSZ1J/gBw/NPgKwXkRtnI+xCAKdOiP2khpKuEVnvFett3x2CiCDQxFY4rysQsz2CVPbw== 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Check that vmalloc poisoning is not disabled via command line when running the vmalloc-related KASAN tests. Skip the tests otherwise. Signed-off-by: Andrey Konovalov --- mm/kasan/hw_tags.c | 1 + mm/kasan/kasan.h | 5 +++++ mm/kasan/kasan_test.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 80f11a3eccd5..2b994092a2d4 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -62,6 +62,7 @@ DEFINE_STATIC_KEY_TRUE(kasan_flag_vmalloc); #else DEFINE_STATIC_KEY_FALSE(kasan_flag_vmalloc); #endif +EXPORT_SYMBOL_GPL(kasan_flag_vmalloc); #define PAGE_ALLOC_SAMPLE_DEFAULT 1 #define PAGE_ALLOC_SAMPLE_ORDER_DEFAULT 3 diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index dee105ba32dd..acc1a9410f0d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -83,6 +83,11 @@ static inline bool kasan_sample_page_alloc(unsigned int order) #else /* CONFIG_KASAN_HW_TAGS */ +static inline bool kasan_vmalloc_enabled(void) +{ + return IS_ENABLED(CONFIG_KASAN_VMALLOC); +} + static inline bool kasan_async_fault_possible(void) { return false; diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 1c77c73ff287..496154e38965 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -1540,6 +1540,9 @@ static void vmalloc_helpers_tags(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + ptr = vmalloc(PAGE_SIZE); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); @@ -1574,6 +1577,9 @@ static void vmalloc_oob(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + v_ptr = vmalloc(size); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); @@ -1627,6 +1633,9 @@ static void vmap_tags(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + p_page = alloc_pages(GFP_KERNEL, 1); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); p_ptr = page_address(p_page); @@ -1745,7 +1754,7 @@ static void match_all_not_assigned(struct kunit *test) free_pages((unsigned long)ptr, order); } - if (!IS_ENABLED(CONFIG_KASAN_VMALLOC)) + if (!kasan_vmalloc_enabled()) return; for (i = 0; i < 256; i++) {