diff options
Diffstat (limited to 'kernel/Makefile')
| -rw-r--r-- | kernel/Makefile | 112 |
1 files changed, 79 insertions, 33 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 43c4c920f30a..65ef3846fbe8 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -114,46 +114,74 @@ $(obj)/config_data.h: $(obj)/config_data.gz FORCE | |||
| 114 | 114 | ||
| 115 | ############################################################################### | 115 | ############################################################################### |
| 116 | # | 116 | # |
| 117 | # Roll all the X.509 certificates that we can find together and pull them into | 117 | # When a Kconfig string contains a filename, it is suitable for |
| 118 | # the kernel so that they get loaded into the system trusted keyring during | 118 | # passing to shell commands. It is surrounded by double-quotes, and |
| 119 | # boot. | 119 | # any double-quotes or backslashes within it are escaped by |
| 120 | # backslashes. | ||
| 120 | # | 121 | # |
| 121 | # We look in the source root and the build root for all files whose name ends | 122 | # This is no use for dependencies or $(wildcard). We need to strip the |
| 122 | # in ".x509". Unfortunately, this will generate duplicate filenames, so we | 123 | # surrounding quotes and the escaping from quotes and backslashes, and |
| 123 | # have make canonicalise the pathnames and then sort them to discard the | 124 | # we *do* need to escape any spaces in the string. So, for example: |
| 124 | # duplicates. | 125 | # |
| 126 | # Usage: $(eval $(call config_filename,FOO)) | ||
| 127 | # | ||
| 128 | # Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, | ||
| 129 | # transformed as described above to be suitable for use within the | ||
| 130 | # makefile. | ||
| 131 | # | ||
| 132 | # Also, if the filename is a relative filename and exists in the source | ||
| 133 | # tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to | ||
| 134 | # be prefixed to *both* command invocation and dependencies. | ||
| 135 | # | ||
| 136 | # Note: We also print the filenames in the quiet_cmd_foo text, and | ||
| 137 | # perhaps ought to have a version specially escaped for that purpose. | ||
| 138 | # But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good | ||
| 139 | # enough. It'll strip the quotes in the common case where there's no | ||
| 140 | # space and it's a simple filename, and it'll retain the quotes when | ||
| 141 | # there's a space. There are some esoteric cases in which it'll print | ||
| 142 | # the wrong thing, but we don't really care. The actual dependencies | ||
| 143 | # and commands *do* get it right, with various combinations of single | ||
| 144 | # and double quotes, backslashes and spaces in the filenames. | ||
| 125 | # | 145 | # |
| 126 | ############################################################################### | 146 | ############################################################################### |
| 127 | ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) | 147 | # |
| 128 | X509_CERTIFICATES-y := $(wildcard *.x509) $(wildcard $(srctree)/*.x509) | 148 | quote := $(firstword " ") |
| 129 | X509_CERTIFICATES-$(CONFIG_MODULE_SIG) += $(objtree)/signing_key.x509 | 149 | space := |
| 130 | X509_CERTIFICATES-raw := $(sort $(foreach CERT,$(X509_CERTIFICATES-y), \ | 150 | space += |
| 131 | $(or $(realpath $(CERT)),$(CERT)))) | 151 | space_escape := %%%SPACE%%% |
| 132 | X509_CERTIFICATES := $(subst $(realpath $(objtree))/,,$(X509_CERTIFICATES-raw)) | 152 | # |
| 133 | 153 | define config_filename | |
| 134 | ifeq ($(X509_CERTIFICATES),) | 154 | ifneq ($$(CONFIG_$(1)),"") |
| 135 | $(warning *** No X.509 certificates found ***) | 155 | $(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) |
| 156 | ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) | ||
| 157 | else | ||
| 158 | ifeq ($$(wildcard $$($(1)_FILENAME)),) | ||
| 159 | ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) | ||
| 160 | $(1)_SRCPREFIX := $(srctree)/ | ||
| 136 | endif | 161 | endif |
| 137 | |||
| 138 | ifneq ($(wildcard $(obj)/.x509.list),) | ||
| 139 | ifneq ($(shell cat $(obj)/.x509.list),$(X509_CERTIFICATES)) | ||
| 140 | $(warning X.509 certificate list changed to "$(X509_CERTIFICATES)" from "$(shell cat $(obj)/.x509.list)") | ||
| 141 | $(shell rm $(obj)/.x509.list) | ||
| 142 | endif | 162 | endif |
| 143 | endif | 163 | endif |
| 164 | endif | ||
| 165 | endef | ||
| 166 | # | ||
| 167 | ############################################################################### | ||
| 168 | |||
| 169 | ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) | ||
| 144 | 170 | ||
| 145 | kernel/system_certificates.o: $(obj)/x509_certificate_list | 171 | $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS)) |
| 146 | 172 | ||
| 147 | quiet_cmd_x509certs = CERTS $@ | 173 | # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871) |
| 148 | cmd_x509certs = cat $(X509_CERTIFICATES) /dev/null >$@ $(foreach X509,$(X509_CERTIFICATES),; $(kecho) " - Including cert $(X509)") | 174 | $(obj)/system_certificates.o: $(obj)/x509_certificate_list |
| 149 | 175 | ||
| 150 | targets += $(obj)/x509_certificate_list | 176 | # Cope with signing_key.x509 existing in $(srctree) not $(objtree) |
| 151 | $(obj)/x509_certificate_list: $(X509_CERTIFICATES) $(obj)/.x509.list | 177 | AFLAGS_system_certificates.o := -I$(srctree) |
| 152 | $(call if_changed,x509certs) | ||
| 153 | 178 | ||
| 154 | targets += $(obj)/.x509.list | 179 | quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) |
| 155 | $(obj)/.x509.list: | 180 | cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1) |
| 156 | @echo $(X509_CERTIFICATES) >$@ | 181 | |
| 182 | targets += x509_certificate_list | ||
| 183 | $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE | ||
| 184 | $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) | ||
| 157 | endif | 185 | endif |
| 158 | 186 | ||
| 159 | clean-files := x509_certificate_list .x509.list | 187 | clean-files := x509_certificate_list .x509.list |
| @@ -170,7 +198,11 @@ ifndef CONFIG_MODULE_SIG_HASH | |||
| 170 | $(error Could not determine digest type to use from kernel config) | 198 | $(error Could not determine digest type to use from kernel config) |
| 171 | endif | 199 | endif |
| 172 | 200 | ||
| 173 | signing_key.priv signing_key.x509: x509.genkey | 201 | # We do it this way rather than having a boolean option for enabling an |
| 202 | # external private key, because 'make randconfig' might enable such a | ||
| 203 | # boolean option and we unfortunately can't make it depend on !RANDCONFIG. | ||
| 204 | ifeq ($(CONFIG_MODULE_SIG_KEY),"signing_key.pem") | ||
| 205 | signing_key.pem: x509.genkey | ||
| 174 | @echo "###" | 206 | @echo "###" |
| 175 | @echo "### Now generating an X.509 key pair to be used for signing modules." | 207 | @echo "### Now generating an X.509 key pair to be used for signing modules." |
| 176 | @echo "###" | 208 | @echo "###" |
| @@ -181,8 +213,8 @@ signing_key.priv signing_key.x509: x509.genkey | |||
| 181 | @echo "###" | 213 | @echo "###" |
| 182 | openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ | 214 | openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ |
| 183 | -batch -x509 -config x509.genkey \ | 215 | -batch -x509 -config x509.genkey \ |
| 184 | -outform DER -out signing_key.x509 \ | 216 | -outform PEM -out signing_key.pem \ |
| 185 | -keyout signing_key.priv 2>&1 | 217 | -keyout signing_key.pem 2>&1 |
| 186 | @echo "###" | 218 | @echo "###" |
| 187 | @echo "### Key pair generated." | 219 | @echo "### Key pair generated." |
| 188 | @echo "###" | 220 | @echo "###" |
| @@ -207,3 +239,17 @@ x509.genkey: | |||
| 207 | @echo >>x509.genkey "subjectKeyIdentifier=hash" | 239 | @echo >>x509.genkey "subjectKeyIdentifier=hash" |
| 208 | @echo >>x509.genkey "authorityKeyIdentifier=keyid" | 240 | @echo >>x509.genkey "authorityKeyIdentifier=keyid" |
| 209 | endif | 241 | endif |
| 242 | |||
| 243 | $(eval $(call config_filename,MODULE_SIG_KEY)) | ||
| 244 | |||
| 245 | # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it | ||
| 246 | ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) | ||
| 247 | X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) | ||
| 248 | endif | ||
| 249 | |||
| 250 | # GCC PR#66871 again. | ||
| 251 | $(obj)/system_certificates.o: signing_key.x509 | ||
| 252 | |||
| 253 | signing_key.x509: scripts/extract-cert include/config/module/sig/key.h $(X509_DEP) | ||
| 254 | $(call cmd,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) | ||
| 255 | endif | ||
