From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric W. Biederman" Subject: [PATCH 08/23] vfs: Teach readdir to use file_hotplug_lock Date: Mon, 1 Jun 2009 14:50:33 -0700 Message-ID: <1243893048-17031-8-git-send-email-ebiederm@xmission.com> References: Cc: , , , , Hugh Dickins , Tejun Heo , Alexey Dobriyan , Linus Torvalds , Alan Cox , Greg Kroah-Hartman , Nick Piggin , Andrew Morton , Christoph Hellwig , "Eric W. Biederman" , "Eric W. Biederman" To: Al Viro Return-path: Received: from out01.mta.xmission.com ([166.70.13.231]:43355 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753653AbZFAVu6 (ORCPT ); Mon, 1 Jun 2009 17:50:58 -0400 In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Eric W. Biederman Signed-off-by: Eric W. Biederman --- fs/readdir.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/readdir.c b/fs/readdir.c index 7723401..2e147cf 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -21,18 +21,26 @@ int vfs_readdir(struct file *file, filldir_t filler, void *buf) { - struct inode *inode = file->f_path.dentry->d_inode; - int res = -ENOTDIR; - if (!file->f_op || !file->f_op->readdir) + struct inode *inode; + int res; + + res = -EIO; + if (!file_hotplug_read_trylock(file)) goto out; + inode = file->f_path.dentry->d_inode; + + res = -ENOTDIR; + if (!file->f_op || !file->f_op->readdir) + goto out_unlock; + res = security_file_permission(file, MAY_READ); if (res) - goto out; + goto out_unlock; res = mutex_lock_killable(&inode->i_mutex); if (res) - goto out; + goto out_unlock; res = -ENOENT; if (!IS_DEADDIR(inode)) { @@ -40,6 +48,8 @@ int vfs_readdir(struct file *file, filldir_t filler, void *buf) file_accessed(file); } mutex_unlock(&inode->i_mutex); +out_unlock: + file_hotplug_read_unlock(file); out: return res; } -- 1.6.3.1.54.g99dd.dirty