From patchwork Wed Nov 29 20:35:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10083561 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 D3B526020B for ; Wed, 29 Nov 2017 20:36:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C70E129BC8 for ; Wed, 29 Nov 2017 20:36:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBDB429BFC; Wed, 29 Nov 2017 20:36:58 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 6B44E29BFF for ; Wed, 29 Nov 2017 20:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752769AbdK2Ug4 (ORCPT ); Wed, 29 Nov 2017 15:36:56 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:38443 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752722AbdK2Ugz (ORCPT ); Wed, 29 Nov 2017 15:36:55 -0500 Received: by mail-it0-f67.google.com with SMTP id r6so5745403itr.3 for ; Wed, 29 Nov 2017 12:36:54 -0800 (PST) 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=4kOCr7Wv070LirxrD+POWfCrKh432CFkpVUBOd7Qvd8=; b=fJh906IqTm0v4bo2ALGoXuzVkPB6r/F3lQdzXOf3sx29TLS6ThaduRSeoO6orpmelH nygTbbIf1Zh3zXYsqwsfFcdBXsFQfFuXArdrInQLBrCj2F6g1YI2uvnCmyJCntT7X/xv wRSlGRYuausWv1ScY8UqU067W6bLZ5jifHsX+Lj2o5dKpAzdhBHHib9FENgmn79lvEZ8 MtEmfI8p14I0lXLGhg0byefCHsWEfwj9yN2Jytcx80vTmHiWRntYm+VG1idoxMvbboVK pnaCPJc4h0DT1hA188YVtrpQ4JR+gB9cqtidmn3dRtBal7MaIb3ROYerNhf2EujlnIaT 9A2Q== 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=4kOCr7Wv070LirxrD+POWfCrKh432CFkpVUBOd7Qvd8=; b=XePLeVfXc3XAljoxGHUpNljaXEyGnkWJErTFZeD/zS/TbugoxqIA5jbddvScNj0Esh q+39fz4x/cdFqEdbMKd/rHSod2tHaX+oKhPiNrANWjpxN2BRRSEgU7GgaPSnLZRaX4Gp 1FqyKAESG1TjDnEv6bHyjUZHl3IMl7JOZ0WU0EJ8Sw9EVOyDOBpYexh/Fi4GeyAOyU6t ZDGZNkzjVGQmb297YLOdD3kY6S5SH75lcJsrMkK/PwfMloVTYCmMQsp+4+FqMJ6tRTUB B24Ql7x6O0p2RCnMKvlRmDN6UnKp+qAolICIBt6utSM12qJ+JnIiHzpNA+L72GfQwnYq Oyaw== X-Gm-Message-State: AJaThX4PpYWY5Fg4C7Q3cfr7jlYS3Gy7BvcnRUEuta/0/xMurG8qsIu4 vHEEWWW5p7g0pEllfyMyLP0= X-Google-Smtp-Source: AGs4zMZUI+bd+/3ca080b2XkzTh1fs9LOXwqz2L6u1ikHmTBiJE2YJ974ZRzu77xfBHloinss6uN4A== X-Received: by 10.36.148.6 with SMTP id j6mr118090ite.104.1511987814388; Wed, 29 Nov 2017 12:36:54 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.175.88]) by smtp.gmail.com with ESMTPSA id 15sm1149652ioj.80.2017.11.29.12.36.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Nov 2017 12:36:53 -0800 (PST) From: Eric Biggers To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , linux-fscrypt@vger.kernel.org, Eric Biggers Subject: [PATCH v2 3/5] f2fs: switch to fscrypt_prepare_rename() Date: Wed, 29 Nov 2017 12:35:30 -0800 Message-Id: <20171129203532.87729-4-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.0.531.g2ccb3012c9-goog In-Reply-To: <20171129203532.87729-1-ebiggers3@gmail.com> References: <20171129203532.87729-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 Reviewed-by: Chao Yu Signed-off-by: Eric Biggers --- fs/f2fs/namei.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index dcf5c3a97059..e910d2ebe0c6 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -800,18 +800,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - if ((f2fs_encrypted_inode(old_dir) && - !fscrypt_has_encryption_key(old_dir)) || - (f2fs_encrypted_inode(new_dir) && - !fscrypt_has_encryption_key(new_dir))) - return -ENOKEY; - - if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) && - !fscrypt_has_permitted_context(new_dir, old_inode)) { - err = -EPERM; - goto out; - } - if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && (!projid_eq(F2FS_I(new_dir)->i_projid, F2FS_I(old_dentry->d_inode)->i_projid))) @@ -1002,18 +990,6 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - if ((f2fs_encrypted_inode(old_dir) && - !fscrypt_has_encryption_key(old_dir)) || - (f2fs_encrypted_inode(new_dir) && - !fscrypt_has_encryption_key(new_dir))) - return -ENOKEY; - - if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) && - (old_dir != new_dir) && - (!fscrypt_has_permitted_context(new_dir, old_inode) || - !fscrypt_has_permitted_context(old_dir, new_inode))) - return -EPERM; - if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && !projid_eq(F2FS_I(new_dir)->i_projid, F2FS_I(old_dentry->d_inode)->i_projid)) || @@ -1153,9 +1129,16 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { + int err; + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) return -EINVAL; + err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry, + flags); + if (err) + return err; + if (flags & RENAME_EXCHANGE) { return f2fs_cross_rename(old_dir, old_dentry, new_dir, new_dentry);