From patchwork Wed Jul 12 21:00:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9837383 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 B396E602D8 for ; Wed, 12 Jul 2017 21:02:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3F07286AB for ; Wed, 12 Jul 2017 21:02:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98210286C6; Wed, 12 Jul 2017 21:02:22 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 2096B286AB for ; Wed, 12 Jul 2017 21:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753410AbdGLVCP (ORCPT ); Wed, 12 Jul 2017 17:02:15 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33073 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbdGLVCN (ORCPT ); Wed, 12 Jul 2017 17:02:13 -0400 Received: by mail-pg0-f68.google.com with SMTP id u62so4335244pgb.0; Wed, 12 Jul 2017 14:02:13 -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=m7zgkDxmSVeEJ6ga2ZVZ4Mi4gsqQN/5t2XrKYdKIwTE=; b=lRR4PhItWe4X/wN60IE3t9vQHUGhVl87ovRj0nbTqdVByEFcUU21i+SW93N85YFPFI 2pcNrojzMZrUtX2Yz1IKM9zMqXDj/RlxRVOd7kyKiOZetAm1CvrOSU9zrvo82pbcbfcW flKRhXaAMDkdM0sgI0uEBjKUDv7MUSJ1gL9QYb1krU7zmW+W6l0yU7LE/6raNjf53r7H tG+hRS4E56pTxUmOJ9UALOoXHl4KJCK+uqU1Ez5RllUDqm70xk4uOsBTDrfmvymjhKgy pVNuB9eWvJepY8X1hs5kBckVuzxw6akyx2LwZL72eUkB/0FOIHMaPM+Be7s4IigYGXDw FrFA== 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=m7zgkDxmSVeEJ6ga2ZVZ4Mi4gsqQN/5t2XrKYdKIwTE=; b=ZIgfl5ZarHC1pWMDwLjt1WwiIeWDgyCf2nkIHHs9F+PkklY6wkxYK13AFIgqdHCfB7 rf/mc0zDqLqELE4SjgI5zSPW97fucn4aU7CIecrquAq3yJ0glhGIsRiku3aG3k+yJV2Q 0qyiFBtTiYAbNZJizoDTeVN93Lfu0nSIOzKRyHxejKkgX/LhTtttYHJJLGLF8HKbNrQl BBeAePYLXfR7tYgJkHuZaNgks7vP26qTTIS5XgegSkzM+i7b7Ig9JfiY5OkP0hWKTEJ/ pJPl40QFmWjrUUpZiR4O+jsaMsgENQCXOVDutNhPJ+ZXuqIZcGr5PBG36LaNl3wEDoP1 VQzw== X-Gm-Message-State: AIVw111RzfTo5AW4E5BI90KkOFwnDTArXIPuHf98BpKv2MCOOXRaGahu tXMOUGmAtWZUJ1MndJw= X-Received: by 10.98.159.16 with SMTP id g16mr56936761pfe.21.1499893332288; Wed, 12 Jul 2017 14:02:12 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id m16sm8002488pfj.130.2017.07.12.14.02.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Jul 2017 14:02:11 -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-crypto@vger.kernel.org, "Theodore Y . Ts'o" , Jaegeuk Kim , Alex Cope , Eric Biggers Subject: [PATCH 6/6] fscrypt: for v2 policies, support "fscrypt:" key prefix only Date: Wed, 12 Jul 2017 14:00:35 -0700 Message-Id: <20170712210035.51534-7-ebiggers3@gmail.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170712210035.51534-1-ebiggers3@gmail.com> References: <20170712210035.51534-1-ebiggers3@gmail.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Since v2 encryption policies are opt-in, take the opportunity to also drop support for the legacy filesystem-specific key description prefixes "ext4:", "f2fs:", and "ubifs:", instead requiring the generic prefix "fscrypt:". The generic prefix is preferred since it works for all filesystems. Also there is a performance benefit from not having to search the keyrings twice. The old prefixes remain supported for v1 encryption policies. Signed-off-by: Eric Biggers Reviewed-by: Michael Halcrow --- fs/crypto/fscrypt_private.h | 3 +-- fs/crypto/keyinfo.c | 16 ++++------------ fs/crypto/policy.c | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 4b158717a8c3..201906ff7033 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -167,8 +167,7 @@ extern struct page *fscrypt_alloc_bounce_page(struct fscrypt_ctx *ctx, gfp_t gfp_flags); /* keyinfo.c */ -extern int fscrypt_compute_key_hash(const struct inode *inode, - const struct fscrypt_policy *policy, +extern int fscrypt_compute_key_hash(const struct fscrypt_policy *policy, u8 hash[FSCRYPT_KEY_HASH_SIZE]); extern void __exit fscrypt_essiv_cleanup(void); diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c index bf60e76f9599..e20b5e85c1b3 100644 --- a/fs/crypto/keyinfo.c +++ b/fs/crypto/keyinfo.c @@ -385,8 +385,7 @@ find_and_lock_keyring_key(const char *prefix, } static struct fscrypt_master_key * -load_master_key_from_keyring(const struct inode *inode, - const u8 descriptor[FS_KEY_DESCRIPTOR_SIZE], +load_master_key_from_keyring(const u8 descriptor[FS_KEY_DESCRIPTOR_SIZE], unsigned int min_keysize) { struct key *keyring_key; @@ -395,11 +394,6 @@ load_master_key_from_keyring(const struct inode *inode, keyring_key = find_and_lock_keyring_key(FS_KEY_DESC_PREFIX, descriptor, min_keysize, &payload); - if (keyring_key == ERR_PTR(-ENOKEY) && inode->i_sb->s_cop->key_prefix) { - keyring_key = find_and_lock_keyring_key( - inode->i_sb->s_cop->key_prefix, - descriptor, min_keysize, &payload); - } if (IS_ERR(keyring_key)) return ERR_CAST(keyring_key); @@ -441,8 +435,7 @@ find_or_create_master_key(const struct inode *inode, /* * The needed master key isn't in memory yet. Load it from the keyring. */ - master_key = load_master_key_from_keyring(inode, - ctx->master_key_descriptor, + master_key = load_master_key_from_keyring(ctx->master_key_descriptor, min_keysize); if (IS_ERR(master_key)) return master_key; @@ -676,8 +669,7 @@ void __exit fscrypt_essiv_cleanup(void) crypto_free_shash(essiv_hash_tfm); } -int fscrypt_compute_key_hash(const struct inode *inode, - const struct fscrypt_policy *policy, +int fscrypt_compute_key_hash(const struct fscrypt_policy *policy, u8 hash[FSCRYPT_KEY_HASH_SIZE]) { struct fscrypt_master_key *k; @@ -691,7 +683,7 @@ int fscrypt_compute_key_hash(const struct inode *inode, max(available_modes[policy->contents_encryption_mode].keysize, available_modes[policy->filenames_encryption_mode].keysize); - k = load_master_key_from_keyring(inode, policy->master_key_descriptor, + k = load_master_key_from_keyring(policy->master_key_descriptor, min_keysize); if (IS_ERR(k)) return PTR_ERR(k); diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 7661c66a3533..cd8c9c7cc9a9 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -117,7 +117,7 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg) pr_warn_once("%s (pid %d) is setting less secure v0 encryption policy; recommend upgrading to v2.\n", current->comm, current->pid); } else { - ret = fscrypt_compute_key_hash(inode, &policy, key_hash); + ret = fscrypt_compute_key_hash(&policy, key_hash); if (ret) return ret; }