Skip to content

Commit 07875e9

Browse files
Pingfan LiuKernel Patches Daemon
authored andcommitted
kexec: Integrate bpf light skeleton to load zboot image
All kexec PE bpf prog should align with the interface exposed by the light skeleton four maps: struct bpf_map_desc ringbuf_1; struct bpf_map_desc ringbuf_2; struct bpf_map_desc ringbuf_3; struct bpf_map_desc ringbuf_4; four sections: struct bpf_map_desc rodata; struct bpf_map_desc data; struct bpf_map_desc bss; struct bpf_map_desc rodata_str1_1; two progs: SEC("fentry.s/bpf_handle_pefile") SEC("fentry.s/bpf_post_handle_pefile") With the above presumption, the integration consists of two parts: -1. Call API exposed by light skeleton from kexec -2. The opts_insn[] and opts_data[] are bpf-prog dependent and can be extracted and passed in from the user space. In the kexec_file_load design, a PE file has a .bpf section, which data content is a ELF, and the ELF contains opts_insn[] opts_data[]. As a bonus, BPF bytecode can be placed under the protection of the entire PE signature. (Note, since opts_insn[] contains the information of the ringbuf size, the bpf-prog writer can change its proper size according to the kernel image size without modifying the kernel code) Signed-off-by: Pingfan Liu <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Philipp Rudo <[email protected]> Cc: [email protected] To: [email protected]
1 parent bd79947 commit 07875e9

File tree

4 files changed

+61
-288
lines changed

4 files changed

+61
-288
lines changed

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
142142

143143
CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
144144
CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
145+
CFLAGS_kexec_pe_image.o += -I$(srctree)/tools/lib
145146
obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
146147
KASAN_SANITIZE_kstack_erase.o := n
147148
KCSAN_SANITIZE_kstack_erase.o := n

kernel/kexec_bpf/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ clean:
3939
kexec_pe_parser_bpf.lskel.h: $(OUTPUT)/kexec_pe_parser_bpf.o | $(BPFTOOL)
4040
$(call msg,GEN-SKEL,$@)
4141
$(Q)$(BPFTOOL) gen skeleton -L $< > $@
42+
@# The following sed commands make opts_data[] and opts_insn[] visible in a file instead of only in a function.
43+
@# And it removes the bytecode
44+
$(Q) sed -i '/static const char opts_data\[\].*=/,/";$$/d' $@
45+
$(Q) sed -i '/static const char opts_insn\[\].*=/,/";$$/d' $@
46+
$(Q) sed -i \
47+
-e 's/opts\.data_sz = sizeof(opts_data) - 1;/opts.data_sz = opts_data_sz;/' \
48+
-e 's/opts\.insns_sz = sizeof(opts_insn) - 1;/opts.insns_sz = opts_insn_sz;/' $@
49+
$(Q) sed -i '7i static char *opts_data, *opts_insn;\nstatic unsigned int opts_data_sz, opts_insn_sz;' $@
4250

4351
$(OUTPUT)/vmlinux.h: $(VMLINUX) $(BPFOBJ) | $(OUTPUT)
4452
@$(BPFTOOL) btf dump file $(VMLINUX) format c > $(OUTPUT)/vmlinux.h

0 commit comments

Comments
 (0)