From patchwork Wed Nov 29 20:43:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10083581 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 8C3466020B for ; Wed, 29 Nov 2017 20:44:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CC7429C1A for ; Wed, 29 Nov 2017 20:44:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7186129C18; Wed, 29 Nov 2017 20:44:20 +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 0C6D629C17 for ; Wed, 29 Nov 2017 20:44:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586AbdK2UoT (ORCPT ); Wed, 29 Nov 2017 15:44:19 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:44527 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752361AbdK2UoT (ORCPT ); Wed, 29 Nov 2017 15:44:19 -0500 Received: by mail-it0-f65.google.com with SMTP id b5so5644027itc.3 for ; Wed, 29 Nov 2017 12:44:19 -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=6lb9r2Tpng3MeYboqwqNi3q0hyK/1KeRugukBanQDpk=; b=l09MbJ6mVOwK3rT4AMmOZ/9cIIMv3evAVqRWbXq/lHGL1TGebI9a+NZqsRRevQldiH 95QuzklpiRniHdPUe+6AXtpMft/t9euKTl9RrNhfAqspcUywpAz19a6OgQEjvop0/129 MdTXmXVgSy+vGyppeiBezKsXA8rSbQShh7wVYnHdA4Krho/S9dqHwZ9AkR+l49XU3nt5 10tGlI2pcW5q2caqiUDYJBFv03gil2NQKxq0C5d4xoShzL0znd7Ecxp6oiGIY+cyePPZ 11lUUTHYn/Vit2nOnxIjlcN+QI8E55N/sCVCkybZ/SU6NFIOzEqx4kwTWhz0Dh8Q2aP4 b2gg== 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=6lb9r2Tpng3MeYboqwqNi3q0hyK/1KeRugukBanQDpk=; b=rCX+nj7mW94KPIb45uU62y3uSEFTtsxVad35SwFu5iGpJe+GZT0fAkCIi0vj+34nUm gja/s/2Bow7igxCNCZwu0BAHRF5dN5mJ+wRgdcCJia2pBAbJsbyxALcrWw0V2vub70WE Y253E0MIw+dD114Na8/j1XI3XIkxXFtQvXpnxIYjfqB3bhI4BJkz/wJA7zIEP/+vxxko AJV5xCjfbNsModfckZ5O3rdMaS3qvIMNv+MQNOvX9id6YPCnN/eLWICZ0yPNo043hbjR l/f1tV/AvuCd9IWYVRYUaPcVW0vJxiHAi+x6955ZN5RgOtns67JseYC5q791yuge+Is8 z4zA== X-Gm-Message-State: AJaThX5gKMUdimYR7bT4C1xSLKeHSmZdZlTihZgafLbI45YiF96ry+l+ IOV7NXe16Ys0ldGV8XImhRZvgqvDtts= X-Google-Smtp-Source: AGs4zMbWmEgEiX/bllaJQ570ctrqiCBp0Ao0hStI6dFvV0GIRt6lco1P4d2rhPH9bFzpqEBxqbytQg== X-Received: by 10.36.20.68 with SMTP id 65mr94882itg.147.1511988258562; Wed, 29 Nov 2017 12:44:18 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.175.88]) by smtp.gmail.com with ESMTPSA id l4sm1111112ioc.69.2017.11.29.12.44.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Nov 2017 12:44:18 -0800 (PST) From: Eric Biggers To: linux-mtd@lists.infradead.org, Richard Weinberger Cc: linux-fscrypt@vger.kernel.org, Artem Bityutskiy , Adrian Hunter , Eric Biggers Subject: [PATCH v2 3/5] ubifs: switch to fscrypt_prepare_rename() Date: Wed, 29 Nov 2017 12:43:15 -0800 Message-Id: <20171129204317.91205-4-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.0.531.g2ccb3012c9-goog In-Reply-To: <20171129204317.91205-1-ebiggers3@gmail.com> References: <20171129204317.91205-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 Signed-off-by: Eric Biggers --- fs/ubifs/dir.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 09e6c56b11bc..7bf847d79b4a 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1353,12 +1353,6 @@ static int do_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); if (err) @@ -1573,13 +1567,6 @@ 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) || - ubifs_crypt_is_encrypted(new_dir)) && - (old_dir != new_dir) && - (!fscrypt_has_permitted_context(new_dir, fst_inode) || - !fscrypt_has_permitted_context(old_dir, snd_inode))) - return -EPERM; - err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &fst_nm); if (err) return err; @@ -1624,12 +1611,19 @@ static int ubifs_rename(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_WHITEOUT | RENAME_EXCHANGE)) return -EINVAL; ubifs_assert(inode_is_locked(old_dir)); ubifs_assert(inode_is_locked(new_dir)); + err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry, + flags); + if (err) + return err; + if (flags & RENAME_EXCHANGE) return ubifs_xrename(old_dir, old_dentry, new_dir, new_dentry);