Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp187428pxb; Fri, 15 Jan 2021 10:23:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwXlAs9/093folIdwJ7MV/DMEIVxK8XTBwrIkTx12LN2UL3LhMG1/8fEES6MrDsqQWHO4d X-Received: by 2002:a50:d552:: with SMTP id f18mr10603776edj.168.1610735012203; Fri, 15 Jan 2021 10:23:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610735012; cv=none; d=google.com; s=arc-20160816; b=Zky9gZ8w6mX41w8g/LISh8Z/OOggV4gs8fSpbBAAjf3M3wm4YvYn7OAk56Hqg52Xm+ DBoSi/pBnlWGxznsPBcdW6NxHoVsGUG+pCdFJBux7cE3r8ovNvKrz8WUe2AME3XYNRQz Xbo6El+8pDZqADdccqQ4BDYpw4fka6Zr6L/jPC1//aMXqiFVVrvUg65T6pVnDWQiVROp NvtDxB3PCNNIlsGlFC2ycbxrB80YUrrEiXsf47QjXQ/M7Zt7zMxR1Z3I5nEjMEmqtrni HO2j9vqO8eszqz7F4xgj5jBA/49HTyvgC7J0NI3AwgwEEAJnr+6ByJ8K0MDWWd7XWAbe bNRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZhZfXItCF784UDtjoJUd59i7e+8xnIsCZhpWLs72wAA=; b=wNSHssSry83Em4q8H3fPrucyhGXDSRIB17Qw/MGups8Hg1XpHIV5urfzCkRhKqHhN/ H6QojcMEATbFd56+5YaexB6XJEA/hP83Rre9zkz6BBBiZ040V69YWEtApSUsxEWOHE2O k3PZKZ38BZRLMwNcbwTKbyXz1RCcSpRby6u8mV0ZIpzLJ7dDE9kHJlD/K7B8N2pixO7O 7TYKoICUiAKrgPllaKLF4LbeHciXeuYKEMMcCbW9mYcftZhXZGUVGOfRBkAmuYE9Gwj0 YCQ8A8r+QxEzPZUfx3qzAa4/5k4LPPgZWvEdrkVOCnyjiV+M4lkIQtPUiC9gMWgShnEg kH2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S+zoOQ/f"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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. [23.128.96.18]) by mx.google.com with ESMTP id o9si3489911ejr.672.2021.01.15.10.23.00; Fri, 15 Jan 2021 10:23:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S+zoOQ/f"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S2388630AbhAOSV0 (ORCPT + 99 others); Fri, 15 Jan 2021 13:21:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:43474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388076AbhAOSUy (ORCPT ); Fri, 15 Jan 2021 13:20:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 851D523A6C; Fri, 15 Jan 2021 18:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610734774; bh=DBm5POVqThVqB6dR0uFKTktVEXLstitiHg1DG/aF4QM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S+zoOQ/fI9iHtksm84CuXz1loVV1PH1en9rM/bpCSgerSJhppwjg5/JABqS/Q/5MN YmeKczMMxKNkLgO3M7tG1m2t4LcJ0iyoLF7dq8JrL/dSouRxvEmWmh2S3KxJ2GkWz0 kyDALixxhhcVKKmePXO6AGp6523+Cyhwhb+IlT5TKnnUqf8FoszDmmecHTSLey6Xk2 UKF40HtqlrfFyYUhgFcChzqtRb0e3HyystLXBkB9/ijX/ZMXf73iV1RyQM1Timzr/D uZdJjKdLF2/tFlMXM28HHK6z1pRLPMlCDuj5wECLquhkZ7pQNWID7kyiykpYEmP1X1 J9zA0rCEu6/OA== From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-api@vger.kernel.org, Theodore Ts'o , Jaegeuk Kim , Victor Hsieh Subject: [PATCH 6/6] fs-verity: support reading signature with ioctl Date: Fri, 15 Jan 2021 10:18:19 -0800 Message-Id: <20210115181819.34732-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115181819.34732-1-ebiggers@kernel.org> References: <20210115181819.34732-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Add support for FS_VERITY_METADATA_TYPE_SIGNATURE to FS_IOC_READ_VERITY_METADATA. This allows a userspace server program to retrieve the built-in signature (if present) of a verity file for serving to a client which implements fs-verity compatible verification. See the patch which introduced FS_IOC_READ_VERITY_METADATA for more details. The ability for userspace to read the built-in signatures is also useful because it allows a system that is using the in-kernel signature verification to migrate to userspace signature verification. This has been tested using a new xfstest which calls this ioctl via a new subcommand for the 'fsverity' program from fsverity-utils. Signed-off-by: Eric Biggers --- Documentation/filesystems/fsverity.rst | 9 +++++++- fs/verity/read_metadata.c | 30 ++++++++++++++++++++++++++ include/uapi/linux/fsverity.h | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/fsverity.rst b/Documentation/filesystems/fsverity.rst index 6dc5772037ef9..1d831e3cbcb33 100644 --- a/Documentation/filesystems/fsverity.rst +++ b/Documentation/filesystems/fsverity.rst @@ -236,6 +236,7 @@ This ioctl takes in a pointer to the following structure:: #define FS_VERITY_METADATA_TYPE_MERKLE_TREE 1 #define FS_VERITY_METADATA_TYPE_DESCRIPTOR 2 + #define FS_VERITY_METADATA_TYPE_SIGNATURE 3 struct fsverity_read_metadata_arg { __u64 metadata_type; @@ -256,6 +257,10 @@ This ioctl takes in a pointer to the following structure:: - ``FS_VERITY_METADATA_TYPE_DESCRIPTOR`` reads the fs-verity descriptor. See `fs-verity descriptor`_. +- ``FS_VERITY_METADATA_TYPE_SIGNATURE`` reads the signature which was + passed to FS_IOC_ENABLE_VERITY, if any. See `Built-in signature + verification`_. + The semantics are similar to those of ``pread()``. ``offset`` specifies the offset in bytes into the metadata item to read from, and ``length`` specifies the maximum number of bytes to read from the @@ -279,7 +284,9 @@ FS_IOC_READ_VERITY_METADATA can fail with the following errors: - ``EINTR``: the ioctl was interrupted before any data was read - ``EINVAL``: reserved fields were set, or ``offset + length`` overflowed -- ``ENODATA``: the file is not a verity file +- ``ENODATA``: the file is not a verity file, or + FS_VERITY_METADATA_TYPE_SIGNATURE was requested but the file doesn't + have a built-in signature - ``ENOTTY``: this type of filesystem does not implement fs-verity, or this ioctl is not yet implemented on it - ``EOPNOTSUPP``: the kernel was not configured with fs-verity diff --git a/fs/verity/read_metadata.c b/fs/verity/read_metadata.c index 2dea6dd3bb05a..7e2d0c7bdf0de 100644 --- a/fs/verity/read_metadata.c +++ b/fs/verity/read_metadata.c @@ -114,6 +114,34 @@ static int fsverity_read_descriptor(struct inode *inode, kfree(desc); return res; } + +static int fsverity_read_signature(struct inode *inode, + void __user *buf, u64 offset, int length) +{ + struct fsverity_descriptor *desc; + size_t desc_size; + int res; + + res = fsverity_get_descriptor(inode, &desc, &desc_size); + if (res) + return res; + + if (desc->sig_size == 0) { + res = -ENODATA; + goto out; + } + + /* + * Include only the signature. Note that fsverity_get_descriptor() + * already verified that sig_size is in-bounds. + */ + res = fsverity_read_buffer(buf, offset, length, desc->signature, + le32_to_cpu(desc->sig_size)); +out: + kfree(desc); + return res; +} + /** * fsverity_ioctl_read_metadata() - read verity metadata from a file * @filp: file to read the metadata from @@ -158,6 +186,8 @@ int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg) length); case FS_VERITY_METADATA_TYPE_DESCRIPTOR: return fsverity_read_descriptor(inode, buf, arg.offset, length); + case FS_VERITY_METADATA_TYPE_SIGNATURE: + return fsverity_read_signature(inode, buf, arg.offset, length); default: return -EINVAL; } diff --git a/include/uapi/linux/fsverity.h b/include/uapi/linux/fsverity.h index 41abc283dbccb..15384e22e331e 100644 --- a/include/uapi/linux/fsverity.h +++ b/include/uapi/linux/fsverity.h @@ -85,6 +85,7 @@ struct fsverity_formatted_digest { #define FS_VERITY_METADATA_TYPE_MERKLE_TREE 1 #define FS_VERITY_METADATA_TYPE_DESCRIPTOR 2 +#define FS_VERITY_METADATA_TYPE_SIGNATURE 3 struct fsverity_read_metadata_arg { __u64 metadata_type; -- 2.30.0