Skip to content

Commit 32aecf4

Browse files
authored
Merge pull request #7180 from douzzer/20240126-LINUXKM_LKCAPI_REGISTER
20240126-LINUXKM_LKCAPI_REGISTER
2 parents f9bf96d + 10645de commit 32aecf4

13 files changed

Lines changed: 3305 additions & 91 deletions

File tree

configure.ac

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ then
745745
test "$enable_psk" = "" && enable_psk=yes
746746
test "$enable_cmac" = "" && enable_cmac=yes
747747
test "$enable_siphash" = "" && enable_siphash=yes
748-
test "$enable_xts" = "" && enable_xts=yes
748+
test "$enable_aesxts" = "" && enable_aesxts=yes
749749
test "$enable_ocsp" = "" && enable_ocsp=yes
750750
test "$enable_ocspstapling" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling=yes
751751
test "$enable_ocspstapling2" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling2=yes
@@ -933,7 +933,7 @@ then
933933
test "$enable_psk" = "" && enable_psk=yes
934934
test "$enable_cmac" = "" && enable_cmac=yes
935935
test "$enable_siphash" = "" && enable_siphash=yes
936-
test "$enable_xts" = "" && enable_xts=yes
936+
test "$enable_aesxts" = "" && enable_aesxts=yes
937937
test "$enable_ocsp" = "" && enable_ocsp=yes
938938
test "$enable_ocspstapling" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling=yes
939939
test "$enable_ocspstapling2" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling2=yes
@@ -4836,17 +4836,23 @@ AS_IF([test "x$ENABLED_CMAC" = "xyes"],
48364836

48374837

48384838
# AES-XTS
4839+
AC_ARG_ENABLE([aesxts],
4840+
[AS_HELP_STRING([--enable-aesxts],[Enable AES XTS (default: disabled)])],
4841+
[ ENABLED_AESXTS=$enableval ],
4842+
[ ENABLED_AESXTS=no ]
4843+
)
4844+
4845+
# legacy old option name, for compatibility:
48394846
AC_ARG_ENABLE([xts],
4840-
[AS_HELP_STRING([--enable-xts],[Enable XTS (default: disabled)])],
4841-
[ ENABLED_XTS=$enableval ],
4842-
[ ENABLED_XTS=no ]
4847+
[AS_HELP_STRING([--enable-xts],[Please use --enable-aesxts])],
4848+
[ ENABLED_AESXTS=$enableval ]
48434849
)
48444850

4845-
AS_IF([test "x$ENABLED_XTS" = "xyes"],
4851+
AS_IF([test "x$ENABLED_AESXTS" = "xyes"],
48464852
[AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_AES_XTS -DWOLFSSL_AES_DIRECT"])
4847-
AS_IF([test "x$ENABLED_XTS" = "xyes" && test "x$ENABLED_INTELASM" = "xyes"],
4853+
AS_IF([test "x$ENABLED_AESXTS" = "xyes" && test "x$ENABLED_INTELASM" = "xyes"],
48484854
[AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_AES_XTS"])
4849-
AS_IF([test "x$ENABLED_XTS" = "xyes" && test "x$ENABLED_AESNI" = "xyes"],
4855+
AS_IF([test "x$ENABLED_AESXTS" = "xyes" && test "x$ENABLED_AESNI" = "xyes"],
48504856
[AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_AES_XTS"])
48514857

48524858
# Web Server Build
@@ -8028,6 +8034,37 @@ if test -n "$MPI_MAX_KEY_BITS" -o -n "$WITH_MAX_ECC_BITS"; then
80288034
fi
80298035
fi
80308036

8037+
AC_ARG_ENABLE([linuxkm-lkcapi-register],
8038+
[AS_HELP_STRING([--enable-linuxkm-lkcapi-register],[Register wolfCrypt implementations with the Linux Kernel Crypto API backplane. Possible values are "none", "all", "cbc(aes)", "cfb(aes)", "gcm(aes)", and "xts(aes)", or a comma-separate combination. (default: none)])],
8039+
[ENABLED_LINUXKM_LKCAPI_REGISTER=$enableval],
8040+
[ENABLED_LINUXKM_LKCAPI_REGISTER=none]
8041+
)
8042+
if test "$ENABLED_LINUXKM_LKCAPI_REGISTER" != "none"
8043+
then
8044+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER"
8045+
8046+
if test "$ENABLED_AESGCM" != "no" && test "$ENABLED_AESGCM_STREAM" = "no" && test "$ENABLED_AESNI" = "no" && test "$ENABLED_ARMASM" = "no" && test "$ENABLED_FIPS" = "no"; then
8047+
ENABLED_AESGCM_STREAM=yes
8048+
fi
8049+
8050+
for lkcapi_alg in $(echo "$ENABLED_LINUXKM_LKCAPI_REGISTER" | tr ',' ' ')
8051+
do
8052+
case "$lkcapi_alg" in
8053+
all) AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_ALL" ;;
8054+
'cbc(aes)') test "$ENABLED_AESCBC" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: AES-CBC implementation not enabled.])
8055+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_AESCBC" ;;
8056+
'cfb(aes)') test "$ENABLED_AESCFB" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: AES-CFB implementation not enabled.])
8057+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_AESCFB" ;;
8058+
'gcm(aes)') test "$ENABLED_AESGCM" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: AES-GCM implementation not enabled.])
8059+
test "$ENABLED_AESGCM_STREAM" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: --enable-aesgcm-stream is required for LKCAPI.])
8060+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_AESGCM" ;;
8061+
'xts(aes)') test "$ENABLED_AESXTS" != "no" || AC_MSG_ERROR([linuxkm-lkcapi-register ${lkcapi_alg}: AES-XTS implementation not enabled.])
8062+
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER_AESXTS" ;;
8063+
*) AC_MSG_ERROR([Unsupported LKCAPI algorithm "$lkcapi_alg".]) ;;
8064+
esac
8065+
done
8066+
fi
8067+
80318068
# Library Suffix
80328069
LIBSUFFIX=""
80338070
AC_ARG_WITH([libsuffix],
@@ -8958,7 +8995,7 @@ AM_CONDITIONAL([BUILD_SNIFFER], [ test "x$ENABLED_SNIFFER" = "xyes" || test "
89588995
AM_CONDITIONAL([BUILD_SNIFFTEST],[ test "x$ENABLED_SNIFFTEST" = "xyes"])
89598996
AM_CONDITIONAL([BUILD_AESGCM],[test "x$ENABLED_AESGCM" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
89608997
AM_CONDITIONAL([BUILD_AESCCM],[test "x$ENABLED_AESCCM" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
8961-
AM_CONDITIONAL([BUILD_XTS],[test "x$ENABLED_XTS" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
8998+
AM_CONDITIONAL([BUILD_AESXTS],[test "x$ENABLED_AESXTS" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
89628999
AM_CONDITIONAL([BUILD_ARMASM],[test "x$ENABLED_ARMASM" = "xyes"])
89639000
AM_CONDITIONAL([BUILD_ARMASM_INLINE],[test "x$ENABLED_ARMASM_INLINE" = "xyes"])
89649001
AM_CONDITIONAL([BUILD_ARMASM_CRYPTO],[test "x$ENABLED_ARMASM_CRYPTO" = "xyes"])
@@ -9397,6 +9434,7 @@ echo " * AES-CCM: $ENABLED_AESCCM"
93979434
echo " * AES-CTR: $ENABLED_AESCTR"
93989435
echo " * AES-CFB: $ENABLED_AESCFB"
93999436
echo " * AES-OFB: $ENABLED_AESOFB"
9437+
echo " * AES-XTS: $ENABLED_AESXTS"
94009438
echo " * AES-SIV: $ENABLED_AESSIV"
94019439
echo " * AES-EAX: $ENABLED_AESEAX"
94029440
echo " * AES Bitspliced: $ENABLED_AESBS"

linuxkm/Kbuild

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ WOLFSSL_CFLAGS += -ffreestanding -Wframe-larger-than=$(MAX_STACK_FRAME_SIZE) -is
3232

3333
ifeq "$(KERNEL_ARCH)" "x86"
3434
WOLFSSL_CFLAGS += -mpreferred-stack-boundary=4
35+
else ifeq "$(KERNEL_ARCH)" "aarch64"
36+
WOLFSSL_CFLAGS += -mno-outline-atomics
37+
else ifeq "$(KERNEL_ARCH)" "arm64"
38+
WOLFSSL_CFLAGS += -mno-outline-atomics
3539
endif
3640

3741
obj-m := libwolfssl.o
@@ -47,9 +51,14 @@ $(obj)/linuxkm/module_exports.o: $(WOLFSSL_OBJ_TARGETS)
4751
# this mechanism only works in kernel 5.x+ (fallback to hardcoded value)
4852
hostprogs := linuxkm/get_thread_size
4953
always-y := $(hostprogs)
54+
55+
HOST_EXTRACFLAGS += $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CFLAGS) -static -fno-omit-frame-pointer
56+
5057
# "-mindirect-branch=keep -mfunction-return=keep" to avoid "undefined reference
5158
# to `__x86_return_thunk'" on CONFIG_RETHUNK kernels (5.19.0-rc7)
52-
HOST_EXTRACFLAGS += $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CFLAGS) -static -fno-omit-frame-pointer -mindirect-branch=keep -mfunction-return=keep
59+
ifeq "$(KERNEL_ARCH)" "x86"
60+
HOST_EXTRACFLAGS += -mindirect-branch=keep -mfunction-return=keep
61+
endif
5362

5463
# this rule is needed to get build to succeed in 4.x (get_thread_size still doesn't get built)
5564
$(obj)/linuxkm/get_thread_size: $(src)/linuxkm/get_thread_size.c
@@ -149,10 +158,10 @@ ifneq "$(quiet)" "silent_"
149158
endif
150159
@cd "$(obj)" || exit $$?; \
151160
for file in $(WOLFCRYPT_PIE_FILES); do \
152-
$(OBJCOPY) --rename-section .text=.text.wolfcrypt --rename-section .data=.data.wolfcrypt "$$file" || exit $$?; \
161+
$(OBJCOPY) --rename-section .text=.text.wolfcrypt --rename-section .data=.data.wolfcrypt --rename-section .rodata=.rodata.wolfcrypt "$$file" || exit $$?; \
153162
done
154163
ifneq "$(quiet)" "silent_"
155-
@echo ' wolfCrypt .{text,data} sections containerized to .{text,data}.wolfcrypt'
164+
@echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
156165
endif
157166

158167
$(src)/linuxkm/module_exports.c: rename-pie-text-and-data-sections

linuxkm/include.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ EXTRA_DIST += m4/ax_linuxkm.m4 \
1212
linuxkm/pie_redirect_table.c \
1313
linuxkm/pie_last.c \
1414
linuxkm/linuxkm_memory.c \
15-
linuxkm/linuxkm_wc_port.h
15+
linuxkm/linuxkm_wc_port.h \
16+
linuxkm/lkcapi_glue.c

linuxkm/linuxkm_memory.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ WARN_UNUSED_RESULT int save_vector_registers_x86(void)
275275
{
276276
struct wc_thread_fpu_count_ent *pstate = wc_linuxkm_fpu_state_assoc(1);
277277
if (pstate == NULL)
278-
return ENOMEM;
278+
return MEMORY_E;
279279

280280
/* allow for nested calls */
281281
if (pstate->fpu_state != 0U) {
@@ -314,7 +314,7 @@ WARN_UNUSED_RESULT int save_vector_registers_x86(void)
314314
if (! warned_fpu_forbidden)
315315
pr_err("save_vector_registers_x86 called from IRQ handler.\n");
316316
wc_linuxkm_fpu_state_release(pstate);
317-
return EPERM;
317+
return BAD_STATE_E;
318318
} else {
319319
#if defined(CONFIG_SMP) && !defined(CONFIG_PREEMPT_COUNT) && \
320320
(LINUX_VERSION_CODE >= KERNEL_VERSION(5, 7, 0)) && \
@@ -380,3 +380,11 @@ void my__show_free_areas(
380380
return;
381381
}
382382
#endif
383+
384+
#if defined(__PIE__) && defined(CONFIG_FORTIFY_SOURCE)
385+
/* needed because FORTIFY_SOURCE inline implementations call fortify_panic(). */
386+
void __my_fortify_panic(const char *name) {
387+
pr_emerg("__my_fortify_panic in %s\n", name);
388+
BUG();
389+
}
390+
#endif

0 commit comments

Comments
 (0)