Skip to content

Commit 0836ebb

Browse files
author
Eric Chanudet
committed
layer: require out-of-tree signing key for modules
If module signing is enabled and key/cert are provided, add the necessary dependencies between do_configure/do_sign_module to depend on the out-of-tree key/cert. If module signing is disabled, nothing is done, no dependency is added. If module signing is enabled, but key/cert are not provided, error out, this inevitably ends up re-generating a throw-away signing key when out-of-tree modules dependencies are resolved (do_shared_workdir does not store state, including signing keys). Signed-off-by: Eric Chanudet <chanudete@ainfosec.com>
1 parent 39a7b5f commit 0836ebb

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

classes/kernel-module-signing.bbclass

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ SIGN_FILE = "${B}/scripts/sign-file"
77
export KERNEL_MODULE_SIG_CERT
88

99
do_configure_append() {
10+
if [ -z "${KERNEL_MODULE_SIG_CERT}" ] || \
11+
[ -z "${KERNEL_MODULE_SIG_KEY}" ] && \
12+
grep -q '^CONFIG_MODULE_SIG=y' "${B}/.config"; then
13+
bbfatal "Kernel module signing should only be used when setting \
14+
KERNEL_MODULE_SIG_{CERT,KEY} in local.conf."
15+
fi
16+
1017
if [ -n "${KERNEL_MODULE_SIG_CERT}" ] &&
1118
grep -q '^CONFIG_MODULE_SIG=y' ${B}/.config ; then
1219
sed -i -e '/CONFIG_MODULE_SIG_KEY[ =]/d' ${B}/.config
@@ -18,8 +25,4 @@ do_configure_append() {
1825
fi
1926
}
2027

21-
def get_signing_key(d):
22-
path = d.getVar("KERNEL_MODULE_SIG_CERT") or os.path.join(d.getVar("STAGING_KERNEL_BUILDDIR"),"certs","signing_key.x509")
23-
return path + ":" + str(os.path.exists(path))
24-
25-
do_shared_workdir[file-checksums] = "${@get_signing_key(d)}"
28+
do_configure[file-checksums] += "${@get_signing_cert(d)}"

classes/module-signing.bbclass

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,35 @@ INHIBIT_PACKAGE_STRIP = "1"
1010
export HOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS}"
1111

1212
# Set KERNEL_MODULE_SIG_KEY in local.conf to the filepath of a private key
13-
# for signing kernel modules. If unset, signing can be done offline.
13+
# for signing kernel modules.
1414
export KERNEL_MODULE_SIG_KEY
1515
# Set KERNEL_MODULE_SIG_CERT in local.conf to the filepath of the corresponging
16-
# public key to verify the signed modules. If unset, an autogenerated
17-
# build-time keypair will be generated and used for signing and embedding.
16+
# public key to verify the signed modules.
1817
export KERNEL_MODULE_SIG_CERT
1918

19+
def get_signing_cert(d):
20+
path = d.getVar("KERNEL_MODULE_SIG_CERT")
21+
if path:
22+
return path + ":" + str(os.path.exists(path))
23+
return ""
24+
25+
def get_signing_key(d):
26+
path = d.getVar("KERNEL_MODULE_SIG_KEY")
27+
if path:
28+
return path + ":" + str(os.path.exists(path))
29+
return ""
30+
2031
# Kernel builds will override this with ${B}/scripts/sign-file
2132
SIGN_FILE = "${STAGING_KERNEL_BUILDDIR}/scripts/sign-file"
2233

2334
fakeroot do_sign_modules() {
35+
if [ -z "${KERNEL_MODULE_SIG_CERT}" ] || \
36+
[ -z "${KERNEL_MODULE_SIG_KEY}" ] && \
37+
grep -q '^CONFIG_MODULE_SIG=y' "${B}/.config"; then
38+
bbfatal "Kernel module signing should only be used when setting \
39+
KERNEL_MODULE_SIG_{CERT,KEY} in local.conf."
40+
fi
41+
2442
if [ -n "${KERNEL_MODULE_SIG_KEY}" ] &&
2543
grep -q '^CONFIG_MODULE_SIG=y' ${STAGING_KERNEL_BUILDDIR}/.config; then
2644
SIG_HASH=$( grep CONFIG_MODULE_SIG_HASH= \
@@ -44,3 +62,6 @@ addtask sign_modules after do_install before do_package
4462
do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
4563
# Explicit keys sign modules in do_sign_modules
4664
do_sign_modules[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
65+
66+
do_sign_modules[depends] += "virtual/kernel:do_shared_workdir"
67+
do_sign_modules[file-checksums] += "${@get_signing_key(d)} ${@get_signing_cert(d)}"

0 commit comments

Comments
 (0)