Fix module signing with PKCS#11 URIs
Subsystems (3)
v2 cover Fix module signing with PKCS#11 URIs
Hi,
here are two patches to fix kernel module signing when using a key via PKCS#11, including the case where the URI contains semicolons to separate components.
Compared to v1, I've used the change suggested by Masahiro Yamada in the first patch.
Jan Luebbe (2):
certs: Fix build error when PKCS#11 URI contains semicolon
kbuild: modinst: Fix build error when CONFIG_MODULE_SIG_KEY is a
PKCS#11 URI
certs/Makefile | 4 ++-- scripts/Makefile.modinst | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/2 certs: Fix build error when PKCS#11 URI contains semicolon
When CONFIG_MODULE_SIG_KEY is PKCS#11 URI (pkcs11:*) and contains a semicolon, signing_key.x509 fails to build:
certs/extract-cert pkcs11:token=foo;object=bar;pin-value=1111 certs/signing_key.x509
Usage: extract-cert <source> <dest>
Add quotes to the extract-cert argument to avoid splitting by the shell.
This approach was suggested by Masahiro Yamada <[email protected]>.
--- certs/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
certs/Makefile +2 -2
@@ -23,8 +23,8 @@ $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE targets += blacklist_hash_list quiet_cmd_extract_certs = CERT $@ - cmd_extract_certs = $(obj)/extract-cert $(extract-cert-in) $@ -extract-cert-in = $(or $(filter-out $(obj)/extract-cert, $(real-prereqs)),"") + cmd_extract_certs = $(obj)/extract-cert "$(extract-cert-in)" $@ +extract-cert-in = $(filter-out $(obj)/extract-cert, $(real-prereqs)) $(obj)/system_certificates.o: $(obj)/x509_certificate_list
Signature · 1 line
2.30.2
Re: [PATCH v2 1/2] certs: Fix build error when PKCS#11 URI contains semicolon
Quoted 7 lines · Jan Luebbe
When
CONFIG_MODULE_SIG_KEYis PKCS#11 URI (pkcs11:*) and contains a semicolon, signing_key.x509 fails to build:
certs/extract-certpkcs11:token=foo;object=bar;pin-value=1111certs/signing_key.x509
Usage: extract-cert <source> <dest>
Quoted 6 lines
Add quotes to the extract-cert argument to avoid splitting by the shell.
This approach was suggested by Masahiro Yamada <[email protected]>.
Fixes 129ab0d2d9f3 ("kbuild: do not quote string values in include/config/auto.conf")Signed-off-by Jan Luebbe <[email protected]>
Both applied to linux-kbuild/fixes.
Thanks.
Quoted 22 lines
--- certs/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)certs/Makefile +2
-3@@ -23,8 +23,8 @@ $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE targets += blacklist_hash_list quiet_cmd_extract_certs = CERT $@ - cmd_extract_certs = $(obj)/extract-cert $(extract-cert-in) $@ -extract-cert-in = $(or $(filter-out $(obj)/extract-cert, $(real-prereqs)),"") + cmd_extract_certs = $(obj)/extract-cert "$(extract-cert-in)" $@ +extract-cert-in = $(filter-out $(obj)/extract-cert, $(real-prereqs)) $(obj)/system_certificates.o: $(obj)/x509_certificate_list --2.30.2
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v2 2/2 kbuild: modinst: Fix build error when CONFIG_MODULE_SIG_KEY is a PKCS#11 URI
In reply to Jan LuebbeWhen CONFIG_MODULE_SIG_KEY is PKCS#11 URI (pkcs11:*), signing of modules fails:
scripts/sign-file sha256 /.../linux/pkcs11:token=foo;object=bar;pin-value=1111 certs/signing_key.x509 /.../kernel/crypto/tcrypt.ko
Usage: scripts/sign-file [-dp] <hash algo> <key> <x509> <module> [<dest>]
scripts/sign-file -s <raw sig> <hash algo> <x509> <module> [<dest>]
First, we need to avoid adding the $(srctree)/ prefix to the URL.
Second, since the kconfig string values no longer include quotes, we need to add them again when passing a PKCS#11 URI to sign-file. This avoids splitting by the shell if the URI contains semicolons.
--- scripts/Makefile.modinst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/Makefile.modinst +5 -1
@@ -66,9 +66,13 @@ endif # Don't stop modules_install even if we can't sign external modules. # ifeq ($(CONFIG_MODULE_SIG_ALL),y) +ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) +else +sig-key := $(CONFIG_MODULE_SIG_KEY) +endif quiet_cmd_sign = SIGN $@ - cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(sig-key) certs/signing_key.x509 $@ \ + cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \ $(if $(KBUILD_EXTMOD),|| true) else quiet_cmd_sign :=
Signature · 1 line
2.30.2