From: Trond Myklebust <Trond.Myklebust@netapp.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH 24/24] NFS: Prevent the mount code from looping forever on broken exports
Date: Fri, 16 Apr 2010 16:31:22 -0400 [thread overview]
Message-ID: <1271449882-8580-25-git-send-email-Trond.Myklebust@netapp.com> (raw)
In-Reply-To: <1271449882-8580-24-git-send-email-Trond.Myklebust@netapp.com>
Keep a global count of how many referrals that the current task has
traversed on a path lookup. Return ELOOP if the count exceeds
MAX_NESTED_LINKS.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/nfs/super.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index cb196eb..33f355f 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2672,6 +2672,72 @@ out_freepage:
free_page((unsigned long)page);
}
+struct nfs_referral_count {
+ struct list_head list;
+ const struct task_struct *task;
+ unsigned int referral_count;
+};
+
+static LIST_HEAD(nfs_referral_count_list);
+static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
+
+static struct nfs_referral_count *nfs_find_referral_count(void)
+{
+ struct nfs_referral_count *p;
+
+ list_for_each_entry(p, &nfs_referral_count_list, list) {
+ if (p->task == current)
+ return p;
+ }
+ return NULL;
+}
+
+#define NFS_MAX_NESTED_REFERRALS 2
+
+static int nfs_referral_loop_protect(void)
+{
+ struct nfs_referral_count *p, *new;
+ int ret = -ENOMEM;
+
+ new = kmalloc(sizeof(*new), GFP_KERNEL);
+ if (!new)
+ goto out;
+ new->task = current;
+ new->referral_count = 1;
+
+ ret = 0;
+ spin_lock(&nfs_referral_count_list_lock);
+ p = nfs_find_referral_count();
+ if (p != NULL) {
+ if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
+ ret = -ELOOP;
+ else
+ p->referral_count++;
+ } else {
+ list_add(&new->list, &nfs_referral_count_list);
+ new = NULL;
+ }
+ spin_unlock(&nfs_referral_count_list_lock);
+ kfree(new);
+out:
+ return ret;
+}
+
+static void nfs_referral_loop_unprotect(void)
+{
+ struct nfs_referral_count *p;
+
+ spin_lock(&nfs_referral_count_list_lock);
+ p = nfs_find_referral_count();
+ p->referral_count--;
+ if (p->referral_count == 0)
+ list_del(&p->list);
+ else
+ p = NULL;
+ spin_unlock(&nfs_referral_count_list_lock);
+ kfree(p);
+}
+
static int nfs_follow_remote_path(struct vfsmount *root_mnt,
const char *export_path, struct vfsmount *mnt_target)
{
@@ -2689,9 +2755,14 @@ static int nfs_follow_remote_path(struct vfsmount *root_mnt,
if (IS_ERR(ns_private))
goto out_mntput;
+ ret = nfs_referral_loop_protect();
+ if (ret != 0)
+ goto out_put_mnt_ns;
+
ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
export_path, LOOKUP_FOLLOW, nd);
+ nfs_referral_loop_unprotect();
put_mnt_ns(ns_private);
if (ret != 0)
@@ -2709,6 +2780,8 @@ static int nfs_follow_remote_path(struct vfsmount *root_mnt,
kfree(nd);
down_write(&s->s_umount);
return 0;
+out_put_mnt_ns:
+ put_mnt_ns(ns_private);
out_mntput:
mntput(root_mnt);
out_err:
--
1.6.6.1
next prev parent reply other threads:[~2010-04-16 20:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-16 20:30 [PATCH 00/24] Reduce the stack foot print of the NFS client Trond Myklebust
2010-04-16 20:30 ` [PATCH 01/24] NFS: Add helper functions for allocating filehandles and fattr structs Trond Myklebust
2010-04-16 20:31 ` [PATCH 02/24] NFSv4: Eliminate nfs4_path_walk() Trond Myklebust
2010-04-16 20:31 ` [PATCH 03/24] NFS: Reduce the stack footprint of nfs_follow_mountpoint() Trond Myklebust
2010-04-16 20:31 ` [PATCH 04/24] NFS: Reduce the stack footprint of nfs_create_server Trond Myklebust
2010-04-16 20:31 ` [PATCH 05/24] NFSv4: Reduce the stack footprint of try_location() Trond Myklebust
2010-04-16 20:31 ` [PATCH 06/24] NFS: Reduce the stack footprint of nfs_lookup Trond Myklebust
2010-04-16 20:31 ` [PATCH 07/24] NFS: Reduce the stack footprint of nfs_follow_remote_path() Trond Myklebust
2010-04-16 20:31 ` [PATCH 08/24] NFSv4: Reduce stack footprint of nfs4_get_root() Trond Myklebust
2010-04-16 20:31 ` [PATCH 09/24] NFSv4: Reduce the stack footprint of nfs4_remote_referral_get_sb Trond Myklebust
2010-04-16 20:31 ` [PATCH 10/24] NFSv4: Reduce stack footprint of nfs4_proc_access() and nfs3_proc_access() Trond Myklebust
2010-04-16 20:31 ` [PATCH 11/24] NFS: Reduce stack footprint of nfs_revalidate_inode() Trond Myklebust
2010-04-16 20:31 ` [PATCH 12/24] NFS: Reduce stack footprint of nfs3_proc_rename() and nfs4_proc_rename() Trond Myklebust
2010-04-16 20:31 ` [PATCH 13/24] NFS: Reduce stack footprint of nfs_readdir() Trond Myklebust
2010-04-16 20:31 ` [PATCH 14/24] NFS: Reduce the stack footprint of nfs_link() Trond Myklebust
2010-04-16 20:31 ` [PATCH 15/24] NFS: Reduce stack footprint of nfs3_proc_readlink() Trond Myklebust
2010-04-16 20:31 ` [PATCH 16/24] NFS: Reduce stack footprint of nfs_proc_remove() Trond Myklebust
2010-04-16 20:31 ` [PATCH 17/24] NFS: Reduce the stack footprint of nfs_rmdir Trond Myklebust
2010-04-16 20:31 ` [PATCH 18/24] NFS: Reduce the stack footprint of nfs_proc_create Trond Myklebust
2010-04-16 20:31 ` [PATCH 19/24] NFS: Reduce the stack footprint of nfs_proc_symlink() Trond Myklebust
2010-04-16 20:31 ` [PATCH 20/24] NFS: Reduce stack footprint of nfs4_proc_create() Trond Myklebust
2010-04-16 20:31 ` [PATCH 21/24] NFS: Reduce stack footprint of nfs_setattr() Trond Myklebust
2010-04-16 20:31 ` [PATCH 22/24] NFS: Reduce stack footprint of nfs_statfs() Trond Myklebust
2010-04-16 20:31 ` [PATCH 23/24] NFS: Reduce stack footprint of nfs3_proc_getacl() and nfs3_proc_setacl() Trond Myklebust
2010-04-16 20:31 ` Trond Myklebust [this message]
2010-04-19 21:03 ` [PATCH 08/24] NFSv4: Reduce stack footprint of nfs4_get_root() Chuck Lever
2010-04-19 21:43 ` [PATCH 00/24] Reduce the stack foot print of the NFS client Chuck Lever
2010-04-19 23:29 ` Trond Myklebust
[not found] ` <1271719778.25129.73.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-04-19 23:37 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1271449882-8580-25-git-send-email-Trond.Myklebust@netapp.com \
--to=trond.myklebust@netapp.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox