Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933459AbcJUMt3 (ORCPT ); Fri, 21 Oct 2016 08:49:29 -0400 Received: from mail.sigma-star.at ([95.130.255.111]:46006 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933138AbcJUMtQ (ORCPT ); Fri, 21 Oct 2016 08:49:16 -0400 From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, dedekind1@gmail.com, adrian.hunter@intel.com, tytso@mit.edu, jaegeuk@kernel.org, david@sigma-star.at, wd@denx.de, sbabic@denx.de, dengler@linutronix.de, Richard Weinberger Subject: [PATCH 10/26] ubifs: Enforce crypto policy in ->link and ->rename Date: Fri, 21 Oct 2016 14:48:25 +0200 Message-Id: <1477054121-10198-11-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1477054121-10198-1-git-send-email-richard@nod.at> References: <1477054121-10198-1-git-send-email-richard@nod.at> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1112 Lines: 38 When a file is moved or linked into another directory its current crypto policy has to be compatible with the target policy. Signed-off-by: Richard Weinberger --- fs/ubifs/dir.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index e80de3852c3e..a77edc5ca5c9 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -544,6 +544,10 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir, ubifs_assert(inode_is_locked(dir)); ubifs_assert(inode_is_locked(inode)); + if (ubifs_crypt_is_encrypted(dir) && + !fscrypt_has_permitted_context(dir, inode)) + return -EPERM; + err = dbg_check_synced_i_size(c, inode); if (err) return err; @@ -1027,6 +1031,11 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlink) ubifs_assert(inode_is_locked(new_inode)); + if (old_dir != new_dir) { + if (ubifs_crypt_is_encrypted(new_dir) && + !fscrypt_has_permitted_context(new_dir, old_inode)) + return -EPERM; + } if (unlink && is_dir) { err = ubifs_check_dir_empty(new_inode); -- 2.7.3