Re: [PATCH+discussion] symlink recursion

Linus Torvalds (torvalds@transmeta.com)
Tue, 18 Jun 2002 16:57:06 -0700 (PDT)


On Wed, 19 Jun 2002 Andries.Brouwer@cwi.nl wrote:
>
> As promised below an implementation of nonrecursive symlink resolution.

There is no such thing as a non-recursive symlink resolution.

Symlink walking is by it's very nature recursive, since we have to be able
to look a symlink up in the middle of another one.

So either it's recursive in C (caller ends up calling itself) or it
linearizes the recursion by hand (caller keeps track of the stack by hand
using a linked list or by expanding the pathname in place or whatever,
instead of using the C stack).

Both are recursive, it's only a question of whether the recursion is
handled by the language or by hand, and whether the interim state is held
on the stack or in explicit data structures.

I see no advantages to handling it by hand, since this isn't even a very
deep recursion, and since even if you do the recursive part by hand by a
linked list you still need to limit the depth _anyway_ to avoid DoS
attacks.

In fact, we avoid following symlinks too deeply even for the
_non_recursive_ case (see "total_link_count") exactly because of these DoS
issues.

Could we allow deeper recursion if we did it by hand? Sure. Are there any
real advantages in 15 levels of recursion over 5 levels of recursion? I
don't see any.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/