Skip to content

Commit 41cbbfe

Browse files
committed
linuxkm: updates for kernel 6.10: use new _noprof names for newly macro-shimmed kmalloc, krealloc, kzmalloc, kvmalloc_node, and kmalloc_trace, and refactor linuxkm/Makefile and linuxkm/Kbuild to set up links to sources in the dest tree (works around breakage from linux commit 9a0ebe5011).
1 parent 3e9f656 commit 41cbbfe

4 files changed

Lines changed: 56 additions & 18 deletions

File tree

linuxkm/Kbuild

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ ifneq "$(quiet)" "silent_"
172172
@echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
173173
endif
174174

175-
$(src)/linuxkm/module_exports.c: rename-pie-text-and-data-sections
175+
$(obj)/linuxkm/module_exports.c: rename-pie-text-and-data-sections
176176

177177
endif
178178

179179

180180
# auto-generate the exported symbol list, leveraging the WOLFSSL_API visibility tags.
181181
# exclude symbols that don't match wc_* or wolf*.
182-
$(src)/linuxkm/module_exports.c: $(src)/linuxkm/module_exports.c.template $(WOLFSSL_OBJ_TARGETS)
182+
$(obj)/linuxkm/module_exports.c: $(src)/module_exports.c.template $(WOLFSSL_OBJ_TARGETS)
183183
@cp $< $@
184184
@readelf --symbols --wide $(WOLFSSL_OBJ_TARGETS) | \
185185
awk '/^ *[0-9]+: / { \
@@ -190,4 +190,4 @@ $(src)/linuxkm/module_exports.c: $(src)/linuxkm/module_exports.c.template $(WOLF
190190
}' >> $@
191191
@echo -e '#ifndef NO_CRYPT_TEST\nEXPORT_SYMBOL_NS_GPL(wolfcrypt_test, WOLFSSL);\n#endif' >> $@
192192

193-
clean-files := module_exports.c linuxkm src wolfcrypt/src wolfcrypt/test wolfcrypt
193+
clean-files := linuxkm src wolfcrypt

linuxkm/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ libwolfssl.ko:
6464
@if test -z "$(src_libwolfssl_la_OBJECTS)"; then echo '$$src_libwolfssl_la_OBJECTS is unset.' >&2; exit 1; fi
6565
@mkdir -p linuxkm src wolfcrypt/src wolfcrypt/test
6666
@if test ! -h $(SRC_TOP)/Kbuild; then ln -s $(MODULE_TOP)/Kbuild $(SRC_TOP)/Kbuild; fi
67+
# after commit 9a0ebe5011 (6.10), sources must be in $(obj). work around this by making links to all needed sources:
68+
@cp --no-dereference --symbolic-link --update=none '$(MODULE_TOP)'/*.[ch] '$(MODULE_TOP)'/linuxkm/
69+
@cp --no-dereference --symbolic-link --update=none --recursive '$(SRC_TOP)'/wolfcrypt/src '$(MODULE_TOP)'/wolfcrypt/
70+
@cp --no-dereference --symbolic-link --update=none --recursive '$(SRC_TOP)'/wolfcrypt/test '$(MODULE_TOP)'/wolfcrypt/
71+
@cp --no-dereference --symbolic-link --update=none --recursive '$(SRC_TOP)'/src '$(MODULE_TOP)'/
6772
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
68-
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) $(KBUILD_EXTRA_FLAGS) CC_FLAGS_FTRACE=
73+
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) $(KBUILD_EXTRA_FLAGS) CC_FLAGS_FTRACE=
6974
else
70-
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) $(KBUILD_EXTRA_FLAGS)
75+
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) $(KBUILD_EXTRA_FLAGS)
7176
endif
7277

7378
libwolfssl.ko.signed: libwolfssl.ko

linuxkm/linuxkm_wc_port.h

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,22 +532,31 @@
532532

533533
const unsigned char *_ctype;
534534

535+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
536+
typeof(kmalloc_noprof) *kmalloc_noprof;
537+
typeof(krealloc_noprof) *krealloc_noprof;
538+
typeof(kzalloc_noprof) *kzalloc_noprof;
539+
typeof(kvmalloc_node_noprof) *kvmalloc_node_noprof;
540+
typeof(kmalloc_trace_noprof) *kmalloc_trace_noprof;
541+
#else /* <6.10.0 */
535542
typeof(kmalloc) *kmalloc;
536-
typeof(kfree) *kfree;
537-
typeof(ksize) *ksize;
538543
typeof(krealloc) *krealloc;
539544
#ifdef HAVE_KVMALLOC
540545
typeof(kvmalloc_node) *kvmalloc_node;
541-
typeof(kvfree) *kvfree;
542546
#endif
543-
typeof(is_vmalloc_addr) *is_vmalloc_addr;
544-
545547
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
546548
typeof(kmalloc_trace) *kmalloc_trace;
547549
#else
548550
typeof(kmem_cache_alloc_trace) *kmem_cache_alloc_trace;
549551
typeof(kmalloc_order_trace) *kmalloc_order_trace;
550552
#endif
553+
#endif /* <6.10.0 */
554+
#ifdef HAVE_KVMALLOC
555+
typeof(kvfree) *kvfree;
556+
#endif
557+
typeof(kfree) *kfree;
558+
typeof(ksize) *ksize;
559+
typeof(is_vmalloc_addr) *is_vmalloc_addr;
551560

552561
typeof(get_random_bytes) *get_random_bytes;
553562
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
@@ -675,22 +684,35 @@
675684

676685
#define _ctype (wolfssl_linuxkm_get_pie_redirect_table()->_ctype)
677686

687+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
688+
/* see include/linux/alloc_tag.h and include/linux/slab.h */
689+
#define kmalloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_noprof)
690+
#define krealloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->krealloc_noprof)
691+
#define kzalloc_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kzalloc_noprof)
692+
#define kvmalloc_node_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node_noprof)
693+
#define kmalloc_trace_noprof (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_trace_noprof)
694+
#else /* <6.10.0 */
678695
#define kmalloc (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc)
679-
#define kfree (wolfssl_linuxkm_get_pie_redirect_table()->kfree)
680-
#define ksize (wolfssl_linuxkm_get_pie_redirect_table()->ksize)
681696
#define krealloc (wolfssl_linuxkm_get_pie_redirect_table()->krealloc)
682697
#define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO)
683698
#ifdef HAVE_KVMALLOC
684699
#define kvmalloc_node (wolfssl_linuxkm_get_pie_redirect_table()->kvmalloc_node)
685-
#define kvfree (wolfssl_linuxkm_get_pie_redirect_table()->kvfree)
686700
#endif
687-
#define is_vmalloc_addr (wolfssl_linuxkm_get_pie_redirect_table()->is_vmalloc_addr)
688701
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
689702
#define kmalloc_trace (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_trace)
690703
#else
691704
#define kmem_cache_alloc_trace (wolfssl_linuxkm_get_pie_redirect_table()->kmem_cache_alloc_trace)
692705
#define kmalloc_order_trace (wolfssl_linuxkm_get_pie_redirect_table()->kmalloc_order_trace)
693706
#endif
707+
#endif /* <6.10.0 */
708+
709+
#define kfree (wolfssl_linuxkm_get_pie_redirect_table()->kfree)
710+
#ifdef HAVE_KVMALLOC
711+
#define kvfree (wolfssl_linuxkm_get_pie_redirect_table()->kvfree)
712+
#endif
713+
#define ksize (wolfssl_linuxkm_get_pie_redirect_table()->ksize)
714+
715+
#define is_vmalloc_addr (wolfssl_linuxkm_get_pie_redirect_table()->is_vmalloc_addr)
694716

695717
#define get_random_bytes (wolfssl_linuxkm_get_pie_redirect_table()->get_random_bytes)
696718
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)

linuxkm/module_hooks.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,18 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
459459

460460
wolfssl_linuxkm_pie_redirect_table._ctype = _ctype;
461461

462+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
463+
wolfssl_linuxkm_pie_redirect_table.kmalloc_noprof = kmalloc_noprof;
464+
wolfssl_linuxkm_pie_redirect_table.krealloc_noprof = krealloc_noprof;
465+
wolfssl_linuxkm_pie_redirect_table.kzalloc_noprof = kzalloc_noprof;
466+
wolfssl_linuxkm_pie_redirect_table.kvmalloc_node_noprof = kvmalloc_node_noprof;
467+
wolfssl_linuxkm_pie_redirect_table.kmalloc_trace_noprof = kmalloc_trace_noprof;
468+
#else
462469
wolfssl_linuxkm_pie_redirect_table.kmalloc = kmalloc;
463-
wolfssl_linuxkm_pie_redirect_table.kfree = kfree;
464-
wolfssl_linuxkm_pie_redirect_table.ksize = ksize;
465470
wolfssl_linuxkm_pie_redirect_table.krealloc = krealloc;
466471
#ifdef HAVE_KVMALLOC
467472
wolfssl_linuxkm_pie_redirect_table.kvmalloc_node = kvmalloc_node;
468-
wolfssl_linuxkm_pie_redirect_table.kvfree = kvfree;
469473
#endif
470-
wolfssl_linuxkm_pie_redirect_table.is_vmalloc_addr = is_vmalloc_addr;
471474
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
472475
wolfssl_linuxkm_pie_redirect_table.kmalloc_trace =
473476
kmalloc_trace;
@@ -477,6 +480,14 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
477480
wolfssl_linuxkm_pie_redirect_table.kmalloc_order_trace =
478481
kmalloc_order_trace;
479482
#endif
483+
#endif
484+
485+
wolfssl_linuxkm_pie_redirect_table.kfree = kfree;
486+
wolfssl_linuxkm_pie_redirect_table.ksize = ksize;
487+
#ifdef HAVE_KVMALLOC
488+
wolfssl_linuxkm_pie_redirect_table.kvfree = kvfree;
489+
#endif
490+
wolfssl_linuxkm_pie_redirect_table.is_vmalloc_addr = is_vmalloc_addr;
480491

481492
wolfssl_linuxkm_pie_redirect_table.get_random_bytes = get_random_bytes;
482493
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)

0 commit comments

Comments
 (0)