4

In the book The Linux Programming Interface, it says

The kernel imposes limits on the number of dereferences to handle the possibility of circular chains of symbolic links.

Where can I find this limit?

extremeaxe5
  • 1,133
  • 9
  • 19
  • I can think of 2 very different ways to answer this question... either with the API to find the limit within a program, or with a pointer to the kernel code that enforces the limit. –  Aug 12 '18 at 23:24
  • @WumpusQ.Wumbley Really? I was hoping for a particular file in procfs. – extremeaxe5 Aug 12 '18 at 23:28
  • I went looking for the API, I believe I found it (`SYMLOOP_MAX` defined in POSIX [``](http://pubs.opengroup.org/onlinepubs/009604499/basedefs/limits.h.html) and more dynamically, [`sysconf(_SC_SYMLOOP_MAX)`](http://pubs.opengroup.org/onlinepubs/009604499/functions/sysconf.html)) but it seems to be unimplemented in Linux. –  Aug 12 '18 at 23:51

1 Answers1

7

Looking at the 4.18 kernel sources, I see a constant named MAXSYMLINKS in include/linux/namei.h whose value is 40.

Reference: https://elixir.bootlin.com/linux/latest/source/include/linux/namei.h#L12

#include <linux/kernel.h>
#include <linux/path.h>
#include <linux/fcntl.h>
#include <linux/errno.h>
    
enum { MAX_NESTED_LINKS = 8 };
    
#define MAXSYMLINKS 40
Andy Dalton
  • 13,654
  • 1
  • 25
  • 45