Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1015129imc; Mon, 11 Mar 2019 04:45:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzX0kzn0J5uk6WW4LalRdXy7fXPPOrgQClq3HgZWM8VQ7qr5UulyeDtQma3pJ/GzCA+gb32 X-Received: by 2002:a63:145b:: with SMTP id 27mr29068209pgu.74.1552304704797; Mon, 11 Mar 2019 04:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552304704; cv=none; d=google.com; s=arc-20160816; b=JYyJYarqxem9qGO3r0ZgxY1wiAJir+H5vP3YO2LLtrQNl1mSBirQGOl3FZgkBZyKl8 NZydM8vQS4y9SQGMukHxpzG9XQbB8g46OGcGRqa5dnmP3/z3s8sLqFyLGglWrpm7FPxM CnoAQuEi0SPgYiLkIE+M9J2ZhyV7xS93dCL6ZKqCYDWn4LX9GIKB0GGOpgFm7uwwRWXw DTE7La9EbYD3lhvs1Snli78rx6ODdJT/WuuM+7/ZL9zDA2ruDVyZFG2wuKcRShzlz6S0 YcSDqGrlPWhLz6k73aQbF9c5lJIe0OQpCNhKCYv3CNJ39dPBLygP1+1m/Km4gN4neaAZ uCkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=jSqAq9/F9zzVO2lARJ/2TXMN5CR5bIdemL6wPJxgFWk=; b=KmeCR0s014WG/cQY+nYDxnPV8QH5XqqAvf/IgYPPFoRMDMYjxGD4WNx8/yVpTRdJ4e qBeqV47W9Y+zqYoCuygnjrPPWrY/kB74Hc1obiJ5o4TYCrsxL2O/6FG+RsyxY8HnIyqF Mx4i/6tmB+fP40+bjkF46NHel/jL7kWfs/SKHD506AIgKR0twmgh/i+QUAk82jX2oOvk B4KQcB30uYbjrTMCpxKw67hXrg0NtyePVVMhNMz5DhCQWCXVjbUxjpiyI4KSvIN5bWDA sMxg3xUrxUtOg4bJRtoSpdqqsR6bD0wZNUUebENViNBzdPda+dzrzVb79jUFz8YsCQL+ CU0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si4848571pfb.189.2019.03.11.04.44.49; Mon, 11 Mar 2019 04:45:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727436AbfCKLmA (ORCPT + 99 others); Mon, 11 Mar 2019 07:42:00 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49010 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727408AbfCKLl7 (ORCPT ); Mon, 11 Mar 2019 07:41:59 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2BBev1E121921 for ; Mon, 11 Mar 2019 07:41:58 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r5mycwj87-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 11 Mar 2019 07:41:58 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Mar 2019 11:41:55 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 11 Mar 2019 11:41:53 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2BBfqq954395092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 11 Mar 2019 11:41:52 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BB6F11C05C; Mon, 11 Mar 2019 11:41:52 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A2A411C04A; Mon, 11 Mar 2019 11:41:51 +0000 (GMT) Received: from localhost.ibm.com (unknown [9.80.93.170]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 11 Mar 2019 11:41:51 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Petr Vorel , Dave Young , Matthew Garrett , Mimi Zohar Subject: [PATCH v3 2/7] selftests/ima: define a set of common functions Date: Mon, 11 Mar 2019 07:41:08 -0400 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1552304473-3966-1-git-send-email-zohar@linux.ibm.com> References: <1552304473-3966-1-git-send-email-zohar@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19031111-0028-0000-0000-00000352A2FE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031111-0029-0000-0000-000024112114 Message-Id: <1552304473-3966-3-git-send-email-zohar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-11_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=895 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903110088 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define, update and move get_secureboot_mode() to a common file for use by other tests. Updated to check both the efivar SecureBoot-$(UUID) and SetupMode-$(UUID), based on Dave Young's review. Signed-off-by: Mimi Zohar Reviewed-by: Petr Vorel Cc: Dave Young --- tools/testing/selftests/ima/Makefile | 1 + tools/testing/selftests/ima/ima_common_lib.sh | 36 ++++++++++++++++++++++++++ tools/testing/selftests/ima/test_kexec_load.sh | 17 +++--------- 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100755 tools/testing/selftests/ima/ima_common_lib.sh diff --git a/tools/testing/selftests/ima/Makefile b/tools/testing/selftests/ima/Makefile index 0b3adf5444b6..04501516831b 100644 --- a/tools/testing/selftests/ima/Makefile +++ b/tools/testing/selftests/ima/Makefile @@ -5,6 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) ifeq ($(ARCH),x86) TEST_PROGS := test_kexec_load.sh +TEST_FILES := ima_common_lib.sh include ../lib.mk diff --git a/tools/testing/selftests/ima/ima_common_lib.sh b/tools/testing/selftests/ima/ima_common_lib.sh new file mode 100755 index 000000000000..403666247b10 --- /dev/null +++ b/tools/testing/selftests/ima/ima_common_lib.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +# Check efivar SecureBoot-$(the UUID) and SetupMode-$(the UUID). +# The secure boot mode can be accessed either as the last integer +# of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from +# "od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data". The efi +# SetupMode can be similarly accessed. +# Return 1 for SecureBoot mode enabled and SetupMode mode disabled. +get_secureboot_mode() +{ + local efivarfs="/sys/firmware/efi/efivars" + local secure_boot_file=$efivarfs/../vars/SecureBoot-*/data + local setup_mode_file=$efivarfs/../vars/SetupMode-*/data + local secureboot_mode=0 + local setup_mode=0 + + # Make sure that efivars is mounted in the normal location + if ! grep -q "^\S\+ $efivarfs efivarfs" /proc/mounts; then + log_skip "efivars is not mounted on $efivarfs" + fi + + if [ ! -e $secure_boot_file ] || [ ! -e $setup_mode_file ]; then + log_skip "unknown secureboot/setup mode" + fi + + secureboot_mode=`od -An -t u1 $secure_boot_file` + setup_mode=`od -An -t u1 $setup_mode_file` + + if [ $secureboot_mode -eq 1 ] && [ $setup_mode -eq 0 ]; then + log_info "ima: secure boot mode enabled" + return 1; + fi + log_info "secure boot mode not enabled" + return 0; +} diff --git a/tools/testing/selftests/ima/test_kexec_load.sh b/tools/testing/selftests/ima/test_kexec_load.sh index 36f3089ac225..e84139c1506b 100755 --- a/tools/testing/selftests/ima/test_kexec_load.sh +++ b/tools/testing/selftests/ima/test_kexec_load.sh @@ -5,7 +5,7 @@ # is booted in secureboot mode. TEST="$0" -EFIVARFS="/sys/firmware/efi/efivars" +. ./ima_common_lib.sh rc=0 # Kselftest framework requirement - SKIP code is 4. @@ -17,19 +17,8 @@ if [ $(id -ru) -ne 0 ]; then exit $ksft_skip fi -# Make sure that efivars is mounted in the normal location -if ! grep -q "^\S\+ $EFIVARFS efivarfs" /proc/mounts; then - echo "$TEST: efivars is not mounted on $EFIVARFS" >&2 - exit $ksft_skip -fi - -# Get secureboot mode -file="$EFIVARFS/SecureBoot-*" -if [ ! -e $file ]; then - echo "$TEST: unknown secureboot mode" >&2 - exit $ksft_skip -fi -secureboot=`hexdump $file | awk '{print substr($4,length($4),1)}'` +get_secureboot_mode +secureboot=$? # kexec_load should fail in secure boot mode KERNEL_IMAGE="/boot/vmlinuz-`uname -r`" -- 2.7.5