xref: /freebsd/sys/contrib/openzfs/module/os/linux/zfs/kasan_compat.c (revision 546d3d08e5993cbe2d6141b256e8c2ebad5aa102)
1*546d3d08SMartin Matuska // SPDX-License-Identifier: CDDL-1.0
2*546d3d08SMartin Matuska /*
3*546d3d08SMartin Matuska  * CDDL HEADER START
4*546d3d08SMartin Matuska  *
5*546d3d08SMartin Matuska  * The contents of this file are subject to the terms of the
6*546d3d08SMartin Matuska  * Common Development and Distribution License (the "License").
7*546d3d08SMartin Matuska  * You may not use this file except in compliance with the License.
8*546d3d08SMartin Matuska  *
9*546d3d08SMartin Matuska  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*546d3d08SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
11*546d3d08SMartin Matuska  * See the License for the specific language governing permissions
12*546d3d08SMartin Matuska  * and limitations under the License.
13*546d3d08SMartin Matuska  *
14*546d3d08SMartin Matuska  * When distributing Covered Code, include this CDDL HEADER in each
15*546d3d08SMartin Matuska  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*546d3d08SMartin Matuska  * If applicable, add the following below this CDDL HEADER, with the
17*546d3d08SMartin Matuska  * fields enclosed by brackets "[]" replaced with your own identifying
18*546d3d08SMartin Matuska  * information: Portions Copyright [yyyy] [name of copyright owner]
19*546d3d08SMartin Matuska  *
20*546d3d08SMartin Matuska  * CDDL HEADER END
21*546d3d08SMartin Matuska  */
22*546d3d08SMartin Matuska 
23*546d3d08SMartin Matuska /*
24*546d3d08SMartin Matuska  * Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
25*546d3d08SMartin Matuska  */
26*546d3d08SMartin Matuska 
27*546d3d08SMartin Matuska #ifndef _ZFS_LINUX_KASAN_ENABLED_H
28*546d3d08SMartin Matuska #define	_ZFS_LINUX_KASAN_ENABLED_H
29*546d3d08SMartin Matuska 
30*546d3d08SMartin Matuska #ifdef HAVE_KASAN_ENABLED_GPL_ONLY
31*546d3d08SMartin Matuska /*
32*546d3d08SMartin Matuska  * The kernel supports a runtime setting to enable/disable KASAN. The control
33*546d3d08SMartin Matuska  * flag kasan_flag_enabled is a GPL-only symbol, which prevents us from
34*546d3d08SMartin Matuska  * accessing it. Unfortunately, this is called by the header function
35*546d3d08SMartin Matuska  * kasan_enabled(), which in turn is used to call or skip instrumentation
36*546d3d08SMartin Matuska  * functions in various header-based kernel facilities. If we inadvertently
37*546d3d08SMartin Matuska  * call one, the build breaks.
38*546d3d08SMartin Matuska  *
39*546d3d08SMartin Matuska  * To work around this, we define our own `kasan_flag_enabled` set to "false",
40*546d3d08SMartin Matuska  * disabling use of KASAN inside our code. The linker will resolve this symbol
41*546d3d08SMartin Matuska  * at build time, and so never need to reach out to the off-limits kernel
42*546d3d08SMartin Matuska  * symbol.
43*546d3d08SMartin Matuska  */
44*546d3d08SMartin Matuska #include <linux/static_key.h>
45*546d3d08SMartin Matuska struct static_key_false kasan_flag_enabled = STATIC_KEY_FALSE_INIT;
46*546d3d08SMartin Matuska #endif
47*546d3d08SMartin Matuska 
48*546d3d08SMartin Matuska #endif
49