From patchwork Mon Dec 19 22:20:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9480797 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 061E4601C2 for ; Mon, 19 Dec 2016 22:21:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2BB2837F for ; Mon, 19 Dec 2016 22:21:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFB87284FC; Mon, 19 Dec 2016 22:21:09 +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 8AB092837F for ; Mon, 19 Dec 2016 22:21:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754325AbcLSWVG (ORCPT ); Mon, 19 Dec 2016 17:21:06 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:34915 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754285AbcLSWVF (ORCPT ); Mon, 19 Dec 2016 17:21:05 -0500 Received: by mail-it0-f65.google.com with SMTP id b123so11987443itb.2 for ; Mon, 19 Dec 2016 14:21:05 -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=nA7U0Pj6OI8s5o5vT7/KFXQAwniZQeTD6qjKawXiFHM=; b=UjEFPU8x/BpQgO4DLcrZrEL41IL/Bl7ciXke0HS12vfKLG3EplAbBcGz4ATj0ienk0 BnIDAGDg3TJ7jOsZ3n+Wvy7sXGAEikAlBR26AKyUpbHV4QZdqQLBLYPCxXCxa2ocTcIV yhdE+mT71sqiVSp6/GxwryyuHPmcRDz8fc5E+Tlr0izqEG1Vjd7ZHYoZDgMyq87M3/mD 0nX7hio+UEbMDFDvWRZt6hLkkPd1IS0T3MOwr/7CvMkQW8IkVdVOjLTCsPC6WhOJ8dj2 POjXNvdjJ//u2nR7GoQKyQd3jkoDme7rKu7P6jhN5S1uOTzidO4f45J7bSvWffWH0YL7 d+pw== 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=nA7U0Pj6OI8s5o5vT7/KFXQAwniZQeTD6qjKawXiFHM=; b=UWy2oMi7m5nTfPfNv2mhJFUu9+U4E+GWEVrVnlYkSlbdOYle3LAWmzZsN2F1ND2Bcj S134CICYuoSm1PViUuaIfhapKgUuta0AVcKgukz7AQKvsOGs7HpSSd2CEUtgquHgJSOt CSc8jZo2G5vXB3Tobt3sQGl/4iujHmHFmpu1PJvIn5UIgyijtuCnsVmJrgJjnB9oRIiD 8FGEBjyrC1U3ZYidP09+nLts/mINOsYhk4GhnZuZdtv0cnFspTfmfvLs0fJB345ZaV4I Qqaf5Ums02Ta6BcyLJDlFD9IcmpVmpZdCRNuqiljKgev+wBh/034CS0cUHIrE1w4qrJr aPDg== X-Gm-Message-State: AKaTC00CoCTIZWw3smYW1IIRKZa0+MxfbkI+eH1uUt7RRWlbwaT49N2HseaMsNJotLABQg== X-Received: by 10.36.196.135 with SMTP id v129mr19692916itf.100.1482186064746; Mon, 19 Dec 2016 14:21:04 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id g186sm7687106itb.21.2016.12.19.14.21.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Dec 2016 14:21:04 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: "Theodore Y . Ts'o" , Jaegeuk Kim , Richard Weinberger , Eric Biggers Subject: [PATCH v2 3/5] ext4: consolidate fscrypt_has_permitted_context() checks Date: Mon, 19 Dec 2016 14:20:14 -0800 Message-Id: <1482186016-107643-3-git-send-email-ebiggers3@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1482186016-107643-1-git-send-email-ebiggers3@gmail.com> References: <1482186016-107643-1-git-send-email-ebiggers3@gmail.com> 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 Now that fscrypt_has_permitted_context() compares the fscrypt_context rather than the fscrypt_info when needed, it is no longer necessary to delay fscrypt_has_permitted_context() from ->lookup() to ->open() for regular files, as introduced in commit ff978b09f973 ("ext4 crypto: move context consistency check to ext4_file_open()"). Therefore the check in ->open(), along with the dget_parent() hack, can be removed. It's also no longer necessary to check the file type before calling fscrypt_has_permitted_context(). This patch should not be applied before my other two patches: fscrypt: fix loophole in one-encryption-policy-per-tree enforcement fscrypt: fix renaming and linking special files Signed-off-by: Eric Biggers --- fs/ext4/file.c | 12 ------------ fs/ext4/namei.c | 10 ++-------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index b5f1844..2123cd8 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -398,7 +398,6 @@ static int ext4_file_open(struct inode * inode, struct file * filp) struct super_block *sb = inode->i_sb; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct vfsmount *mnt = filp->f_path.mnt; - struct dentry *dir; struct path path; char buf[64], *cp; int ret; @@ -443,17 +442,6 @@ static int ext4_file_open(struct inode * inode, struct file * filp) return -ENOKEY; } - dir = dget_parent(file_dentry(filp)); - if (ext4_encrypted_inode(d_inode(dir)) && - !fscrypt_has_permitted_context(d_inode(dir), inode)) { - ext4_warning(inode->i_sb, - "Inconsistent encryption contexts: %lu/%lu", - (unsigned long) d_inode(dir)->i_ino, - (unsigned long) inode->i_ino); - dput(dir); - return -EPERM; - } - dput(dir); /* * Set up the jbd2_inode if we are opening the inode for * writing and the journal is present diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index eadba91..eb8b064 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1612,17 +1612,11 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi return ERR_PTR(-EFSCORRUPTED); } if (!IS_ERR(inode) && ext4_encrypted_inode(dir) && - (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && !fscrypt_has_permitted_context(dir, inode)) { - int nokey = ext4_encrypted_inode(inode) && - !fscrypt_has_encryption_key(inode); - iput(inode); - if (nokey) - return ERR_PTR(-ENOKEY); ext4_warning(inode->i_sb, "Inconsistent encryption contexts: %lu/%lu", - (unsigned long) dir->i_ino, - (unsigned long) inode->i_ino); + dir->i_ino, inode->i_ino); + iput(inode); return ERR_PTR(-EPERM); } }