Skip to content

Commit 06d3d6d

Browse files
committed
linuxkm/Kbuild and linuxkm/module_hooks.c: refactor wc_linuxkm_pie_reloc_tab to include ground truth segment tag from ELF metadata.
tweaks for ARM32: recognize R_ARM_* relocations, and add -fno-unwind-tables to PIE_FLAGS. linuxkm/linuxkm_wc_port.h: * __PIE__: don't declare static pmd_to_page() unless USE_SPLIT_PMD_PTLOCKS. * add wc_lkm_refcount_to_int() helper with -Wnested-externs suppressed. wolfcrypt/src/fe_operations.c: in fe_frombytes() and fe_sq2(), use explicit XMEMSET()s to initialize working vars, rather than implicit, to avoid implicit (unshimmable) memset() calls. wolfcrypt/src/ge_operations.c: fix gate on _wc_curve25519_dummy() to require CURVED25519_ASM.
1 parent 96dde5b commit 06d3d6d

File tree

6 files changed

+252
-127
lines changed

6 files changed

+252
-127
lines changed

linuxkm/Kbuild

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
127127

128128
OBJECT_FILES_NON_STANDARD := y
129129
endif
130+
ifeq "$(KERNEL_ARCH)" "arm"
131+
PIE_FLAGS += -fno-unwind-tables
132+
endif
130133
ifeq "$(KERNEL_ARCH)" "mips"
131134
PIE_FLAGS += -mabicalls
132135
endif

linuxkm/Makefile

Lines changed: 133 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ OVERRIDE_PATHS :=
7373

7474
ifdef CC
7575
ifneq "$(CC)" "cc"
76-
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'CC=$(CC)'
76+
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'CC=$(CC)'
7777
endif
7878
endif
7979
ifdef AS
8080
ifneq "$(AS)" "as"
81-
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'AS=$(AS)'
81+
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'AS=$(AS)'
8282
endif
8383
endif
8484
ifdef LD
8585
ifneq "$(LD)" "ld"
86-
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'LD=$(LD)'
86+
OVERRIDE_PATHS := $(OVERRIDE_PATHS) 'LD=$(LD)'
8787
endif
8888
endif
8989

@@ -103,14 +103,39 @@ ifndef MAKE_TMPDIR
103103
MAKE_TMPDIR := $(TMPDIR)
104104
endif
105105

106-
GENERATE_RELOC_TAB := $(AWK) 'BEGIN { \
106+
GENERATE_SECTION_MAP := $(AWK) 'BEGIN { printf("") >ENVIRON["SECTION_MAP"]; } \
107+
{ \
108+
if ($$7 !~ "^[0-9]+$$") \
109+
next; \
110+
if ($$4 == "SECTION") { \
111+
sections[$$7] = $$8; \
112+
next; \
113+
} \
114+
if (($$4 == "NOTYPE") || ($$4 == "OBJECT") || ($$4 == "FUNC")) { \
115+
if (($$8 == "$$d") || ($$8 == "$$t")) \
116+
next; \
117+
if ($$7 in sections) { \
118+
if (sections[$$7] ~ "_wolfcrypt$$") \
119+
print $$8 "\t" sections[$$7] >>ENVIRON["SECTION_MAP"]; \
120+
} else \
121+
print $$8 " is in section " $$7 " with no name mapping." >"/dev/stderr";\
122+
} \
123+
}'
124+
125+
GENERATE_RELOC_TAB := $(AWK) ' \
126+
BEGIN { \
107127
n=0; \
108128
bad_relocs=0; \
109129
print "\#include <wolfssl/wolfcrypt/libwolfssl_sources.h>"; \
110130
printf("%s\n ", \
111-
"WOLFSSL_LOCAL const unsigned int wc_linuxkm_pie_reloc_tab[] = { "); \
131+
"WOLFSSL_LOCAL const unsigned int wc_linuxkm_pie_reloc_tab[] = { "); \
132+
if ("SECTION_MAP" in ENVIRON) { \
133+
while (getline <ENVIRON["SECTION_MAP"] > 0) \
134+
section_map[$$1] = $$2; \
135+
close(ENVIRON["SECTION_MAP"]); \
136+
} \
112137
} \
113-
/^Relocation section '\''\.rela\.text_wolfcrypt'\''/ { \
138+
/^Relocation section '\''\.rela?\.text_wolfcrypt'\''/ { \
114139
p=1; \
115140
next; \
116141
} \
@@ -119,19 +144,55 @@ GENERATE_RELOC_TAB := $(AWK) 'BEGIN { \
119144
} \
120145
/^0/ { \
121146
if (p) { \
122-
if ($$3 !~ "^(R_X86_64_PLT32|R_X86_64_PC32|R_AARCH64_.*)$$") { \
123-
print "Unexpected relocation type:\n" $$0 >"/dev/stderr"; \
124-
++bad_relocs; \
125-
} \
126-
printf("0x%s%s", \
127-
gensub("^0*","",1,$$1), \
128-
((++n%8) ? ", " : ",\n ")); \
147+
if ($$3 !~ "^(R_X86_64_PLT32|R_X86_64_PC32|R_AARCH64_.*|R_ARM.*)$$") { \
148+
print "Unexpected relocation type:\n" $$0 >"/dev/stderr"; \
149+
++bad_relocs; \
150+
} \
151+
if ($$5 in section_map) \
152+
section = section_map[$$5]; \
153+
else if ($$5 ~ "^\\.") \
154+
section = $$5; \
155+
else \
156+
section = ""; \
157+
if (section) { \
158+
switch (section) { \
159+
case ".text_wolfcrypt": \
160+
section_tag = 0; \
161+
break; \
162+
case ".rodata_wolfcrypt": \
163+
section_tag = 1; \
164+
break; \
165+
case ".data_wolfcrypt": \
166+
section_tag = 2; \
167+
break; \
168+
case ".bss_wolfcrypt": \
169+
section_tag = 3; \
170+
break; \
171+
default: \
172+
print "Unexpected section:\n" $$0 >"/dev/stderr"; \
173+
++bad_relocs; \
174+
section_tag = 4; \
175+
} \
176+
} else { \
177+
print "Unresolvable symbol reference for relocation:\n" $$0 >"/dev/stderr";\
178+
++bad_relocs; \
179+
section_tag = 4; \
180+
} \
181+
if (strtonum("0x" gensub("^0*","",1,$$1)) >= lshift(1, 29)) { \
182+
print "Relocation offset overflow:" >"/dev/stderr"; \
183+
print >"/dev/stderr"; \
184+
exit(1); \
185+
} \
186+
printf("0x%xU%s", \
187+
or(strtonum("0x" gensub("^0*","",1,$$1)), \
188+
lshift(section_tag, 29)), \
189+
((++n%8) ? ", " : ",\n ")); \
129190
} \
130191
} \
131192
END { \
132193
if (bad_relocs) { \
133-
print "Found " bad_relocs " unexpected relocations." >"/dev/stderr"; \
134-
exit(1); \
194+
print "Found " bad_relocs " unresolvable relocations." >"/dev/stderr"; \
195+
exit(1); \
135196
} \
136197
print "~0U };\nWOLFSSL_LOCAL const unsigned long wc_linuxkm_pie_reloc_tab_length = sizeof wc_linuxkm_pie_reloc_tab / sizeof wc_linuxkm_pie_reloc_tab[0];";\
137198
}'
@@ -140,88 +201,98 @@ ifeq "$(V)" "1"
140201
vflag := --verbose
141202
endif
142203

204+
# This rule is .PHONY because it doesn't actually build the module -- Kbuild
205+
# does, and we always need to call Kbuild to enforce rebuild for dependencies
206+
# and config changes.
143207
.PHONY: libwolfssl.ko
144208
libwolfssl.ko:
145-
@function resolved_link_is_equal() { [[ -L "$$1" && ("$$(readlink -f "$$1")" == "$$(readlink -f "$$2")") ]] }
209+
@set -e
210+
@function resolved_link_is_equal() { [[ -L "$$1" && "$$(readlink -f "$$1")" == "$$(readlink -f "$$2")" ]]; }
146211
@if test -z '$(KERNEL_ROOT)'; then echo '$$KERNEL_ROOT is unset' >&2; exit 1; fi
147212
@if test -z '$(AM_CFLAGS)$(CFLAGS)'; then echo '$$AM_CFLAGS and $$CFLAGS are both unset.' >&2; exit 1; fi
148213
@if test -z '$(src_libwolfssl_la_OBJECTS)'; then echo '$$src_libwolfssl_la_OBJECTS is unset.' >&2; exit 1; fi
149-
# after commit 9a0ebe5011 (6.10), sources must be in $(obj). work around this by making links to all needed sources:
214+
# after commit 9a0ebe5011 (6.10), sources must be in $(obj). work around this by making links to all needed sources:
150215
@mkdir -p '$(MODULE_TOP)/linuxkm'
151216
@resolved_link_is_equal '$(MODULE_TOP)/linuxkm/module_hooks.c' '$(MODULE_TOP)/module_hooks.c' || cp $(vflag) --no-dereference --symbolic-link --no-clobber '$(MODULE_TOP)'/*.[ch] '$(MODULE_TOP)/linuxkm/'
152217
@resolved_link_is_equal '$(MODULE_TOP)/wolfcrypt/src/wc_port.c' '$(SRC_TOP)/wolfcrypt/src/wc_port.c' || cp $(vflag) --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/wolfcrypt' '$(MODULE_TOP)/'
153218
@resolved_link_is_equal '$(MODULE_TOP)/src/wolfio.c' '$(SRC_TOP)/src/wolfio.c' || cp $(vflag) --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/src' '$(MODULE_TOP)/'
154219
ifeq "$(FIPS_OPTEST)" "1"
155-
@resolved_link_is_equal '$(MODULE_TOP)/linuxkm/optest-140-3/linuxkm_optest_wrapper.c' '$(SRC_TOP)/../fips/optest-140-3/linuxkm_optest_wrapper.c' || cp $(vflag) --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/../fips/optest-140-3' '$(MODULE_TOP)/linuxkm'
220+
@resolved_link_is_equal '$(MODULE_TOP)/linuxkm/optest-140-3/linuxkm_optest_wrapper.c' '$(SRC_TOP)/../fips/optest-140-3/linuxkm_optest_wrapper.c' || cp $(vflag) --no-dereference --symbolic-link --no-clobber --recursive '$(SRC_TOP)/../fips/optest-140-3' '$(MODULE_TOP)/linuxkm/'
156221
endif
157222
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
158223
@[[ -f '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c' && ! -L '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c' ]] || \
159224
{ $(RM) -f '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c' && $(GENERATE_RELOC_TAB) < /dev/null > '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c'; }
160-
@$(eval RELOC_TMP := $(shell mktemp "$(MAKE_TMPDIR)/wc_linuxkm_pie_reloc_tab.c.XXXXXX"))
161-
@if [[ -f libwolfssl.ko ]]; then touch -r libwolfssl.ko '$(RELOC_TMP)'; fi
225+
@RELOC_TMP=$$(mktemp "$(MAKE_TMPDIR)/wc_linuxkm_pie_reloc_tab.c.XXXXXX")
226+
@trap 'rm "$$RELOC_TMP"' EXIT
227+
@if [[ -f "$@" ]]; then touch -r "$@" "$$RELOC_TMP"; fi
162228
+$(MAKE) ARCH='$(KERNEL_ARCH)' $(OVERRIDE_PATHS) $(CROSS_COMPILE) -C '$(KERNEL_ROOT)' M='$(MODULE_TOP)' $(KBUILD_EXTRA_FLAGS) CC_FLAGS_FTRACE=
163229
# if the above make didn't build a fresh libwolfssl.ko, then the module is already up to date and we leave it untouched, assuring stability for purposes of module-update-fips-hash.
164-
@if [[ ! libwolfssl.ko -nt '$(RELOC_TMP)' ]]; then rm '$(RELOC_TMP)'; echo ' Module already up-to-date.'; exit 0; fi
165-
@$(READELF) --wide -r libwolfssl.ko | $(GENERATE_RELOC_TAB) >| '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c'
230+
@if [[ ! "$@" -nt "$$RELOC_TMP" ]]; then echo ' Module already up-to-date.'; exit 0; fi
231+
@SECTION_MAP=$$(mktemp)
232+
@trap 'rm "$$SECTION_MAP"' EXIT
233+
@export SECTION_MAP
234+
@$(READELF) --wide --symbols "$@" | $(GENERATE_SECTION_MAP)
235+
@$(READELF) --wide --relocs "$@" | $(GENERATE_RELOC_TAB) >| '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c'
166236
+$(MAKE) ARCH='$(KERNEL_ARCH)' $(OVERRIDE_PATHS) $(CROSS_COMPILE) -C '$(KERNEL_ROOT)' M='$(MODULE_TOP)' $(KBUILD_EXTRA_FLAGS) CC_FLAGS_FTRACE=
167-
@$(READELF) --wide -r libwolfssl.ko | $(GENERATE_RELOC_TAB) >| '$(RELOC_TMP)'
168-
@if diff '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c' '$(RELOC_TMP)'; then echo " Relocation table is stable."; else echo "PIE failed: relocation table is unstable." 1>&2; rm '$(RELOC_TMP)'; exit 1; fi
169-
@rm '$(RELOC_TMP)'
237+
@$(READELF) --wide --relocs "$@" | $(GENERATE_RELOC_TAB) >| "$$RELOC_TMP"
238+
@if diff '$(MODULE_TOP)/linuxkm/wc_linuxkm_pie_reloc_tab.c' "$$RELOC_TMP"; then echo " Relocation table is stable."; else echo "PIE failed: relocation table is unstable." 1>&2; exit 1; fi
170239
else
171240
+$(MAKE) ARCH='$(KERNEL_ARCH)' $(OVERRIDE_PATHS) $(CROSS_COMPILE) -C '$(KERNEL_ROOT)' M='$(MODULE_TOP)' $(KBUILD_EXTRA_FLAGS)
172241
endif
173242

174243
.PHONY: module-update-fips-hash
175244
module-update-fips-hash: libwolfssl.ko
176-
@if test -z '$(FIPS_HASH)'; then echo ' $$FIPS_HASH is unset' >&2; exit 1; fi
245+
@set -e
246+
@if test -z '$(FIPS_HASH)'; then echo ' $$FIPS_HASH is unset' >&2; exit 1; fi
177247
@if [[ ! '$(FIPS_HASH)' =~ [0-9a-fA-F]{64} ]]; then echo ' $$FIPS_HASH is malformed' >&2; exit 1; fi
178-
@readarray -t rodata_segment < <($(READELF) --wide --sections libwolfssl.ko | \
248+
@readarray -t rodata_segment < <($(READELF) --wide --sections "$<" | \
179249
sed -E -n 's/^[[:space:]]*\[[[:space:]]*([0-9]+)\][[:space:]]+\.rodata_wolfcrypt[[:space:]]+PROGBITS[[:space:]]+[0-9a-fA-F]+[[:space:]]+([0-9a-fA-F]+)[[:space:]].*$$/\1\n\2/p'); \
180250
if [[ $${#rodata_segment[@]} != 2 ]]; then echo ' unexpected rodata_segment.' >&2; exit 1; fi; \
181-
readarray -t verifyCore_attrs < <($(READELF) --wide --symbols libwolfssl.ko | \
251+
readarray -t verifyCore_attrs < <($(READELF) --wide --symbols "$<" | \
182252
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'); \
183253
if [[ $${#verifyCore_attrs[@]} != 2 ]]; then echo ' unexpected verifyCore_attrs.' >&2; exit 1; fi; \
184-
if [[ "$${verifyCore_attrs[1]}" != "65" ]]; then echo " verifyCore has unexpected length $${verifyCore_attrs[1]}." >&2; exit 1; fi; \
254+
if [[ "$${verifyCore_attrs[1]}" != "65" ]]; then echo " verifyCore has unexpected length $${verifyCore_attrs[1]}." >&2; exit 1; fi; \
185255
verifyCore_offset=$$((0x$${rodata_segment[1]} + 0x$${verifyCore_attrs[0]})); \
186-
current_verifyCore=$$(dd bs=1 if=libwolfssl.ko skip=$$verifyCore_offset count=64 status=none); \
256+
current_verifyCore=$$(dd bs=1 if="$<" skip=$$verifyCore_offset count=64 status=none); \
187257
if [[ ! "$$current_verifyCore" =~ [0-9a-fA-F]{64} ]]; then echo " verifyCore at offset $$verifyCore_offset has unexpected value." >&2; exit 1; fi; \
188-
if [[ '$(FIPS_HASH)' == "$$current_verifyCore" ]]; then echo ' Supplied FIPS_HASH matches existing verifyCore -- no update needed.'; exit 0; fi; \
189-
echo -n '$(FIPS_HASH)' | dd bs=1 conv=notrunc of=libwolfssl.ko seek=$$verifyCore_offset count=64 status=none && \
190-
echo " FIPS verifyCore updated successfully." && \
258+
if [[ '$(FIPS_HASH)' == "$$current_verifyCore" ]]; then echo ' Supplied FIPS_HASH matches existing verifyCore -- no update needed.'; exit 0; fi; \
259+
echo -n '$(FIPS_HASH)' | dd bs=1 conv=notrunc of="$<" seek=$$verifyCore_offset count=64 status=none && \
260+
echo " FIPS verifyCore updated successfully." && \
191261
if [[ -f libwolfssl.ko.signed ]]; then $(MAKE) -C . libwolfssl.ko.signed; fi
192262

193263
libwolfssl.ko.signed: libwolfssl.ko
194264
ifdef FORCE_NO_MODULE_SIG
195265
@echo 'Skipping module signature operation because FORCE_NO_MODULE_SIG.'
196266
else
197-
@cd '$(KERNEL_ROOT)' || exit $$?; \
198-
while read configline; do \
199-
case "$$configline" in \
200-
CONFIG_MODULE_SIG*=*) \
201-
declare "$${configline%=*}"="$${configline#*=}" \
202-
;; \
203-
esac; \
204-
done < .config || exit $$?; \
205-
if [[ "$${CONFIG_MODULE_SIG}" = "y" && -n "$${CONFIG_MODULE_SIG_KEY}" && \
206-
-n "$${CONFIG_MODULE_SIG_HASH}" && ( ! -f '$(MODULE_TOP)/$@' || \
207-
'$(MODULE_TOP)/$<' -nt '$(MODULE_TOP)/$@' ) ]]; then \
208-
CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY#\"}"; \
209-
CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY%\"}"; \
210-
CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH#\"}"; \
211-
CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH%\"}"; \
212-
cp -p '$(MODULE_TOP)/$<' '$(MODULE_TOP)/$@' || exit $$?; \
213-
./scripts/sign-file "$${CONFIG_MODULE_SIG_HASH}" \
214-
"$${CONFIG_MODULE_SIG_KEY}" \
215-
"$${CONFIG_MODULE_SIG_KEY/%.pem/.x509}" \
216-
'$(MODULE_TOP)/$@'; \
217-
sign_file_exitval=$$?; \
218-
if [[ $$sign_file_exitval != 0 ]]; then \
219-
$(RM) -f '$(MODULE_TOP)/$@'; \
220-
exit $$sign_file_exitval; \
221-
fi; \
222-
if [[ "$(quiet)" != "silent_" ]]; then \
223-
echo " Module $@ signed by $${CONFIG_MODULE_SIG_KEY}."; \
224-
fi \
267+
@set -e
268+
@cd '$(KERNEL_ROOT)'
269+
while read configline; do
270+
case "$$configline" in
271+
CONFIG_MODULE_SIG*=*)
272+
declare "$${configline%=*}"="$${configline#*=}"
273+
;;
274+
esac
275+
done < .config
276+
if [[ "$${CONFIG_MODULE_SIG}" = "y" && -n "$${CONFIG_MODULE_SIG_KEY}" && \
277+
-n "$${CONFIG_MODULE_SIG_HASH}" && ( ! -f '$(MODULE_TOP)/$@' || \
278+
'$(MODULE_TOP)/$<' -nt '$(MODULE_TOP)/$@' ) ]]; then
279+
CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY#\"}"
280+
CONFIG_MODULE_SIG_KEY="$${CONFIG_MODULE_SIG_KEY%\"}"
281+
CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH#\"}"
282+
CONFIG_MODULE_SIG_HASH="$${CONFIG_MODULE_SIG_HASH%\"}"
283+
cp -p '$(MODULE_TOP)/$<' '$(MODULE_TOP)/$@' || exit $$?
284+
./scripts/sign-file "$${CONFIG_MODULE_SIG_HASH}" \
285+
"$${CONFIG_MODULE_SIG_KEY}" \
286+
"$${CONFIG_MODULE_SIG_KEY/%.pem/.x509}" \
287+
'$(MODULE_TOP)/$@'
288+
sign_file_exitval=$$?
289+
if [[ $$sign_file_exitval != 0 ]]; then
290+
$(RM) -f '$(MODULE_TOP)/$@'
291+
exit $$sign_file_exitval
292+
fi
293+
if [[ "$(quiet)" != "silent_" ]]; then
294+
echo " Module $@ signed by $${CONFIG_MODULE_SIG_KEY}."
295+
fi
225296
fi
226297
endif
227298

@@ -234,10 +305,10 @@ install modules_install:
234305
# note, must supply $(MODULE_TOP) as the src value for clean so that Kbuild is included, else
235306
# the top Makefile (which is not for the kernel build) would be included here.
236307
clean:
308+
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(MODULE_TOP) clean
237309
$(RM) -rf '$(MODULE_TOP)/linuxkm'
238310
$(RM) -rf '$(MODULE_TOP)/wolfcrypt'
239311
$(RM) -rf '$(MODULE_TOP)/src'
240-
+$(MAKE) -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(MODULE_TOP) clean
241312

242313
.PHONY: check
243314
check:

linuxkm/linuxkm_wc_port.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@
428428
*/
429429
#ifdef __PIE__
430430
#include <linux/mm_types.h>
431+
#if USE_SPLIT_PMD_PTLOCKS
431432
static __always_inline struct page *pmd_to_page(pmd_t *pmd);
433+
#endif
432434
#endif
433435
#include <linux/mm.h>
434436
#endif
@@ -496,10 +498,21 @@
496498
#endif /* linux ver >= 6.13 */
497499

498500
#if defined(_LINUX_REFCOUNT_H) || defined(_LINUX_REFCOUNT_TYPES_H)
499-
#define WC_LKM_REFCOUNT_TO_INT(refcount) (atomic_read(&(refcount.refs)))
501+
static inline int wc_lkm_refcount_to_int(refcount_t *refcount) {
502+
_Pragma("GCC diagnostic push");
503+
_Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
504+
return atomic_read(&(refcount->refs));
505+
_Pragma("GCC diagnostic pop");
506+
}
500507
#else
501-
#define WC_LKM_REFCOUNT_TO_INT(refcount) (atomic_read(&(refcount)))
508+
static inline int wc_lkm_refcount_to_int(atomic_t *refcount) {
509+
_Pragma("GCC diagnostic push");
510+
_Pragma("GCC diagnostic ignored \"-Wnested-externs\"");
511+
return atomic_read(&refcount);
512+
_Pragma("GCC diagnostic pop");
513+
}
502514
#endif
515+
#define WC_LKM_REFCOUNT_TO_INT(refcount) wc_lkm_refcount_to_int(&(refcount))
503516
#endif /* !__PIE__ */
504517
#endif /* LINUXKM_LKCAPI_REGISTER */
505518

@@ -747,7 +760,7 @@
747760
__wc_bss_start[],
748761
__wc_bss_end[];
749762
extern const unsigned int wc_linuxkm_pie_reloc_tab[];
750-
extern const size_t wc_linuxkm_pie_reloc_tab_length;
763+
extern const unsigned long wc_linuxkm_pie_reloc_tab_length;
751764
extern ssize_t wc_linuxkm_normalize_relocations(
752765
const u8 *text_in,
753766
size_t text_in_len,

0 commit comments

Comments
 (0)