2017-03-31 15:18:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# extend a TPM PCR with a module and then load it
|
|
|
|
# any arguments will also be measured.
|
|
|
|
# The default PCR to be extended is 5, but can be
|
|
|
|
# overridden with the MODULE_PCR environment variable
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo >&2 "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE="$1"; shift
|
|
|
|
|
|
|
|
if [ -z "$MODULE_PCR" ]; then
|
|
|
|
MODULE_PCR=5
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$MODULE" ]; then
|
|
|
|
die "Usage: $0 module [args...]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -r "$MODULE" ]; then
|
|
|
|
die "$MODULE: not found?"
|
|
|
|
fi
|
|
|
|
|
2017-04-10 21:48:52 +00:00
|
|
|
if [ ! -r /sys/class/tpm/tpm0/pcrs -o ! -x /bin/tpm ]; then
|
|
|
|
tpm_missing=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$tpm_missing" ]; then
|
|
|
|
tpm extend -ix "$MODULE_PCR" -if "$MODULE" \
|
|
|
|
|| die "$MODULE: tpm extend failed"
|
|
|
|
fi
|
2017-03-31 15:18:46 +00:00
|
|
|
|
2017-04-11 10:31:25 +00:00
|
|
|
if [ ! -z "$*" -a -z "$tpm_missing" ]; then
|
2017-03-31 15:18:46 +00:00
|
|
|
TMPFILE=/tmp/insmod.$$
|
|
|
|
echo "$@" > $TMPFILE
|
2017-04-10 21:48:52 +00:00
|
|
|
tpm extend -ix "$MODULE_PCR" -if $TMPFILE \
|
|
|
|
|| die "$MODULE: tpm extend on arguments failed"
|
2017-03-31 15:18:46 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Since we have replaced the real insmod, we must invoke
|
|
|
|
# the busybox insmod via the original executable
|
2017-04-10 21:48:52 +00:00
|
|
|
busybox insmod "$MODULE" "$@" \
|
|
|
|
|| die "$MODULE: insmod failed"
|