|
77 | 77 | #define ALIGN16 __attribute__ ( (aligned (32))) |
78 | 78 | #endif |
79 | 79 |
|
80 | | - /* kvmalloc()/kvfree() and friends added in linux commit a7c3e901 */ |
81 | | - #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) |
| 80 | + /* kvmalloc()/kvfree() and friends added in linux commit a7c3e901, merged for 4.12. |
| 81 | + * kvrealloc() added in de2860f463, merged for 5.15, backported to 5.10.137. |
| 82 | + * moved to ultimate home (slab.h) in 8587ca6f34, merged for 5.16. |
| 83 | +
|
| 84 | + */ |
| 85 | + #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \ |
| 86 | + ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 137)) && \ |
| 87 | + (LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 90))) |
82 | 88 | #define HAVE_KVMALLOC |
83 | 89 | #endif |
84 | 90 |
|
|
258 | 264 | #undef memmove |
259 | 265 | #define memmove my_memmove |
260 | 266 |
|
261 | | - #endif /* CONFIG_FORTIFY_SOURCE */ |
| 267 | + #else /* !CONFIG_FORTIFY_SOURCE */ |
| 268 | + |
| 269 | + #include <linux/string.h> |
| 270 | + |
| 271 | + #endif /* !CONFIG_FORTIFY_SOURCE */ |
| 272 | + |
| 273 | + #ifdef LINUXKM_LKCAPI_REGISTER |
| 274 | + /* the LKCAPI assumes that expanded encrypt and decrypt keys will stay |
| 275 | + * loaded simultaneously, and the Linux in-tree implementations have two |
| 276 | + * AES key structs in each context, one for each direction. in |
| 277 | + * linuxkm/lkcapi_aes_glue.c, we do the same |
| 278 | + * thing with "struct km_AesCtx". however, wolfCrypt struct AesXts |
| 279 | + * already has two AES expanded keys, the main and tweak, and the tweak |
| 280 | + * is always used in the encrypt direction regardless of the main |
| 281 | + * direction. to avoid allocating and computing a duplicate second |
| 282 | + * tweak encrypt key, we set |
| 283 | + * WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS, which adds a second |
| 284 | + * Aes slot to wolfCrypt's struct AesXts, and activates support for |
| 285 | + * AES_ENCRYPTION_AND_DECRYPTION on AES-XTS. |
| 286 | + */ |
| 287 | + #ifndef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS |
| 288 | + #define WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS |
| 289 | + #endif |
| 290 | + #endif /* LINUXKM_LKCAPI_REGISTER */ |
262 | 291 |
|
263 | 292 | #include <linux/init.h> |
| 293 | +#ifndef __PIE__ |
264 | 294 | #include <linux/module.h> |
265 | 295 | #include <linux/delay.h> |
| 296 | +#endif |
266 | 297 |
|
267 | | - #ifdef __PIE__ |
268 | | - /* without this, mm.h brings in static, but not inline, pmd_to_page(), |
269 | | - * with direct references to global vmem variables. |
270 | | - */ |
271 | | - #undef USE_SPLIT_PMD_PTLOCKS |
272 | | - #define USE_SPLIT_PMD_PTLOCKS 0 |
273 | | - |
274 | | - #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) |
275 | | - /* without this, static show_free_areas() mm.h brings in direct |
276 | | - * reference to unexported __show_free_areas(). |
277 | | - */ |
278 | | - #define __show_free_areas my__show_free_areas |
279 | | - void my__show_free_areas( |
280 | | - unsigned int flags, |
281 | | - nodemask_t *nodemask, |
282 | | - int max_zone_idx); |
283 | | - #endif |
284 | | - #endif |
| 298 | +#ifdef __PIE__ |
| 299 | + /* linux/slab.h will recursively bring in linux/page-flags.h, polluting the |
| 300 | + * wolfCrypt container objects with static functions const_folio_flags() and |
| 301 | + * folio_flags(), unless we kludge it off thusly. |
| 302 | + */ |
| 303 | + #define PAGE_FLAGS_H |
| 304 | +#else |
285 | 305 | #include <linux/mm.h> |
| 306 | +#endif |
| 307 | + |
| 308 | + #include <linux/slab.h> |
| 309 | + |
| 310 | +#ifndef __PIE__ |
286 | 311 | #ifndef SINGLE_THREADED |
287 | 312 | #include <linux/kthread.h> |
288 | 313 | #endif |
289 | 314 | #include <linux/net.h> |
290 | | - #include <linux/slab.h> |
291 | 315 |
|
292 | 316 | #ifdef LINUXKM_LKCAPI_REGISTER |
293 | 317 | #include <linux/crypto.h> |
|
306 | 330 | #include <linux/kprobes.h> |
307 | 331 | #endif |
308 | 332 |
|
309 | | - /* the LKCAPI assumes that expanded encrypt and decrypt keys will stay |
310 | | - * loaded simultaneously, and the Linux in-tree implementations have two |
311 | | - * AES key structs in each context, one for each direction. in |
312 | | - * linuxkm/lkcapi_aes_glue.c, we do the same |
313 | | - * thing with "struct km_AesCtx". however, wolfCrypt struct AesXts |
314 | | - * already has two AES expanded keys, the main and tweak, and the tweak |
315 | | - * is always used in the encrypt direction regardless of the main |
316 | | - * direction. to avoid allocating and computing a duplicate second |
317 | | - * tweak encrypt key, we set |
318 | | - * WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS, which adds a second |
319 | | - * Aes slot to wolfCrypt's struct AesXts, and activates support for |
320 | | - * AES_ENCRYPTION_AND_DECRYPTION on AES-XTS. |
321 | | - */ |
322 | | - #ifndef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS |
323 | | - #define WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS |
324 | | - #endif |
325 | | - |
326 | 333 | #if defined(_LINUX_REFCOUNT_H) || defined(_LINUX_REFCOUNT_TYPES_H) |
327 | 334 | #define WC_LKM_REFCOUNT_TO_INT(refcount) (atomic_read(&(refcount.refs))) |
328 | 335 | #else |
329 | 336 | #define WC_LKM_REFCOUNT_TO_INT(refcount) (atomic_read(&(refcount))) |
330 | 337 | #endif |
331 | 338 | #endif |
| 339 | +#endif /* !__PIE__ */ |
332 | 340 |
|
333 | 341 | #if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \ |
334 | 342 | defined(WOLFSSL_SP_X86_64_ASM) |
|
622 | 630 | typeof(kzalloc_noprof) *kzalloc_noprof; |
623 | 631 | typeof(__kvmalloc_node_noprof) *__kvmalloc_node_noprof; |
624 | 632 | typeof(__kmalloc_cache_noprof) *__kmalloc_cache_noprof; |
| 633 | + typeof(kvrealloc_noprof) *kvrealloc_noprof; |
625 | 634 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0) |
626 | 635 | typeof(kmalloc_noprof) *kmalloc_noprof; |
627 | 636 | typeof(krealloc_noprof) *krealloc_noprof; |
628 | 637 | typeof(kzalloc_noprof) *kzalloc_noprof; |
629 | 638 | typeof(kvmalloc_node_noprof) *kvmalloc_node_noprof; |
630 | 639 | typeof(kmalloc_trace_noprof) *kmalloc_trace_noprof; |
| 640 | + typeof(kvrealloc_noprof) *kvrealloc_noprof; |
631 | 641 | #else /* <6.10.0 */ |
632 | 642 | typeof(kmalloc) *kmalloc; |
633 | 643 | typeof(krealloc) *krealloc; |
634 | 644 | #ifdef HAVE_KVMALLOC |
635 | | - typeof(kvmalloc_node) *kvmalloc_node; |
| 645 | + typeof(kvmalloc_node) *kvmalloc_node; |
| 646 | + typeof(kvrealloc) *kvrealloc; |
636 | 647 | #endif |
637 | 648 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) |
638 | 649 | typeof(kmalloc_trace) *kmalloc_trace; |
|
646 | 657 | #endif |
647 | 658 | typeof(kfree) *kfree; |
648 | 659 | typeof(ksize) *ksize; |
649 | | - typeof(is_vmalloc_addr) *is_vmalloc_addr; |
650 | 660 |
|
651 | 661 | typeof(get_random_bytes) *get_random_bytes; |
652 | 662 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) |
|
854 | 864 | #define kzalloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kzalloc_noprof) |
855 | 865 | #define __kvmalloc_node_noprof (wolfssl_linuxkm_get_pie_redirect_table()->__kvmalloc_node_noprof) |
856 | 866 | #define __kmalloc_cache_noprof (wolfssl_linuxkm_get_pie_redirect_table()->__kmalloc_cache_noprof) |
| 867 | + #define kvrealloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kvrealloc_noprof) |
857 | 868 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0) |
858 | 869 | /* see include/linux/alloc_tag.h and include/linux/slab.h */ |
859 | 870 | #define kmalloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_noprof) |
860 | 871 | #define krealloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->krealloc_noprof) |
861 | 872 | #define kzalloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kzalloc_noprof) |
862 | 873 | #define kvmalloc_node_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node_noprof) |
863 | 874 | #define kmalloc_trace_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_trace_noprof) |
| 875 | + #define kvrealloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kvrealloc_noprof) |
864 | 876 | #else /* <6.10.0 */ |
865 | 877 | #define kmalloc (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc) |
866 | 878 | #define krealloc (wolfssl_linuxkm_get_pie_redirect_table()->krealloc) |
867 | 879 | #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) |
868 | 880 | #ifdef HAVE_KVMALLOC |
869 | 881 | #define kvmalloc_node (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node) |
| 882 | + #define kvrealloc (wolfssl_linuxkm_get_pie_redirect_table()->kvrealloc) |
870 | 883 | #endif |
871 | 884 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) |
872 | 885 | #define kmalloc_trace (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_trace) |
|
882 | 895 | #endif |
883 | 896 | #define ksize (wolfssl_linuxkm_get_pie_redirect_table()->ksize) |
884 | 897 |
|
885 | | - #define is_vmalloc_addr (wolfssl_linuxkm_get_pie_redirect_table()->is_vmalloc_addr) |
886 | | - |
887 | 898 | #define get_random_bytes (wolfssl_linuxkm_get_pie_redirect_table()->get_random_bytes) |
888 | 899 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) |
889 | 900 | #define getnstimeofday (wolfssl_linuxkm_get_pie_redirect_table()->getnstimeofday) |
|
1162 | 1173 | _alloc_sz; \ |
1163 | 1174 | }) |
1164 | 1175 | #ifdef HAVE_KVMALLOC |
1165 | | -#define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) |
| 1176 | + #define malloc(size) kvmalloc_node(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC), NUMA_NO_NODE) |
1166 | 1177 | #define free(ptr) kvfree(ptr) |
1167 | | - void *lkm_realloc(void *ptr, size_t newsize); |
1168 | | - #define realloc(ptr, newsize) lkm_realloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize)) |
| 1178 | + #define realloc(ptr, newsize) kvrealloc(ptr, WC_LINUXKM_ROUND_UP_P_OF_2(newsize), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
1169 | 1179 | #else |
1170 | 1180 | #define malloc(size) kmalloc(WC_LINUXKM_ROUND_UP_P_OF_2(size), (preempt_count() == 0 ? GFP_KERNEL : GFP_ATOMIC)) |
1171 | 1181 | #define free(ptr) kfree(ptr) |
|
0 commit comments