From: David Jacobson <davidj@linux.ibm.com>
To: linux-integrity <linux-integrity@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Cc: David Jacobson <david@davidej.com>, Petr Vorel <pvorel@suze.cz>,
David Jacobson <davidj@linux.ibm.com>
Subject: [PATCH 5/7] evmtest: validate boot record
Date: Tue, 14 Aug 2018 14:05:49 -0400 [thread overview]
Message-ID: <20180814180551.28311-5-davidj@linux.ibm.com> (raw)
In-Reply-To: <20180814180551.28311-1-davidj@linux.ibm.com>
The first record in the IMA runtime measurement list is the boot
aggregate - a hash of PCRs 0-7. This test calculates the boot aggregate
based off the PCRs and compares it to IMA's boot aggregate.
Dependencies: a TPM, IBMTSS2.
Signed-off-by: David Jacobson <davidj@linux.ibm.com>
---
evmtest/functions/r_validate_boot_record.sh | 140 ++++++++++++++++++++
1 file changed, 140 insertions(+)
create mode 100755 evmtest/functions/r_validate_boot_record.sh
diff --git a/evmtest/functions/r_validate_boot_record.sh b/evmtest/functions/r_validate_boot_record.sh
new file mode 100755
index 0000000..421cbf1
--- /dev/null
+++ b/evmtest/functions/r_validate_boot_record.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+# Author: David Jacobson <davidj@linux.ibm.com>
+TEST="r_validate_boot_record"
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/.."
+source $ROOT/files/common.sh
+
+TPM_VERSION="2.0" # DEFAULT
+VERBOSE=0
+TSS_DIR=`locate ibmtpm20tss | head -1`
+EVENT_EXTEND=$TSS_DIR/utils12/eventextend
+LD_LIBRARY_PATH=$TSS_DIR/utils:$TSS_DIR/utils12
+MEASUREMENT_FILE=$EVMTEST_SECFS/tpm0/binary_bios_measurements
+# This test validates the eventlog against the hardware PCRs in the TPM, and
+# the boot aggregate against IMA.
+
+usage (){
+ echo "r_validate_boot_record [-hv]"
+ echo ""
+ echo " This test must be run as root"
+ echo ""
+ echo " This test will attempt to validate PCRs 0-7 in the TPM"
+ echo " It will also validate the boot_aggregate based those PCRs"
+ echo " against what IMA has recorded"
+ echo ""
+ echo " -h,--help Display this help message"
+ echo " -v,--verbose Verbose logging"
+}
+
+
+TEMP=`getopt -o 'hv' -l 'help,verbose' -n 'r_validate_boot_record' -- "$@"`
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -h|--help) usage; exit; shift;;
+ -v|--verbose) VERBOSE=1; shift;;
+ --) shift; break;;
+ *) echo "[*] Unrecognized option $1"; exit 1 ;;
+ esac
+done
+
+EVMTEST_require_root
+
+echo "[*] Starting test: $TEST"
+
+v_out "Checking if securityfs is mounted..."
+if [[ -z $EVMTEST_SECFS_EXISTS ]]; then
+ fail "securityfs not found..."
+fi
+
+v_out "Verifying TPM is present..."
+if [[ ! -d $EVMTEST_SECFS/tpm0 ]]; then
+ fail "Could not locate TPM in $EVMTEST_SECFS"
+fi
+
+v_out "TPM found..."
+
+v_out "Checking if system supports reading event log..."
+
+if [[ ! -f $EVMTEST_SECFS/tpm0/binary_bios_measurements ]]; then
+ fail "Kernel does not support reading BIOS measurements,
+ please update to at least 4.16.0"
+fi
+
+
+
+v_out "Verifying TPM Version"
+if [[ -e /sys/class/tpm/tpm0/device/caps ]]; then
+ contains_12=`grep 'TCG version: 1.2' /sys/class/tpm/tpm0/device/caps`
+ if [[ -z $contains12 ]]; then
+ v_out "TPM 1.2"
+ TPM_VERSION="1.2"
+ fi
+else
+ v_out "TPM 2.0"
+fi
+
+v_out "Checking if system supports reading PCRs..."
+
+if [[ ! -d $TSS_DIR ]]; then
+ fail "Could not find TSS2, please install using the package and
+ try again"
+fi
+
+v_out "Grabbing PCR values..."
+pcrs=() # array to store the Hardware PCR values
+sim_pcrs=() # What PCRs should be according to the event log
+halg=$(grep boot_aggregate $EVMTEST_SECFS/ima/ascii_runtime_measurements|\
+ sed -n 's/.*\(sha[^:]*\):.*/\1/p')
+
+for ((i=0; i<=7; i++)); do
+ if [[ $TPM_VERSION == "1.2" ]]; then
+ pcrs[i]=`TPM_INTERFACE_TYPE=dev $TSS_DIR/utils12/pcrread \
+ -ha $i -ns`
+ else
+ pcrs[i]=`TPM_INTERFACE_TYPE=dev $TSS_DIR/utils/pcrread \
+ -ha $i -halg $halg -ns`
+ fi
+done
+
+tss_out=`LD_LIBRARY_PATH=$LD_LIBRARY_PATH $EVENT_EXTEND -if \
+ $MEASUREMENT_FILE -sim -ns`
+for ((y=2; y<=9; y++)); do
+ # Parse TSS output - first strip away PCR, then split on :, then
+ # remove leading whitespace
+ x=`echo $tss_out | awk -v y=$y -F 'PCR' '{print $y}'`
+ x=`echo "$x" | awk -F ":" '{print $2}' | sed -e 's/^[ \t]*//'`
+ index=$((y-2))
+ sim_pcrs[$index]=$x
+done
+
+v_out "Validating PCRs.."
+for ((i=0; i<=7; i++)); do
+ v_out "SIM PCR [$i]: ${sim_pcrs[$i]}"
+ v_out "TPM PCR [$i]: ${pcrs[$i]}"
+ if [[ "${pcrs[$i]}" = "${sim_pcrs[$i]}" ]]; then
+ v_out "PCRs are incorrect..."
+ fail "Mismatch at PCR "$i" "
+ else
+ v_out "PCR $i validated..."
+ fi
+done
+
+
+v_out "Validating Boot Aggregate..."
+tss_boot_agg=`echo $tss_out | awk -F "boot aggregate:" '{print $2}'| tr -d " "`
+ima_boot_agg=`grep boot_aggregate \
+$EVMTEST_SECFS/ima/ascii_runtime_measurements|cut -d ":" -f2|cut -d " " -f1`
+v_out "TSS BOOT AGG: $tss_boot_agg"
+v_out "IMA BOOT AGG: $ima_boot_agg"
+
+if [ "$tss_boot_agg" != "$ima_boot_agg" ]; then
+ fail "Boot Aggregate is inconsistent"
+else
+ v_out "Boot Aggregate validated"
+fi
+
+echo "[*] TEST: PASSED"
+exit 0
--
2.17.1
next prev parent reply other threads:[~2018-08-14 20:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 18:05 [PATCH 1/7] evmtest: Regression testing Integrity Subsystem David Jacobson
2018-08-14 18:05 ` David Jacobson
2018-08-14 18:05 ` [PATCH 2/7] evmtest: test appraisal on policy loading with signature David Jacobson
2018-08-14 18:05 ` [PATCH 3/7] evmtest: test kernel module loading David Jacobson
2018-08-14 18:05 ` [PATCH 4/7] evmtest: test kexec signature policy David Jacobson
2018-08-14 18:05 ` David Jacobson [this message]
2018-08-14 18:05 ` [PATCH 6/7] evmtest: test the preservation of extended attributes David Jacobson
2018-08-14 18:05 ` [PATCH 7/7] emvtest: Add ability to run all tests David Jacobson
2018-08-14 18:29 ` [PATCH 1/7] evmtest: Regression testing Integrity Subsystem James Morris
2018-08-14 18:29 ` James Morris
2018-08-22 11:21 ` Dmitry Kasatkin
2018-08-22 11:21 ` Dmitry Kasatkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180814180551.28311-5-davidj@linux.ibm.com \
--to=davidj@linux.ibm.com \
--cc=david@davidej.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pvorel@suze.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.