From patchwork Mon Apr 24 21:46:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 9697293 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 5F6DF601E9 for ; Mon, 24 Apr 2017 21:46:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5375428066 for ; Mon, 24 Apr 2017 21:46:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47532283FE; Mon, 24 Apr 2017 21:46:31 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 B2F8428066 for ; Mon, 24 Apr 2017 21:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S978456AbdDXVqa (ORCPT ); Mon, 24 Apr 2017 17:46:30 -0400 Received: from mail.sigma-star.at ([95.130.255.111]:45996 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S978420AbdDXVq3 (ORCPT ); Mon, 24 Apr 2017 17:46:29 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id 3FCAD24E0002; Mon, 24 Apr 2017 23:46:26 +0200 (CEST) Received: from linux.site (richard.vpn.sigmapriv.at [10.3.0.5]) by mail.sigma-star.at (Postfix) with ESMTPSA id 7319A24E0001; Mon, 24 Apr 2017 23:46:25 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, david@sigma-star.at, David Oberhollenzer , Richard Weinberger Subject: [PATCH] ubifs: Return -ENOKEY from rename if encryption keys are missing Date: Mon, 24 Apr 2017 23:46:21 +0200 Message-Id: <1493070381-20075-1-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 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: David Oberhollenzer If either source or destination directory is encrypted and the encryption key is unknown, make sure we return -ENOKEY instead of -EPERM, similar to how this case is handled in ext4. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index ff77a0aa2f2b..c342f23581d2 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1340,6 +1340,12 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlink) ubifs_assert(inode_is_locked(new_inode)); + if ((ubifs_crypt_is_encrypted(old_dir) && + !fscrypt_has_encryption_key(old_dir)) || + (ubifs_crypt_is_encrypted(new_dir) && + !fscrypt_has_encryption_key(new_dir))) + return -ENOKEY; + if (old_dir != new_dir) { if (ubifs_crypt_is_encrypted(new_dir) && !fscrypt_has_permitted_context(new_dir, old_inode)) @@ -1564,6 +1570,12 @@ static int ubifs_xrename(struct inode *old_dir, struct dentry *old_dentry, ubifs_assert(fst_inode && snd_inode); + if ((ubifs_crypt_is_encrypted(old_dir) && + !fscrypt_has_encryption_key(old_dir)) || + (ubifs_crypt_is_encrypted(new_dir) && + !fscrypt_has_encryption_key(new_dir))) + return -ENOKEY; + if ((ubifs_crypt_is_encrypted(old_dir) || ubifs_crypt_is_encrypted(new_dir)) && (old_dir != new_dir) &&