From patchwork Tue Apr 4 22:39:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Richey X-Patchwork-Id: 9662723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E68B60353 for ; Tue, 4 Apr 2017 22:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1984628395 for ; Tue, 4 Apr 2017 22:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E20D284D5; Tue, 4 Apr 2017 22:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBA4528395 for ; Tue, 4 Apr 2017 22:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755284AbdDDWkD (ORCPT ); Tue, 4 Apr 2017 18:40:03 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35634 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754238AbdDDWkC (ORCPT ); Tue, 4 Apr 2017 18:40:02 -0400 Received: by mail-pg0-f67.google.com with SMTP id g2so39764370pge.2; Tue, 04 Apr 2017 15:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1kes4owOrR1+IpkstZM7lBoBYxdYAhlUma6i2xGjXPU=; b=Je5qfX+TBr+IOpyylHMgLj8B/auzbHpIci1ZmL4kVT5T615XcthW6ozvmpPre1yBVX TMc0XoTA1QRHfq85lxQvRgjPNXbtLvKvhCL2kpjQjvxLVUIZQKrXo/osYwAK+eqdMSAm uFAr2/Cys3kTrlk8A5xsAZlzJLD1bLsB26Fe/57aUJCr+IiZbDEb+PjIx8I1SlMKUC3J 5sXGS/IF2psDxbkbeM7cQkNj4cgNfZmBW6LfksgMYn+KhkXMhnyCN4E/V7jRM71HCcNF yJnvo8TK//ewdMcbIaEgC/yQYQoMevSFwvdOs+orUU2/b/BGAcDYFxfkuZxtw5Z2fFul F8Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1kes4owOrR1+IpkstZM7lBoBYxdYAhlUma6i2xGjXPU=; b=J4V1ZzblTIP7LOmU7e+W1TbWMlxyzdpLCxI0OxyNNkCBpXbglFnT6UYUoNco0vMe1Q o2SEXd6D3GVMr5SoofRFCT8pHipQk9Hnwff3tBv7TTOCA8hl26AcSwfyk8Jmh08rpjoT RDGWrh0nWw9+PP3Sm7tu5kfA+p8adK5HcqgdsESg4gzay9xr4k70KZux9pDhIWQTrurD LPXaS3ECnFKjRvVUOGU8Lnv0nU/voMZb7w9fAL267AMGKp+JLPpH8HWwpy2i3/uy1OzV zWKX0pDa7P+heUYg2ZpM3CDJScvibnQD0ht3hL8Y+JwAbCdcGWdPIfQQVpnIFZE9MUYi KnFA== X-Gm-Message-State: AFeK/H19VM/lFo0fNMXdFx7Tgz1b5Z0xoaGor2OwVmBTxdAAn7QJ15ZheafPfwjuZdGGpg== X-Received: by 10.98.78.4 with SMTP id c4mr25292125pfb.241.1491345600518; Tue, 04 Apr 2017 15:40:00 -0700 (PDT) Received: from joerichey.kir.corp.google.com ([172.23.164.75]) by smtp.gmail.com with ESMTPSA id j19sm33596923pfk.4.2017.04.04.15.39.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Apr 2017 15:39:59 -0700 (PDT) From: Joe Richey To: linux-fsdevel@vger.kernel.org Cc: linux-fscrypt@vger.kernel.org, linux-api@vger.kernel.org, Jaegeuk Kim , Theodore Ts'o , Michael Halcrow , Joe Richey Subject: [PATCH] fscrypt: Move key structure and constants to uapi Date: Tue, 4 Apr 2017 15:39:13 -0700 Message-Id: <20170404223913.62817-1-joerichey94@gmail.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Joe Richey This commit exposes the necessary constants and structures for a userspace program to pass filesystem encryption keys into the keyring. The fscrypt_key structure was already part of the kernel ABI, this change just makes it so programs no longer have to redeclare these structures (like e4crypt in e2fsprogs currently does). Note that we do not expose the other FS_*_KEY_SIZE constants as they are not necessary. Only XTS is supported for contents_encryption_mode, so currently FS_MAX_KEY_SIZE bytes of key material must always be passed to the kernel. This commit also removes __packed from fscrypt_key as it does not contain any implicit padding and does not refer to an on-disk structure. Change-Id: Iafc7d0f2127a5521a4566e59f2ed1ffc1526a62b Signed-off-by: Joe Richey Reviewed-by: Richard Weinberger --- fs/crypto/fscrypt_private.h | 11 ----------- include/uapi/linux/fs.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index e39696e64494..e08ca6d1ca0f 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -22,10 +22,6 @@ #define FS_AES_256_CBC_KEY_SIZE 32 #define FS_AES_256_CTS_KEY_SIZE 32 #define FS_AES_256_XTS_KEY_SIZE 64 -#define FS_MAX_KEY_SIZE 64 - -#define FS_KEY_DESC_PREFIX "fscrypt:" -#define FS_KEY_DESC_PREFIX_SIZE 8 #define FS_KEY_DERIVATION_NONCE_SIZE 16 @@ -51,13 +47,6 @@ struct fscrypt_context { #define FS_ENCRYPTION_CONTEXT_FORMAT_V1 1 -/* This is passed in from userspace into the kernel keyring */ -struct fscrypt_key { - u32 mode; - u8 raw[FS_MAX_KEY_SIZE]; - u32 size; -} __packed; - /* * A pointer to this structure is stored in the file system's in-core * representation of an inode. diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 048a85e9f017..9691fda01245 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -285,6 +285,19 @@ struct fscrypt_policy { #define FS_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16]) #define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy) +/* Parameters for passing an encryption key into the kernel keyring */ +#define FS_KEY_DESC_PREFIX "fscrypt:" +#define FS_KEY_DESC_PREFIX_SIZE 8 + +/* Structure that userspace passes to the kernel keyring */ +#define FS_MAX_KEY_SIZE 64 + +struct fscrypt_key { + __u32 mode; + __u8 raw[FS_MAX_KEY_SIZE]; + __u32 size; +}; + /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) *