Skip to content

Commit a1ce873

Browse files
committed
eclass/coreos-kernel,sys-kernel/coreos-modules:
Move module signing key to /tmp, so that it stays in RAM. Disable shredding signing key after coreos-modules finishes, but rather shred it after coreos-kernel finishes, so that out of tree modules (like ZFS from upstream portage) can also use the key before it is shreded.
1 parent a1eab3f commit a1ce873

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,36 @@ getconfig() {
136136
echo "${value}"
137137
}
138138

139+
get_sig_key() {
140+
local sig_key="$(getconfig MODULE_SIG_KEY)"
141+
142+
if [ "$sig_key" == "${sig_key#/}" ]
143+
then
144+
echo "build/$sig_key"
145+
else
146+
echo $sig_key
147+
fi
148+
}
149+
139150
# Generate the module signing key for this build.
140151
setup_keys() {
141152
local sig_hash sig_key
142153
sig_hash=$(getconfig MODULE_SIG_HASH)
143-
sig_key="build/$(getconfig MODULE_SIG_KEY)"
154+
sig_key="$(get_sig_key)"
155+
156+
echo "Preparing keys at $sig_key"
144157

145158
if [[ "${sig_key}" == "build/certs/signing_key.pem" ]]; then
146159
die "MODULE_SIG_KEY is using the default value"
147160
fi
148161

162+
if [ "$sig_key" == "${sig_key#/tmp/}" ]
163+
then
164+
die "Refusing to generate the key outside of /tmp, so that it stays in RAM only."
165+
fi
166+
167+
pushd /tmp
168+
149169
mkdir -p certs "${sig_key%/*}" || die
150170

151171
# based on the default config the kernel auto-generates
@@ -174,14 +194,19 @@ setup_keys() {
174194
-keyout certs/modules.key.pem \
175195
|| die "Generating module signing key failed"
176196
cat certs/modules.pub.pem certs/modules.key.pem > "${sig_key}"
197+
cp certs/modules.pub.pem $MODULES_SIGN_CERT
198+
199+
popd
177200
}
178201

179202
# Discard the module signing key but keep public certificate.
180203
shred_keys() {
181204
local sig_key
182-
sig_key="build/$(getconfig MODULE_SIG_KEY)"
183-
shred -u certs/modules.key.pem "${sig_key}" || die
184-
cp certs/modules.pub.pem "${sig_key}" || die
205+
sig_key="$(get_sig_key)"
206+
echo "Shredding the key in $sig_key"
207+
shred -u /tmp/certs/modules.key.pem "${sig_key}" || die
208+
mv /tmp/certs/modules.pub.pem "${sig_key}" || die
209+
rm -f /tmp/certs/modules.cnf
185210
}
186211

187212
# Populate /lib/modules/$(uname -r)/{build,source}

sdk_container/src/third_party/coreos-overlay/profiles/coreos/base/make.defaults

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ CGO_ENABLED=1
124124

125125
# Keep using old binary format for now.
126126
BINPKG_FORMAT=xpak
127+
128+
# move signing key and cert to /tmp so that the ephemeral key is not stored on a disk
129+
MODULES_SIGN_KEY="/tmp/certs/modules.pem"
130+
MODULES_SIGN_CERT="/tmp/certs/modules.pub.pem"
131+
132+
# enable signing kernel modules from portage
133+
USE="${USE} modules-sign"

sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-kernel/coreos-kernel-6.6.75.ebuild

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,24 @@ src_prepare() {
6161
# Pull in the config and public module signing key
6262
KV_OUT_DIR="${SYSROOT%/}/lib/modules/${COREOS_SOURCE_NAME#linux-}/build"
6363
cp -v "${KV_OUT_DIR}/.config" build/ || die
64+
echo cp -v "${KV_OUT_DIR}/.config" build/
65+
66+
# shred_keys needs to have config in place, so that it can read the MODULE_SIG_KEY
67+
shred_keys
6468
local sig_key="$(getconfig MODULE_SIG_KEY)"
65-
mkdir -p "build/${sig_key%/*}" || die
66-
cp -v "${KV_OUT_DIR}/${sig_key}" "build/${sig_key}" || die
69+
70+
if [ "$sig_key" == "${sig_key#/tmp/}" ]
71+
then
72+
die "Refusing to use module key stored outside of /tmp."
73+
fi
74+
75+
# keeping the old logic here for now, unreacheble due to the previous condition
76+
if [ "$sig_key" == "${sig_key#/}" ]
77+
then
78+
# sig_key is a relative path
79+
mkdir -p "build/${sig_key%/*}" || die
80+
cp -v "${KV_OUT_DIR}/${sig_key}" "build/${sig_key}" || die
81+
fi
6782

6883
# Symlink to bootengine.cpio so we can stick with relative paths in .config
6984
ln -sv "${SYSROOT%/}"/usr/share/bootengine/bootengine.cpio build/ || die

sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-modules/coreos-modules-6.6.75.ebuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ src_install() {
5252
rm "${D}/usr/lib/debug/usr/lib/modules/${KV_FULL}/build" || die
5353

5454
# Clean up the build tree
55-
shred_keys
5655
kmake clean
5756
find "build/" -type d -empty -delete || die
5857
rm "build/.config.old" || die

sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-modules/files/commonconfig-6.6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ CONFIG_MMC_SDHCI_PCI=m
459459
CONFIG_MODULES=y
460460
CONFIG_MODULE_COMPRESS_XZ=y
461461
CONFIG_MODULE_SIG=y
462-
CONFIG_MODULE_SIG_KEY="certs/modules.pem"
462+
CONFIG_MODULE_SIG_KEY="/tmp/certs/modules.pem"
463463
CONFIG_MODULE_SIG_SHA256=y
464464
CONFIG_MODULE_UNLOAD=y
465465
CONFIG_MOUSE_PS2=m

0 commit comments

Comments
 (0)