| 1 |
|
| 2 | CFLAGS = -Wall
|
| 3 | CFLAGS += -Wno-nonnull
|
| 4 | CFLAGS += $(KHDR_INCLUDES)
|
| 5 |
|
| 6 | LDLIBS += -lcap
|
| 7 |
|
| 8 | ALIGNS := 0x1000 0x200000 0x1000000
|
| 9 | ALIGN_PIES := $(patsubst %,load_address.%,$(ALIGNS))
|
| 10 | ALIGN_STATIC_PIES := $(patsubst %,load_address.static.%,$(ALIGNS))
|
| 11 | ALIGNMENT_TESTS := $(ALIGN_PIES) $(ALIGN_STATIC_PIES)
|
| 12 |
|
| 13 | TEST_PROGS := binfmt_script.py check-exec-tests.sh
|
| 14 | TEST_GEN_PROGS := execveat non-regular $(ALIGNMENT_TESTS)
|
| 15 | TEST_GEN_PROGS_EXTENDED := false inc set-exec script-exec.inc script-noexec.inc
|
| 16 | TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
|
| 17 |
|
| 18 | TEST_FILES := Makefile
|
| 19 |
|
| 20 | TEST_GEN_PROGS += recursion-depth
|
| 21 | TEST_GEN_PROGS += null-argv
|
| 22 | TEST_GEN_PROGS += check-exec
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 | TEST_GEN_PROGS += binfmt_misc_selfpin
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 | TEST_GEN_PROGS += binfmt_misc_interplimit
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 | TEST_GEN_PROGS += binfmt_misc_disabled
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 | TEST_GEN_PROGS += binfmt_misc_transparent
|
| 39 | TEST_GEN_FILES += binfmt_transparent_interp
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 | TEST_GEN_PROGS += binfmt_misc_loader
|
| 46 | TEST_GEN_FILES += binfmt_loader_payload binfmt_loader_payload_static
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 | TEST_GEN_PROGS += binfmt_misc_delim
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 | CLANG ?= clang
|
| 58 | BPFTOOL ?= bpftool
|
| 59 | VMLINUX_BTF ?= /sys/kernel/btf/vmlinux
|
| 60 | HAVE_BPF_TOOLCHAIN ?= $(shell command -v $(CLANG) >/dev/null 2>&1 && \
|
| 61 | command -v $(BPFTOOL) >/dev/null 2>&1 && \
|
| 62 | test -r $(VMLINUX_BTF) && \
|
| 63 | pkg-config --exists libbpf 2>/dev/null && echo y)
|
| 64 | ifeq ($(HAVE_BPF_TOOLCHAIN),y)
|
| 65 | TEST_GEN_PROGS += binfmt_misc_bpf
|
| 66 | TEST_GEN_FILES += bpf_interp.bpf.o nix_origin.bpf.o transparent.bpf.o
|
| 67 | TEST_GEN_FILES += loader.bpf.o interp_bind.bpf.o
|
| 68 | TEST_GEN_FILES += binfmt_bpf_interp binfmt_bpf_app binfmt_bind_interp
|
| 69 | else
|
| 70 | $(info exec selftests: skipping binfmt_misc_bpf, needs clang, bpftool, vmlinux BTF and libbpf)
|
| 71 | endif
|
| 72 |
|
| 73 | EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/xxxxx* \
|
| 74 | $(OUTPUT)/S_I*.test
|
| 75 |
|
| 76 | LOCAL_HDRS += binfmt_misc_common.h
|
| 77 |
|
| 78 | include ../lib.mk
|
| 79 |
|
| 80 | CHECK_EXEC_SAMPLES := $(top_srcdir)/samples/check-exec
|
| 81 |
|
| 82 | $(OUTPUT)/subdir:
|
| 83 | mkdir -p $@
|
| 84 | $(OUTPUT)/script: Makefile
|
| 85 | echo '#!/bin/bash' > $@
|
| 86 | echo 'exit $$*' >> $@
|
| 87 | chmod +x $@
|
| 88 | $(OUTPUT)/execveat.symlink: $(OUTPUT)/execveat
|
| 89 | cd $(OUTPUT) && ln -s -f $(shell basename $<) $(shell basename $@)
|
| 90 | $(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
|
| 91 | cp $< $@
|
| 92 | chmod -x $@
|
| 93 | $(OUTPUT)/load_address.0x%: load_address.c
|
| 94 | $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=$(lastword $(subst ., ,$@)) \
|
| 95 | -fPIE -pie $< -o $@
|
| 96 | $(OUTPUT)/load_address.static.0x%: load_address.c
|
| 97 | $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=$(lastword $(subst ., ,$@)) \
|
| 98 | -fPIE -static-pie $< -o $@
|
| 99 | $(OUTPUT)/false: false.c
|
| 100 | $(CC) $(CFLAGS) $(LDFLAGS) -static $< -o $@
|
| 101 | $(OUTPUT)/inc: $(CHECK_EXEC_SAMPLES)/inc.c
|
| 102 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
| 103 | $(OUTPUT)/set-exec: $(CHECK_EXEC_SAMPLES)/set-exec.c
|
| 104 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
| 105 | $(OUTPUT)/script-exec.inc: $(CHECK_EXEC_SAMPLES)/script-exec.inc
|
| 106 | cp $< $@
|
| 107 | $(OUTPUT)/script-noexec.inc: $(CHECK_EXEC_SAMPLES)/script-noexec.inc
|
| 108 | cp $< $@
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 | $(OUTPUT)/binfmt_misc_selfpin: CFLAGS += $(TOOLS_INCLUDES)
|
| 114 | $(OUTPUT)/binfmt_misc_selfpin: ../filesystems/utils.c
|
| 115 | $(OUTPUT)/binfmt_misc_interplimit: CFLAGS += $(TOOLS_INCLUDES)
|
| 116 | $(OUTPUT)/binfmt_misc_interplimit: ../filesystems/utils.c
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 | BPF_CFLAGS ?= -I$(OUTPUT)
|
| 123 | LIBBPF_CFLAGS ?=
|
| 124 | LIBBPF_LDLIBS ?= -lbpf -lelf -lz
|
| 125 |
|
| 126 | $(OUTPUT)/vmlinux.h:
|
| 127 | $(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
|
| 128 |
|
| 129 |
|
| 130 | $(OUTPUT)/%.bpf.o: %.bpf.c $(OUTPUT)/vmlinux.h
|
| 131 | $(CLANG) -g -O2 -target bpf -mcpu=v3 -DBPF_NO_KFUNC_PROTOTYPES \
|
| 132 | $(BPF_CFLAGS) $(LIBBPF_CFLAGS) -c $< -o $@
|
| 133 |
|
| 134 | $(OUTPUT)/binfmt_misc_bpf: binfmt_misc_bpf.c binfmt_misc_common.h
|
| 135 | $(CC) $(CFLAGS) $(LIBBPF_CFLAGS) $(LDFLAGS) $< $(LIBBPF_LDLIBS) -o $@
|
| 136 |
|
| 137 | $(OUTPUT)/binfmt_bpf_interp: binfmt_bpf_interp.c
|
| 138 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
| 139 |
|
| 140 | $(OUTPUT)/binfmt_bind_interp: binfmt_bind_interp.c
|
| 141 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
| 142 |
|
| 143 | $(OUTPUT)/binfmt_loader_payload: binfmt_loader_payload.c binfmt_misc_common.h
|
| 144 | $(CC) $(CFLAGS) $(LDFLAGS) -fPIE -pie $< -o $@
|
| 145 |
|
| 146 | $(OUTPUT)/binfmt_loader_payload_static: binfmt_loader_payload.c binfmt_misc_common.h
|
| 147 | $(CC) $(CFLAGS) $(LDFLAGS) -static $< -o $@
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 | $(OUTPUT)/binfmt_bpf_app: binfmt_bpf_app.c
|
| 152 | $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--dynamic-linker,'$$ORIGIN/binfmt_bpf_interp' $< -o $@
|
| 153 |
|
| 154 | EXTRA_CLEAN += $(OUTPUT)/vmlinux.h $(OUTPUT)/*.bpf.o
|