Skip to content

Commit 102ab56

Browse files
committed
Phase 3: Security and FIPS Compliance Audit + 12-OE source-of-truth enablement
Security and FIPS-compliance audit remediation for the wolfCrypt v7.0.0 post-quantum FIPS 140-3 module, plus the source changes required to build and validate the module across all 12 Operational Environments (userspace and Linux kernel module; x86_64/i386/aarch64/armv7; Intel/AMD). linuxkm (Linux kernel module): - Generalize the per-CPU vector-register save/restore service from x86 to ARM (kernel_neon_begin/end via WC_LINUXKM_FPU_BEGIN/END); broaden arch guards. - Extend the in-core-integrity relocation canonicalizer to i386 (R_386_32/R_386_PC32) and ARM (R_ARM_CALL/R_ARM_JUMP24). - Kbuild arch-conditional crypto -march for wolfcrypt/src/port/arm/*.S; arm32 EABI integer-divide helpers and PIE container mem* placeholders. 32-bit x86 AES-NI: - Compile the WOLFSSL_X86_BUILD AES-NI path in aes_asm.S / aes_xts_asm.S; gate AES-GCM-AESNI to x86_64 (32-bit uses C GHASH + AES-NI blocks); AES_ECB_decrypt_AESNI argument-offset fix. configure.ac: enable -march=armv8-a+crypto for the arm32 armasm crypto path. random.c / random.h: RDSEED entropy scale and retry tuning for x86 OE portability.
1 parent dd6da70 commit 102ab56

45 files changed

Lines changed: 2529 additions & 240 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IDE/WIN-SRTP-KDF-140-3/test.vcxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@
162162
<OptimizeReferences>true</OptimizeReferences>
163163
<EnableCOMDATFolding>true</EnableCOMDATFolding>
164164
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
165+
<!-- FIPS in-core integrity (WIN-SRTP-KDF README): ASLR OFF so every
166+
build loads at a fixed base and the in-core hash stays stable.
167+
Mirrors the Release|x64 config; FixedBaseAddress (/FIXED) strips
168+
the .reloc section so the i386 image is pinned at its preferred
169+
ImageBase (0x00400000), matching the proven x86_64 (U4) behavior. -->
165170
<RandomizedBaseAddress>false</RandomizedBaseAddress>
171+
<FixedBaseAddress>true</FixedBaseAddress>
166172
</Link>
167173
</ItemDefinitionGroup>
168174
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -177,6 +183,10 @@
177183
</ClCompile>
178184
<Link>
179185
<GenerateDebugInformation>true</GenerateDebugInformation>
186+
<!-- FIPS in-core integrity (WIN-SRTP-KDF README): ASLR OFF so every
187+
build loads at a fixed base and the in-core hash stays stable. -->
188+
<RandomizedBaseAddress>false</RandomizedBaseAddress>
189+
<FixedBaseAddress>true</FixedBaseAddress>
180190
<SubSystem>Console</SubSystem>
181191
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
182192
<OptimizeReferences>true</OptimizeReferences>

IDE/WIN-SRTP-KDF-140-3/wolfssl-fips.vcxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@
314314
<ClCompile Include="..\..\src\dtls13.c" />
315315
<ClCompile Include="..\..\src\dtls.c" />
316316
<ClCompile Include="..\..\wolfcrypt\src\wc_encrypt.c" />
317+
<!-- FIPS v7.0.0 post-quantum module sources (FIPS 203/204/205, SP 800-208).
318+
In-boundary placement is by .fipsA$/.fipsB$ section, not project order. -->
319+
<ClCompile Include="..\..\wolfcrypt\src\wc_mlkem.c" />
320+
<ClCompile Include="..\..\wolfcrypt\src\wc_mlkem_poly.c" />
321+
<ClCompile Include="..\..\wolfcrypt\src\wc_mldsa.c" />
322+
<ClCompile Include="..\..\wolfcrypt\src\wc_lms.c" />
323+
<ClCompile Include="..\..\wolfcrypt\src\wc_lms_impl.c" />
324+
<ClCompile Include="..\..\wolfcrypt\src\wc_xmss.c" />
325+
<ClCompile Include="..\..\wolfcrypt\src\wc_xmss_impl.c" />
326+
<ClCompile Include="..\..\wolfcrypt\src\wc_slhdsa.c" />
317327
<ClCompile Include="..\..\wolfcrypt\src\wolfcrypt_last.c" />
318328
<ClCompile Include="..\..\wolfcrypt\src\wolfmath.c" />
319329
<ClCompile Include="..\..\wolfcrypt\src\wolfevent.c" />

configure.ac

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,13 +3777,22 @@ then
37773777
AC_MSG_NOTICE([32bit ARMv4 found])
37783778
;;
37793779
*)
3780-
AM_CPPFLAGS="$AM_CPPFLAGS -mfpu=crypto-neon-fp-armv8 -marm"
3780+
# AArch32 ARMv8 crypto-extension asm (armv8-32-*-asm.S: sha256h,
3781+
# aese/aesmc, pmull) needs an explicit -march=armv8-a+crypto. The
3782+
# ARMv8-A crypto extension is OPTIONAL, so the SHA/AES instructions
3783+
# are gated by the "+crypto" arch feature -- NOT enabled by -mfpu
3784+
# alone, and NOT by a bare -march=armv8-a (nor -mcpu=cortex-a53 on
3785+
# some toolchains). Cross toolchains whose default -mcpu is ARMv7
3786+
# (e.g. Xilinx Vitis cortex-a9) otherwise reject them with
3787+
# "selected processor does not support sha256h.32 in ARM mode".
3788+
# Mirrors the in-kernel ARM armasm enablement (port/arm/*.S crypto).
3789+
AM_CPPFLAGS="$AM_CPPFLAGS -march=armv8-a+crypto -mfpu=crypto-neon-fp-armv8 -marm"
37813790
# Include options.h
37823791
AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN"
37833792
ENABLED_ARMASM_CRYPTO=yes
37843793
ENABLED_ARMASM_NEON=yes
37853794
ENABLED_ARM_32=yes
3786-
AC_MSG_NOTICE([32bit ARMv8 found, setting mfpu to crypto-neon-fp-armv8])
3795+
AC_MSG_NOTICE([32bit ARMv8 found, setting -march=armv8-a+crypto + mfpu=crypto-neon-fp-armv8])
37873796
;;
37883797
esac
37893798
esac
@@ -6315,13 +6324,7 @@ AS_CASE([$FIPS_VERSION],
63156324
-DWC_RSA_NO_PADDING \
63166325
-DECC_USER_CURVES \
63176326
-DHAVE_ECC384 \
6318-
-DHAVE_ECC521 \
6319-
-DWOLFSSL_VALIDATE_FFC_IMPORT \
6320-
-DHAVE_FFDHE_Q \
6321-
-DHAVE_FFDHE_3072 \
6322-
-DHAVE_FFDHE_4096 \
6323-
-DHAVE_FFDHE_6144 \
6324-
-DHAVE_FFDHE_8192"
6327+
-DHAVE_ECC521"
63256328
63266329
# KCAPI API does not support custom k for sign, don't force enable ECC key sizes and don't use seed callback
63276330
AS_IF([test "x$ENABLED_KCAPI_ECC" = "xno"],
@@ -6335,6 +6338,20 @@ AS_CASE([$FIPS_VERSION],
63356338
-DHAVE_ECC256"])
63366339
63376340
DEFAULT_MAX_CLASSIC_ASYM_KEY_BITS=8192
6341+
6342+
# Classic DH and DSA are OUT OF SCOPE for the FIPS 140-3 v7 PQ module.
6343+
# (FIPS 186-5 retires DSA; v7 boundary keeps only ECDH/ECDSA + PQ KEM/DSA.)
6344+
# Hard-error if explicitly enabled; otherwise force off and add NO_DH/NO_DSA.
6345+
AS_IF([test "$enable_dh" = "yes"],
6346+
[AC_MSG_ERROR([--enable-dh is not supported with --enable-fips=$FIPS_VERSION. Classic finite-field DH is out of scope for the FIPS 140-3 v7 PQ module. Use --enable-fips=v6 if you need DH support.])],
6347+
[test "$ENABLED_DH" != "no"],
6348+
[ENABLED_DH="no"; enable_dh="no"; AM_CFLAGS="$AM_CFLAGS -DNO_DH"])
6349+
6350+
AS_IF([test "$enable_dsa" = "yes"],
6351+
[AC_MSG_ERROR([--enable-dsa is not supported with --enable-fips=$FIPS_VERSION. DSA is retired by FIPS 186-5 and is out of scope for the FIPS 140-3 v7 PQ module. Use --enable-fips=v6 if you need DSA support.])],
6352+
[test "$ENABLED_DSA" != "no"],
6353+
[ENABLED_DSA="no"; enable_dsa="no"; AM_CFLAGS="$AM_CFLAGS -DNO_DSA"])
6354+
63386355
# optimizations section
63396356
63406357
# protocol section
@@ -8889,8 +8906,17 @@ then
88898906
fi
88908907
if test "x$ENABLED_DH" = "xno"
88918908
then
8892-
ENABLED_DH="yes"
8893-
AM_CFLAGS="$AM_CFLAGS -DHAVE_DH"
8909+
# Classic DH is out of scope for the FIPS 140-3 v7 PQ module.
8910+
# JNI normally auto-enables DH for legacy TLS suites; with FIPS v7+
8911+
# we report and skip the auto-enable rather than silently turning DH
8912+
# back on (which would conflict with the boundary).
8913+
if test "$FIPS_VERSION" = "v7" || test "$FIPS_VERSION" = "ready" || test "$FIPS_VERSION" = "dev"
8914+
then
8915+
AC_MSG_NOTICE([JNI enabled but FIPS is $FIPS_VERSION, NOT turning on DH with this module])
8916+
else
8917+
ENABLED_DH="yes"
8918+
AM_CFLAGS="$AM_CFLAGS -DHAVE_DH"
8919+
fi
88948920
fi
88958921
if test "x$ENABLED_PSK" = "xno"
88968922
then

fips-hash.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ then
1313
fi
1414

1515
OUT=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
16-
NEWHASH=$(echo "$OUT" | cut -c1-64)
16+
# FIPS v7.0.0+ uses HMAC-SHA-512 (128 hex chars); older FIPS versions
17+
# use HMAC-SHA-256 (64 hex chars). Take the whole captured hash; the
18+
# static_assert on sizeof(verifyCore) guards against wrong length at
19+
# compile time after this script runs.
20+
NEWHASH=$(echo "$OUT" | head -n1 | tr -d '[:space:]')
1721
if test -n "$NEWHASH"
1822
then
1923
cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak

linuxkm/Kbuild

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ $(LIBWOLFSSL_NAME)-y := $(WOLFSSL_OBJ_FILES) linuxkm/module_hooks.o linuxkm/modu
9999

100100
ifeq "$(FIPS_OPTEST)" "1"
101101
$(LIBWOLFSSL_NAME)-y += linuxkm/optest-140-3/linuxkm_optest_wrapper.o
102+
# The optest TEST wrapper (#includes test.c / invalid_tests.c) aggregates
103+
# several AES contexts per invalid-input test function. Under WOLFSSL_AESNI
104+
# the Aes struct carries an inline ALIGN16 streamData[5*WC_AES_BLOCK_SIZE]
105+
# (wolfssl/wolfcrypt/aes.h) plus use_aesni, so a handful of those functions
106+
# (aes_{,mac_,ofb_,cfb_,kw_}invalid_data_tests) exceed the conservative i386
107+
# THREAD_SIZE/4 = 2048 frame *warning*. They build cleanly on x86_64 (whose
108+
# THREAD_SIZE/4 = 4096 already accommodates them) and run in a kernel thread
109+
# well within THREAD_SIZE. Relax the cap to 4096 for the wrapper ONLY: it is
110+
# test/evidence tooling OUTSIDE the FIPS module boundary, so the FIPS module
111+
# objects keep the strict MAX_STACK_FRAME_SIZE. No effect on x86_64 (its
112+
# default is already 4096).
113+
$(obj)/linuxkm/optest-140-3/linuxkm_optest_wrapper.o: ccflags-y += -Wframe-larger-than=4096
102114
endif
103115

104116
WOLFSSL_CFLAGS_NO_VECTOR_INSNS := $(CFLAGS_SIMD_DISABLE) $(CFLAGS_FPU_DISABLE)
@@ -127,6 +139,10 @@ ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
127139
endif
128140
endif
129141
endif
142+
ifeq ($(KERNEL_ARCH),i386)
143+
NO_PIE_FLAG := 1
144+
$(info Note: disabling -fPIE on 32-bit x86 -- i386 -fPIE routes every local symbol through the GOT (R_386_GOTOFF), which the wolfCrypt PIE containerization forbids.)
145+
endif
130146
endif
131147

132148
ifdef NO_PIE_FLAG
@@ -217,6 +233,25 @@ $(obj)/wolfcrypt/src/wc_mlkem_asm.o: OBJECT_FILES_NON_STANDARD := y
217233
$(obj)/wolfcrypt/src/wc_mldsa_asm.o: asflags-y := $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
218234
$(obj)/wolfcrypt/src/wc_mldsa_asm.o: OBJECT_FILES_NON_STANDARD := y
219235

236+
# ARM/ARM64 crypto+NEON asm (wolfcrypt/src/port/arm/*.S) needs the crypto/NEON
237+
# -march enabled at assembly time. The wolfSSL ARM asm carries no .arch/.fpu
238+
# directives, and configure leaves ASFLAGS_*_SIMD_ENABLE empty on ARM: the
239+
# userspace build inherits +crypto from the toolchain's default -mcpu (e.g.
240+
# cortex-a72), but the kernel build forces its own baseline -march without it,
241+
# so the AES/SHA/PMULL instructions are rejected ("selected processor does not
242+
# support `aesd ...'"). Supply the right -march here per kernel arch. (The
243+
# wrong-arch port/arm files are #ifdef'd to empty objects, so the flag is a
244+
# no-op for them; OBJECT_FILES_NON_STANDARD silences objtool on the hand asm.)
245+
ifeq ($(CONFIG_ARM64),y)
246+
WOLFSSL_ARM_ASM_MARCH := -march=armv8-a+crypto
247+
else ifeq ($(CONFIG_ARM),y)
248+
WOLFSSL_ARM_ASM_MARCH := -march=armv8-a -mfpu=crypto-neon-fp-armv8
249+
endif
250+
ifdef WOLFSSL_ARM_ASM_MARCH
251+
$(obj)/wolfcrypt/src/port/arm/%.o: asflags-y := $(WOLFSSL_ASFLAGS) $(WOLFSSL_ARM_ASM_MARCH)
252+
$(obj)/wolfcrypt/src/port/arm/%.o: OBJECT_FILES_NON_STANDARD := y
253+
endif
254+
220255
ifndef READELF
221256
READELF := readelf
222257
endif
@@ -325,7 +360,7 @@ RENAME_PIE_TEXT_AND_DATA_SECTIONS := \
325360
next; \
326361
} \
327362
else if ($$4 == "OBJECT") { \
328-
if (! ($$7 in wolfcrypt_data_sections)) { \
363+
if (! ($$7 in wolfcrypt_data_sections) && ! ($$7 in wolfcrypt_text_sections)) { \
329364
if ((other_sections[$$7] == ".printk_index") || \
330365
(($$8 ~ /^_entry\.[0-9]+$$|^kernel_read_file_str$$/) && \
331366
(other_sections[$$7] == ".data.rel.ro.local"))) \

linuxkm/Makefile

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ ifndef SRC_TOP
4545
SRC_TOP=$(shell dirname $(MODULE_TOP))
4646
endif
4747

48-
WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Wno-declaration-after-statement -Wno-redundant-decls -DLIBWOLFSSL_GLOBAL_EXTRA_CFLAGS="\" $(KERNEL_EXTRA_CFLAGS)\""
48+
# -Wno-nested-externs: the Linux kernel's compile-time-assert machinery
49+
# (<linux/compiler_types.h> _compiletime_assert, reached via the atomic / per-CPU /
50+
# printk-once macros used in linuxkm/x86_vector_register_glue.c) expands to an
51+
# "extern void __compiletime_assert_N(void)" declaration *inside* a function body.
52+
# That is by-design kernel code, but trips wolfSSL's -Wnested-externs -> with
53+
# -Werror it breaks the i386 + AES-NI kernel build (the glue is only compiled when
54+
# WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set, i.e. with a PAA enabled). Suppress it
55+
# for the whole linuxkm build, same as the two kernel-incompatible warnings already
56+
# stripped here. This only silences a diagnostic -> emitted object code (and the
57+
# FIPS in-core hash) is byte-identical on every arch.
58+
WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Wno-declaration-after-statement -Wno-redundant-decls -Wno-nested-externs -DLIBWOLFSSL_GLOBAL_EXTRA_CFLAGS="\" $(KERNEL_EXTRA_CFLAGS)\""
4959
ifdef KERNEL_EXTRA_CFLAGS
5060
WOLFSSL_CFLAGS += $(KERNEL_EXTRA_CFLAGS)
5161
endif
@@ -55,7 +65,13 @@ endif
5565

5666
WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS)
5767

58-
WOLFSSL_OBJ_FILES=$(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)))))
68+
# Strip libtool's per-target object prefix (src_libwolfssl_la-) so Kbuild sees the
69+
# real source-derived object names. The innermost patsubst handles the ARM asm
70+
# under wolfcrypt/src/port/arm/ (armv8-*/armv8-32-*/thumb2-*), which the
71+
# directory-specific src/ and wolfcrypt/src/ patsubsts below do NOT match --
72+
# without it, --enable-armasm kernel builds fail with "No rule to make target
73+
# .../src_libwolfssl_la-armv8-aes-asm.o".
74+
WOLFSSL_OBJ_FILES=$(patsubst %.lo, %.o, $(patsubst src/src_libwolfssl_la-%, src/%, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(patsubst wolfcrypt/src/port/arm/src_libwolfssl_la-%, wolfcrypt/src/port/arm/%, $(src_libwolfssl_la_OBJECTS))))))
5975

6076
ifeq "$(ENABLED_CRYPT_TESTS)" "yes"
6177
WOLFSSL_OBJ_FILES+=wolfcrypt/test/test.o
@@ -197,7 +213,7 @@ GENERATE_RELOC_TAB := $(AWK) ' \
197213
next; \
198214
} \
199215
/^0/ { \
200-
if ($$3 !~ "^(R_X86_.*|R_AARCH64_.*|R_ARM.*)$$") { \
216+
if ($$3 !~ "^(R_X86_.*|R_386_.*|R_AARCH64_.*|R_ARM.*)$$") { \
201217
print "Unexpected relocation type in " cur_seg ":\n" $$0 >"/dev/stderr"; \
202218
++bad_relocs; \
203219
} \
@@ -361,12 +377,12 @@ module-update-fips-hash: $(LIBWOLFSSL_NAME).ko
361377
readarray -t verifyCore_attrs < <($(READELF) --wide --symbols "$<" | \
362378
sed -E -n 's/^[[:space:]]*[0-9]+: ([0-9a-fA-F]+)[[:space:]]+([0-9]+)[[:space:]]+OBJECT[[:space:]]+[A-Z]+[[:space:]]+[A-Z]+[[:space:]]+'"$${rodata_segment[0]}"'[[:space:]]+verifyCore$$/\1\n\2/p'); \
363379
if [[ $${#verifyCore_attrs[@]} != 2 ]]; then echo ' unexpected verifyCore_attrs.' >&2; exit 1; fi; \
364-
if [[ "$${verifyCore_attrs[1]}" != "65" ]]; then echo " verifyCore has unexpected length $${verifyCore_attrs[1]}." >&2; exit 1; fi; \
380+
if [[ "$${verifyCore_attrs[1]}" != "129" ]]; then echo " verifyCore has unexpected length $${verifyCore_attrs[1]}." >&2; exit 1; fi; \
365381
verifyCore_offset=$$((0x$${rodata_segment[1]} + 0x$${verifyCore_attrs[0]})); \
366-
current_verifyCore=$$(dd bs=1 if="$<" skip=$$verifyCore_offset count=64 status=none); \
382+
current_verifyCore=$$(dd bs=1 if="$<" skip=$$verifyCore_offset count=128 status=none); \
367383
if [[ ! "$$current_verifyCore" =~ [0-9a-fA-F]{64} ]]; then echo " verifyCore at offset $$verifyCore_offset has unexpected value." >&2; exit 1; fi; \
368384
if [[ '$(FIPS_HASH)' == "$$current_verifyCore" ]]; then echo ' Supplied FIPS_HASH matches existing verifyCore -- no update needed.'; exit 0; fi; \
369-
echo -n '$(FIPS_HASH)' | dd bs=1 conv=notrunc of="$<" seek=$$verifyCore_offset count=64 status=none && \
385+
echo -n '$(FIPS_HASH)' | dd bs=1 conv=notrunc of="$<" seek=$$verifyCore_offset count=128 status=none && \
370386
echo " FIPS verifyCore updated successfully." && \
371387
if [[ -f '$(LIBWOLFSSL_NAME).ko.signed' ]]; then $(MAKE) $(QFLAG) --no-print-directory --no-silent -C . '$(LIBWOLFSSL_NAME).ko.signed'; fi
372388

linuxkm/linuxkm_memory.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static const struct reloc_layout_ent {
5252
[WC_R_X86_64_64] = { "R_X86_64_64", ~0UL, 64, .is_signed = 0, .is_relative = 0 },
5353
[WC_R_X86_64_PC32] = { "R_X86_64_PC32", ~0UL, 32, .is_signed = 1, .is_relative = 1 },
5454
[WC_R_X86_64_PLT32] = { "R_X86_64_PLT32", ~0UL, 32, .is_signed = 1, .is_relative = 1 },
55+
[WC_R_386_32] = { "R_386_32", ~0UL, 32, .is_signed = 0, .is_relative = 0 },
56+
[WC_R_386_PC32] = { "R_386_PC32", ~0UL, 32, .is_signed = 1, .is_relative = 1 },
5557
[WC_R_AARCH64_ABS32] = { "R_AARCH64_ABS32", ~0UL, 32, .is_signed = 1, .is_relative = 0, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
5658
[WC_R_AARCH64_ABS64] = { "R_AARCH64_ABS64", ~0UL, 64, .is_signed = 1, .is_relative = 0, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
5759
[WC_R_AARCH64_ADD_ABS_LO12_NC] = { "R_AARCH64_ADD_ABS_LO12_NC", 0b00000000001111111111110000000000, 32, .is_signed = 0, .is_relative = 0, .is_pages = 0, .is_pair_lo = 1, .is_pair_hi = 0 },
@@ -64,6 +66,10 @@ static const struct reloc_layout_ent {
6466
[WC_R_AARCH64_LDST64_ABS_LO12_NC] = { "R_AARCH64_LDST64_ABS_LO12_NC", 0b00000000001111111111110000000000, 32, .is_signed = 0, .is_relative = 0, .is_pages = 0, .is_pair_lo = 1, .is_pair_hi = 0 },
6567
[WC_R_AARCH64_PREL32] = { "R_AARCH64_PREL32", ~0UL, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
6668
[WC_R_ARM_ABS32] = { "R_ARM_ABS32", ~0UL, 32, .is_signed = 0, .is_relative = 0, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
69+
/* ARM-mode BL/B: signed 24-bit word offset in bits [23:0] (cf. AARCH64_CALL26's
70+
* 26-bit field). Emitted by the arm32 ARM-mode (non-Thumb) kernel module build. */
71+
[WC_R_ARM_CALL] = { "R_ARM_CALL", 0b00000000111111111111111111111111, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
72+
[WC_R_ARM_JUMP24] = { "R_ARM_JUMP24", 0b00000000111111111111111111111111, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
6773
[WC_R_ARM_PREL31] = { "R_ARM_PREL31", 0b01111111111111111111111111111111, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
6874
[WC_R_ARM_REL32] = { "R_ARM_REL32", ~0UL, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
6975
[WC_R_ARM_THM_CALL] = { "R_ARM_THM_CALL", 0b00000111111111110010111111111111, 32, .is_signed = 1, .is_relative = 1, .is_pages = 0, .is_pair_lo = 0, .is_pair_hi = 0 },
@@ -363,6 +369,12 @@ ssize_t wc_reloc_normalize_segment(
363369
case WC_R_X86_64_32:
364370
case WC_R_X86_64_32S:
365371
case WC_R_X86_64_64:
372+
/* i386 shares the x86_64 normalization: R_386_32 is absolute
373+
* (is_relative=0), R_386_PC32 is PC-relative (is_relative=1). The
374+
* math below is driven by layout->is_relative/is_signed and is
375+
* width-correct via uintptr_t (32-bit on i386). */
376+
case WC_R_386_32:
377+
case WC_R_386_PC32:
366378

367379
if (dest_seg != WC_R_SEG_OTHER) {
368380
#ifdef DEBUG_LINUXKM_PIE_SUPPORT
@@ -410,6 +422,8 @@ ssize_t wc_reloc_normalize_segment(
410422
break;
411423

412424
case WC_R_ARM_ABS32:
425+
case WC_R_ARM_CALL:
426+
case WC_R_ARM_JUMP24:
413427
case WC_R_ARM_PREL31:
414428
case WC_R_ARM_REL32:
415429
case WC_R_ARM_THM_CALL:

linuxkm/linuxkm_memory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ enum wc_reloc_type {
4040
WC_R_X86_64_64,
4141
WC_R_X86_64_PC32,
4242
WC_R_X86_64_PLT32,
43+
/* 32-bit x86 (i386). With NO_PIE_FLAG the wolfCrypt container emits only
44+
* R_386_32 (absolute) and R_386_PC32 (PC-relative); these are semantically
45+
* identical to R_X86_64_32 / R_X86_64_PC32 and share their canonicalization
46+
* case below. */
47+
WC_R_386_32,
48+
WC_R_386_PC32,
4349
WC_R_AARCH64_ABS32,
4450
WC_R_AARCH64_ABS64,
4551
WC_R_AARCH64_ADD_ABS_LO12_NC,
@@ -52,6 +58,8 @@ enum wc_reloc_type {
5258
WC_R_AARCH64_LDST64_ABS_LO12_NC,
5359
WC_R_AARCH64_PREL32,
5460
WC_R_ARM_ABS32,
61+
WC_R_ARM_CALL,
62+
WC_R_ARM_JUMP24,
5563
WC_R_ARM_PREL31,
5664
WC_R_ARM_REL32,
5765
WC_R_ARM_THM_CALL,

0 commit comments

Comments
 (0)