Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ config ARCH_SELECTS_KEXEC_FILE
def_bool y
depends on KEXEC_FILE
select HAVE_IMA_KEXEC if IMA
select KEXEC_PE_IMAGE

config ARCH_SUPPORTS_KEXEC_SIG
def_bool y
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/include/asm/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct kimage_arch {

#ifdef CONFIG_KEXEC_FILE
extern const struct kexec_file_ops kexec_image_ops;
extern const struct kexec_file_ops kexec_pe_image_ops;

int arch_kimage_file_post_load_cleanup(struct kimage *image);
#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/kernel/machine_kexec_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

const struct kexec_file_ops * const kexec_file_loaders[] = {
&kexec_image_ops,
#ifdef CONFIG_KEXEC_PE_IMAGE
&kexec_pe_image_ops,
#endif
NULL
};

Expand Down
42 changes: 42 additions & 0 deletions include/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3709,4 +3709,46 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
const char **linep, int *nump);
struct bpf_prog *bpf_prog_find_from_stack(void);

enum alloc_type {
TYPE_KALLOC,
TYPE_VMALLOC,
TYPE_VMAP,
};

struct mem_range_result {
struct kref ref;
char *buf;
uint32_t buf_sz;
uint32_t data_sz;
/* kmalloc-ed, vmalloc-ed, or vmap-ed */
enum alloc_type alloc_type;
/* Valid if vmap-ed */
struct page **pages;
unsigned int pg_cnt;
int status;
struct mem_cgroup *memcg;
};

struct mem_range_result *mem_range_result_alloc(void);
void mem_range_result_get(struct mem_range_result *r);
void mem_range_result_put(struct mem_range_result *r);

__bpf_kfunc int bpf_mem_range_result_put(struct mem_range_result *result);
__bpf_kfunc int bpf_copy_to_kernel(const char *name, char *buf, int size);

typedef int (*resource_handler)(const char *name, struct mem_range_result *r);

struct carrier_listener {
struct hlist_node node;
char *name;
resource_handler handler;
/*
* bpf_copy_to_kernel() knows the size in advance, so vmap-ed is not
* supported.
*/
enum alloc_type alloc_type;
};

int register_carrier_listener(struct carrier_listener *listener);
int unregister_carrier_listener(char *str);
#endif /* _LINUX_BPF_H */
7 changes: 7 additions & 0 deletions include/linux/decompress/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ MALLOC_VISIBLE void free(void *where)
#define large_malloc(a) vmalloc(a)
#define large_free(a) vfree(a)

#ifdef CONFIG_KEEP_DECOMPRESSOR
#define INIT
#define INITCONST
#else
#define INIT __init
#define INITCONST __initconst
#endif

#define STATIC

#include <linux/init.h>
Expand Down
10 changes: 10 additions & 0 deletions include/linux/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <uapi/linux/kexec.h>
#include <linux/verification.h>

#if defined(CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY) || defined(CONFIG_KEXEC_PE_IMAGE)
#include <linux/module.h>
#endif

extern note_buf_t __percpu *crash_notes;

#ifdef CONFIG_CRASH_DUMP
Expand Down Expand Up @@ -158,6 +162,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[];

int kexec_image_probe_default(struct kimage *image, void *buf,
unsigned long buf_len);
void *kexec_image_load_default(struct kimage *image);
int kexec_image_post_load_cleanup_default(struct kimage *image);

/*
Expand Down Expand Up @@ -443,6 +448,7 @@ static inline int machine_kexec_post_load(struct kimage *image) { return 0; }

extern struct kimage *kexec_image;
extern struct kimage *kexec_crash_image;
extern const struct kexec_file_ops pe_image_ops;

bool kexec_load_permitted(int kexec_image_type);

Expand Down Expand Up @@ -548,6 +554,10 @@ void set_kexec_sig_enforced(void);
static inline void set_kexec_sig_enforced(void) {}
#endif

#if defined(CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY) || defined(CONFIG_KEXEC_PE_IMAGE)
const Elf_Sym *elf_find_symbol(const Elf_Ehdr *ehdr, const char *name);
#endif

#endif /* !defined(__ASSEBMLY__) */

#endif /* LINUX_KEXEC_H */
9 changes: 9 additions & 0 deletions kernel/Kconfig.kexec
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ config KEXEC_FILE
for kernel and initramfs as opposed to list of segments as
accepted by kexec system call.

config KEXEC_PE_IMAGE
bool "Enable parsing UEFI PE file through kexec file based system call"
select KEEP_DECOMPRESSOR
depends on KEXEC_FILE
depends on DEBUG_INFO_BTF && BPF_SYSCALL
help
This option makes the kexec_file_load() syscall cooperates with bpf-prog
to parse PE format file

config KEXEC_SIG
bool "Verify kernel signature during kexec_file_load() syscall"
depends on ARCH_SUPPORTS_KEXEC_SIG
Expand Down
2 changes: 2 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_core.o
obj-$(CONFIG_CRASH_DM_CRYPT) += crash_dump_dm_crypt.o
obj-$(CONFIG_KEXEC) += kexec.o
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o
obj-$(CONFIG_KEXEC_PE_IMAGE) += kexec_pe_image.o
obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o
obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o
obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
Expand Down Expand Up @@ -141,6 +142,7 @@ obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o

CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
CFLAGS_kexec_pe_image.o += -I$(srctree)/tools/lib
obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
KASAN_SANITIZE_kstack_erase.o := n
KCSAN_SANITIZE_kstack_erase.o := n
Expand Down
3 changes: 3 additions & 0 deletions kernel/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o
ifeq ($(CONFIG_DMA_SHARED_BUFFER),y)
obj-$(CONFIG_BPF_SYSCALL) += dmabuf_iter.o
endif
ifeq ($(CONFIG_KEXEC_PE_IMAGE),y)
obj-$(CONFIG_BPF_SYSCALL) += helpers_carrier.o
endif

CFLAGS_REMOVE_percpu_freelist.o = $(CC_FLAGS_FTRACE)
CFLAGS_REMOVE_bpf_lru_list.o = $(CC_FLAGS_FTRACE)
Expand Down
Loading
Loading