From patchwork Tue Apr 12 23:31:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 8817311 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 668509F54F for ; Tue, 12 Apr 2016 23:31:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CEC32021A for ; Tue, 12 Apr 2016 23:31:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C9C4201FE for ; Tue, 12 Apr 2016 23:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965937AbcDLXb1 (ORCPT ); Tue, 12 Apr 2016 19:31:27 -0400 Received: from mail.kernel.org ([198.145.29.136]:57332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964879AbcDLXb0 (ORCPT ); Tue, 12 Apr 2016 19:31:26 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAFD420219; Tue, 12 Apr 2016 23:31:24 +0000 (UTC) Received: from localhost (107-1-141-74-ip-static.hfc.comcastbusiness.net [107.1.141.74]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00520201FE; Tue, 12 Apr 2016 23:31:23 +0000 (UTC) Date: Tue, 12 Apr 2016 16:31:23 -0700 From: Jaegeuk Kim To: Al Viro Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Theodore Ts'o Subject: Re: [PATCH 1/3] fscrypto: use dget_parent() in fscrypt_d_revalidate() Message-ID: <20160412233123.GA17607@jaegeuk.gateway> References: <1460482042-14011-1-git-send-email-jaegeuk@kernel.org> <20160412223303.GQ25498@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160412223303.GQ25498@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 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 On Tue, Apr 12, 2016 at 11:33:03PM +0100, Al Viro wrote: > On Tue, Apr 12, 2016 at 10:27:20AM -0700, Jaegeuk Kim wrote: > > This patch updates fscrypto along with the below ext4 crypto change. > > > > Fixes: 3d43bcfef5f0 ("ext4 crypto: use dget_parent() in ext4_d_revalidate()") > > > static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) > > { > > - struct inode *dir = d_inode(dentry->d_parent); > > - struct fscrypt_info *ci = dir->i_crypt_info; > > + struct dentry *dir; > > + struct fscrypt_info *ci; > > int dir_has_key, cached_with_key; > > > > - if (!dir->i_sb->s_cop->is_encrypted(dir)) > > + dir = dget_parent(dentry); > > + if (!d_inode(dir)->i_sb->s_cop->is_encrypted(d_inode(dir))) { > > + dput(dir); > > ... and as soon as you call it from RCU mode, you are screwed. Thank you for pointing this out. IIUC, did you mean this? Thanks, From a0ac7972189b7c366720a0b456e39516d622a6d4 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Tue, 12 Apr 2016 16:05:36 -0700 Subject: [PATCH] ext4/fscrypto: avoid RCU lookup in d_revalidate As Al pointed, d_revalidate should return RCU lookup before using d_inode. This was originally introduced by: commit 34286d666230 ("fs: rcu-walk aware d_revalidate method"). Reported-by: Al Viro Signed-off-by: Jaegeuk Kim Cc: Theodore Ts'o Cc: stable --- fs/crypto/crypto.c | 4 ++++ fs/ext4/crypto.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index da70520..2fc8c43 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -353,6 +354,9 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) struct fscrypt_info *ci; int dir_has_key, cached_with_key; + if (flags & LOOKUP_RCU) + return -ECHILD; + dir = dget_parent(dentry); if (!d_inode(dir)->i_sb->s_cop->is_encrypted(d_inode(dir))) { dput(dir); diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index db9ae6e..6a6c273 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "ext4_extents.h" #include "xattr.h" @@ -482,6 +483,9 @@ static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags) struct ext4_crypt_info *ci; int dir_has_key, cached_with_key; + if (flags & LOOKUP_RCU) + return -ECHILD; + dir = dget_parent(dentry); if (!ext4_encrypted_inode(d_inode(dir))) { dput(dir);