+ * This limits recursive symlink follows to 8, while
+ * limiting consecutive symlinks to 40.
+ *
+ * Without that kind of total limit, nasty chains of consecutive
+ * symlinks can cause almost arbitrarily long lookups.
+ */
+static inline int nested_symlink(struct path *path, struct nameidata *nd)
+{
+ int res;
+
+ BUG_ON(nd->depth >= MAX_NESTED_LINKS);
+ if (unlikely(current->link_count >= MAX_NESTED_LINKS)) {
+ path_put_conditional(path, nd);
+ path_put(&nd->path);
+ return -ELOOP;
+ }
+
+ nd->depth++;
+ current->link_count++;
+
+ do {
+ struct path link = *path;
+ void *cookie;
+ if (unlikely(current->total_link_count >= 40)) {
+ path_put_conditional(path, nd);
+ path_put(&nd->path);
+ res = -ELOOP;
+ break;
+ }
+ cond_resched();
+ current->total_link_count++;
+ res = __do_follow_link(&link, nd, &cookie);
+ if (!res)
+ res = walk_component(nd, path, &nd->last,
+ nd->last_type, LOOKUP_FOLLOW);
+ if (!IS_ERR(cookie) && link.dentry->d_inode->i_op->put_link)
+ link.dentry->d_inode->i_op->put_link(link.dentry, nd, cookie);
+ path_put(&link);
+ } while (res > 0);
+
+ current->link_count--;
+ nd->depth--;
+ return res;
+}
+
+/*