Skip to content

Commit 36328e3

Browse files
authored
Merge pull request #9857 from douzzer/20260303-linuxkm-aarch64-fixes
20260303-linuxkm-aarch64-fixes
2 parents 1c8d593 + 67bcaff commit 36328e3

9 files changed

Lines changed: 117 additions & 32 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ WC_DILITHIUM_FIXED_ARRAY
637637
WC_DISABLE_RADIX_ZERO_PAD
638638
WC_FLAG_DONT_USE_AESNI
639639
WC_FORCE_LINUXKM_FORTIFY_SOURCE
640-
WC_LINUXKM_SUPPORT_DUMP_TO_FILE
641640
WC_LMS_FULL_HASH
642641
WC_NO_ASYNC_SLEEP
643642
WC_NO_RNG_SIMPLE

configure.ac

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,14 @@ AC_ARG_ENABLE([benchmark],
754754

755755
ENABLED_LINUXKM_PIE=$ENABLED_FIPS
756756

757-
AC_ARG_ENABLE([linuxkm-pie],
758-
[AS_HELP_STRING([--enable-linuxkm-pie],[Enable relocatable object build of Linux kernel module (default: disabled)])],
759-
[ENABLED_LINUXKM_PIE=$enableval])
760-
761757
AC_ARG_ENABLE([kernel-reloc-tables],
762758
[AS_HELP_STRING([--enable-kernel-reloc-tables],[Enable containerized object build of wolfCrypt module in kernel build (default: disabled)])],
763759
[ENABLED_LINUXKM_PIE=$enableval])
764760

761+
AC_ARG_ENABLE([linuxkm-pie],
762+
[AS_HELP_STRING([--enable-linuxkm-pie],[Alias for --enable-kernel-reloc-tables])],
763+
[ENABLED_LINUXKM_PIE=$enableval])
764+
765765
if test "$ENABLED_LINUXKM" = "yes" && test "$ENABLED_LINUXKM_PIE" = "yes"
766766
then
767767
AM_CFLAGS="$AM_CFLAGS -DWC_SYM_RELOC_TABLES"
@@ -1701,13 +1701,13 @@ AC_ARG_WITH([liboqs],
17011701
# Used:
17021702
# - SHA3, Shake128 and Shake256
17031703
AC_ARG_ENABLE([mlkem],
1704-
[AS_HELP_STRING([--enable-mlkem],[Enable MLKEM (default: disabled)])],
1704+
[AS_HELP_STRING([--enable-mlkem],[Enable ML-KEM/Kyber (default: disabled)])],
17051705
[ ENABLED_MLKEM=$enableval ],
17061706
[ ENABLED_MLKEM=no ]
17071707
)
17081708
# note, inherits default from "mlkem" clause above.
17091709
AC_ARG_ENABLE([kyber],
1710-
[AS_HELP_STRING([--enable-kyber],[Enable Kyber/MLKEM (default: disabled)])],
1710+
[AS_HELP_STRING([--enable-kyber],[Alias for --enable-mlkem])],
17111711
[ ENABLED_MLKEM=$enableval ]
17121712
)
17131713

@@ -1837,13 +1837,13 @@ fi
18371837
# Dilithium
18381838
# - SHA3, Shake128, Shake256 and AES-CTR
18391839
AC_ARG_ENABLE([mldsa],
1840-
[AS_HELP_STRING([--enable-mldsa],[Enable MLDSA (default: disabled)])],
1840+
[AS_HELP_STRING([--enable-mldsa],[Enable ML-DSA/Dilithium (default: disabled)])],
18411841
[ ENABLED_DILITHIUM=$enableval ],
18421842
[ ENABLED_DILITHIUM=no ]
18431843
)
18441844
# note, inherits default from "mldsa" clause above.
18451845
AC_ARG_ENABLE([dilithium],
1846-
[AS_HELP_STRING([--enable-dilithium],[Enable Dilithium/MLDSA (default: disabled)])],
1846+
[AS_HELP_STRING([--enable-dilithium],[Alias for --enable-mldsa])],
18471847
[ ENABLED_DILITHIUM=$enableval ]
18481848
)
18491849

@@ -4107,7 +4107,7 @@ AC_ARG_ENABLE([amdrdseed],
41074107
)
41084108

41094109
AC_ARG_ENABLE([amdrand],
4110-
[AS_HELP_STRING([--enable-amdrand],[Enable AMD rdseed as preferred RNG seeding source (default: disabled)])],
4110+
[AS_HELP_STRING([--enable-amdrand],[Alias for --enable-amdrdseed])],
41114111
[ ENABLED_AMDRDSEED=$enableval ]
41124112
)
41134113

@@ -6016,8 +6016,12 @@ AC_ARG_ENABLE([wolfEntropy],
60166016
[ ENABLED_ENTROPY_MEMUSE=$enableval ],
60176017
[ ENABLED_ENTROPY_MEMUSE=$ENABLED_ENTROPY_MEMUSE_DEFAULT ]
60186018
)
6019+
AC_ARG_ENABLE([wolfentropy],
6020+
[AS_HELP_STRING([--enable-wolfentropy],[Alias for --enable-wolfEntropy])],
6021+
[ ENABLED_ENTROPY_MEMUSE=$enableval ],
6022+
)
60196023
AC_ARG_ENABLE([entropy-memuse],
6020-
[AS_HELP_STRING([--enable-entropy-memuse],[Enable memuse entropy support (default: disabled)])],
6024+
[AS_HELP_STRING([--enable-entropy-memuse],[Alias for --enable-wolfEntropy])],
60216025
[ ENABLED_ENTROPY_MEMUSE=$enableval ]
60226026
)
60236027

@@ -11046,8 +11050,11 @@ AX_HARDEN_CC_COMPILER_FLAGS
1104611050
1104711051
# -Wdeprecated-enum-enum-conversion is on by default in C++20, but conflicts with
1104811052
# our use of enum constructs to define fungible constants.
11049-
AX_CHECK_COMPILE_FLAG([-Werror -Wno-deprecated-enum-enum-conversion],
11050-
[AX_APPEND_FLAG([-Wno-deprecated-enum-enum-conversion], [AM_CFLAGS])])
11053+
if test "$KERNEL_MODE_DEFAULTS" != "yes"
11054+
then
11055+
AX_CHECK_COMPILE_FLAG([-Werror -Wno-deprecated-enum-enum-conversion],
11056+
[AX_APPEND_FLAG([-Wno-deprecated-enum-enum-conversion], [AM_CFLAGS])])
11057+
fi
1105111058
1105211059
case $host_os in
1105311060
mingw*)

linuxkm/Kbuild

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ endif
3939

4040
WOLFSSL_CFLAGS += -ffreestanding -Wframe-larger-than=$(MAX_STACK_FRAME_SIZE) -isystem $(shell $(CC) -print-file-name=include)
4141

42+
# -moutline-atomics added in gcc 10.1 for ARMv8.0.
43+
AARCH64_NO_OUTLINE_ATOMICS := $(shell { echo -e 'int f(void) {\n return 0;\n}\n' | $(CC) -mno-outline-atomics -x c -c - -o /dev/null 2>/dev/null; } && echo -mno-outline-atomics)
44+
4245
ifeq "$(KERNEL_ARCH)" "aarch64"
43-
WOLFSSL_CFLAGS += -mno-outline-atomics
46+
WOLFSSL_CFLAGS += $(AARCH64_NO_OUTLINE_ATOMICS)
4447
else ifeq "$(KERNEL_ARCH)" "arm64"
45-
WOLFSSL_CFLAGS += -mno-outline-atomics
48+
WOLFSSL_CFLAGS += $(AARCH64_NO_OUTLINE_ATOMICS)
4649
else ifeq "$(KERNEL_ARCH)" "arm"
4750
# avoids R_ARM_THM_JUMP11 relocations, including a stubborn tail recursion
4851
# optimization from wc_sp_cmp to wc_sp_cmp_mag:
@@ -111,7 +114,21 @@ ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
111114
# note, we need -fno-stack-protector to avoid references to
112115
# "__stack_chk_fail" from the wolfCrypt container.
113116
PIE_FLAGS := -DWC_CONTAINERIZE_THIS -fno-stack-protector -fno-toplevel-reorder
114-
# some targets can't handle -fpie. E.g. ARM32 on kernel <=5.10 has no handling for R_ARM_REL32.
117+
118+
ifndef NO_PIE_FLAG
119+
ifeq ($(KERNEL_ARCH),arm)
120+
ifeq ($(intcmp $(VERSION),5,1,0,0),1)
121+
NO_PIE_FLAG :=
122+
$(info Note: disabling -fPIE to avoid R_ARM_REL32 on pre-5.11 target kernel.)
123+
else
124+
ifeq ($(intcmp $(VERSION),5,0,1,0)-$(intcmp $(PATCHLEVEL),11,1,0,0),1-1)
125+
NO_PIE_FLAG :=
126+
$(info Note: disabling -fPIE to avoid R_ARM_REL32 on pre-5.11 target kernel.)
127+
endif
128+
endif
129+
endif
130+
endif
131+
115132
ifdef NO_PIE_FLAG
116133
PIE_FLAGS += -DWC_NO_PIE_FLAG
117134
else

linuxkm/linuxkm_wc_port.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@
301301
#endif
302302

303303
#if defined(WC_CONTAINERIZE_THIS) && defined(CONFIG_ARM64)
304-
#define alt_cb_patch_nops my__alt_cb_patch_nops
304+
/* alt_cb_patch_nops and queued_spin_lock_slowpath are defined early
305+
* to allow shimming in system headers.
306+
*/
307+
/* alt_cb_patch_nops added by d926079f17, release 6.1 */
308+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
309+
#define alt_cb_patch_nops my__alt_cb_patch_nops
310+
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) */
305311
#define queued_spin_lock_slowpath my__queued_spin_lock_slowpath
306312
#endif
307313

@@ -509,6 +515,11 @@
509515
#endif /* !WOLFCRYPT_ONLY */
510516
#endif /* !WC_CONTAINERIZE_THIS */
511517

518+
#if defined(WC_SYM_RELOC_TABLES) && defined(DEBUG_LINUXKM_PIE_SUPPORT) && \
519+
!defined(WC_LINUXKM_SUPPORT_DUMP_TO_FILE)
520+
#define WC_LINUXKM_SUPPORT_DUMP_TO_FILE
521+
#endif
522+
512523
#ifdef WC_LINUXKM_SUPPORT_DUMP_TO_FILE
513524
#include <linux/fs.h>
514525
#include <linux/uaccess.h>
@@ -1116,12 +1127,16 @@
11161127
* to allow shimming in system headers, but now we need the native
11171128
* ones.
11181129
*/
1130+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
11191131
#undef alt_cb_patch_nops
11201132
typeof(my__alt_cb_patch_nops) *alt_cb_patch_nops;
1133+
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) */
11211134
#undef queued_spin_lock_slowpath
11221135
typeof(my__queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
11231136
#else
1137+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
11241138
typeof(alt_cb_patch_nops) *alt_cb_patch_nops;
1139+
#endif
11251140
typeof(queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
11261141
#endif
11271142
#endif

linuxkm/module_hooks.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,19 @@ static ssize_t dump_to_file(const char *path, const u8 *buf, size_t buf_len)
268268
return ret;
269269
}
270270

271-
fp = filp_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
271+
fp = filp_open(path, O_WRONLY | O_CREAT, 0644);
272272
if (IS_ERR(fp)) {
273273
pr_err("libwolfssl: cannot open %s: %ld\n", path, PTR_ERR(fp));
274274
return PTR_ERR(fp);
275275
}
276276

277277
WC_SANITIZE_DISABLE();
278-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
279-
/* kernel_write() exported by 7bb307e894d51 */
278+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
279+
/* kernel_write() fixed by e13ec939e9 */
280280
ret = kernel_write(fp, buf, buf_len, &pos);
281+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
282+
/* kernel_write() exported by 7bb307e894d51 */
283+
ret = kernel_write(fp, (char *)buf, buf_len, pos);
281284
#else
282285
ret = vfs_write(fp, buf, buf_len, &pos);
283286
#endif
@@ -575,12 +578,26 @@ static int wolfssl_init(void)
575578

576579
#ifdef WC_SYM_RELOC_TABLES
577580
if (text_dump_path) {
578-
if (dump_to_file(text_dump_path, (u8 *)__wc_text_start, (size_t)((uintptr_t)__wc_text_end - (uintptr_t)__wc_text_start)) == 0)
579-
pr_info("libwolfssl: dumped .wolfcrypt_text (%zu bytes) to %s.\n", (size_t)((uintptr_t)__wc_text_end - (uintptr_t)__wc_text_start), text_dump_path);
581+
if (dump_to_file(text_dump_path,
582+
(u8 *)__wc_text_start,
583+
(size_t)((uintptr_t)__wc_text_end - (uintptr_t)__wc_text_start))
584+
> 0)
585+
{
586+
pr_info("libwolfssl: dumped .wolfcrypt_text (%zu bytes) to %s.\n",
587+
(size_t)((uintptr_t)__wc_text_end - (uintptr_t)__wc_text_start),
588+
text_dump_path);
589+
}
580590
}
581591
if (rodata_dump_path) {
582-
if (dump_to_file(rodata_dump_path, (u8 *)__wc_rodata_start, (size_t)(__wc_rodata_end - __wc_rodata_start)) == 0)
583-
pr_info("libwolfssl: dumped .wolfcrypt_rodata (%zu bytes) to %s.\n", (size_t)((uintptr_t)__wc_rodata_end - (uintptr_t)__wc_rodata_start), text_dump_path);
592+
if (dump_to_file(rodata_dump_path,
593+
(u8 *)__wc_rodata_start,
594+
(size_t)((uintptr_t)__wc_rodata_end - (uintptr_t)__wc_rodata_start))
595+
> 0)
596+
{
597+
pr_info("libwolfssl: dumped .wolfcrypt_rodata (%zu bytes) to %s.\n",
598+
(size_t)((uintptr_t)__wc_rodata_end - (uintptr_t)__wc_rodata_start),
599+
rodata_dump_path);
600+
}
584601
}
585602
#else
586603
if ((text_dump_path != NULL) ||
@@ -1536,7 +1553,9 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
15361553

15371554
#ifdef CONFIG_ARM64
15381555
#ifndef CONFIG_ARCH_TEGRA
1556+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
15391557
wolfssl_linuxkm_pie_redirect_table.alt_cb_patch_nops = alt_cb_patch_nops;
1558+
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) */
15401559
wolfssl_linuxkm_pie_redirect_table.queued_spin_lock_slowpath = queued_spin_lock_slowpath;
15411560
#endif
15421561
#endif

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18879,7 +18879,7 @@ static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
1887918879
const unsigned char* p;
1888018880
unsigned char *der = NULL;
1888118881
unsigned char *tmp = NULL;
18882-
int derLen;
18882+
int derLen = -1;
1888318883
unsigned char pub_buf[65];
1888418884
unsigned char pub_spki_buf[91];
1888518885
const int pub_len = 65;
@@ -18989,7 +18989,7 @@ static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
1898918989
};
1899018990
int derInLen = sizeof(derIn);
1899118991
byte* derOut = NULL;
18992-
int derOutLen;
18992+
int derOutLen = -1;
1899318993
byte* p = derIn;
1899418994

1899518995
/* Check that params can be successfully decoded. */

tests/api/test_pkcs7.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3143,7 +3143,7 @@ int test_wc_PKCS7_GetEnvelopedDataKariRid(void)
31433143
byte rid[256];
31443144
byte cms[1024];
31453145
XFILE cmsFile = XBADFILE;
3146-
int ret;
3146+
int ret = -1;
31473147
word32 ridSz = sizeof(rid);
31483148
XFILE skiHexFile = XBADFILE;
31493149
byte skiHex[256];

wolfcrypt/src/wc_port.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,12 +5008,15 @@ char* wolfSSL_strnstr(const char* s1, const char* s2, unsigned int n)
50085008
#if defined(WOLFSSL_LINUXKM) && defined(CONFIG_ARM64) && \
50095009
defined(WC_SYM_RELOC_TABLES)
50105010
#ifndef CONFIG_ARCH_TEGRA
5011+
5012+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
50115013
noinstr void my__alt_cb_patch_nops(struct alt_instr *alt, __le32 *origptr,
50125014
__le32 *updptr, int nr_inst)
50135015
{
50145016
return WC_PIE_INDIRECT_SYM(alt_cb_patch_nops)
50155017
(alt, origptr, updptr, nr_inst);
50165018
}
5019+
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) */
50175020

50185021
void my__queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
50195022
{

0 commit comments

Comments
 (0)