MODSIGN: Automatically generate module signing keys if missing
Subsystems (2)
PATCH 1/1 MODSIGN: Automatically generate module signing keys if missing
Automatically generate keys for module signing if they're absent so that allyesconfig doesn't break. The builder should consider generating their own keyrings, however, so that the keys are appropriately named and any extra keys required get imported.
Also change the names of the keyring files to modsign.pub and modsign.sec so that they are then a more obvious what they're about and add a dependency for the signing rules on the keyring files so that the signatures get regenerated if the keyrings change.
Signed-off-by David Howells <[email protected]>
---
Documentation/module-signing.txt | 16 +++++++------ kernel/Makefile | 46 +++++++++++++++++++++++++++++++++++++- kernel/modsign-pubkey.c | 4 ++- scripts/Makefile.modpost | 8 ++++--- 4 files changed, 60 insertions(+), 14 deletions(-)
Documentation/module-signing.txt +8 -8
@@ -28,16 +28,16 @@ SUPPLYING PUBLIC KEYS A set of public keys must be supplied at kernel image build time. This is done by taking a GPG public key file and placing it in the base of the kernel -directory in a file called kernel.pub. +directory in a file called modsign.pub. For example, a throwaway key could be generated automatically by something like the following: cat >genkey <<EOF - %pubring kernel.pub - %secring kernel.sec - Key-Type: DSA - Key-Length: 512 + %pubring modsign.pub + %secring modsign.sec + Key-Type: RSA + Key-Length: 4096 Name-Real: A. N. Other Name-Comment: Kernel Module GPG key %commit
@@ -53,7 +53,7 @@ in the background. Note that no GPG password is used in the above scriptlet. -The kernel.pub file is compiled into the kernel directly by the assembler by +The modsign.pub file is compiled into the kernel directly by the assembler by means of an ".incbin" directive in kernel/modsign-pubkey.c. Once the kernel is running, the keys are visible to root as kernel crypto keys
@@ -98,12 +98,12 @@ include the following options: (*) MODSECKEY=<secret-key-ring-path> This indicates the whereabouts of the GPG keyring that is the source of - the secret key to be used. The default is "./kernel.sec". + the secret key to be used. The default is "./modsign.sec". (*) MODPUBKEY=<public-key-ring-path> This indicates the whereabouts of the GPG keyring that is the source of - the public key to be used. The default is "./kernel.pub". + the public key to be used. The default is "./modsign.pub". (*) MODKEYNAME=<key-name>
kernel/Makefile +45 -1
55 lines not on this page · raw message
kernel/modsign-pubkey.c +2 -2
@@ -17,13 +17,13 @@ extern __initdata const u8 modsign_public_keys[];extern __initdata const u8 modsign_public_keys_end[]; asm(".section .init.data,\"aw\"\n" "modsign_public_keys:\n" -".incbin \"kernel.pub\"\n" +".incbin \"modsign.pub\"\n" "modsign_public_keys_end:" );/* * We need to make sure ccache doesn't cache the .o file as it doesn't notice -* if kernel.pub changes. +* if modsign.pub changes. */ static __initdata const char annoy_ccache[] = __TIME__"foo" ;
scripts/Makefile.modpost +5 -3
@@ -143,8 +143,8 @@ $(modules:.ko=.ko.unsigned): %.ko.unsigned :%.o %.mod.o FORCE targets += $(modules:.ko=.ko.unsigned) # Step 7), sign the modules -MODSECKEY = ./kernel.sec -MODPUBKEY = ./kernel.pub +MODSECKEY = ./modsign.sec +MODPUBKEY = ./modsign.pub KEYFLAGS = --no-default-keyring --secret-keyring $(MODSECKEY) --keyring $(MODPUBKEY) --no-default-keyring --homedir . --no-options --no-auto-check-trustdb --no-permission-warning ifdef CONFIG_MODULE_SIG_SHA1
@@ -190,6 +190,7 @@ SIGN_MODULES := 0 endif ifeq ($(SIGN_MODULES),1) +KEYRING_DEP := modsign.sec modsign.pub quiet_cmd_sign_ko_ko_unsigned = SIGN [M] $@ cmd_sign_ko_ko_unsigned = \ scripts/mod/mod-extract $< [email protected] && \
@@ -199,12 +200,13 @@ quiet_cmd_sign_ko_ko_unsigned = SIGN [M] $@ $(CC) -x assembler-with-cpp $(c_flags) $(CFLAGS_MODULE) -c -o [email protected] - && \ $(LD) -r $(LDFLAGS) -o $@ $< [email protected] else +KEYRING_DEP := quiet_cmd_sign_ko_ko_unsigned = NO SIGN [M] $@ cmd_sign_ko_ko_unsigned = \ cp $< $@ endif -$(modules): %.ko :%.ko.unsigned FORCE +$(modules): %.ko :%.ko.unsigned $(KEYRING_DEP) FORCE $(call if_changed,sign_ko_ko_unsigned) targets += $(modules)