^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # This file is included by the generic Kbuild makefile to permit the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # architecture to perform postlink actions on vmlinux and any .ko module file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # In this case, we only need it for fips140.ko, which needs some postprocessing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # for the integrity check mandated by FIPS. This involves making copies of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # relocation sections so that the module will have access to them at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # initialization time, and calculating and injecting a HMAC digest into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # module. All other targets are NOPs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) PHONY := __archpost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) __archpost:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) -include include/config/auto.conf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) include scripts/Kbuild.include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) CMD_FIPS140_GEN_HMAC = crypto/fips140_gen_hmac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) quiet_cmd_gen_hmac = HMAC $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) cmd_gen_hmac = $(OBJCOPY) $@ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) --dump-section=$(shell $(READELF) -SW $@|grep -Eo '\.rela\.text\S*')=$@.rela.text \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) --dump-section=$(shell $(READELF) -SW $@|grep -Eo '\.rela\.rodata\S*')=$@.rela.rodata \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) --add-section=.init.rela.text=$@.rela.text \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) --add-section=.init.rela.rodata=$@.rela.rodata \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) --set-section-flags=.init.rela.text=alloc,readonly \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) --set-section-flags=.init.rela.rodata=alloc,readonly && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) $(CMD_FIPS140_GEN_HMAC) $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # `@true` prevents complaints when there is nothing to be done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) vmlinux: FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) @true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) $(objtree)/crypto/fips140.ko: FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) $(call cmd,gen_hmac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) %.ko: FORCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) @true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) clean:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) rm -f $(objtree)/crypto/fips140.ko.rela.*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) PHONY += FORCE clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) FORCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .PHONY: $(PHONY)