diff --git a/linuxkm/Makefile b/linuxkm/Makefile index b3f445a66..9ef383985 100644 --- a/linuxkm/Makefile +++ b/linuxkm/Makefile @@ -22,9 +22,10 @@ ifeq "$(src_libwolfssl_la_OBJECTS)" "" $(error $$src_libwolfssl_la_OBJECTS is unset.) endif -WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CFLAGS) $(CFLAGS) -Wframe-larger-than=262144 +WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CFLAGS) $(CFLAGS) -Wframe-larger-than=65536 -mpreferred-stack-boundary=4 WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS) -WOLFSSL_OBJ_FILES=linuxkm/module_hooks.o $(patsubst %.lo, %.o, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(src_libwolfssl_la_OBJECTS)))) + +WOLFSSL_OBJ_FILES=linuxkm/module_hooks.o $(patsubst %.lo, %.o, $(patsubst src/src_libwolfssl_la-%, src/%, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(src_libwolfssl_la_OBJECTS))))) export WOLFSSL_CFLAGS WOLFSSL_ASFLAGS WOLFSSL_OBJ_FILES @@ -32,3 +33,8 @@ libwolfssl.ko: @mkdir -p linuxkm src wolfcrypt/src @if [[ ! -h $(SRC_TOP)/Kbuild ]]; then ln -s $(MODULE_TOP)/Kbuild $(SRC_TOP)/Kbuild; fi make -C $(KROOT) M=$(MODULE_TOP) src=$(SRC_TOP) + +.PHONY: clean + +clean: + @cd $(MODULE_TOP) && rm -f libwolfssl.ko Module.symvers built-in.a modules.order libwolfssl.mod libwolfssl.mod.c src/*.o wolfcrypt/src/*.o diff --git a/m4/ax_linuxkm.m4 b/m4/ax_linuxkm.m4 index 88aea5bb4..0605c3d49 100644 --- a/m4/ax_linuxkm.m4 +++ b/m4/ax_linuxkm.m4 @@ -27,16 +27,3 @@ else AC_MSG_RESULT([no default configured kernel arch found]) fi ]) - -dnl AC_DEFUN([AC_DEFINE_KERNEL_KFLAGS], -dnl [ -dnl AC_MSG_CHECKING([flags for compiling objects for kernel module]) -dnl if test -z "${KROOT}" || test -z "${KARCH}"; then -dnl AC_MSG_ERROR([Linux kernel configuration incomplete (KROOT=${KROOT}, KARCH=${KARCH}).]) -dnl else -dnl GCC_SHORT_VERSION="$($CC -dumpversion)" -dnl KFLAGS="-I${KROOT}/include -I${KROOT}/include/uapi -I${KROOT}/arch/${KARCH}/include -I${KROOT}/arch/${KARCH}/include/generated -I${KROOT}/arch/${KARCH}/include/generated/uapi -I${KROOT}/arch/${KARCH}/include/uapi -I${KROOT}/tools/include -I${KROOT}/tools/arch/${KARCH}/include -I${KROOT}/tools/include/uapi -I/usr/lib/gcc/${host_cpu}-${host_vendor}-${host_os}/${GCC_SHORT_VERSION}/include" -dnl AC_MSG_RESULT([$KFLAGS]) -dnl fi -dnl ]) -dnl diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 3ec2b2162..0a40ddae6 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -176,7 +176,7 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b) { intel_flags = cpuid_get_flags(); } - #ifdef HAVE_INTEL_RDSEED + #if defined(HAVE_INTEL_RDSEED) && !defined(WOLFSSL_LINUXKM) static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz); #endif #ifdef HAVE_INTEL_RDRAND @@ -1438,6 +1438,7 @@ static WC_INLINE int IntelRDseed64_r(word64* rnd) return -1; } +#ifndef WOLFSSL_LINUXKM /* return 0 on success */ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz) { @@ -1468,6 +1469,7 @@ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz) return 0; } +#endif #endif /* HAVE_INTEL_RDSEED */ diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index f3826e30e..6c831affb 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -2099,10 +2099,8 @@ extern void uITRON4_free(void *p) ; #undef WOLFSSL_HAVE_MIN #undef WOLFSSL_HAVE_MAX #define WOLFSSL_DH_CONST 1 /* Linux kernel doesn't have floating point math facilities. */ - #define WOLFSSL_NO_MALLOC 1 #define WOLFSSL_NO_SOCK 1 #define WOLFSSL_USER_IO 1 - #undef HAVE_INTEL_RDSEED /* prevents -Wunused-function on wc_GenerateSeed_IntelRD() */ #define USE_WOLF_STRTOK #define NO_CRYPT_BENCHMARK 1 #define NO_CRYPT_TEST 1 diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index d51992466..0345a841e 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -357,7 +357,7 @@ decouple library dependencies with standard string, memory and so on. #endif #elif defined(WOLFSSL_LINUXKM) - #include + /* the requisite linux/slab.h is included in wc_port.h, with incompatible warnings masked out. */ #define XMALLOC(s, h, t) ((void)h, (void)t, kmalloc((s), GFP_KERNEL)) #define XFREE(p, h, t) {void* xp = (p); if((xp)) kfree((xp));} #define XREALLOC(p, n, h, t) krealloc((p), (n), GFP_KERNEL) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index d630109a9..f05b92e43 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -55,23 +55,6 @@ #endif #ifdef WOLFSSL_LINUXKM - -/* -note, leaving out --enable-pkcs11 in this (depends on -ldl): - -KROOT=/usr/src/linux KARCH=x86 CFLAGS="-I${KROOT}/include -I${KROOT}/arch/${KARCH}/include -I${KROOT}/arch/${KARCH}/include/generated -I${KROOT}/arch/${KARCH}/include/generated/uapi -I${KROOT}/arch/${KARCH}/include/uapi -I${KROOT}/include/uapi -I${KROOT}/tools/include/uapi -I${KROOT}/tools/arch/${KARCH}/include -I${KROOT}/tools/include -I/usr/lib/gcc/${KARCH}_64-pc-linux-gnu/9.3.0/include" ./configure --disable-jobserver --enable-keygen --enable-tls13 --enable-dtls --enable-dtls-mtu --enable-openssh --enable-wpas --enable-wpas-dpp --enable-opensslall --enable-opensslextra --enable-aesccm --enable-aesctr --enable-aesofb --enable-intelasm --enable-sp --enable-sp-asm --enable-curve25519 --enable-ed25519 --enable-curve448 --enable-blake2 --enable-blake2s --enable-camellia --enable-ed448 --enable-hc128 --enable-idea --enable-md2 --enable-rabbit --enable-srp --enable-fpecc --enable-certreq --enable-certgen --enable-certext --enable-certgencache --enable-eccencrypt --enable-mcast --enable-ssh --enable-pkcs7 --enable-pkcallbacks --enable-cryptocb --enable-libwebsockets --enable-linuxkm --disable-examples - -(for coverage, build with and without --enable-fpecc, and with and without --enable-intelasm --enable-sp --enable-sp-asm) - -probably better if lib objs are compiled -ffreestanding -nostdinc. - -building so far: - -make -j src/libwolfssl.la - -still to do: actual kernel module construction per https://www.kernel.org/doc/Documentation/kbuild/modules.txt -*/ - #ifdef HAVE_CONFIG_H #ifndef PACKAGE_NAME #error wc_port.h included before config.h @@ -80,10 +63,6 @@ still to do: actual kernel module construction per https://www.kernel.org/doc/Do #undef HAVE_CONFIG_H #endif - #ifndef __KERNEL__ - #define __KERNEL__ - #endif - _Pragma("GCC diagnostic push"); /* Linux kernel header files generate profuse warnings unless these are masked out: */ _Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); @@ -94,6 +73,10 @@ still to do: actual kernel module construction per https://www.kernel.org/doc/Do _Pragma("GCC diagnostic ignored \"-Wsign-compare\""); _Pragma("GCC diagnostic ignored \"-Wpointer-sign\""); _Pragma("GCC diagnostic ignored \"-Wbad-function-cast\""); + /* these includes bring in all the needed kernel headers. + * they need to be included here while the incompatible warnings are disabled, + * and before undefining conflicting kernel macros afterward. + */ #include #include #include @@ -103,19 +86,22 @@ still to do: actual kernel module construction per https://www.kernel.org/doc/Do #ifndef SINGLE_THREADED #include #endif - #include /* include this here, while the incompatible warnings are disabled, and before undefining conflicting kernel macros below. */ + #include #include _Pragma("GCC diagnostic pop"); - /* a multifariously conflicting macro is picked up from - * Linux arch//include/asm/current.h, which must be - * removed here. + /* remove this multifariously conflicting macro, picked up from + * Linux arch//include/asm/current.h. */ #undef current /* prevent gcc's mm_malloc.h from being included, since it unconditionally includes stdlib.h, which is kernel-incompatible: */ #define _MM_MALLOC_H_INCLUDED + #define malloc(x) kmalloc(x, GFP_KERNEL) + #define free(x) kfree(x) + #define realloc(x,y) krealloc(x, y, GFP_KERNEL) + /* min() and max() in linux/kernel.h over-aggressively type-check, producing myriad spurious -Werrors throughout the codebase. */ #undef min #undef max