From patchwork Fri Jan 15 18:28:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1427263 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=nqQdPkPo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHVBH1GgFz9sVn for ; Sat, 16 Jan 2021 05:31:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387679AbhAOSbB (ORCPT ); Fri, 15 Jan 2021 13:31:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:49324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732702AbhAOSbB (ORCPT ); Fri, 15 Jan 2021 13:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E6BF823A59; Fri, 15 Jan 2021 18:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610735420; bh=TyRLY9HOrw4FJ9cPyh5lToCNCoiKY1YY9L+hh8t7VKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqQdPkPoV2mj5m0otY41WNCWvsiLgZz7MBYQpxNhHdCJoOO6mD7OqYW5GvM/RqWmE cPoDBYi7yrsycvgzC2ZIj1m+7nOfcIwWvi/i/6HGElGqpkJVj5TkxLMyBk73Lx3DO1 5iwLuXxxRzGa7JH1w/u7/XOS+OekMO3SEXuf/Pe8zo1KO4bBCcV91go6K/x8Xovgli gBaXkB3RzvCG1IAzfOmk3gGft3hC+9fPsouRQK1d4onid+y2fMorlpyA11LpB1PZMq n6N74gjuxMhWtw9MOPU4O4uAwFNL6w225KknoAKE26qtLju9ltei1A+liSWdsVl/Wg nV9CaMSg2poZw== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o , Jaegeuk Kim , Victor Hsieh Subject: [xfstests RFC PATCH 1/4] generic: factor out helpers for fs-verity built-in signatures Date: Fri, 15 Jan 2021 10:28:34 -0800 Message-Id: <20210115182837.36333-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115182837.36333-1-ebiggers@kernel.org> References: <20210115182837.36333-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers The test for retrieving a verity file's built-in signature using FS_IOC_READ_VERITY_METADATA will need to set up a file with a built-in signature, which requires the same commands that generic/577 does. Factor this out into helper functions in common/verity. Signed-off-by: Eric Biggers --- common/verity | 37 ++++++++++++++++++++++++++++++++++++- tests/generic/577 | 15 +++------------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/common/verity b/common/verity index a8d3de06..9a182240 100644 --- a/common/verity +++ b/common/verity @@ -48,12 +48,47 @@ _require_scratch_verity() FSV_BLOCK_SIZE=$(get_page_size) } -# Check for CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y. +# Check for CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y, as well as the userspace +# commands needed to generate certificates and add them to the kernel. _require_fsverity_builtin_signatures() { if [ ! -e /proc/sys/fs/verity/require_signatures ]; then _notrun "kernel doesn't support fs-verity builtin signatures" fi + _require_command "$OPENSSL_PROG" openssl + _require_command "$KEYCTL_PROG" keyctl +} + +# Use the openssl program to generate a private key and a X.509 certificate for +# use with fs-verity built-in signature verification, and convert the +# certificate to DER format. +_fsv_generate_cert() +{ + local keyfile=$1 + local certfile=$2 + local certfileder=$3 + + if ! $OPENSSL_PROG req -newkey rsa:4096 -nodes -batch -x509 \ + -keyout $keyfile -out $certfile &>> $seqres.full; then + _fail "Failed to generate certificate and private key (see $seqres.full)" + fi + $OPENSSL_PROG x509 -in $certfile -out $certfileder -outform der +} + +# Clear the .fs-verity keyring. +_fsv_clear_keyring() +{ + $KEYCTL_PROG clear %keyring:.fs-verity +} + +# Load the given X.509 certificate in DER format into the .fs-verity keyring so +# that the kernel can use it to verify built-in signatures. +_fsv_load_cert() +{ + local certfileder=$1 + + $KEYCTL_PROG padd asymmetric '' %keyring:.fs-verity \ + < $certfileder >> $seqres.full } # Disable mandatory signatures for fs-verity files, if they are supported. diff --git a/tests/generic/577 b/tests/generic/577 index 0e945942..114463be 100755 --- a/tests/generic/577 +++ b/tests/generic/577 @@ -34,8 +34,6 @@ rm -f $seqres.full _supported_fs generic _require_scratch_verity _require_fsverity_builtin_signatures -_require_command "$OPENSSL_PROG" openssl -_require_command "$KEYCTL_PROG" keyctl _scratch_mkfs_verity &>> $seqres.full _scratch_mount @@ -53,21 +51,14 @@ othersigfile=$tmp.othersig echo -e "\n# Generating certificates and private keys" for suffix in '' '.2'; do - if ! $OPENSSL_PROG req -newkey rsa:4096 -nodes -batch -x509 \ - -keyout $keyfile$suffix -out $certfile$suffix \ - &>> $seqres.full; then - _fail "Failed to generate certificate and private key (see $seqres.full)" - fi - $OPENSSL_PROG x509 -in $certfile$suffix -out $certfileder$suffix \ - -outform der + _fsv_generate_cert $keyfile$suffix $certfile$suffix $certfileder$suffix done echo -e "\n# Clearing fs-verity keyring" -$KEYCTL_PROG clear %keyring:.fs-verity +_fsv_clear_keyring echo -e "\n# Loading first certificate into fs-verity keyring" -$KEYCTL_PROG padd asymmetric '' %keyring:.fs-verity \ - < $certfileder >> $seqres.full +_fsv_load_cert $certfileder echo -e "\n# Enabling fs.verity.require_signatures" _enable_fsverity_signatures From patchwork Fri Jan 15 18:28:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1427264 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=t/O8dyvA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHVBH5gckz9sVr for ; Sat, 16 Jan 2021 05:31:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387686AbhAOSbC (ORCPT ); Fri, 15 Jan 2021 13:31:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:49340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728784AbhAOSbB (ORCPT ); Fri, 15 Jan 2021 13:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45C5923A58; Fri, 15 Jan 2021 18:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610735420; bh=OlnfKFkoxSsw83/Nn4nLPOmT1fppOZvKCzhP/LtAIl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/O8dyvApsG/tAs049qpWPh34uTtY8zTJEtQe176sA4nna21Mz1l6QhUo2LUFQuwN m4BeX8w+ZP+QvKvz39MUWoOk8FtWQ/gdztA+SXheMn1KIN7J7KQImiNRu6PFReI3E5 OSD82W/izCrxFEUXEkfYpnK0lD0YklHed3ff43G13izvGG1iA7YtxFwULaWIWNvTwg 7mqfiHlRf3Q4qiIxZ35GBHZ6ykdpwnyCPZz43i6IoCGsIQygMe4a6h9IN6XcuqB0/Y 9HQPn79xSztl+3Vdgj/hw7DFDCX2s8daIBfu0xDkLMN1hHWJEXM3Y974ap7nbjfRhb ZuG/QL1S4cp4A== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o , Jaegeuk Kim , Victor Hsieh Subject: [xfstests RFC PATCH 2/4] generic: add helpers for dumping fs-verity metadata Date: Fri, 15 Jan 2021 10:28:35 -0800 Message-Id: <20210115182837.36333-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115182837.36333-1-ebiggers@kernel.org> References: <20210115182837.36333-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers In common/verity, add helper functions for dumping a file's fs-verity metadata using the new FS_IOC_READ_VERITY_METADATA ioctl. Signed-off-by: Eric Biggers --- common/verity | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/common/verity b/common/verity index 9a182240..38eea157 100644 --- a/common/verity +++ b/common/verity @@ -120,6 +120,27 @@ _restore_fsverity_signatures() fi } +# Require userspace and kernel support for 'fsverity dump_metadata'. +# $1 must be a file with fs-verity enabled. +_require_fsverity_dump_metadata() +{ + local verity_file=$1 + local tmpfile=$tmp.require_fsverity_dump_metadata + + if _fsv_dump_merkle_tree "$verity_file" 2>"$tmpfile" >/dev/null; then + return + fi + if grep -q "^ERROR: unrecognized command: 'dump_metadata'$" "$tmpfile" + then + _notrun "Missing 'fsverity dump_metadata' command" + fi + if grep -q "^ERROR: FS_IOC_READ_VERITY_METADATA failed on '.*': Inappropriate ioctl for device$" "$tmpfile" + then + _notrun "Kernel doesn't support FS_IOC_READ_VERITY_METADATA" + fi + _fail "Unexpected output from 'fsverity dump_metadata': $(<"$tmpfile")" +} + _scratch_mkfs_verity() { case $FSTYP in @@ -157,6 +178,21 @@ _fsv_scratch_begin_subtest() echo -e "\n# $msg" } +_fsv_dump_merkle_tree() +{ + $FSVERITY_PROG dump_metadata merkle_tree "$@" +} + +_fsv_dump_descriptor() +{ + $FSVERITY_PROG dump_metadata descriptor "$@" +} + +_fsv_dump_signature() +{ + $FSVERITY_PROG dump_metadata signature "$@" +} + _fsv_enable() { $FSVERITY_PROG enable "$@" From patchwork Fri Jan 15 18:28:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1427265 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Vttam1w8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHVBJ1C65z9sVt for ; Sat, 16 Jan 2021 05:31:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387692AbhAOSbC (ORCPT ); Fri, 15 Jan 2021 13:31:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:49368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387490AbhAOSbB (ORCPT ); Fri, 15 Jan 2021 13:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9833323A5A; Fri, 15 Jan 2021 18:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610735420; bh=Zq2xXRGPcF0MfdALNvMGtqIAAiivpPFH6hP0tdwW7I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vttam1w8/dE7Z0WFpoIDGXwY85jSAMLMfj/Ym60CHZwY2QyTJC5wP2arZl3oCfiqP TS7wk92uNSwc9j4O9+vVBP0TirvWOYQbR/cX3JqYora8gn16T+uThhgfLKZ8cLVVWR zBgw+z1+6dUcMtPn0qqYvBeBhT21uwqTbXUOr0b/V8dvkIQm62QMdpi9OOTxsfD96X N8F55CUKJrMUIV2Jv7oTxqyV+le0oxQdspVj4XRzcA/9S0lS7H1Zk7FacEEpzWB2VG Volu1d1UNRSRSiFz8N8p3VRC7sxbOLZl/M+OI+uQv2w3wzLM9/NlUPuvOdwbhizfMe JJBl+GveuOV9Q== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o , Jaegeuk Kim , Victor Hsieh Subject: [xfstests RFC PATCH 3/4] generic: test retrieving verity Merkle tree and descriptor Date: Fri, 15 Jan 2021 10:28:36 -0800 Message-Id: <20210115182837.36333-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115182837.36333-1-ebiggers@kernel.org> References: <20210115182837.36333-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Add a test which tests retrieving the Merkle tree and fs-verity descriptor of a verity file using the new FS_IOC_READ_VERITY_METADATA ioctl. Signed-off-by: Eric Biggers --- tests/generic/901 | 79 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/901.out | 16 +++++++++ tests/generic/group | 1 + 3 files changed, 96 insertions(+) create mode 100755 tests/generic/901 create mode 100644 tests/generic/901.out diff --git a/tests/generic/901 b/tests/generic/901 new file mode 100755 index 00000000..24889d63 --- /dev/null +++ b/tests/generic/901 @@ -0,0 +1,79 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright 2021 Google LLC +# +# FS QA Test No. 901 +# +# Test retrieving the Merkle tree and fs-verity descriptor of a verity file +# using FS_IOC_READ_VERITY_METADATA. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +. ./common/rc +. ./common/filter +. ./common/verity + +rm -f $seqres.full + +_supported_fs generic +_require_scratch_verity +_disable_fsverity_signatures +# For the output of this test to always be the same, it has to use a specific +# Merkle tree block size. +if [ $FSV_BLOCK_SIZE != 4096 ]; then + _notrun "4096-byte verity block size not supported on this platform" +fi + +_scratch_mkfs_verity &>> $seqres.full +_scratch_mount + +echo -e "\n# Creating a verity file" +fsv_file=$SCRATCH_MNT/file +# Always use the same file contents, so that the output of the test is always +# the same. Also use a file that is large enough to have multiple Merkle tree +# levels, so that the test verifies that the blocks are returned in the expected +# order. A 1 MB file with SHA-256 and a Merkle tree block size of 4096 will +# have 3 Merkle tree blocks (3*4096 bytes): two at level 0 and one at level 1. +head -c 1000000 /dev/zero > $fsv_file +merkle_tree_size=$((3 * FSV_BLOCK_SIZE)) +fsverity_descriptor_size=256 +_fsv_enable $fsv_file --salt=abcd +_require_fsverity_dump_metadata $fsv_file +_fsv_measure $fsv_file + +echo -e "\n# Dumping Merkle tree" +_fsv_dump_merkle_tree $fsv_file | sha256sum + +echo -e "\n# Dumping Merkle tree (in chunks)" +# The above test may get the whole tree in one read, so also try reading it in +# chunks. +for (( i = 0; i < merkle_tree_size; i += 997 )); do + _fsv_dump_merkle_tree $fsv_file --offset=$i --length=997 +done | sha256sum + +echo -e "\n# Dumping descriptor" +# Note that the hash that is printed here should be the same hash that was +# printed by _fsv_measure above. +_fsv_dump_descriptor $fsv_file | sha256sum + +echo -e "\n# Dumping descriptor (in chunks)" +for (( i = 0; i < fsverity_descriptor_size; i += 13 )); do + _fsv_dump_descriptor $fsv_file --offset=$i --length=13 +done | sha256sum + +# success, all done +status=0 +exit diff --git a/tests/generic/901.out b/tests/generic/901.out new file mode 100644 index 00000000..ab018052 --- /dev/null +++ b/tests/generic/901.out @@ -0,0 +1,16 @@ +QA output created by 901 + +# Creating a verity file +sha256:11e4f886bf2d70a6ef3a8b6ce8e8c62c9e5d3263208b9f120ae46791f124be73 + +# Dumping Merkle tree +db88cdad554734cd648a1bfbb5be7f86646c54397847aab0b3f42a28829fed17 - + +# Dumping Merkle tree (in chunks) +db88cdad554734cd648a1bfbb5be7f86646c54397847aab0b3f42a28829fed17 - + +# Dumping descriptor +11e4f886bf2d70a6ef3a8b6ce8e8c62c9e5d3263208b9f120ae46791f124be73 - + +# Dumping descriptor (in chunks) +11e4f886bf2d70a6ef3a8b6ce8e8c62c9e5d3263208b9f120ae46791f124be73 - diff --git a/tests/generic/group b/tests/generic/group index 30a73605..3f2edfc0 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -624,3 +624,4 @@ 619 auto rw enospc 620 auto mount quick 621 auto quick encrypt +901 auto quick verity From patchwork Fri Jan 15 18:28:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1427266 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=N0L4j8Oc; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DHVBJ58GXz9sVn for ; Sat, 16 Jan 2021 05:31:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387729AbhAOSbD (ORCPT ); Fri, 15 Jan 2021 13:31:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:49390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387524AbhAOSbB (ORCPT ); Fri, 15 Jan 2021 13:31:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB83523A7C; Fri, 15 Jan 2021 18:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610735421; bh=Zx+DKeYBgI/GfjZ0hi4SNhfY3GNWutg/K/C8V9kfqdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N0L4j8OcdiQhWhaA3lFznkCBSPrE6zUF8PqcJjOuy1RL3ttPOC2xIxraA2lLNPOWD hR7vaqwtorwbVYMC5g71KuX9G821NatdnGeMVjOeHfY8L9txlCRz2kjuPQpAY0NuID wNFRErvojCbHW/gQVQuFeagBwyiZ7dJWeH5yA6wps6dRULQgss1JrWJz0dR6AscPon sJ1km6FSX2KsF3KAmFjS97xPA1km91yX6tofMy6L/koqPj52vinla0ljeLky5eHBSQ mWVSzaPV7aJ/PqiFWrTwxeN1kN/QJ5ubDeAkCzAs30mzm+qdazEiHX/jjUROAJmWpE qkIFNWUiidusQ== From: Eric Biggers To: fstests@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o , Jaegeuk Kim , Victor Hsieh Subject: [xfstests RFC PATCH 4/4] generic: test retrieving verity signature Date: Fri, 15 Jan 2021 10:28:37 -0800 Message-Id: <20210115182837.36333-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115182837.36333-1-ebiggers@kernel.org> References: <20210115182837.36333-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Add a test which tests dumping the built-in signature of a verity file using the new FS_IOC_READ_VERITY_METADATA ioctl. Signed-off-by: Eric Biggers --- tests/generic/902 | 66 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/902.out | 7 +++++ tests/generic/group | 1 + 3 files changed, 74 insertions(+) create mode 100644 tests/generic/902 create mode 100644 tests/generic/902.out diff --git a/tests/generic/902 b/tests/generic/902 new file mode 100644 index 00000000..ee1096df --- /dev/null +++ b/tests/generic/902 @@ -0,0 +1,66 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright 2021 Google LLC +# +# FS QA Test No. 902 +# +# Test retrieving the built-in signature of a verity file using +# FS_IOC_READ_VERITY_METADATA. +# +# This is separate from the other tests for FS_IOC_READ_VERITY_METADATA because +# the fs-verity built-in signature support is optional. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +. ./common/rc +. ./common/filter +. ./common/verity + +rm -f $seqres.full + +_supported_fs generic +_require_scratch_verity +_require_fsverity_builtin_signatures + +_scratch_mkfs_verity &>> $seqres.full +_scratch_mount + +echo -e "\n# Setting up signed verity file" +_fsv_generate_cert $tmp.key $tmp.cert $tmp.cert.der +_fsv_clear_keyring +_fsv_load_cert $tmp.cert.der +fsv_file=$SCRATCH_MNT/file +echo foo > $fsv_file +_fsv_sign $fsv_file $tmp.sig --key=$tmp.key --cert=$tmp.cert >> $seqres.full +_fsv_enable $fsv_file --signature=$tmp.sig +_require_fsverity_dump_metadata $fsv_file + +echo -e "\n# Dumping and comparing signature" +_fsv_dump_signature $fsv_file > $tmp.sig2 +# The signature returned by FS_IOC_READ_VERITY_METADATA should exactly match the +# one we passed to FS_IOC_ENABLE_VERITY earlier. +cmp $tmp.sig $tmp.sig2 + +echo -e "\n# Dumping and comparing signature (in chunks)" +sig_size=$(stat -c %s $tmp.sig) +for (( i = 0; i < sig_size; i += 13 )); do + _fsv_dump_signature $fsv_file --offset=$i --length=13 +done > $tmp.sig2 +cmp $tmp.sig $tmp.sig2 + +# success, all done +status=0 +exit diff --git a/tests/generic/902.out b/tests/generic/902.out new file mode 100644 index 00000000..4b8d9f6e --- /dev/null +++ b/tests/generic/902.out @@ -0,0 +1,7 @@ +QA output created by 902 + +# Setting up signed verity file + +# Dumping and comparing signature + +# Dumping and comparing signature (in chunks) diff --git a/tests/generic/group b/tests/generic/group index 3f2edfc0..84fec240 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -625,3 +625,4 @@ 620 auto mount quick 621 auto quick encrypt 901 auto quick verity +902 auto quick verity