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: 754484 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBg0d0MRpz9s8S for ; Tue, 25 Apr 2017 07:46:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="u2CmJF+S"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Ch2mrSScrnhLISLn8SpwO6CM4ElL7iaIociLC3TNGuI=; b=u2C mJF+S7yw0h2ZiHd9udkwKLCSwF4BGihoO/3V10m8nH572UYDSFQjRaDh69ONtxyc3AeweatZGhcfJ RnPe1Gqp7t9esiA54jmqLneQdMvZWSD0P01VUSSzBCnph7Ripz9iNwIFVByk2G1qgfaQxJPEtHjBq bAlemGO6k6PHymJbuRDCENrcPyfqpdxU+v05O2IQ1KV3I3EiDX5sDpKVMu5Wubc99ePqaK8OvPQqN p69Mc6++IM8eRXxDpd3fvicWGmFkg23VME95ZPTO+wrGf9SsnkwE59+x3r8aJ9Cg5eQQglPEmLDSS VQBnMeuepRe7QlSdWOrtutWE8CZSScg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d2lor-0001U9-3h; Mon, 24 Apr 2017 21:46:53 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d2lon-0001SP-2C for linux-mtd@lists.infradead.org; Mon, 24 Apr 2017 21:46:51 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170424_144649_275099_28F80A9B X-CRM114-Status: UNSURE ( 9.31 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, david@sigma-star.at, David Oberhollenzer MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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) &&