Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/m5/Makefile # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / m5 / Makefile` 144 lines ยท 7319 bytes Raw Blame History 1 # AIENOS M5 encrypted-object envelope and security layer in C: key hierarchy, 2 # keyslots, SecurityManifest, chunked AES-256-GCM-SIV envelopes, commit 3 # records, anti-rollback anchors, migration authorization, deterministic 4 # recovery, owner-signed migration records. Built on ../crypto (in-house 5 # AES-256-GCM-SIV, HMAC-SHA-256), ../sig (in-house Ed25519) and 6 # ../argus/sha256.c. No outside library. Library objects import no heap, 7 # clock or I/O; the tests and the m5_migsig tool use hosted libc. 8 # 9 # make build out/libaienos_m5.a 10 # make test rule tests + corruption matrix + header fuzz + owner-signed 11 # migration tests + m5_migsig tool test (host, not QEMU) 12 # make sanitize the same tests and the tool test under ASan+UBSan (Linux) 13 # make mutants remove each GUARD-tagged rule in turn; tests must fail 14 # make clean 15 16 CC ?= cc 17 AR ?= ar 18 CFLAGS ?= -std=gnu11 -O2 -Wall -Wextra -Werror -fstack-protector-strong 19 OUT ?= out 20 21 SRCS = m5_keys.c m5_envelope.c m5_state.c m5_owner_sig.c 22 CRYPTO_SRCS = ../crypto/aes.c ../crypto/polyval.c ../crypto/gcm_siv.c ../crypto/hmac.c ../crypto/ct.c 23 SIG_SRCS = ../sig/sha512.c ../sig/`ed25519`.c ../sig/ct.c 24 OBJS = $(SRCS:%.c=$(OUT)/%.o) 25 DEP_OBJS = $(CRYPTO_SRCS:../crypto/%.c=$(OUT)/crypto_%.o) $(SIG_SRCS:../sig/%.c=$(OUT)/sig_%.o) $(OUT)/sha256.o 26 LIB = $(OUT)/libaienos_m5.a 27 TEST = $(OUT)/m5_test 28 SIGTEST = $(OUT)/m5_migsig_test 29 TOOL = $(OUT)/m5_migsig 30 HDRS = m5.h m5_internal.h ../crypto/aienos_crypto.h ../crypto/crypto_internal.h ../argus/sha256.h ../sig/aienos_sig.h ../sig/sig_internal.h 31 SANFLAGS = -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all -g 32 33 all: $(LIB) 34 35 $(OUT): 36 mkdir -p $(OUT) 37 38 $(OUT)/%.o: %.c $(HDRS) | $(OUT) 39 $(CC) $(CFLAGS) -c -o $@ $< 40 41 $(OUT)/crypto_%.o: ../crypto/%.c $(HDRS) | $(OUT) 42 $(CC) $(CFLAGS) -c -o $@ $< 43 44 $(OUT)/sig_%.o: ../sig/%.c $(HDRS) | $(OUT) 45 $(CC) $(CFLAGS) -c -o $@ $< 46 47 $(OUT)/sha256.o: ../argus/sha256.c ../argus/sha256.h | $(OUT) 48 $(CC) $(CFLAGS) -c -o $@ ../argus/sha256.c 49 50 $(LIB): $(OBJS) $(DEP_OBJS) 51 rm -f $@ 52 $(AR) rcs $@ $^ 53 54 $(TEST): tests/m5_test.c $(LIB) $(HDRS) 55 $(CC) $(CFLAGS) -o $@ tests/m5_test.c $(LIB) 56 57 $(SIGTEST): tests/m5_migsig_test.c $(LIB) $(HDRS) 58 $(CC) $(CFLAGS) -o $@ tests/m5_migsig_test.c $(LIB) 59 60 $(TOOL): tools/m5_migsig.c $(LIB) $(HDRS) 61 $(CC) $(CFLAGS) -o $@ tools/m5_migsig.c $(LIB) 62 63 # M5_NATIVE: PASS is the last line (the qualification gate marker); the 64 # owner-signed migration verdict AIENOS_M5_MIGRATION_SIG: PASS comes first. 65 test: $(TEST) $(SIGTEST) $(TOOL) lib-checks 66 ./$(SIGTEST) 67 bash tests/m5_migsig_tool_test.sh $(TOOL) $(OUT)/migsig_tool_work 68 ./$(TEST) 69 70 # The library objects must not allocate, read a clock, or do their own I/O. 71 lib-checks: $(OBJS) $(DEP_OBJS) 72 @bad=$$(nm -u $(OBJS) $(DEP_OBJS) | awk 'NF {print $$NF}' | sed 's/^_//' | grep -xE 'malloc|calloc|realloc|free|aligned_alloc|posix_memalign|mmap|clock_gettime|time|gettimeofday|open|openat|read|write|pread|pwrite|fopen|fread|fwrite|printf|fprintf|puts|getrandom|rand|random'); \ 73 if [ -n "$$bad" ]; then echo "lib-checks FAIL: library imports $$bad"; exit 1; fi 74 @echo "lib-checks PASS (no heap, clock or direct I/O in libaienos_m5 objects)" 75 76 sanitize: | $(OUT) 77 ifeq ($(shell uname -s),Linux) 78 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/m5_test_asan tests/m5_test.c $(SRCS) $(CRYPTO_SRCS) $(SIG_SRCS) ../argus/sha256.c 79 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/m5_migsig_test_asan tests/m5_migsig_test.c $(SRCS) $(CRYPTO_SRCS) $(SIG_SRCS) ../argus/sha256.c 80 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/m5_migsig_asan tools/m5_migsig.c $(SRCS) $(CRYPTO_SRCS) $(SIG_SRCS) ../argus/sha256.c 81 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/m5_migsig_test_asan 82 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 bash tests/m5_migsig_tool_test.sh $(OUT)/m5_migsig_asan $(OUT)/migsig_tool_work_asan 83 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/m5_test_asan 84 else 85 @echo "sanitize: Linux only" 86 endif 87 88 # Mutants: delete each GUARD-tagged line (in whichever source holds it) in 89 # turn. The tests must fail (or crash) for every mutant, or that rule is not 90 # tested. A mutant that does not compile counts as a harness failure. Each 91 # mutant runs both test programs; it is killed if either fails. 92 GUARDS = class-in-kdf slot-empty slot-check slot-suite slot-kdf slot-flags secman-mac \ 93 ksm-version ksm-reserved ksm-slot-count ksm-payload-range ksm-unused-empty \ 94 env-len env-mode env-envid env-keygen wipe-all \ 95 commit-mac commit-class commit-objid commit-envid commit-keygen \ 96 anchor-mac anchor-class anchor-missing anchor-store \ 97 rb-storegen rb-keygen rb-counter \ 98 mig-mac mig-class mig-self mig-source mig-dest mig-gen mig-anchor mig-digest mig-replay \ 99 rec-store rec-conflict rec-torn \ 100 osig-envset-order osig-magic osig-version osig-reserved osig-len osig-class osig-keyid osig-sig \ 101 osig-self osig-source osig-dest osig-agent osig-gen osig-format osig-envcount osig-envset \ 102 osig-manifest osig-ownergen osig-replay osig-bind-manifest osig-bind-counter 103 104 M5_MUT_TEST_OBJS = $(OUT)/t_m5_test.o $(OUT)/t_m5_migsig_test.o 105 $(OUT)/t_%_test.o: tests/%_test.c $(HDRS) | $(OUT) 106 $(CC) $(CFLAGS) -Wno-error -I. -c -o $@ $< 107 108 mutants: $(OBJS) $(DEP_OBJS) $(M5_MUT_TEST_OBJS) | $(OUT) 109 @ulimit -c 0; fail=0; \ 110 dups=$$(printf '%s\n' $(GUARDS) | sort | uniq -d); \ 111 [ -z "$$dups" ] || { echo "duplicate guard names (parallel runs would collide):" $$dups; echo "M5_NATIVE_MUTANTS: FAIL"; exit 1; }; \ 112 for g in $(GUARDS); do \ 113 d=$(OUT)/mut_$$g; rm -rf $$d; mkdir -p $$d; \ 114 ( f=$$(grep -l "GUARD:$$g \*/" $(SRCS)); \ 115 if [ $$(echo "$$f" | wc -w) -ne 1 ]; then echo "mutant $$g: guard tag missing or duplicated" > $$d/msg; echo 1 > $$d/fail; exit 0; fi; \ 116 if [ $$(grep -c "GUARD:$$g \*/" $$f) -ne 1 ]; then echo "mutant $$g: guard tag duplicated" > $$d/msg; echo 1 > $$d/fail; exit 0; fi; \ 117 sed "/GUARD:$$g \*\//d" $$f > $$d/$$f; \ 118 others=""; for s in $(SRCS); do [ "$$s" = "$$f" ] || others="$$others $(OUT)/$${s%.c}.o"; done; \ 119 $(CC) $(CFLAGS) -Wno-error -I. -c -o $$d/m.o $$d/$$f 2> $$d/cc.log \ 120 && $(CC) $(CFLAGS) -Wno-error -o $$d/t $(OUT)/t_m5_test.o $$d/m.o $$others $(DEP_OBJS) 2>> $$d/cc.log \ 121 && $(CC) $(CFLAGS) -Wno-error -o $$d/t2 $(OUT)/t_m5_migsig_test.o $$d/m.o $$others $(DEP_OBJS) 2>> $$d/cc.log \ 122 || { echo "mutant $$g: does not compile (FAIL)" > $$d/msg; echo 1 > $$d/fail; exit 0; }; \ 123 case "$$f" in \ 124 m5_owner_sig.c) order="t2 t" ;; \ 125 *) order="t t2" ;; \ 126 esac; \ 127 pass=1; : > $$d/run.log; \ 128 for b in $$order; do ./$$d/$$b >> $$d/run.log 2>&1 || { pass=0; break; }; done; \ 129 if [ $$pass -eq 1 ]; then echo "mutant $$g: SURVIVED (FAIL)" > $$d/msg; echo 1 > $$d/fail; \ 130 else echo "mutant $$g: killed" > $$d/msg; : > $$d/killed; fi \ 131 ) & \ 132 done; \ 133 wait; \ 134 for g in $(GUARDS); do \ 135 d=$(OUT)/mut_$$g; \ 136 if [ -f $$d/msg ]; then cat $$d/msg; else echo "mutant $$g: no result recorded (FAIL)"; fi; \ 137 [ -f $$d/killed ] && [ ! -f $$d/fail ] || fail=1; \ 138 done; \ 139 if [ $$fail -eq 0 ]; then echo "M5_NATIVE_MUTANTS: PASS"; else echo "M5_NATIVE_MUTANTS: FAIL"; exit 1; fi 140 141 clean: 142 rm -rf $(OUT) 143 144 .PHONY: all test lib-checks sanitize mutants clean