Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1225141img; Tue, 26 Feb 2019 17:03:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9GWioy0d+txir7j08bLSTMeHCrRI4OI1RMgzOaLlGrSWV+Rp0fDqy2qmKyz9Zv7iY054I X-Received: by 2002:a63:2f47:: with SMTP id v68mr318963pgv.144.1551229419376; Tue, 26 Feb 2019 17:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551229419; cv=none; d=google.com; s=arc-20160816; b=0mRs9O7C28mnFqiktgd2JqkWOWeWuSoEIcHjA+RDdvCceLZa8oryKjkpQzpmd5BxAD v3YlkiBVE8naIETQ627c1sL8VICo+7onoexAxk6yTg2hcXXkM1Si8UpUh4wmnmEg6H2e 91Cdv8393gGfjYygnxQVM1RIhFnqmFwBmBks2YJlOSQ3wJ97naBMZGDmzKHd1I/tvxzg BvySUmlWg51csRgazFGMHgT2GFDDymbGKzCiEHSzaBErsr9zqHEhihnrJuj2+734ek/Z xKjOta4Q1l93DTH0XgrX4voOi+KL7ojIkj/U86w1biYGh7xRCUf6VQVcteCBj86cD3oX VFag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=njyHYF0YQ9fnKXwMLmHFFgqyKpr8jRFr487+cgdriD0=; b=iVs4M6m9bmYQcBd3RiwiZVa/e78p1uFI0zKj+Gk48sRv869GKK3ShThQKAIgNYXwUf 8O2NNDAF0pF+qHA/bh1LPRR2DCF655n6/6R5KeY90qwccSVJgIL5ENKdR02oOrc62jOz gyFSk/o42rCNzVLjvtZqTxNO85AxDdYrY6iyEtg9Og2HT7dr6GIwHcXUADuHhGpDvkuz s+y7jDIBZIdD5OOi3cP10gCJXxgjGtsJu0IPZA5HklB/8mlX87xk7Lr6UeSEoPdSBmH6 g0eSduaLRo3coMx/Gh2se6mZym+23cDl8aZpbojXevMeHPwMXpcq3J3LitXOjnbeEMhS W2ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pHjjIxWa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t24si12760163pgv.141.2019.02.26.17.03.24; Tue, 26 Feb 2019 17:03:39 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=pHjjIxWa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729246AbfB0BBt (ORCPT + 99 others); Tue, 26 Feb 2019 20:01:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:56854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727998AbfB0BBt (ORCPT ); Tue, 26 Feb 2019 20:01:49 -0500 Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 38022218CD; Wed, 27 Feb 2019 01:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551229308; bh=6zA+U4WOwsKcG0AZ/lDOgTEZ/bXk9KzQYompDCTL+d0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=pHjjIxWaR0/GkD7Ui0KebQ/4OJrGxL3DkZ5wEpx1y3bJcx3xjvlphwAapu3niYvIu L5eAha+v2Mp6lVLiCFDbXIewbB++45KILB+bYb9NL5mVRRO3r8ucsjHgG5Jjlin1jD cANIbB4Onp/d+xG20xYl2yKbnN9FL2dzXFrsRRRw= Subject: Re: [PATCH v2 2/5] selftests/ima: define a set of common functions To: Mimi Zohar , linux-kselftest@vger.kernel.org Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, shuah References: <1551223620-11586-1-git-send-email-zohar@linux.ibm.com> <1551223620-11586-3-git-send-email-zohar@linux.ibm.com> From: shuah Message-ID: Date: Tue, 26 Feb 2019 18:01:47 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1551223620-11586-3-git-send-email-zohar@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/26/19 4:26 PM, Mimi Zohar wrote: > Define, update and move get_secureboot_mode() to a common file for use > by other tests. > > Signed-off-by: Mimi Zohar > Reviewed-by: Petr Vorel > --- > tools/testing/selftests/ima/Makefile | 1 + > tools/testing/selftests/ima/common_lib.sh | 24 ++++++++++++++++++++++++ > tools/testing/selftests/ima/test_kexec_load.sh | 17 +++-------------- > 3 files changed, 28 insertions(+), 14 deletions(-) > create mode 100755 tools/testing/selftests/ima/common_lib.sh > > diff --git a/tools/testing/selftests/ima/Makefile b/tools/testing/selftests/ima/Makefile > index 0b3adf5444b6..46b9e04d2737 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 := common_lib.sh > > include ../lib.mk > > diff --git a/tools/testing/selftests/ima/common_lib.sh b/tools/testing/selftests/ima/common_lib.sh > new file mode 100755 > index 000000000000..5583ea74c14e > --- /dev/null > +++ b/tools/testing/selftests/ima/common_lib.sh > @@ -0,0 +1,24 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0 > + > +# 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". > +# Return 1 for SecureBoot mode enabled. > +get_secureboot_mode() > +{ > + local efivarfs="/sys/firmware/efi/efivars" > + # 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 > + local file="$efivarfs/../vars/SecureBoot-*/data" > + if [ ! -e $file ]; then > + echo "$TEST: unknown secureboot mode" >&2 > + exit $ksft_skip > + fi > + return `od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data` > +} > diff --git a/tools/testing/selftests/ima/test_kexec_load.sh b/tools/testing/selftests/ima/test_kexec_load.sh > index 0345803e7bec..35934e0665f1 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" > +. ./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`" > The rest looks good to me. thanks, -- Shuah