From patchwork Mon Dec 19 19:15:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9480677 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 881DA601C2 for ; Mon, 19 Dec 2016 19:15:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A21F284CA for ; Mon, 19 Dec 2016 19:15:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EB90284D5; Mon, 19 Dec 2016 19:15:59 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 029FE284CA for ; Mon, 19 Dec 2016 19:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755042AbcLSTP5 (ORCPT ); Mon, 19 Dec 2016 14:15:57 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36221 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754720AbcLSTP4 (ORCPT ); Mon, 19 Dec 2016 14:15:56 -0500 Received: by mail-pg0-f67.google.com with SMTP id w68so3291150pgw.3 for ; Mon, 19 Dec 2016 11:15:56 -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; bh=I42aMW/r2s73qCBwXdzmOmbgNYYaqf5qY+CBy5XDwFE=; b=GJJAVsCHvqYMFp8MHOOc/Ropgyg0LPdXl+ipxpj2XafUZ4XfVqPOl7rEv4NnUxKF6O O9p3BE+OlfxWhnXfwb4GuFJXeR8s5XS/X8Po5lkFH2JQudTTOubF/8DDMebHKEtusd1I qKPb+qTKNrq52zmEhlODWM7yhDdcs6R/VmkeaogQMF/8wHLMedhGJzGi4Jqphig/BnWc U1DNyLNKouzUd2wdwlCHGobYr5uJVhwLXeqy9IZxTt9/+SD/CcpMb7+86YuwKfif3bZV qOzpIlthY3QiVvljjR1LaqH8HiMmLe6158P4ItfbXwR9pAIGNzXghjSu6uieg3OEDJtF 9y7A== 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; bh=I42aMW/r2s73qCBwXdzmOmbgNYYaqf5qY+CBy5XDwFE=; b=KSf7TIq34len0KALZGnrm6zlFRBEctRMskbad9pttFLXnEdAZUgFvgqUzabaG/kqCH aH4sBgoJO+TH6kvyYayTZK1/HzDW4Wb+EZLM/YpXKwdADhk/B5jZVkvJ1jyD6bJbkN7h TzcoCe+YyuswmXLcl0f37jPpUr6dl+Gm2bbZNGORFA/DKxddn4M70LwxNigCmBDBk44J G/T1Dxo+PKSjBZNoxvSqy85PFPnMq8Fu4Th3RFjIRIIqWDVl1WcUm19DtRP1OlNSAYaT InFz1viK1Q+53cvTdsloG8an/hTwON3+SCpo2KrdcQMgTrci0NsF2Y5WHKdmBDMLZfsw 9UEA== X-Gm-Message-State: AKaTC00WwWQe+YZFSJEibdoFIYkZRfXNxHdZspJwM4F/MO/f1slpUAJvV3j9rJlpdodUdw== X-Received: by 10.84.133.69 with SMTP id 63mr37656805plf.15.1482174955788; Mon, 19 Dec 2016 11:15:55 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id a11sm33252540pfe.96.2016.12.19.11.15.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Dec 2016 11:15:55 -0800 (PST) From: Eric Biggers To: linux-mtd@lists.infradead.org Cc: Richard Weinberger , Artem Bityutskiy , Adrian Hunter , linux-fsdevel@vger.kernel.org, Eric Biggers Subject: [PATCH] ubifs: remove redundant checks for encryption key Date: Mon, 19 Dec 2016 11:15:48 -0800 Message-Id: <1482174948-104602-1-git-send-email-ebiggers3@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers In several places, ubifs checked for an encryption key before creating a file in an encrypted directory. This was redundant with fscrypt_setup_filename() or ubifs_new_inode(), and in the case of ubifs_link() it broke linking to special files. So remove the extra checks. Signed-off-by: Eric Biggers --- fs/ubifs/dir.c | 58 +++------------------------------------------------------- 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 9de9eaa..d346f1e 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -400,16 +400,6 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry, dbg_gen("dent '%pd', mode %#hx in dir ino %lu", dentry, mode, dir->i_ino); - if (ubifs_crypt_is_encrypted(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) - return err; - - if (!fscrypt_has_encryption_key(dir)) { - return -EPERM; - } - } - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); if (err) return err; @@ -751,17 +741,9 @@ 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)) { - if (!fscrypt_has_permitted_context(dir, inode)) - return -EPERM; - - err = fscrypt_get_encryption_info(inode); - if (err) - return err; - - if (!fscrypt_has_encryption_key(inode)) - return -EPERM; - } + if (ubifs_crypt_is_encrypted(dir) && + !fscrypt_has_permitted_context(dir, inode)) + return -EPERM; err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); if (err) @@ -1010,17 +992,6 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) if (err) return err; - if (ubifs_crypt_is_encrypted(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) - goto out_budg; - - if (!fscrypt_has_encryption_key(dir)) { - err = -EPERM; - goto out_budg; - } - } - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); if (err) goto out_budg; @@ -1106,17 +1077,6 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry, return err; } - if (ubifs_crypt_is_encrypted(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) - goto out_budg; - - if (!fscrypt_has_encryption_key(dir)) { - err = -EPERM; - goto out_budg; - } - } - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); if (err) goto out_budg; @@ -1241,18 +1201,6 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, goto out_inode; } - err = fscrypt_get_encryption_info(inode); - if (err) { - kfree(sd); - goto out_inode; - } - - if (!fscrypt_has_encryption_key(inode)) { - kfree(sd); - err = -EPERM; - goto out_inode; - } - ostr.name = sd->encrypted_path; ostr.len = disk_link.len;