zephyr/arch/common/Makefile.kobjects
Andrew Boie 945af95f42 kernel: introduce object validation mechanism
All system calls made from userspace which involve pointers to kernel
objects (including device drivers) will need to have those pointers
validated; userspace should never be able to crash the kernel by passing
it garbage.

The actual validation with _k_object_validate() will be in the system
call receiver code, which doesn't exist yet.

- CONFIG_USERSPACE introduced. We are somewhat far away from having an
  end-to-end implementation, but at least need a Kconfig symbol to
  guard the incoming code with. Formal documentation doesn't exist yet
  either, but will appear later down the road once the implementation is
  mostly finalized.

- In the memory region for RAM, the data section has been moved last,
  past bss and noinit. This ensures that inserting generated tables
  with addresses of kernel objects does not change the addresses of
  those objects (which would make the table invalid)

- The DWARF debug information in the generated ELF binary is parsed to
  fetch the locations of all kernel objects and pass this to gperf to
  create a perfect hash table of their memory addresses.

- The generated gperf code doesn't know that we are exclusively working
  with memory addresses and uses memory inefficently. A post-processing
  script process_gperf.py adjusts the generated code before it is
  compiled to work with pointer values directly and not strings
  containing them.

- _k_object_init() calls inserted into the init functions for the set of
  kernel object types we are going to support so far

Issue: ZEP-2187
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-07 16:33:33 -07:00

57 lines
1.9 KiB
Text

GEN_KOBJ_LIST := $(srctree)/scripts/gen_kobject_list.py
PROCESS_GPERF := $(srctree)/scripts/process_gperf.py
OBJ_LIST := kobject_hash.gperf
OUTPUT_SRC_PRE := kobject_hash_preprocessed.c
OUTPUT_SRC := kobject_hash.c
OUTPUT_OBJ := kobject_hash.o
OUTPUT_OBJ_RENAMED := kobject_hash_renamed.o
SCRIPT_EXTRA_ARGS :=
ifeq ($(KBUILD_VERBOSE),1)
SCRIPT_EXTRA_ARGS += --verbose
endif
# Scan the kernel binary's DWARF information to produce a table of
# kernel objects which we will pass to gperf
quiet_cmd_gen_kobj_list = KOBJ $@
cmd_gen_kobj_list = $(GEN_KOBJ_LIST) --kernel $< --output $@ \
$(SCRIPT_EXTRA_ARGS)
$(OBJ_LIST): $(PREBUILT_KERNEL) $(GEN_KOBJ_LIST)
$(call cmd,gen_kobj_list)
# Generate C code which implements a perfect hashtable based on our
# table of kernel objects
quiet_cmd_gperf = GPERF $@
cmd_gperf = gperf --output-file=$@ $<
$(OUTPUT_SRC_PRE): $(OBJ_LIST)
$(call cmd,gperf)
# For our purposes, the code/data generated by gperf is not optimal.
# This script adjusts the generated .c file to greatly reduce the amount
# of code/data generated since we know we are always working with
# pointer values
quiet_cmd_process_gperf = PROCESS $@
cmd_process_gperf = $(PROCESS_GPERF) -i $< -o $@ $(SCRIPT_EXTRA_ARGS)
$(OUTPUT_SRC): $(OUTPUT_SRC_PRE) $(PROCESS_GPERF)
$(call cmd,process_gperf)
# We need precise control of where generated text/data ends up in the final
# kernel image. Disable function/data sections and use objcopy to move
# generated data into special section names
$(OUTPUT_OBJ): KBUILD_CFLAGS += -fno-function-sections -fno-data-sections
quiet_cmd_kobject_objcopy = OBJCOPY $@
cmd_kobject_objcopy = $(OBJCOPY) \
--rename-section .data=.kobject_data.data \
--rename-section .rodata=.kobject_data.rodata \
--rename-section .text=.kobject_data.text \
$< $@
$(OUTPUT_OBJ_RENAMED): $(OUTPUT_OBJ)
$(call cmd,kobject_objcopy)
GENERATED_KERNEL_OBJECT_FILES += $(OUTPUT_OBJ_RENAMED)