public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Linda Walsh <lkml@tlinx.org>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Linux-Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] Use one constant to control MAX SYMLINKS in a name
Date: Sun, 12 Feb 2006 12:46:14 -0800	[thread overview]
Message-ID: <43EF9E96.109@tlinx.org> (raw)
In-Reply-To: <Pine.LNX.4.61.0602121126410.25363@yvahk01.tjqt.qr>

Jan Engelhardt wrote:
> # grep 40 fs/namei.c
> namei.c: * limiting consecutive symlinks to 40.
> namei.c:        if (current->total_link_count >= 40)
>   
---
    I believe that is the case of appending successive path entries for
sequential case of case "a->b->c->d..." where successive entries
can replace previous entries.  I hit the nested symlink amount
where a symlink contains two or more path components with a symlink in the
non-terminal position, i.e.in the dir-component of a dir/target.
I had something like "./symdir1/myfile"; with a symlink chain extending
along the directory chain.  Not the end file.

    Here are the lines in question:


include/linux/namei.h:14:enum { MAX_NESTED_LINKS = 5 };
&&
fs/namei.c:

590: * This limits recursive symlink follows to 8, while
591: * limiting consecutive symlinks to 40.
592: *
593: * Without that kind of total limit, nasty chains of consecutive
594: * symlinks can cause almost arbitrarily long lookups.
595: */
596:static inline int do_follow_link(struct path *path, struct nameidata
 *nd)

599:    if (current->link_count >= MAX_NESTED_LINKS)
600:            goto loop;
601:    if (current->total_link_count >= 40)
602:            goto loop;
----------
    The comment on line 590 refers to the "enum", MAX_NESTED_LINKS
on line 599 defined as "5" in namei.h, line 14.

    My original post showed the nesting via the gnu namei command, which
appears  to correctly expand the symlink even though the OS fails.

    I'd suggest changing the number in line 14 in namei.h to 40
as well, thus using the same limit in both cases and clearing up
such confusion.

The following patch (against 2.6.15.4) seems to make this change and fixes
up the comments:
-----------------------

--- include/linux/namei.h       2006-01-02 19:21:10.000000000 -0800
+++ include/linux/namei.h       2006-02-12 12:25:37.500504876 -0800
@@ -11,7 +11,7 @@
        struct file *file;
 };
 
-enum { MAX_NESTED_LINKS = 5 };
+enum { MAX_PATH_SYMLINKS = 40 };
 
 struct nameidata {
        struct dentry   *dentry;
@@ -20,7 +20,7 @@
        unsigned int    flags;
        int             last_type;
        unsigned        depth;
-       char *saved_names[MAX_NESTED_LINKS + 1];
+       char *saved_names[MAX_PATH_SYMLINKS + 1];
 
        /* Intent data */
        union {


--- fs/namei.c.orig     2006-01-02 19:21:10.000000000 -0800
+++ fs/namei.c  2006-02-12 12:20:45.382792407 -0800
@@ -587,8 +587,7 @@
 }
 
 /*
- * This limits recursive symlink follows to 8, while
- * limiting consecutive symlinks to 40.
+ * This limits max symlinks in a pathname to "MAX_PATH_SYMLINKS"
  *
  * Without that kind of total limit, nasty chains of consecutive
  * symlinks can cause almost arbitrarily long lookups.
@@ -596,11 +595,11 @@
 static inline int do_follow_link(struct path *path, struct nameidata *nd)
 {
        int err = -ELOOP;
-       if (current->link_count >= MAX_NESTED_LINKS)
+       if (current->link_count >= MAX_PATH_SYMLINKS ||
+               current->total_link_count >= MAX_PATH_SYMLINKS)
                goto loop;
-       if (current->total_link_count >= 40)
-               goto loop;
-       BUG_ON(nd->depth >= MAX_NESTED_LINKS);
+       /* Not sure next BUG_ON statement is ever needed */
+       BUG_ON(nd->depth >= MAX_PATH_SYMLINKS);
        cond_resched();
        err = security_inode_follow_link(path->dentry, nd);
        if (err)

  reply	other threads:[~2006-02-12 20:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-11  3:31 max symlink = 5? ?bug? ?feature deficit? Linda Walsh
2006-02-12 10:27 ` Jan Engelhardt
2006-02-12 20:46   ` Linda Walsh [this message]
2006-02-12 21:16     ` [PATCH] Use one constant to control MAX SYMLINKS in a name Al Viro
2006-02-12 18:06 ` max symlink = 5? ?bug? ?feature deficit? Al Viro
2006-02-12 19:19   ` Dave Jones
2006-02-12 19:36   ` Matthew Wilcox
2006-02-12 19:48     ` Al Viro
2006-02-12 21:18   ` Linda Walsh
2006-02-12 21:25     ` Al Viro
2006-02-12 22:54       ` Linda Walsh
2006-02-13  0:08         ` Al Viro
2006-02-13  0:54           ` Linda Walsh
2006-02-13  7:37             ` Willy Tarreau
2006-02-13  7:48               ` Arjan van de Ven
2006-02-13  8:03                 ` Willy Tarreau
2006-02-13  8:11                   ` Al Viro
2006-02-13 14:10                   ` Olivier Galibert
2006-02-13  8:20               ` Helge Hafting

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=43EF9E96.109@tlinx.org \
    --to=lkml@tlinx.org \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@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