Skip to content

Commit d3be061

Browse files
StollDqzed
authored andcommitted
Add secureboot pre-signing to the kernel
If it detects a secure boot certificate at `keys/MOK.key` and `keys/MOK.cer`, the kernel Makefile will automatically sign the vmlinux / bzImage file that gets generated, and that is then used in packaging. By integrating it into the kernel build system directly, it is fully integrated with targets like `make deb-pkg` (opposed to `make all`, sign, `make bindeb-pkg`) and it gets added to every tree by the same mechanism that is used to apply the other surface patches anyways. Signed-off-by: Dorian Stoll <[email protected]>
1 parent 9bc5c94 commit d3be061

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ signing_key.priv
158158
signing_key.x509
159159
x509.genkey
160160

161+
# Secureboot certificate
162+
/keys/
163+
161164
# Kconfig presets
162165
/all.config
163166
/alldef.config

arch/x86/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ endif
312312
$(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
313313
$(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
314314
$(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
315+
$(Q)$(srctree)/scripts/sign_kernel.sh $(objtree)/arch/$(UTS_MACHINE)/boot/$@
315316

316317
$(BOOT_TARGETS): vmlinux
317318
$(Q)$(MAKE) $(build)=$(boot) $@

scripts/sign_kernel.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# The path to the compiled kernel image is passed as the first argument
5+
BUILDDIR=$(dirname $(dirname $0))
6+
VMLINUX=$1
7+
8+
# Keys are stored in a toplevel directory called keys
9+
# The following files need to be there:
10+
# * MOK.priv (private key)
11+
# * MOK.pem (public key)
12+
#
13+
# If the files don't exist, this script will do nothing.
14+
if [ ! -f "$BUILDDIR/keys/MOK.key" ]; then
15+
exit 0
16+
fi
17+
if [ ! -f "$BUILDDIR/keys/MOK.crt" ]; then
18+
exit 0
19+
fi
20+
21+
# Both required certificates were found. Check if sbsign is installed.
22+
echo "Keys for automatic secureboot signing found."
23+
if [ ! -x "$(command -v sbsign)" ]; then
24+
echo "ERROR: sbsign not found!"
25+
exit -2
26+
fi
27+
28+
# Sign the kernel
29+
sbsign --key $BUILDDIR/keys/MOK.key --cert $BUILDDIR/keys/MOK.crt \
30+
--output $VMLINUX $VMLINUX

0 commit comments

Comments
 (0)