Makefile.postlink 1.4 KB

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