Files
nanoBench/kernel/Makefile
Cathy Zhang e13f0aee33 fix kernel mode crashing in Ubuntu 22.04
While build nanoBench kernel module in Ubuntu 22.04, gcc is with
-mfunction-return=thunk-extern as default option. According to chapter
6.1.1 JMP2RET in the following reference:
https://www.amd.com/system/files/documents/\
technical-guidance-for-mitigating-branch-type-confusion.pdf
all 'ret' instructions are consolidated into a single piece of code.
Instead of functions ending with a 'ret' instruction, they instead end
with "jump __x86_return_thunk".

Since a 'jmp' instruction is provided instead of 'ret' at the end of
each function, it cause functions like create_runtime_code() copy much
more assembler code into runtime_code memory than it should during
runtime. Memory protection fault happens finally while running.

To address the above issue, option -mfunction-return=keep is provided
for kernel mode to overwrite the gcc default behavior in Ubuntu 22.04.
This can ensure function has 'ret' instruction generated.

Signed-off-by: Cathy Zhang <cathy.zhang@intel.com>
2022-12-06 21:48:56 -08:00

28 lines
889 B
Makefile

MODULE_NAME = nb
BUILD_DIR = /lib/modules/$(shell uname -r)/build
HEADERS_EXIST = $(shell if [ -d "${BUILD_DIR}" ]; then echo "${BUILD_DIR}"; \
else echo ""; fi)
ifneq (${HEADERS_EXIST}, ${BUILD_DIR})
$(warning "Check you have linux headers installed")
$(error "${BUILD_DIR} does not exist!")
endif
SRC := nb_km.c ../common/nanoBench.c
$(MODULE_NAME)-objs += $(SRC:.c=.o)
obj-m += $(MODULE_NAME).o
ccflags-y+=-std=gnu99 -Wno-declaration-after-statement -Wno-vla -isystem $(shell $(CC) -print-file-name=include) -mfunction-return=keep
OBJECT_FILES_NON_STANDARD := y
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
rm -f ../common/*.o ../common/*.ur-safe ../common/*.dwo ../common/.nanoBench.*
rm -rf *.o *.ko *.mod *.mod.c *.ur-safe *.dwo .tmp_versions .cache.mk .nb.* .nb_km.* .modules.* .Module.* modules.order Module.symvers