Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9529062ybl; Fri, 17 Jan 2020 13:44:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxqLh667Mf+/w2WzwGIjYypfNncPwbZAvyd/uM6/BcncXaHzGd/aM13cmGp3qXo9hGL382c X-Received: by 2002:aca:4a08:: with SMTP id x8mr5068933oia.39.1579297464491; Fri, 17 Jan 2020 13:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579297464; cv=none; d=google.com; s=arc-20160816; b=MBDvlbI7DJuaTxfmKZ5EwGmId3H80+tUUOaBzz7oTlIGd7gJ+4fMOpItxqN54Ss8KI Vj8Rf6zYKCfwdJXUYy0keUkYZixrw6voPPxK6vSJlLfKnttOWaGjd0gRxj/ILaFK3q0q AJk7RVxfdPiyUlVxUmaX3i5/CxjMlXOQFp7b+H/Krj5JCG0iDot9//11RjL6pltCMyC/ XRxA4YFgO1Z4wHsmXHdt4pi0mK9fiZg+7O3OI3W2n5U8N2za3j0gb/RZQBqxxxvsDcTT xg9P4lPO0bC1HOSbYRVVpWnrOTeXV8ObJzH1mevUFv45T++jytz4PsoJ4rtkRRVW3llQ 8QKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=ijaPqYX9QMZlgJNEqLIabbahqNoro6V7G/0uSLsc++o=; b=TRF0hJ0yZVHseiMisHii1t9Lme1j/h/1bKxpjDsZurbjZUIBt2gLLzokvRWqImTrLA 1pLo2LiBG4i4hnrNvoDNBDX+pGm5XksCLrf+YgtM5wblFYxk5Km1hGYjDHyoy3XV1rwi et+aPVBvRsIt1VWoEYySkeQH5uebCT0hG5ivFGMkGohB7gZsxDaOuQqGxeIYF6jlmaSN lD+9M4ifatr7+MHZT6owUCPeyh1BBtzi28DpfcyTQZBC7cgphEZutpj9icv/5/yFSd3w fTypVANQQvOD2KlmOrzruWWYgSFFSQXGVckHnzL8hFngf4BXMdCrEGla8gAB7uuxoyaL SfFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WHQxC8Nh; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si18257110otf.237.2020.01.17.13.44.14; Fri, 17 Jan 2020 13:44:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WHQxC8Nh; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729064AbgAQVnm (ORCPT + 99 others); Fri, 17 Jan 2020 16:43:42 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:45004 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727033AbgAQVnA (ORCPT ); Fri, 17 Jan 2020 16:43:00 -0500 Received: by mail-pf1-f202.google.com with SMTP id r127so15840160pfc.11 for ; Fri, 17 Jan 2020 13:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ijaPqYX9QMZlgJNEqLIabbahqNoro6V7G/0uSLsc++o=; b=WHQxC8Nh4cFd+mKz0Z5y8hCNfaRWaIIItg6rAD4vRRKh08n1rF1ROJp9bdNhKHjJEe dB+QzSzQk+37KIA3xLEYSV5jYc4LXnUAkScu6uDLEfQxiLJhWSUqLkSk9o/lj3OGUOFv x7d1El6VyYGxobDvLS1U1KrD73lJ1hHS4/+7B8qljX4+5zRjTKVAcKRaD+DQJ+DOSszS Quz0IYsmfSMa9Ytm8SlgE4uCUjy38oOsimu9gdN9/5CWb0bp8uDvRUzsZv7KYdIVZQFk 3LnqAgjGyE/d2ro52ABbHg/HE7dIctRYBIsBeLkMsAqgNdPO0t9LQXQxfHUAMHwqtmvi 0wNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ijaPqYX9QMZlgJNEqLIabbahqNoro6V7G/0uSLsc++o=; b=nOeN5ZRmLd+AoQI3K9XEDkPVa2vq6vidwJTtPIcWkMFA9MnECqr9zu44OpV1UvMWS+ +TwGl2fVrNL9wq4YYm+MVUsXib5+EwOoGQypkcqDPsfJ3UIzp5WxbM0L/oV/16xEOEJ6 K+hnfgFJYYtzVds78YuottkW66idsINKSCb+xvBozYDfjO4ngFR9BDUmohqV+kj4QEuo k5VBzdPutb/AbDgvDr2dfPvmzph0U9mxJhCUGjXeeWv3Ek/dgCWpJgSjXZNYsy3eneGp ITIrooGyV355DXI34mMU7wE1QUwLmeIOGHXzHaDNeYDsnpOv7v4ae0KQm3pXfc7qF00u YJiA== X-Gm-Message-State: APjAAAXJKwQeP2XN+qb2q4iF9bs4XCuQtmbfQJqCKKtkmUMLT8V/qMA/ X+d8RCgcIgQA66YOT9MSCCaUQ7tiZEQ= X-Received: by 2002:a63:3756:: with SMTP id g22mr47225338pgn.375.1579297379818; Fri, 17 Jan 2020 13:42:59 -0800 (PST) Date: Fri, 17 Jan 2020 13:42:39 -0800 In-Reply-To: <20200117214246.235591-1-drosen@google.com> Message-Id: <20200117214246.235591-3-drosen@google.com> Mime-Version: 1.0 References: <20200117214246.235591-1-drosen@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v3 2/9] fscrypt: Don't allow v1 policies with casefolding From: Daniel Rosenberg To: "Theodore Ts'o" , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Alexander Viro Cc: Andreas Dilger , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi , kernel-team@android.com, Daniel Rosenberg Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Casefolding currently requires a derived key for computing the siphash. This is available for v2 policies, but not v1, so we disallow it for v1. Signed-off-by: Daniel Rosenberg --- fs/crypto/policy.c | 28 ++++++++++++++++++++++++++++ fs/inode.c | 3 ++- include/linux/fscrypt.h | 11 +++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index f1cff83c151ac..2cd9a940d8f46 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -124,6 +124,12 @@ static bool fscrypt_supported_v1_policy(const struct fscrypt_policy_v1 *policy, policy->filenames_encryption_mode)) return false; + if (IS_CASEFOLDED(inode)) { + fscrypt_warn(inode, + "v1 policy does not support casefolded directories"); + return false; + } + return true; } @@ -579,3 +585,25 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child, return preload ? fscrypt_get_encryption_info(child): 0; } EXPORT_SYMBOL(fscrypt_inherit_context); + +int fscrypt_ioc_setflags_prepare(struct inode *inode, + unsigned int oldflags, + unsigned int flags) +{ + union fscrypt_policy policy; + int err; + + /* + * When a directory is encrypted, the CASEFOLD flag can only be turned + * on if the fscrypt policy supports it. + */ + if (IS_ENCRYPTED(inode) && (flags & ~oldflags & FS_CASEFOLD_FL)) { + err = fscrypt_get_policy(inode, &policy); + if (err) + return err; + if (policy.version != FSCRYPT_POLICY_V2) + return -EINVAL; + } + + return 0; +} diff --git a/fs/inode.c b/fs/inode.c index 96d62d97694ef..8f6267858d0c1 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" @@ -2252,7 +2253,7 @@ int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags, !capable(CAP_LINUX_IMMUTABLE)) return -EPERM; - return 0; + return fscrypt_ioc_setflags_prepare(inode, oldflags, flags); } EXPORT_SYMBOL(vfs_ioc_setflags_prepare); diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 1dfbed855beeb..2c292f19c6b94 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -142,6 +142,10 @@ extern int fscrypt_ioctl_get_policy_ex(struct file *, void __user *); extern int fscrypt_has_permitted_context(struct inode *, struct inode *); extern int fscrypt_inherit_context(struct inode *, struct inode *, void *, bool); +extern int fscrypt_ioc_setflags_prepare(struct inode *inode, + unsigned int oldflags, + unsigned int flags); + /* keyring.c */ extern void fscrypt_sb_free(struct super_block *sb); extern int fscrypt_ioctl_add_key(struct file *filp, void __user *arg); @@ -383,6 +387,13 @@ static inline int fscrypt_inherit_context(struct inode *parent, return -EOPNOTSUPP; } +static inline int fscrypt_ioc_setflags_prepare(struct inode *inode, + unsigned int oldflags, + unsigned int flags) +{ + return 0; +} + /* keyring.c */ static inline void fscrypt_sb_free(struct super_block *sb) { -- 2.25.0.341.g760bfbb309-goog