2

I am reading The Linux Programming Interface, this book says:

SUSv3 requires that an implementation allow at least _POSIX_SYMLOOP_MAX dereferences of each symbolic link component of a pathname. The specified value for _POSIX_SYMLOOP_MAX is 8. However, before kernel 2.6.18, Linux imposed a limit of 5 dereferences when following a chain of symbolic links. Starting with kernel 2.6.18, Linux implements the SUSv3-specified minimum of 8 dereferences. Linux also imposes a total of 40 dereferences for an entire pathname.

I didn't quite understand the last two sentences, what is the difference between these 8 and 40 limitations? I tested myself, creating a bunch of symlinks in my machine to try to reach the limitation:

$ l Permissions Links Size User Group Date Modified Name .rw-r--r--@ 1 12 steve steve 20 Oct 16:35 a lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:34 b -> a lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 c -> b lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 d -> c lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 e -> d lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 f -> e lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 g -> f lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 h -> g lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 i -> h lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 j -> i lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 k -> i lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 l -> k lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 m -> l lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 n -> m lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:38 o -> n lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:38 p -> o lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:40 q -> p lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 r -> q lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 s -> r lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 t -> s lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 u -> t lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 v -> u lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 w -> v lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 x -> w lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 y -> x lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 z -> y lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:42 z1 -> z lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z2 -> z1 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z3 -> z2 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z4 -> z3 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z5 -> z4 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z6 -> z5 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z7 -> z6 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z8 -> z7 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z9 -> z8 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z10 -> z9 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z11 -> z10 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z12 -> z11 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z13 -> z12 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z14 -> z13 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z15 -> z14 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z16 -> z15 lrwxrwxrwx 1 3 steve steve 20 Oct 16:45 z17 -> z16 
$ cat a You did it. $ cat z17 cat: z17: Too many levels of symbolic links $ cat z16 You did it. 

Seems that I have triggered that 40 limitation, then what is that 8 one?

5
  • 1
    8 sounds like a lower limit that any POSIX system must support, and 40 seems to be the upper limit that Linux imposes. Commented Oct 20, 2022 at 9:06
  • If I read it correctly it says 8 must be supported no matter what, anything about it is optional. Probably it was a config option in the past but it's long been removed, so now we have 40. Commented Oct 20, 2022 at 9:06
  • 1
    @Kusalananda @Artem S. Tashkinov Thanks for your comments. So these two limitations are limiting the same thing, 8 is the POSIX minimal limit that any implementations must follow, and 40 is the limit defined by Linux. Commented Oct 20, 2022 at 9:09
  • 1
    On a side note, you can also learn from man path_resolution that "In Linux 4.2, the kernel's pathname-resolution code was reworked to eliminate the use of recursion". Commented Oct 20, 2022 at 9:28
  • @MC68020 Thanks! In Linux 4.2, the kernel's pathname-resolution code was reworked to eliminate the use of recursion, so that the only limit that remains is the maximum of 40 resolutions for the entire pathname. This makes it more clear, 40 is technically NOT the upper limit of symlink resolving, it is the maximum path resolution we can use for a single path. Commented Oct 20, 2022 at 9:33

1 Answer 1

2

These two limitations are limiting the same thing.

8, as defined in _POSIX_SYMLOOP_MAX, is the POSIX minimal limit that every POSIX-conforming OS must follow.

When it comes to a specific OS, the OS can choose a different limit value as long as it satisfies the POSIX minimal limit (i.e., bigger than or equal to 8).

Linux after kernel 2.6.18, chose 8. In kernel 4.2, the kernel's pathname-resolution code was reworked to eliminate the use of recursion, so right now, the only bottleneck that limits symlink resolution is how many times of path resolution we can use for a single path, this value is 40. So the maximum number of symbolic links that will be followed while resolving a pathname is 40

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.