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: 182440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp660015dyi; Thu, 21 Dec 2023 12:07:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEHa0z1WB7h6IK4dyNMxk1vuGbFpqaM4r9B+kanH1JwWNxrgOcCCMMBsQYWWbWQFuQbozV X-Received: by 2002:a1f:df84:0:b0:4b6:ba78:7029 with SMTP id w126-20020a1fdf84000000b004b6ba787029mr161147vkg.32.1703189244036; Thu, 21 Dec 2023 12:07:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703189244; cv=none; d=google.com; s=arc-20160816; b=Tx4vsGhC+qUg45ZNKs6FyraiecGgel5ocTcftpyKbB+IARgxrnF9GKZgnmTGrnFNpe 7uzmgPCp8C7dZHQB1xwnaDm5CEX0xPUxpCRQEbkeLu/2FM5I3rp8D72HiGsnwmPwsODh P49QY7oMFNNz1pz3750OniBsekN6ZR8APBv2mhMzK1SoTdJ0vB8yvo/70DocieYTqo3q CrTRUgrMRdDW4u+AHYpujkmhlC3B9odW9ykIUxoHIbBC8J4ZfXG+ywzUaD4h67tmvp7F XJEEvuQZP6VwK+JbWVPC7O0uMguDV/sTrlF0D7+ZuTWrOqP/txyhxN8WBBX3hGKiTzQ0 C57g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ColijDwhDovJxdnzDPHxNzx5OycMVFqUSNs1GHs5mVk=; fh=GyTEpUCUNPwsl1pqA0jDPXgvja+iZTM9USlQd9sQtQg=; b=IT8HSq/DI9397DEj3eNw1SlqMtv1KRYWpvdGJbLqZQmggf4zgp8O6iRWQlKyOm38rv fXZMockoMsXgI8Xm5XpZ7nE3fDlAxGUeOwTZfkv5bRxqKs+VyM5+8tYpCjKPTQEdJibX I7DqUQAFT4NzNk20ZUcj2Y92YEKaYjriPk3FIONKzMh4xYJUd0AbSsVlok6S+LbK9is3 1UEZVCpbWPlaPIeUH6FMX96gpZERtWK8HJecjLeKOPPrAnhYv+ZLx/JdixSX1tlUgV22 ELR7GOPZYPxL8+JXOHrc5+63rmiRPZCfooUkDYf2nfNSwYoSwyAyBnx96h977ChGXEGh xj1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=USMsmCfc; spf=pass (google.com: domain of linux-kernel+bounces-9026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9026-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t1-20020a1fc301000000b004b2e0a42caasi632107vkf.235.2023.12.21.12.07.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 12:07:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=USMsmCfc; spf=pass (google.com: domain of linux-kernel+bounces-9026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9026-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CA26C1C236E8 for ; Thu, 21 Dec 2023 20:07:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 071F676DD3; Thu, 21 Dec 2023 20:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="USMsmCfc" X-Original-To: linux-kernel@vger.kernel.org Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AD73745D7 for ; Thu, 21 Dec 2023 20:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785923364835570816 X-GMAIL-MSGID: 1785923364835570816 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++) {