From jhs@jhs.muc.de Tue Jul 13 16:00:02 1999
Return-Path: <jhs@jhs.muc.de>
Received: from slarti.muc.de (slarti.muc.de [193.149.48.10])
	by hub.freebsd.org (Postfix) with SMTP id 0C8B815306
	for <FreeBSD-gnats-submit@FreeBSD.ORG>; Tue, 13 Jul 1999 15:59:56 -0700 (PDT)
	(envelope-from jhs@jhs.muc.de)
Received: (qmail 26020 invoked from network); 13 Jul 1999 23:01:01 -0000
Received: from jhs.muc.de (193.149.49.84)
  by slarti.muc.de with SMTP; 13 Jul 1999 23:01:01 -0000
Received: (from jhs@localhost)
	by jhs.muc.de (8.9.3/8.9.3) id WAA24480;
	Tue, 13 Jul 1999 22:40:33 GMT
	(envelope-from jhs)
Message-Id: <199907132240.WAA24480@jhs.muc.de>
Date: Tue, 13 Jul 1999 22:40:33 GMT
From: jhs@FreeBSD.ORG
Sender: jhs@jhs.muc.de
Reply-To: jhs@FreeBSD.ORG
To: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: MAXSYMLINKS correct lib/libc/sys/intro.2 double sys/sys/param.h
X-Send-Pr-Version: 3.2

>Number:         12634
>Category:       bin
>Synopsis:       patch MAXSYMLINKS to correct intro.2 & double param.h
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    n_hibma
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 13 16:10:01 PDT 1999
>Closed-Date:    Sun Jul 25 04:07:18 PDT 1999
>Last-Modified:  Sun Jul 25 04:09:14 PDT 1999
>Originator:     Julian H. Stacey jhs@freebsd.org
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
>Environment:

	I hit the MAXSYMLINKS 32 barrier, so doubled it, to allow for
	larger NFS networks of file systems.  It should have no appreciable
	effect on others, except a slightly longer pause before reporting
	error, when recursive looping on a bad symbolic link.
	I also noticed man 2 intro was previously wrong & corrected it.

>Description:

I run a site of 10 hosts with many ports distfiles, NFS mounted on other hosts.
Here's my actual example of how I hit the barrier, shown so folk won't think
it's a contrived amount of links, it's simply my current site's NFS file system) :
  DIRECTORY			SYMBOLIC LINK (or file, in last line)
  /usr				ports -> /host/park/usr/ports
  /host				park -> /a/park
  /a/park/usr/ports		distfiles@ -> /pub/freebsd/distfiles/links
  /				pub -> public
  /				public -> site/public
  /site				public -> domain/public
  /site/domain			public -> this/public
  /site/domain			this -> jhs.no_domain
  /site/domain/jhs.no_domain	public -> ../../../host/flip/usr2/public
  /host				flip -> /a/flip
  /a/flip/usr2			public@ -> ftp/public
  /a/flip/usr2/ftp/public/freebsd/distfiles/links/	gv-3.5.8.tar.gz -> /usr/ports/distfiles/cd.3.2/./gv-3.5.8.tar.gz
  /usr				ports -> /host/park/usr/ports
  /host				park -> /a/park
  /a/park/usr/ports		distfiles@ -> /pub/freebsd/distfiles/links
  /				pub -> public
  /				public -> site/public
  /site				public -> domain/public
  /site/domain			public -> this/public
  /site/domain			this -> jhs.no_domain
  /site/domain/jhs.no_domain	public -> ../../../host/flip/usr2/public
  /host				flip -> /a/flip
  /a/flip/usr2			public@ -> ftp/public
  /a/flip/usr2/ftp/public/freebsd/distfiles/links/	cd.3.2 ../cd.3.2
  /a/flip/usr2/ftp/public/freebsd/distfiles		3.2-RELEASE/links
  /a/flip/usr2/ftp/public/freebsd/distfiles/3.2-RELEASE/links	gv-3.5.8.tar.gz@ -> ../d4/gv-3.5.8.tar.gz
  /a/flip/usr2/ftp/public/freebsd/distfiles/3.2-RELEASE		d4 -> link/d4
  /a/flip/usr2/ftp/public/freebsd/distfiles/3.2-RELEASE		link -> link.flip
  /a/flip/usr2/ftp/public/freebsd/distfiles/3.2-RELEASE		link.flip -> ../../../../../../usr1/ftp/public/freebsd/ref/3.2-RELEASE/distfiles
  /a/flip/usr1/ftp/public/freebsd/ref/3.2-RELEASE/distfiles/d4	gv-3.5.8.tar.gz [ The real file ]


>How-To-Repeat:

	I hit the problem doing 
		md5 /usr/ports/distfiles/gv-3.5.8.tar.gz
	with the above set of links.

>Fix:
	
*** old/src/sys/sys/param.h	Sat May  8 23:55:42 1999
--- new/src/sys/sys/param.h	Tue Jul 13 23:10:21 1999
***************
*** 168,174 ****
   * infinite loops reasonably quickly.
   */
  #define	MAXPATHLEN	PATH_MAX
! #define MAXSYMLINKS	32
  
  /* Bit map related macros. */
  #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
--- 168,174 ----
   * infinite loops reasonably quickly.
   */
  #define	MAXPATHLEN	PATH_MAX
! #define MAXSYMLINKS	64
  
  /* Bit map related macros. */
  #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))


Having searched all files in /usr/src for sysparam.h, I found just:
	sys/i386/boot/dosboot/fbsdboot.mak
	sys/i386/boot/dosboot/param.h:#include "sysparam.h"
& both had Control Ms in (for Dos), it thus seems highly likely this quote
	"A path name lookup involved more than 8 symbolic links."
was never correct, it should have read "32", & I've now increased it.

*** old/src/lib/libc/sys/intro.2	Fri Mar 12 11:50:36 1999
--- new/src/lib/libc/sys/intro.2	Tue Jul 13 23:44:18 1999
***************
*** 351,357 ****
  refused it.  This usually results from trying to connect
  to a service that is inactive on the foreign host.
  .It Er 62 ELOOP Em "Too many levels of symbolic links" .
! A path name lookup involved more than 8 symbolic links.
  .It Er 63 ENAMETOOLONG Em "File name too long" .
  A component of a path name exceeded 255
  .Pq Dv MAXNAMELEN
--- 351,358 ----
  refused it.  This usually results from trying to connect
  to a service that is inactive on the foreign host.
  .It Er 62 ELOOP Em "Too many levels of symbolic links" .
! A path name lookup involved more than 64 symbolic links (from MAXSYMLINKS in 
! /usr/include/sys/param.h from src/sys/sys/param.h ).
  .It Er 63 ENAMETOOLONG Em "File name too long" .
  A component of a path name exceeded 255
  .Pq Dv MAXNAMELEN

Background Info:
---
These can probably stay unchanged:
	sys/i386/boot/dosboot/sysparam.h:172	
		#define MAXSYMLINKS     8
	gnu/usr.bin/rcs/lib/conf.h:46
		#if has_readlink && !defined(MAXSYMLINKS)
		#	if has_sys_param_h
		#		include <sys/param.h>
		#	endif
		#	ifndef MAXSYMLINKS
		#		define MAXSYMLINKS 20 /* BSD; not standard yet */
		#	endif
		#endif
These use MAXSYMLINKS:
	gnu/usr.bin/rcs/lib/rcsedit.c	resolve_symlink(L)
	lib/libc/stdlib/realpath.c:	realpath(path, resolved)
	lib/libstand/nfs.c:		nfs_open(upath, f)
	lib/libstand/ufs.c:		ufs_open(upath, f)
	sys/kern/vfs_lookup.c:		namei(ndp)
	sys/nfs/nfs_subs.c:		nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, p, kerbflag, pubflag)
These use ELOOP:
	lib/libc/gen/errlst.c:114	"Too many levels of symbolic links"
	lib/libc/gen/exec.c:275		case ELOOP:
	lib/libc/sys/intro.2:354	A path name lookup involved more than 8 symbolic links.
	share/examples/mdoc/example.3:	Too many levels of symbolic links.
	sys/sys/errno.h:		#define ELOOP 62
	lib/libc/stdlib/realpath.c	if (++symlinks > MAXSYMLINKS)
	) )


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: n_hibma 
State-Changed-When: Sat Jul 24 09:53:36 PDT 1999 
State-Changed-Why:  

The change sounds reasonable, but might have odd effect. Feedback from current 
mailing list is required I think. 


Responsible-Changed-From-To: freebsd-bugs->n_hibma 
Responsible-Changed-By: n_hibma 
Responsible-Changed-When: Sat Jul 24 09:53:36 PDT 1999 
Responsible-Changed-Why:  
Remind me to close it in due time. 

From: Nick Hibma <nick.hibma@jrc.it>
To: freebsd-gnats-submit@freebsd.org, jhs@freebsd.org
Cc:  
Subject: Re: bin/12634: patch MAXSYMLINKS to correct intro.2 & double param.h
Date: Sat, 24 Jul 1999 18:46:15 +0200

 Committed change to man page (ELOOP)
 -- 
 ISIS/STA, T.P.270, Joint Research Centre, 21020 Ispra, Italy
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: n_hibma 
State-Changed-When: Sun Jul 25 04:07:18 PDT 1999 
State-Changed-Why:  
Two people in the current mailing list viewed the example given as extreme and 
do not fancy upping the limit. I concur. That makes 3 againt and 1 in favour 
The change in the manpage should be sufficient to point at a possible 
location for fixing the problem in case someone runs into the same limitation. 
>Unformatted:
