Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


Awhileloop caters to the fact that several filesystemscan be mounted one after the other where the last
system mounted conceals all the others.

Implementation ofdo_follow_link


When the kernel follows symbolic links, it must note that users may construct cyclic structures (inten-
tionally or not), as the following example shows:

wolfgang@meitner>ls -l a b c
lrwxrwxrwx 1 wolfgang users 1 Mar 8 22:18 a -> b
lrwxrwxrwx 1 wolfgang users 1 Mar 8 22:18 b -> c
lrwxrwxrwx 1 wolfgang users 1 Mar 8 22:18 c -> a

a,b,andcform an endless loop. This could be exploited to render the system unusable if the kernel did
not take appropriate precautions.

In fact, the kernel recognizes the situation and aborts processing.

wolfgang@meitner>cat a
cat: a: Too many levels of symbolic links

A further problem with symbolic links is the fact that the link target may be located on a different filesys-
tem from the link source. This results in a linkage between filesystem-specific code and VFS functions
that doesn’t normally occur. Low-level code for following links then references VFS functions, whereas
normally only the reverse occurs (the VFS invokes low-level functions of the individual implementa-
tions).

Figure 8-10 shows the code flow diagram fordo_follow_link.

Check link limits

do_follow_link

__do_follow_link i_op->follow_link

current->link_count-

current->link_count++, current-> total_link_count++

Figure 8-10: Code flow diagram fordo_follow_link.

Thetask_structstructure includes two count variables used to follow links.

<sched.h>
struct task_struct {
...
/* file system info */
int link_count, total_link_count;
...
};
Free download pdf