-
Notifications
You must be signed in to change notification settings - Fork 970
Expand file tree
/
Copy pathlinuxkm_wc_port.h
More file actions
1960 lines (1746 loc) · 76.7 KB
/
linuxkm_wc_port.h
File metadata and controls
1960 lines (1746 loc) · 76.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* linuxkm_wc_port.h
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/* included by wolfssl/wolfcrypt/wc_port.h */
#ifndef LINUXKM_WC_PORT_H
#define LINUXKM_WC_PORT_H
#if defined(WOLFSSL_KERNEL_VERBOSE_DEBUG) && !defined(WOLFSSL_LINUXKM_VERBOSE_DEBUG)
#define WOLFSSL_LINUXKM_VERBOSE_DEBUG
#endif
#include <linux/version.h>
#include <linux/kconfig.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
#error Unsupported kernel.
#endif
#if defined(HAVE_FIPS) && defined(LINUXKM_LKCAPI_REGISTER_AESXTS) && defined(CONFIG_CRYPTO_MANAGER_EXTRA_TESTS)
/* CONFIG_CRYPTO_MANAGER_EXTRA_TESTS expects AES-XTS-384 to work, even when CONFIG_CRYPTO_FIPS, but FIPS 140-3 only allows AES-XTS-256 and AES-XTS-512. */
#error CONFIG_CRYPTO_MANAGER_EXTRA_TESTS is incompatible with FIPS wolfCrypt AES-XTS -- please reconfigure the target kernel to disable CONFIG_CRYPTO_MANAGER_EXTRA_TESTS.
#endif
/* The first vector set in /usr/src/linux/crypto/testmgr.h
* ecdsa_nist_p192_tv_template[], ecdsa_nist_p256_tv_template[], and
* ecdsa_nist_p384_tv_template[] use SHA-1 (even if CONFIG_CRYPTO_SHA1 is
* disabled), and kernel module signatures frequently use SHA-1 until quite
* recently (dependent on CONFIG_CRYPTO_SHA1). If either is enabled, force
* downgrade to 186-4.
*/
#if defined(WC_FIPS_186_5_PLUS) && \
(defined(CONFIG_CRYPTO_SHA1) || (defined(CONFIG_CRYPTO_MANAGER) && !defined(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS))) && \
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || defined(LINUXKM_LKCAPI_REGISTER_ALL_KCONFIG) || defined(CONFIG_CRYPTO_ECDSA))
#undef WC_FIPS_186_5_PLUS
#ifdef WC_FIPS_186_5
#undef WC_FIPS_186_5
#else
#error Unknown and incompatible FIPS 186 is enabled.
#endif
#define WC_FIPS_186_4
#endif
#ifdef HAVE_CONFIG_H
#ifndef PACKAGE_NAME
#error wc_port.h included before config.h
#endif
/* config.h is autogenerated without gating, and is subject to repeat
* inclusions, so gate it out here to keep autodetection masking
* intact:
*/
#undef HAVE_CONFIG_H
#endif
/* suppress inclusion of stdint-gcc.h to avoid conflicts with Linux native
* include/linux/types.h:
*/
#define _GCC_STDINT_H
#define WC_PTR_TYPE uintptr_t
/* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */
#define XSNPRINTF snprintf
/* the rigmarole around kstrtoll() here is to accommodate its
* warn-unused-result attribute.
*
* also needed to suppress inclusion of stdlib.h in
* wolfssl/wolfcrypt/types.h.
*/
#define XATOI(s) ({ \
long long _xatoi_res = 0; \
int _xatoi_ret = kstrtoll(s, 10, &_xatoi_res); \
if (_xatoi_ret != 0) { \
_xatoi_res = 0; \
} \
(int)_xatoi_res; \
})
/* Kbuild+gcc on x86 doesn't consistently honor the default ALIGN16 on stack
* objects, but gives adequate alignment with "32".
*/
#if defined(CONFIG_X86) && !defined(ALIGN16)
#define ALIGN16 __attribute__ ( (aligned (32)))
#endif
/* kvmalloc()/kvfree() and friends added in linux commit a7c3e901, merged for 4.12.
* kvrealloc() added in de2860f463, merged for 5.15, backported to 5.10.137.
* moved to ultimate home (slab.h) in 8587ca6f34, merged for 5.16.
*
* however, until 6.12 (commit 590b9d576c), it took an extra argument,
* oldsize, that makes it incompatible with traditional libc usage patterns,
* so we don't try to use it.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) && \
!defined(DONT_HAVE_KVMALLOC) && !defined(HAVE_KVMALLOC)
#define HAVE_KVMALLOC
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0) && \
!defined(DONT_HAVE_KVREALLOC) && !defined(HAVE_KVREALLOC)
#define HAVE_KVREALLOC
#endif
#ifdef WOLFCRYPT_ONLY
#if defined(HAVE_KVMALLOC) && \
!defined(DONT_USE_KVMALLOC) && !defined(USE_KVMALLOC)
#define USE_KVMALLOC
#endif
#if defined(HAVE_KVREALLOC) && \
!defined(DONT_USE_KVREALLOC) && !defined(USE_KVREALLOC)
#define USE_KVREALLOC
#endif
#else
/* functioning realloc() is needed for the TLS stack. */
#if defined(HAVE_KVMALLOC) && defined(HAVE_KVREALLOC) && \
!defined(DONT_USE_KVMALLOC) && !defined(DONT_USE_KVREALLOC)
#ifndef USE_KVMALLOC
#define USE_KVMALLOC
#endif
#ifndef USE_KVREALLOC
#define USE_KVREALLOC
#endif
#endif
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
/* added by 6bab69c650 */
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
#endif
/* kernel printf doesn't implement fp. */
#ifndef WOLFSSL_NO_FLOAT_FMT
#define WOLFSSL_NO_FLOAT_FMT
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \
(defined(RHEL_MAJOR) && \
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
#define WOLFSSL_DEBUG_PRINTF_FN _printk
#else
#define WOLFSSL_DEBUG_PRINTF_FN printk
#endif
#ifndef WOLFSSL_LINUXKM_USE_MUTEXES
struct wolfSSL_Mutex;
extern int wc_lkm_LockMutex(struct wolfSSL_Mutex* m);
#endif
#ifndef WC_LINUXKM_INTR_SIGNALS
#define WC_LINUXKM_INTR_SIGNALS { SIGKILL, SIGABRT, SIGHUP, SIGINT }
#endif
extern int wc_linuxkm_sig_ignore_begin(void);
extern int wc_linuxkm_sig_ignore_end(void);
extern int wc_linuxkm_check_for_intr_signals(void);
#ifndef WC_LINUXKM_MAX_NS_WITHOUT_YIELD
#define WC_LINUXKM_MAX_NS_WITHOUT_YIELD 1000000000
#endif
extern void wc_linuxkm_relax_long_loop(void);
#ifndef WC_SIG_IGNORE_BEGIN
#define WC_SIG_IGNORE_BEGIN() wc_linuxkm_sig_ignore_begin()
#endif
#ifndef WC_SIG_IGNORE_END
#define WC_SIG_IGNORE_END() wc_linuxkm_sig_ignore_end()
#endif
#ifndef WC_CHECK_FOR_INTR_SIGNALS
#define WC_CHECK_FOR_INTR_SIGNALS() wc_linuxkm_check_for_intr_signals()
#endif
#ifndef WC_RELAX_LONG_LOOP
#define WC_RELAX_LONG_LOOP() wc_linuxkm_relax_long_loop()
#endif
enum wc_svr_flags {
WC_SVR_FLAG_NONE = 0,
WC_SVR_FLAG_INHIBIT = 1,
};
#if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \
defined(WOLFSSL_SP_X86_64_ASM)
#ifndef CONFIG_X86
#error X86 SIMD extensions requested, but CONFIG_X86 is not set.
#endif
#define WOLFSSL_LINUXKM_SIMD
#define WOLFSSL_LINUXKM_SIMD_X86
#ifndef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
#endif
#elif defined(WOLFSSL_ARMASM) || defined(WOLFSSL_SP_ARM32_ASM) || \
defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM_THUMB_ASM) ||\
defined(WOLFSSL_SP_ARM_CORTEX_M_ASM)
#if !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
#error ARM SIMD extensions requested, but CONFIG_ARM* is not set.
#endif
#define WOLFSSL_LINUXKM_SIMD
#define WOLFSSL_LINUXKM_SIMD_ARM
#ifndef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
#endif
#endif
#if defined(HAVE_HASHDRBG) && defined(HAVE_FIPS) && \
defined(HAVE_ENTROPY_MEMUSE) && \
!defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)
#define WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER
#elif defined(HAVE_HASHDRBG) && defined(HAVE_FIPS) && \
(defined(HAVE_INTEL_RDSEED) || defined(HAVE_AMD_RDSEED)) && \
!defined(HAVE_ENTROPY_MEMUSE) && \
!defined(WC_LINUXKM_RDSEED_IN_GLUE_LAYER)
#define WC_LINUXKM_RDSEED_IN_GLUE_LAYER
#endif
#if defined(WC_LINUXKM_WOLFENTROPY_IN_GLUE_LAYER)
struct OS_Seed;
extern int wc_linuxkm_GenerateSeed_wolfEntropy(struct OS_Seed* os, unsigned char* output, unsigned int sz);
#define WC_GENERATE_SEED_DEFAULT wc_linuxkm_GenerateSeed_wolfEntropy
#elif defined(WC_LINUXKM_RDSEED_IN_GLUE_LAYER)
struct OS_Seed;
extern int wc_linuxkm_GenerateSeed_IntelRD(struct OS_Seed* os, unsigned char* output, unsigned int sz);
#define WC_GENERATE_SEED_DEFAULT wc_linuxkm_GenerateSeed_IntelRD
#endif
/* setup for LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT needs to be here
* to assure that calls to get_random_bytes() in random.c are gated out
* (they would recurse, potentially infinitely).
*/
#if defined(LINUXKM_LKCAPI_REGISTER_ALL) && \
!defined(LINUXKM_LKCAPI_DONT_REGISTER_HASH_DRBG) && \
!defined(LINUXKM_LKCAPI_DONT_REGISTER_HASH_DRBG_DEFAULT) && \
!defined(NO_LINUXKM_DRBG_GET_RANDOM_BYTES) && \
!defined(LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT) && \
defined(HAVE_HASHDRBG)
#define LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT
#endif
#ifdef BUILDING_WOLFSSL
#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)) || \
(defined(RHEL_MAJOR) && \
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))) && \
defined(CONFIG_X86)
/* linux/slab.h recursively brings in linux/page-flags.h, bringing in
* non-inline implementations of functions folio_flags() and
* const_folio_flags(). but we can retrofit the attribute.
*/
struct folio;
static __always_inline unsigned long *folio_flags(
struct folio *folio, unsigned n);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 9, 0)
static __always_inline const unsigned long *const_folio_flags(
const struct folio *folio, unsigned n);
#endif
#endif
#if defined(CONFIG_MIPS) && defined(WC_SYM_RELOC_TABLES)
/* __ZBOOT__ disables some unhelpful macros around the mem*() funcs in
* legacy arch/mips/include/asm/string.h
*/
#define __ZBOOT__
#define memcmp __builtin_memcmp
#define __ARCH_MEMCMP_NO_REDIRECT
#define __ARCH_MEMCPY_NO_REDIRECT
#define __builtin_memcpy memcpy
extern void *memcpy(void *dest, const void *src, unsigned int n);
#define __ARCH_MEMCPY_NO_REDIRECT
#define __builtin_memset memset
extern void *memset(void *dest, int c, unsigned int n);
#endif
_Pragma("GCC diagnostic push");
/* we include all the needed kernel headers with these masked out. else
* there are profuse warnings, especially on older kernels.
*/
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"");
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"");
_Pragma("GCC diagnostic ignored \"-Wshadow\"");
_Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
_Pragma("GCC diagnostic ignored \"-Wredundant-decls\"");
_Pragma("GCC diagnostic ignored \"-Wsign-compare\"");
_Pragma("GCC diagnostic ignored \"-Wpointer-sign\"");
_Pragma("GCC diagnostic ignored \"-Wbad-function-cast\"");
#ifndef __clang__
_Pragma("GCC diagnostic ignored \"-Wdiscarded-qualifiers\"");
#endif
_Pragma("GCC diagnostic ignored \"-Wtype-limits\"");
_Pragma("GCC diagnostic ignored \"-Wswitch-enum\"");
_Pragma("GCC diagnostic ignored \"-Wcast-function-type\""); /* needed for kernel 4.14.336 */
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\""); /* needed for kernel 4.9.282 */
_Pragma("GCC diagnostic ignored \"-Wattributes\"");
#ifdef CONFIG_KASAN
#ifndef WC_SANITIZE_DISABLE
#define WC_SANITIZE_DISABLE() kasan_disable_current()
#endif
#ifndef WC_SANITIZE_ENABLE
#define WC_SANITIZE_ENABLE() kasan_enable_current()
#endif
#endif
#if defined(CONFIG_FORTIFY_SOURCE) && \
!defined(WC_FORCE_LINUXKM_FORTIFY_SOURCE) && \
(defined(WC_SYM_RELOC_TABLES) || \
(LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)))
/* fortify-source causes all sorts of awkward problems for the PIE
* build, up to and including stubborn external references and multiple
* definitions of string functions.
*
* fortify-source before kernel 5.18 has similar issues regardless of
* PIE, around our macro-shimming of the string functions.
*/
#undef CONFIG_FORTIFY_SOURCE
#endif
#if defined(WC_FORCE_LINUXKM_FORTIFY_SOURCE) && \
!defined(CONFIG_FORTIFY_SOURCE)
#error WC_FORCE_LINUXKM_FORTIFY_SOURCE without CONFIG_FORTIFY_SOURCE.
#endif
#if defined(WC_CONTAINERIZE_THIS) && defined(CONFIG_ARM64)
/* alt_cb_patch_nops and queued_spin_lock_slowpath are defined early
* to allow shimming in system headers.
*/
/* alt_cb_patch_nops added by d926079f17, release 6.1 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
#define alt_cb_patch_nops my__alt_cb_patch_nops
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) */
#define queued_spin_lock_slowpath my__queued_spin_lock_slowpath
#endif
/*
* Disable ARM64 LSE atomics for out-of-tree modules.
*
* When CONFIG_ARM64_LSE_ATOMICS is enabled, the kernel uses static keys
* (jump labels) in system_uses_lse_atomics() to choose between LSE and
* LL/SC atomic implementations at runtime. These static keys generate
* asm goto statements that reference .jump_table section symbols which
* cannot be resolved in out-of-tree modules, causing:
* "error: impossible constraint in 'asm'"
*
* By undefining CONFIG_ARM64_LSE_ATOMICS here (before any kernel headers
* that use atomics are included), we force use of the LL/SC fallback path
* which works correctly in out-of-tree modules.
*/
#undef CONFIG_ARM64_LSE_ATOMICS
#include <linux/kernel.h>
#include <linux/ctype.h>
#if defined(CONFIG_FORTIFY_SOURCE) || defined(DEBUG_LINUXKM_FORTIFY_OVERLAY)
#ifdef WC_CONTAINERIZE_THIS
/* the inline definitions in fortify-string.h use non-inline
* fortify_panic().
*/
extern void __my_fortify_panic(const char *name) __noreturn __cold;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0)
/* see linux 3d965b33e40d9 */
#define fortify_panic(func, write, avail, size, retfail) \
__my_fortify_panic(#func)
#else
#define fortify_panic __my_fortify_panic
#endif
#endif
/* the _FORTIFY_SOURCE macros and implementations for several string
* functions are incompatible with libwolfssl, so just reimplement with
* inlines and remap with macros.
*/
#define __ARCH_STRLEN_NO_REDIRECT
#define __ARCH_MEMCPY_NO_REDIRECT
#define __ARCH_MEMSET_NO_REDIRECT
#define __ARCH_MEMMOVE_NO_REDIRECT
/* the inline definitions in fortify-string.h use non-inline
* strlen().
*/
static inline size_t strlen(const char *s) {
const char *s_start = s;
while (*s)
++s;
return (size_t)((uintptr_t)s - (uintptr_t)s_start);
}
#include <linux/string.h>
#undef strlen
#define strlen(s) \
((__builtin_constant_p(s) && __builtin_constant_p(*(s))) ? \
(sizeof(s) - 1) : strlen(s))
static inline void *my_memcpy(void *dest, const void *src, size_t n) {
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n)
& (uintptr_t)(sizeof(uintptr_t) - 1)))
{
uintptr_t *src_longs = (uintptr_t *)src,
*dest_longs = (uintptr_t *)dest,
*endp = (uintptr_t *)((u8 *)src + n);
while (src_longs < endp)
*dest_longs++ = *src_longs++;
} else {
u8 *src_bytes = (u8 *)src,
*dest_bytes = (u8 *)dest,
*endp = src_bytes + n;
while (src_bytes < endp)
*dest_bytes++ = *src_bytes++;
}
return dest;
}
#undef memcpy
#define memcpy my_memcpy
static inline void *my_memset(void *dest, int c, size_t n) {
if (! (((uintptr_t)dest | (uintptr_t)n)
& (uintptr_t)(sizeof(uintptr_t) - 1)))
{
uintptr_t c_long = __builtin_choose_expr(
sizeof(uintptr_t) == 8,
(uintptr_t)(u8)c * 0x0101010101010101UL,
(uintptr_t)(u8)c * 0x01010101U
);
uintptr_t *dest_longs = (uintptr_t *)dest,
*endp = (uintptr_t *)((u8 *)dest_longs + n);
while (dest_longs < endp)
*dest_longs++ = c_long;
} else {
u8 *dest_bytes = (u8 *)dest, *endp = dest_bytes + n;
while (dest_bytes < endp)
*dest_bytes++ = (u8)c;
}
return dest;
}
#undef memset
#define memset my_memset
static inline void *my_memmove(void *dest, const void *src, size_t n) {
if (n == 0)
return dest;
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n)
& (uintptr_t)(sizeof(uintptr_t) - 1)))
{
uintptr_t *src_longs = (uintptr_t *)src,
*dest_longs = (uintptr_t *)dest;
n >>= __builtin_choose_expr(
sizeof(uintptr_t) == 8,
3U,
2U);
if (src_longs < dest_longs) {
uintptr_t *startp = src_longs;
src_longs += n - 1;
dest_longs += n - 1;
while (src_longs >= startp)
*dest_longs-- = *src_longs--;
} else if (src_longs > dest_longs) {
uintptr_t *endp = src_longs + n;
while (src_longs < endp)
*dest_longs++ = *src_longs++;
}
} else {
u8 *src_bytes = (u8 *)src, *dest_bytes = (u8 *)dest;
if (src_bytes < dest_bytes) {
u8 *startp = src_bytes;
src_bytes += n - 1;
dest_bytes += n - 1;
while (src_bytes >= startp)
*dest_bytes-- = *src_bytes--;
} else if (src_bytes > dest_bytes) {
u8 *endp = src_bytes + n;
while (src_bytes < endp)
*dest_bytes++ = *src_bytes++;
}
}
return dest;
}
#undef memmove
#define memmove my_memmove
#else /* !CONFIG_FORTIFY_SOURCE */
#include <linux/string.h>
#endif /* !CONFIG_FORTIFY_SOURCE */
#ifndef WC_CONTAINERIZE_THIS
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/delay.h>
#endif
#if defined(HAVE_KVMALLOC) && \
(LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)) && \
!(defined(RHEL_MAJOR) && ((RHEL_MAJOR > 9) || \
((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
/* before 5.16, the kvmalloc_node() and kvfree() prototypes were in
* mm.h. however, mm.h brings in static, but not inline, pmd_to_page(),
* with direct references to global vmem variables.
*/
#ifdef WC_CONTAINERIZE_THIS
#include <linux/mm_types.h>
#if USE_SPLIT_PMD_PTLOCKS
static __always_inline struct page *pmd_to_page(pmd_t *pmd);
#endif
#endif
#include <linux/mm.h>
#endif
#ifndef WC_CONTAINERIZE_THIS
#include <linux/kthread.h>
#include <linux/net.h>
#ifndef WOLFCRYPT_ONLY
#include <linux/inet.h>
static inline int wc_linuxkm_inet_pton(int af, const char *src, void *dst)
{
int ret;
if (!src || !dst)
return -EFAULT;
switch (af) {
case AF_INET:
ret = in4_pton(src, -1, (u8 *)dst, '\0', NULL);
return ret == 1 ? 1 : 0;
case AF_INET6:
ret = in6_pton(src, -1, (u8 *)dst, '\0', NULL);
return ret == 1 ? 1 : 0;
default:
return -EAFNOSUPPORT;
}
}
#define XINET_PTON(af, src, dst) wc_linuxkm_inet_pton(af, src, dst)
#endif /* !WOLFCRYPT_ONLY */
#endif /* !WC_CONTAINERIZE_THIS */
#if defined(WC_SYM_RELOC_TABLES) && defined(DEBUG_LINUXKM_PIE_SUPPORT) && \
!defined(WC_LINUXKM_SUPPORT_DUMP_TO_FILE)
#define WC_LINUXKM_SUPPORT_DUMP_TO_FILE
#endif
#ifdef WC_LINUXKM_SUPPORT_DUMP_TO_FILE
#include <linux/fs.h>
#include <linux/uaccess.h>
#endif
#include <linux/slab.h>
#include <linux/sched.h>
#if __has_include(<linux/sched/task_stack.h>)
/* for task_stack_page() */
#include <linux/sched/task_stack.h>
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
/* for signal_pending() */
#include <linux/sched/signal.h>
/* for local_clock() */
#include <linux/sched/clock.h>
#endif
#include <linux/random.h>
#if !defined(WC_CONTAINERIZE_THIS) && defined(CONFIG_HAVE_KPROBES)
#include <linux/kprobes.h>
#endif
#ifdef LINUXKM_LKCAPI_REGISTER
/* the LKCAPI assumes that expanded encrypt and decrypt keys will stay
* loaded simultaneously, and the Linux in-tree implementations have two
* AES key structs in each context, one for each direction. in
* linuxkm/lkcapi_aes_glue.c, we do the same
* thing with "struct km_AesCtx". however, wolfCrypt struct AesXts
* already has two AES expanded keys, the main and tweak, and the tweak
* is always used in the encrypt direction regardless of the main
* direction. to avoid allocating and computing a duplicate second
* tweak encrypt key, we set
* WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS, which adds a second
* Aes slot to wolfCrypt's struct AesXts, and activates support for
* AES_ENCRYPTION_AND_DECRYPTION on AES-XTS.
*/
#ifndef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
#define WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
#endif
#ifndef WC_CONTAINERIZE_THIS
#include <linux/crypto.h>
#include <linux/scatterlist.h>
#include <crypto/scatterwalk.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/rng.h>
#include <crypto/internal/skcipher.h>
#include <crypto/internal/akcipher.h>
#include <crypto/internal/kpp.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 13, 0)
#include <crypto/internal/sig.h>
#endif /* linux ver >= 6.13 */
#if defined(_LINUX_REFCOUNT_H) || defined(_LINUX_REFCOUNT_TYPES_H)
static inline int wc_lkm_refcount_to_int(refcount_t *refcount) {
_Pragma("GCC diagnostic push");
_Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
return atomic_read(&(refcount->refs));
_Pragma("GCC diagnostic pop");
}
#else
static inline int wc_lkm_refcount_to_int(atomic_t *refcount) {
_Pragma("GCC diagnostic push");
_Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
return atomic_read(&refcount);
_Pragma("GCC diagnostic pop");
}
#endif
#define WC_LKM_REFCOUNT_TO_INT(refcount) wc_lkm_refcount_to_int(&(refcount))
#endif /* !WC_CONTAINERIZE_THIS */
#endif /* LINUXKM_LKCAPI_REGISTER */
/* benchmarks.c uses floating point math, so needs a working
* SAVE_VECTOR_REGISTERS().
*/
#if defined(WOLFSSL_LINUXKM_BENCHMARKS) && \
!defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
#endif
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && \
defined(CONFIG_X86)
extern __must_check int allocate_wolfcrypt_linuxkm_fpu_states(void);
extern void free_wolfcrypt_linuxkm_fpu_states(void);
WOLFSSL_API __must_check int wc_can_save_vector_registers_x86(void);
WOLFSSL_API __must_check int wc_save_vector_registers_x86(enum wc_svr_flags flags);
WOLFSSL_API void wc_restore_vector_registers_x86(enum wc_svr_flags flags);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
#include <asm/i387.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
/* added by a62b01cd6c */
#include <asm-generic/simd.h>
#endif
#else
#include <asm/simd.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
/* added by 266d051601 */
#include <crypto/internal/simd.h>
#endif
#endif
#ifndef CAN_SAVE_VECTOR_REGISTERS
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
#define CAN_SAVE_VECTOR_REGISTERS() (wc_can_save_vector_registers_x86() && (SAVE_VECTOR_REGISTERS2_fuzzer() == 0))
#else
#define CAN_SAVE_VECTOR_REGISTERS() wc_can_save_vector_registers_x86()
#endif
#endif
#ifndef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(fail_clause) { \
int _svr_ret = wc_save_vector_registers_x86(WC_SVR_FLAG_NONE); \
if (_svr_ret != 0) { \
fail_clause \
} \
}
#endif
#ifndef SAVE_VECTOR_REGISTERS2
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
#define SAVE_VECTOR_REGISTERS2() ({ \
int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); \
(_fuzzer_ret == 0) ? \
wc_save_vector_registers_x86(WC_SVR_FLAG_NONE) : \
_fuzzer_ret; \
})
#else
#define SAVE_VECTOR_REGISTERS2() wc_save_vector_registers_x86(WC_SVR_FLAG_NONE)
#endif
#endif
#ifndef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() wc_restore_vector_registers_x86(WC_SVR_FLAG_NONE)
#endif
#ifndef DISABLE_VECTOR_REGISTERS
#define DISABLE_VECTOR_REGISTERS() wc_save_vector_registers_x86(WC_SVR_FLAG_INHIBIT)
#endif
#ifndef REENABLE_VECTOR_REGISTERS
#define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86(WC_SVR_FLAG_INHIBIT)
#endif
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
#error kernel module ARM SIMD is not yet tested or usable.
#include <asm/fpsimd.h>
static WARN_UNUSED_RESULT inline int save_vector_registers_arm(void)
{
preempt_disable();
if (! may_use_simd()) {
preempt_enable();
return BAD_STATE_E;
} else {
fpsimd_preserve_current_state();
return 0;
}
}
static inline void restore_vector_registers_arm(void)
{
fpsimd_restore_current_state();
preempt_enable();
}
#ifndef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(fail_clause) { int _svr_ret = save_vector_registers_arm(); if (_svr_ret != 0) { fail_clause } }
#endif
#ifndef SAVE_VECTOR_REGISTERS2
#define SAVE_VECTOR_REGISTERS2() save_vector_registers_arm()
#endif
#ifndef CAN_SAVE_VECTOR_REGISTERS
#define CAN_SAVE_VECTOR_REGISTERS() can_save_vector_registers_arm()
#endif
#ifndef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() restore_vector_registers_arm()
#endif
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
_Pragma("GCC diagnostic pop");
/* avoid -Wpointer-arith, encountered when -DCONFIG_FORTIFY_SOURCE */
#undef __is_constexpr
#define __is_constexpr(x) __builtin_constant_p(x)
/* the kernel uses -std=c89, but not -pedantic, and makes full use of anon
* structs/unions, so we should too.
*/
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 1
#define NO_THREAD_LS
#define NO_ATTRIBUTE_CONSTRUCTOR
#ifdef HAVE_FIPS
extern int wolfCrypt_FIPS_first(void);
extern int wolfCrypt_FIPS_last(void);
extern const unsigned int wolfCrypt_FIPS_ro_start[];
extern const unsigned int wolfCrypt_FIPS_ro_end[];
#if FIPS_VERSION3_GE(6,0,0)
#ifndef NO_AES
extern int wolfCrypt_FIPS_AES_sanity(void);
extern const unsigned int wolfCrypt_FIPS_aes_ro_sanity[2];
#if defined(WOLFSSL_CMAC) && defined(WOLFSSL_AES_DIRECT)
extern int wolfCrypt_FIPS_CMAC_sanity(void);
extern const unsigned int wolfCrypt_FIPS_cmac_ro_sanity[2];
#endif
#endif
#ifndef NO_DH
extern int wolfCrypt_FIPS_DH_sanity(void);
extern const unsigned int wolfCrypt_FIPS_dh_ro_sanity[2];
#endif
#ifdef HAVE_ECC
extern int wolfCrypt_FIPS_ECC_sanity(void);
extern const unsigned int wolfCrypt_FIPS_ecc_ro_sanity[2];
#endif
#ifdef HAVE_ED25519
extern int wolfCrypt_FIPS_ED25519_sanity(void);
extern const unsigned int wolfCrypt_FIPS_ed25519_ro_sanity[2];
#endif
#ifdef HAVE_ED448
extern int wolfCrypt_FIPS_ED448_sanity(void);
extern const unsigned int wolfCrypt_FIPS_ed448_ro_sanity[2];
#endif
extern int wolfCrypt_FIPS_HMAC_sanity(void);
extern const unsigned int wolfCrypt_FIPS_hmac_ro_sanity[2];
#ifndef NO_KDF
extern int wolfCrypt_FIPS_KDF_sanity(void);
extern const unsigned int wolfCrypt_FIPS_kdf_ro_sanity[2];
#endif
#ifdef HAVE_PBKDF2
extern int wolfCrypt_FIPS_PBKDF_sanity(void);
extern const unsigned int wolfCrypt_FIPS_pbkdf_ro_sanity[2];
#endif
#ifdef HAVE_HASHDRBG
extern int wolfCrypt_FIPS_DRBG_sanity(void);
extern const unsigned int wolfCrypt_FIPS_drbg_ro_sanity[2];
#endif
#ifndef NO_RSA
extern int wolfCrypt_FIPS_RSA_sanity(void);
extern const unsigned int wolfCrypt_FIPS_rsa_ro_sanity[2];
#endif
#ifndef NO_SHA
extern int wolfCrypt_FIPS_SHA_sanity(void);
extern const unsigned int wolfCrypt_FIPS_sha_ro_sanity[2];
#endif
#ifndef NO_SHA256
extern int wolfCrypt_FIPS_SHA256_sanity(void);
extern const unsigned int wolfCrypt_FIPS_sha256_ro_sanity[2];
#endif
#ifdef WOLFSSL_SHA512
extern int wolfCrypt_FIPS_SHA512_sanity(void);
extern const unsigned int wolfCrypt_FIPS_sha512_ro_sanity[2];
#endif
#ifdef WOLFSSL_SHA3
extern int wolfCrypt_FIPS_SHA3_sanity(void);
extern const unsigned int wolfCrypt_FIPS_sha3_ro_sanity[2];
#endif
extern int wolfCrypt_FIPS_FT_sanity(void);
extern const unsigned int wolfCrypt_FIPS_ft_ro_sanity[2];
extern const unsigned int wolfCrypt_FIPS_f_ro_sanity[2];
extern int wc_RunAllCast_fips(void);
#endif
#endif
#if !defined(WOLFCRYPT_ONLY) && !defined(NO_CERTS)
/* work around backward dependency of asn.c on ssl.c. */
struct Signer;
struct Signer *GetCA(void *signers, unsigned char *hash);
#ifndef NO_SKID
struct Signer *GetCAByName(void* signers, unsigned char *hash);
#ifdef HAVE_OCSP
struct Signer* GetCAByKeyHash(void* vp, const unsigned char* keyHash);
#endif /* HAVE_OCSP */
#ifdef WOLFSSL_AKID_NAME
#ifdef WOLFSSL_API_PREFIX_MAP
#define GetCAByAKID wolfSSL_GetCAByAKID
#endif
struct Signer* GetCAByAKID(void* vp, const unsigned char* issuer,
unsigned int issuerSz,
const unsigned char* serial,
unsigned int serialSz);
#endif
#endif /* NO_SKID */
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
struct WOLFSSL_X509_NAME;
extern int wolfSSL_X509_NAME_add_entry_by_NID(struct WOLFSSL_X509_NAME *name, int nid,
int type, const unsigned char *bytes,
int len, int loc, int set);
extern void wolfSSL_X509_NAME_free(struct WOLFSSL_X509_NAME* name);
extern struct WOLFSSL_X509_NAME* wolfSSL_X509_NAME_new_ex(void *heap);
#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
#endif /* !WOLFCRYPT_ONLY && !NO_CERTS */
#if defined(WC_CONTAINERIZE_THIS) && !defined(WC_SYM_RELOC_TABLES)
#error "compiling -DWC_CONTAINERIZE_THIS requires relocation tables."
#endif
#ifdef WC_SYM_RELOC_TABLES
extern __attribute__((error("uncallable fencepost"))) int __wc_text_start(void);
extern __attribute__((error("uncallable fencepost"))) int __wc_text_end(void);
#ifdef HAVE_FIPS
static_assert(__builtin_types_compatible_p(typeof(__wc_text_start), typeof(wolfCrypt_FIPS_first)));
static_assert(__builtin_types_compatible_p(typeof(__wc_text_end), typeof(wolfCrypt_FIPS_last)));
#endif
extern const unsigned int __wc_rodata_start[], __wc_rodata_end[];
#ifdef HAVE_FIPS
static_assert(__builtin_types_compatible_p(typeof(__wc_rodata_start), typeof(wolfCrypt_FIPS_ro_start)));
static_assert(__builtin_types_compatible_p(typeof(__wc_rodata_end), typeof(wolfCrypt_FIPS_ro_end)));
#endif
extern const u8
__wc_rwdata_start[],
__wc_rwdata_end[],
__wc_bss_start[],
__wc_bss_end[];
extern ssize_t wc_linuxkm_normalize_relocations(
const u8 *text_in,
size_t text_in_len,
u8 *text_out,
ssize_t *cur_index_p);
#ifndef WOLFSSL_TEXT_SEGMENT_CANONICALIZER
#define WOLFSSL_TEXT_SEGMENT_CANONICALIZER(text_in, text_in_len, text_out, cur_index_p) \
wc_linuxkm_normalize_relocations(text_in, text_in_len, text_out, cur_index_p)
#define WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ 8192
#endif
#ifdef CONFIG_MIPS
#undef __ARCH_MEMCMP_NO_REDIRECT
#undef memcmp
extern int memcmp(const void *s1, const void *s2, size_t n);
#endif
struct wolfssl_linuxkm_pie_redirect_table {
#ifdef HAVE_FIPS
typeof(wc_linuxkm_normalize_relocations) *wc_linuxkm_normalize_relocations;
#endif
#ifndef __ARCH_MEMCMP_NO_REDIRECT
typeof(memcmp) *memcmp;
#endif
#ifndef __ARCH_MEMCPY_NO_REDIRECT
typeof(memcpy) *memcpy;
#endif
#ifndef __ARCH_MEMSET_NO_REDIRECT
typeof(memset) *memset;
#endif
#ifndef __ARCH_MEMMOVE_NO_REDIRECT
typeof(memmove) *memmove;
#endif
#ifndef __ARCH_STRCMP_NO_REDIRECT
typeof(strcmp) *strcmp;
#endif
#ifndef __ARCH_STRNCMP_NO_REDIRECT
typeof(strncmp) *strncmp;
#endif
#ifndef __ARCH_STRCASECMP_NO_REDIRECT
typeof(strcasecmp) *strcasecmp;
#endif
#ifndef __ARCH_STRNCASECMP_NO_REDIRECT
typeof(strncasecmp) *strncasecmp;
#endif
#ifndef __ARCH_STRLEN_NO_REDIRECT
typeof(strlen) *strlen;
#endif
#ifndef __ARCH_STRSTR_NO_REDIRECT
typeof(strstr) *strstr;
#endif
#ifndef __ARCH_STRNCPY_NO_REDIRECT
typeof(strncpy) *strncpy;
#endif
#ifndef __ARCH_STRNCAT_NO_REDIRECT
typeof(strncat) *strncat;
#endif
typeof(kstrtoll) *kstrtoll;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \
(defined(RHEL_MAJOR) && \
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
typeof(_printk) *_printk;
#else
typeof(printk) *printk;
#endif
#ifdef CONFIG_FORTIFY_SOURCE
typeof(__warn_printk) *__warn_printk;
#endif
typeof(snprintf) *snprintf;
const unsigned char *_ctype;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 18, 0)
typeof(kmalloc_noprof) *kmalloc_noprof;
typeof(krealloc_node_align_noprof) *krealloc_node_align_noprof;
typeof(kzalloc_noprof) *kzalloc_noprof;
typeof(__kvmalloc_node_noprof) *__kvmalloc_node_noprof;
typeof(__kmalloc_cache_noprof) *__kmalloc_cache_noprof;
#ifdef HAVE_KVREALLOC
typeof(kvrealloc_node_align_noprof) *kvrealloc_node_align_noprof;
#endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
typeof(kmalloc_noprof) *kmalloc_noprof;
typeof(krealloc_noprof) *krealloc_noprof;
typeof(kzalloc_noprof) *kzalloc_noprof;
typeof(__kvmalloc_node_noprof) *__kvmalloc_node_noprof;
typeof(__kmalloc_cache_noprof) *__kmalloc_cache_noprof;
#ifdef HAVE_KVREALLOC
typeof(kvrealloc_noprof) *kvrealloc_noprof;
#endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
typeof(kmalloc_noprof) *kmalloc_noprof;
typeof(krealloc_noprof) *krealloc_noprof;
typeof(kzalloc_noprof) *kzalloc_noprof;
typeof(kvmalloc_node_noprof) *kvmalloc_node_noprof;
typeof(kmalloc_trace_noprof) *kmalloc_trace_noprof;
#ifdef HAVE_KVREALLOC
typeof(kvrealloc_noprof) *kvrealloc_noprof;
#endif
#else /* <6.10.0 */
typeof(kmalloc) *kmalloc;
typeof(krealloc) *krealloc;
#ifdef HAVE_KVMALLOC
typeof(kvmalloc_node) *kvmalloc_node;
#endif
#ifdef HAVE_KVREALLOC
typeof(kvrealloc) *kvrealloc;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) || \
(defined(RHEL_MAJOR) && \
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
typeof(kmalloc_trace) *kmalloc_trace;
#else
typeof(kmem_cache_alloc_trace) *kmem_cache_alloc_trace;
typeof(kmalloc_order_trace) *kmalloc_order_trace;
#endif