Re: PATCH: smart symlink loop detection.

Linus Torvalds (torvalds@transmeta.com)
Tue, 14 Apr 1998 11:48:07 -0700 (PDT)


On Tue, 14 Apr 1998, C. Scott Ananian wrote:
>
> What seems to be required is the following: those <fs>_follow_link
> implementations that call lookup_dentry could be rewritten to instead
> return the *arguments it would have passed to lookup_dentry*. We can then
> move the actual iteration into lookup_dentry, removing all the recursion
> *and* not requiring a stack. Extreme cleverness is required to avoid
> limiting the path string length.

We still need a specialized per-thread stack for the arguments, because we
will get "recursive" follow-link invocations: when we get the return value
from follow_link(), we not only have to act on that return value, we also
have to act on the continuation of the old path we were traversing while
doing the follow_link in the first place.

However, if we don't use the CPU to create the stack through actual
recursion, the stack can be made physically much smaller (ie on the order
of one long-word per iteration - so we could do something like this:

#define LOOKUP_STACK_DEPTH 20
typedef char * stack_t;

lookup_dentry(char * string)
{
stack_t lookup_stack[LOOKUP_STACK_DEPTH];
int lookup_stack_ptr = 0;

for (;;) {
if (path_exhausted(string)) {
/* Nothing pending? break if so */
if (!lookup_stack_ptr)
break;
lookup_stack_ptr--;
string = lookup_stack[lookup_stack_ptr];
}
string = get_one_component();
lookup(component);
string = follow_link(component, lookup_stack, lookup_stack_ptr);
}
}

where "follow_link()" would push the old path on the stack and return the
new path.

(The above is _pure_ pseudo-code, and any resemblence to C is purely
coincidental. It's probably broken. But it's important to notice that (a)
it's definitely more complex than what we have now, and (b) the stack has
to be per-process which makes it nastier.

The current link_depth thing is actually a kind of "lookup_stack_ptr"
thing, but because we use the native CPU stack we don't actually need it
for anything else than overflow detection because the compiler and the CPU
will do the stacking for us.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu