Skip to content

Commit fee7aa2

Browse files
authored
Merge pull request #1401 from eric-ch/module-signing
module-signing: amend build errors and dependency tracking
2 parents ff3f123 + 890bfd9 commit fee7aa2

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

classes/kernel-module-signing.bbclass

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

99
do_configure_append() {
10-
if [ -n "${KERNEL_MODULE_SIG_CERT}" ] &&
11-
grep -q '^CONFIG_MODULE_SIG=y' ${B}/.config ; then
12-
sed -i -e '/CONFIG_MODULE_SIG_KEY[ =]/d' ${B}/.config
13-
echo "CONFIG_MODULE_SIG_KEY=\"${KERNEL_MODULE_SIG_CERT}\"" >> \
14-
${B}/.config
15-
sed -i -e '/CONFIG_MODULE_SIG_ALL[ =]/d' ${B}/.config
16-
echo "# CONFIG_MODULE_SIG_ALL is not set" >> \
17-
${B}/.config
10+
if ! grep -q '^CONFIG_MODULE_SIG=y' ${B}/.config ; then
11+
return
12+
fi
13+
if [ -z "${KERNEL_MODULE_SIG_CERT}" ]; then
14+
bbfatal "Kernel module signing should only be used when setting \
15+
KERNEL_MODULE_SIG_CERT in local.conf."
1816
fi
19-
}
2017

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))
18+
sed -i -e '/CONFIG_MODULE_SIG_KEY[ =]/d' ${B}/.config
19+
echo "CONFIG_MODULE_SIG_KEY=\"${KERNEL_MODULE_SIG_CERT}\"" >> \
20+
${B}/.config
21+
sed -i -e '/CONFIG_MODULE_SIG_ALL[ =]/d' ${B}/.config
22+
echo "# CONFIG_MODULE_SIG_ALL is not set" >> \
23+
${B}/.config
24+
}
2425

25-
do_shared_workdir[file-checksums] = "${@get_signing_key(d)}"
26+
do_configure[file-checksums] += "${@get_signing_cert(d)}"

classes/module-signing.bbclass

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,51 @@ 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. If unset, signing can be done offline.
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() {
24-
if [ -n "${KERNEL_MODULE_SIG_KEY}" ] &&
25-
grep -q '^CONFIG_MODULE_SIG=y' ${STAGING_KERNEL_BUILDDIR}/.config; then
35+
if ! grep -q '^CONFIG_MODULE_SIG=y' "${STAGING_KERNEL_BUILDDIR}/.config"; then
36+
bbnote "Kernel module signing deactivated in kernel configuration ${STAGING_KERNEL_BUILDDIR}/.config."
37+
return
38+
fi
39+
if [ -z "${KERNEL_MODULE_SIG_CERT}" ]; then
40+
bbfatal "Kernel module signing should only be used when setting \
41+
KERNEL_MODULE_SIG_CERT in local.conf."
42+
fi
43+
44+
if [ -n "${KERNEL_MODULE_SIG_KEY}" ]; then
2645
SIG_HASH=$( grep CONFIG_MODULE_SIG_HASH= \
2746
${STAGING_KERNEL_BUILDDIR}/.config | \
2847
cut -d '"' -f 2 )
29-
[ -z "$SIG_HASH" ] && bbfatal CONFIG_MODULE_SIG_HASH is not set in .config
48+
[ -z "$SIG_HASH" ] && bbfatal "CONFIG_MODULE_SIG_HASH is not set in .config"
3049

3150
[ -x "${SIGN_FILE}" ] || bbfatal "Cannot find scripts/sign-file"
3251

3352
find ${D} -name "*.ko" -print0 | \
34-
xargs --no-run-if-empty -0 -n 1 \
53+
xargs -t --no-run-if-empty -0 -n 1 \
3554
${SIGN_FILE} $SIG_HASH ${KERNEL_MODULE_SIG_KEY} \
3655
${KERNEL_MODULE_SIG_CERT}
56+
else
57+
bbnote "Kernel module offline signing enabled, modules still need to be signed."
3758
fi
3859
}
3960

@@ -44,3 +65,6 @@ addtask sign_modules after do_install before do_package
4465
do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
4566
# Explicit keys sign modules in do_sign_modules
4667
do_sign_modules[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
68+
69+
do_sign_modules[depends] += "virtual/kernel:do_shared_workdir"
70+
do_sign_modules[file-checksums] += "${@get_signing_key(d)} ${@get_signing_cert(d)}"

0 commit comments

Comments
 (0)