From patchwork Mon Oct 23 21:40:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10023167 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 20362603D7 for ; Mon, 23 Oct 2017 21:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1165528932 for ; Mon, 23 Oct 2017 21:42:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05C052893D; Mon, 23 Oct 2017 21:42:33 +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 6691628932 for ; Mon, 23 Oct 2017 21:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932111AbdJWVm0 (ORCPT ); Mon, 23 Oct 2017 17:42:26 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:55139 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751432AbdJWVmO (ORCPT ); Mon, 23 Oct 2017 17:42:14 -0400 Received: by mail-io0-f196.google.com with SMTP id e89so21711925ioi.11; Mon, 23 Oct 2017 14:42:14 -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:in-reply-to:references; bh=UIdBN3CE/fFP8k/jp0riCfEZRfy+HENluYQKnQvJikI=; b=Z5VF66EQ/+TpkjBkAq5HetJTRMqMGRoZsthoenKnv8SUDbRGGI7rAhNCFrI64Bc4CP v1Lbi5iB8dJf3zQmKZhw1JeECFHHam4wpGrEyNvwmbcIdBhPHyFjltgysjt1Dukq9fq1 ApJuQbUCjPagh6Pt8QWDeVvnSlGYhIBhPEcYv29MGfExH47JNXYHSrgcXiiiwDX79Odq jKcu2wyX3LHJPPPY8o4ikxVhd+Z5WJUi03BzkEnPWXC3CXI+J/4IzWIgtoIV2MoDpumj onV2NMdfbG46nlOukMXh11m1G25bZUre6HdH6Fwm9quLwar/Fx9pWoyWaSLA89sIENw3 wPpw== 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:in-reply-to :references; bh=UIdBN3CE/fFP8k/jp0riCfEZRfy+HENluYQKnQvJikI=; b=ghoFHLb7tPGPfX+DLxj8hwG551XvH/m55QcPvMNWISJtNVWbpXcMvTYU+i4rljkNMa fd8pm6B+JIV5QQ/eMUDxl9rEgQtWqp4iuZ8t283N4DKx/8CvgCoao94k9t/JZ4Ujw/C/ O6+2VLZzgyAUpzHalM1Uw5SQ5aW0DpcQa+UlH2U299ljOUvTpurjMSVcRY3+CDRp4xJw s7ISPZZhe0PVp4F0Xkt0KkXJz+oe93jnOIIICO3OKED1xo67vk76mR5O121vJcv8WKEs PFjZcko4f9Kxqw/d4f5hV3l9qHHrOLXY9rhJtWhABvZWSYovr7GRuNUGtfGymz+45BaY /VaA== X-Gm-Message-State: AMCzsaXHSSL+txfvrpmk4i4+WUhbv7nAV7xljnfHIKq5pWCt9c+Ct8dh DtnHObAU45pkuUw9XxiTKSajSbPJ X-Google-Smtp-Source: ABhQp+R+vPFVohyTk2JIx62it0Kze3jLIFez+/V6aCSrPFu5m+AyM/ocFEP3VoRupHy9ehkxXhVFWQ== X-Received: by 10.107.163.15 with SMTP id m15mr18626997ioe.61.1508794933476; Mon, 23 Oct 2017 14:42:13 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.175.88]) by smtp.gmail.com with ESMTPSA id i63sm3558482ioi.68.2017.10.23.14.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 14:42:12 -0700 (PDT) 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-mtd@lists.infradead.org, linux-api@vger.kernel.org, keyrings@vger.kernel.org, "Theodore Y . Ts'o" , Jaegeuk Kim , Gwendal Grignou , Ryo Hashimoto , Sarthak Kukreti , Nick Desaulniers , Michael Halcrow , Eric Biggers Subject: [RFC PATCH 03/25] fscrypt: use FSCRYPT_* definitions, not FS_* Date: Mon, 23 Oct 2017 14:40:36 -0700 Message-Id: <20171023214058.128121-4-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171023214058.128121-1-ebiggers3@gmail.com> References: <20171023214058.128121-1-ebiggers3@gmail.com> 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: Eric Biggers Update the filesystem encryption kernel code to use the new names for the UAPI constants rather than the old names. Signed-off-by: Eric Biggers Reviewed-by: Michael Halcrow --- fs/crypto/fname.c | 4 ++-- fs/crypto/fscrypt_private.h | 4 ++-- fs/crypto/keyinfo.c | 36 +++++++++++++++++------------------- fs/crypto/policy.c | 14 +++++++------- include/linux/fscrypt.h | 8 ++++---- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index 2878289b3ed2..c91bcef65b9f 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -46,7 +46,7 @@ static int fname_encrypt(struct inode *inode, int res = 0; char iv[FS_CRYPTO_BLOCK_SIZE]; struct scatterlist sg; - int padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK); + int padding = 4 << (ci->ci_flags & FSCRYPT_POLICY_FLAGS_PAD_MASK); unsigned int lim; unsigned int cryptlen; @@ -217,7 +217,7 @@ u32 fscrypt_fname_encrypted_size(const struct inode *inode, u32 ilen) struct fscrypt_info *ci = inode->i_crypt_info; if (ci) - padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK); + padding = 4 << (ci->ci_flags & FSCRYPT_POLICY_FLAGS_PAD_MASK); ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE); return round_up(ilen, padding); } diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index a180981ee6d7..5cb80a2d39ea 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -43,7 +43,7 @@ struct fscrypt_context { u8 contents_encryption_mode; u8 filenames_encryption_mode; u8 flags; - u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE]; + u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE]; u8 nonce[FS_KEY_DERIVATION_NONCE_SIZE]; } __packed; @@ -59,7 +59,7 @@ struct fscrypt_info { u8 ci_flags; struct crypto_skcipher *ci_ctfm; struct crypto_cipher *ci_essiv_tfm; - u8 ci_master_key[FS_KEY_DESCRIPTOR_SIZE]; + u8 ci_master_key[FSCRYPT_KEY_DESCRIPTOR_SIZE]; }; typedef enum { diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c index 7aed93bcfb82..ac41f646e7b7 100644 --- a/fs/crypto/keyinfo.c +++ b/fs/crypto/keyinfo.c @@ -38,7 +38,7 @@ static void derive_crypt_complete(struct crypto_async_request *req, int rc) */ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE], const struct fscrypt_key *source_key, - u8 derived_raw_key[FS_MAX_KEY_SIZE]) + u8 derived_raw_key[FSCRYPT_MAX_KEY_SIZE]) { int res = 0; struct skcipher_request *req = NULL; @@ -91,7 +91,7 @@ static int validate_user_key(struct fscrypt_info *crypt_info, int res; description = kasprintf(GFP_NOFS, "%s%*phN", prefix, - FS_KEY_DESCRIPTOR_SIZE, + FSCRYPT_KEY_DESCRIPTOR_SIZE, ctx->master_key_descriptor); if (!description) return -ENOMEM; @@ -121,7 +121,8 @@ static int validate_user_key(struct fscrypt_info *crypt_info, master_key = (struct fscrypt_key *)ukp->data; BUILD_BUG_ON(FS_AES_128_ECB_KEY_SIZE != FS_KEY_DERIVATION_NONCE_SIZE); - if (master_key->size < min_keysize || master_key->size > FS_MAX_KEY_SIZE + if (master_key->size < min_keysize || + master_key->size > FSCRYPT_MAX_KEY_SIZE || master_key->size % AES_BLOCK_SIZE != 0) { printk_once(KERN_WARNING "%s: key size incorrect: %d\n", @@ -140,14 +141,10 @@ static const struct { const char *cipher_str; int keysize; } available_modes[] = { - [FS_ENCRYPTION_MODE_AES_256_XTS] = { "xts(aes)", - FS_AES_256_XTS_KEY_SIZE }, - [FS_ENCRYPTION_MODE_AES_256_CTS] = { "cts(cbc(aes))", - FS_AES_256_CTS_KEY_SIZE }, - [FS_ENCRYPTION_MODE_AES_128_CBC] = { "cbc(aes)", - FS_AES_128_CBC_KEY_SIZE }, - [FS_ENCRYPTION_MODE_AES_128_CTS] = { "cts(cbc(aes))", - FS_AES_128_CTS_KEY_SIZE }, + [FSCRYPT_MODE_AES_256_XTS] = { "xts(aes)", FS_AES_256_XTS_KEY_SIZE }, + [FSCRYPT_MODE_AES_256_CTS] = { "cts(cbc(aes))", FS_AES_256_CTS_KEY_SIZE }, + [FSCRYPT_MODE_AES_128_CBC] = { "cbc(aes)", FS_AES_128_CBC_KEY_SIZE }, + [FSCRYPT_MODE_AES_128_CTS] = { "cts(cbc(aes))", FS_AES_128_CTS_KEY_SIZE }, }; static int determine_cipher_type(struct fscrypt_info *ci, struct inode *inode, @@ -278,9 +275,10 @@ int fscrypt_get_encryption_info(struct inode *inode) /* Fake up a context for an unencrypted directory */ memset(&ctx, 0, sizeof(ctx)); ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; - ctx.contents_encryption_mode = FS_ENCRYPTION_MODE_AES_256_XTS; - ctx.filenames_encryption_mode = FS_ENCRYPTION_MODE_AES_256_CTS; - memset(ctx.master_key_descriptor, 0x42, FS_KEY_DESCRIPTOR_SIZE); + ctx.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS; + ctx.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS; + memset(ctx.master_key_descriptor, 0x42, + FSCRYPT_KEY_DESCRIPTOR_SIZE); } else if (res != sizeof(ctx)) { return -EINVAL; } @@ -288,7 +286,7 @@ int fscrypt_get_encryption_info(struct inode *inode) if (ctx.format != FS_ENCRYPTION_CONTEXT_FORMAT_V1) return -EINVAL; - if (ctx.flags & ~FS_POLICY_FLAGS_VALID) + if (ctx.flags & ~FSCRYPT_POLICY_FLAGS_VALID) return -EINVAL; crypt_info = kmem_cache_alloc(fscrypt_info_cachep, GFP_NOFS); @@ -312,12 +310,12 @@ int fscrypt_get_encryption_info(struct inode *inode) * crypto API as part of key derivation. */ res = -ENOMEM; - raw_key = kmalloc(FS_MAX_KEY_SIZE, GFP_NOFS); + raw_key = kmalloc(FSCRYPT_MAX_KEY_SIZE, GFP_NOFS); if (!raw_key) goto out; - res = validate_user_key(crypt_info, &ctx, raw_key, FS_KEY_DESC_PREFIX, - keysize); + res = validate_user_key(crypt_info, &ctx, raw_key, + FSCRYPT_KEY_DESC_PREFIX, keysize); if (res && inode->i_sb->s_cop->key_prefix) { int res2 = validate_user_key(crypt_info, &ctx, raw_key, inode->i_sb->s_cop->key_prefix, @@ -349,7 +347,7 @@ int fscrypt_get_encryption_info(struct inode *inode) goto out; if (S_ISREG(inode->i_mode) && - crypt_info->ci_data_mode == FS_ENCRYPTION_MODE_AES_128_CBC) { + crypt_info->ci_data_mode == FSCRYPT_MODE_AES_128_CBC) { res = init_essiv_generator(crypt_info, raw_key, keysize); if (res) { pr_debug("%s: error %d (inode %lu) allocating essiv tfm\n", diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 6a63b8a0d46c..19332a6fd52d 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -21,7 +21,7 @@ static bool is_encryption_context_consistent_with_policy( const struct fscrypt_policy *policy) { return memcmp(ctx->master_key_descriptor, policy->master_key_descriptor, - FS_KEY_DESCRIPTOR_SIZE) == 0 && + FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 && (ctx->flags == policy->flags) && (ctx->contents_encryption_mode == policy->contents_encryption_mode) && @@ -36,13 +36,13 @@ static int create_encryption_context_from_policy(struct inode *inode, ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; memcpy(ctx.master_key_descriptor, policy->master_key_descriptor, - FS_KEY_DESCRIPTOR_SIZE); + FSCRYPT_KEY_DESCRIPTOR_SIZE); if (!fscrypt_valid_enc_modes(policy->contents_encryption_mode, policy->filenames_encryption_mode)) return -EINVAL; - if (policy->flags & ~FS_POLICY_FLAGS_VALID) + if (policy->flags & ~FSCRYPT_POLICY_FLAGS_VALID) return -EINVAL; ctx.contents_encryption_mode = policy->contents_encryption_mode; @@ -125,7 +125,7 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg) policy.filenames_encryption_mode = ctx.filenames_encryption_mode; policy.flags = ctx.flags; memcpy(policy.master_key_descriptor, ctx.master_key_descriptor, - FS_KEY_DESCRIPTOR_SIZE); + FSCRYPT_KEY_DESCRIPTOR_SIZE); if (copy_to_user(arg, &policy, sizeof(policy))) return -EFAULT; @@ -199,7 +199,7 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child) if (parent_ci && child_ci) { return memcmp(parent_ci->ci_master_key, child_ci->ci_master_key, - FS_KEY_DESCRIPTOR_SIZE) == 0 && + FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 && (parent_ci->ci_data_mode == child_ci->ci_data_mode) && (parent_ci->ci_filename_mode == child_ci->ci_filename_mode) && @@ -216,7 +216,7 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child) return memcmp(parent_ctx.master_key_descriptor, child_ctx.master_key_descriptor, - FS_KEY_DESCRIPTOR_SIZE) == 0 && + FSCRYPT_KEY_DESCRIPTOR_SIZE) == 0 && (parent_ctx.contents_encryption_mode == child_ctx.contents_encryption_mode) && (parent_ctx.filenames_encryption_mode == @@ -254,7 +254,7 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child, ctx.filenames_encryption_mode = ci->ci_filename_mode; ctx.flags = ci->ci_flags; memcpy(ctx.master_key_descriptor, ci->ci_master_key, - FS_KEY_DESCRIPTOR_SIZE); + FSCRYPT_KEY_DESCRIPTOR_SIZE); get_random_bytes(ctx.nonce, FS_KEY_DERIVATION_NONCE_SIZE); BUILD_BUG_ON(sizeof(ctx) != FSCRYPT_SET_CONTEXT_MAX_SIZE); res = parent->i_sb->s_cop->set_context(child, &ctx, diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index f7aa7d62e235..671ce57e4673 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -99,12 +99,12 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode) static inline bool fscrypt_valid_enc_modes(u32 contents_mode, u32 filenames_mode) { - if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC && - filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS) + if (contents_mode == FSCRYPT_MODE_AES_128_CBC && + filenames_mode == FSCRYPT_MODE_AES_128_CTS) return true; - if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS && - filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS) + if (contents_mode == FSCRYPT_MODE_AES_256_XTS && + filenames_mode == FSCRYPT_MODE_AES_256_CTS) return true; return false;