From patchwork Thu Mar 17 09:02:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 8608351 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CDDA29F6E1 for ; Thu, 17 Mar 2016 09:01:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 585482022A for ; Thu, 17 Mar 2016 09:01:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF79F202EC for ; Thu, 17 Mar 2016 09:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933413AbcCQJB1 (ORCPT ); Thu, 17 Mar 2016 05:01:27 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:32892 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932799AbcCQJA6 (ORCPT ); Thu, 17 Mar 2016 05:00:58 -0400 Received: by mail-wm0-f68.google.com with SMTP id x188so5461278wmg.0 for ; Thu, 17 Mar 2016 02:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZZhRr49+gxn+b5/KGWmvFfwLdGxv5yxfp063jwWuC2c=; b=SoD7LWywDV7ptCppOydTOPeb7Y7eCHFJivpm2RdbEmAAbg9A980VuASlv/2xJrxphy GKF666i+jDD388X+lt8x9xq+BvudU6B8Ene5aZQOk+hWMpTUJFbsGIFRhU73vBPmgGKI V2Xo5prHxzk5p4yRgugFr21RtKr1KBhIDe/Qw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZZhRr49+gxn+b5/KGWmvFfwLdGxv5yxfp063jwWuC2c=; b=GuTYQ45M9yCC/K12aDYFu6aRPyemDXWx6emTE9smiMzNHgTwrx9myowYqYdL2xIJ+5 kGTpo933J9VXedwVC1X0ViBj/JczPK9jDzRERRjWTPY+7erZgCY1yMtEq2FNEUco1dAz F6V0MccrUBBBzNXLsDLbyiOWxYW/dKplscgKlKTzAS2OASYm1ViODQb2OKmKXxCJLqzP LIkXgdHaiDUMFK0CWU7EnNqvUhD/qdIqdv3racr7yYi6VUUfcZZ4LybkuU3p5QuQTb6B gtUM9+6laBPjCNsqR256xlOIiK5yX3NeoCSIRgYEEtvUpl3PABCDcU3ZgeEEx3kTsFxk QWvg== X-Gm-Message-State: AD7BkJJh5O6q0sK4hTrmBsqNwrvBepL9n/+HS4LQaPyWR2nYVCuKD6KophKQPC96Mko3Bw== X-Received: by 10.28.184.148 with SMTP id i142mr9574111wmf.22.1458205256900; Thu, 17 Mar 2016 02:00:56 -0700 (PDT) Received: from tucsk.pomaz.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id n66sm7110841wmg.20.2016.03.17.02.00.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 02:00:56 -0700 (PDT) From: Miklos Szeredi To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: dhowells@redhat.com, viro@zeniv.linux.org.uk, Theodore Ts'o , Subject: [PATCH 3/4] ext4: use dget_parent() in ext4_file_open() Date: Thu, 17 Mar 2016 10:02:02 +0100 Message-Id: <1458205323-25685-3-git-send-email-miklos@szeredi.hu> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458205323-25685-1-git-send-email-miklos@szeredi.hu> References: <1458205323-25685-1-git-send-email-miklos@szeredi.hu> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miklos Szeredi In f_op->open() lock on parent is not held, so there's no guarantee that parent dentry won't go away at any time. Even after this patch there's no guarantee that 'dir' will stay the parent of 'inode', but at least it won't be freed while being used. Fixes: ff978b09f973 ("ext4 crypto: move context consistency check to ext4_file_open()") Signed-off-by: Miklos Szeredi Cc: Theodore Ts'o Cc: # v4.5 --- fs/ext4/file.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 4cd318f31cbe..feb9ffc6f20d 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -335,7 +335,7 @@ 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 inode *dir = filp->f_path.dentry->d_parent->d_inode; + struct dentry *dir; struct path path; char buf[64], *cp; int ret; @@ -379,14 +379,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp) if (ext4_encryption_info(inode) == NULL) return -ENOKEY; } - if (ext4_encrypted_inode(dir) && - !ext4_is_child_context_consistent_with_parent(dir, inode)) { + + dir = dget_parent(filp->f_path.dentry); + if (ext4_encrypted_inode(d_inode(dir)) && + !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) { ext4_warning(inode->i_sb, "Inconsistent encryption contexts: %lu/%lu\n", - (unsigned long) dir->i_ino, + (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