Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Feb 2001 19:44:54 +0100 (CET)
From:      mkamm@gmx.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/25018: lstat(2) returns bogus permissions on symlinks
Message-ID:  <200102101844.f1AIisA11912@homebox.kammerhofer.org>

next in thread | raw e-mail | index | archive | help

>Number:         25018
>Category:       kern
>Synopsis:       lstat(2) returns bogus permissions on symlinks
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Feb 11 14:50:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Martin Kammerhofer
>Release:        FreeBSD 4.2-STABLE i386
>Organization:
Universität Graz
>Environment:
>Description:

I quote a commitlog message here:

##peter       97/03/31 04:03:04
##
##  Treat symlinks as first class citizens with their own uid/gid rather than
##  as shadows of their containing directory.  This should solve the problem
##  of users not being able to delete their symlinks from /tmp once and for
##  all.
##  
##  Symlinks do not have modes though, they are accessable to everything that
##  can read the directory (as before).  They are made to show this fact at
##  lstat time (they appear as mode 0777 always, since that's how the the
##  lookup routines in the kernel treat them).
##  
##  More commits will follow, eg: add a real lchown() syscall and man pages.
##  
##  Revision  Changes    Path
##  1.62      +19 -70    src/sys/kern/vfs_syscalls.c


However the mentioned feature "appear as mode 0777" was broken later
when mount option "nosymfollow" was introduced because the mode was
written to the wrong variable.

For easy reference I quote a part of this second commit log too:

##wosch       1998/04/08 11:32:00 PDT
##  New mount option nosymfollow. If enabled, the kernel lookup()
##  function will not follow symbolic links on the mounted
##  file system and return EACCES (Permission denied).
##  
##  Revision  Changes    Path
##  1.97      +3 -5      src/sys/kern/vfs_syscalls.c
##  1.55      +6 -1      src/sys/kern/vfs_vnops.c


>How-To-Repeat:

(umask 321 && ln -s "have strange but nontheless nonexistant perms" symlinks)
ls -l symlinks

The permissions shown reflect the umask value at the time of the
symlink(2) call rather than the more intuitive "lrwxrwxrwx" or
in case of mount -onosymfollow "l---------".

>Fix:

Don't set a variable that will be overwritten shortly after the
break...

Index: vfs_vnops.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.107
diff -u -11 -r1.107 vfs_vnops.c
--- vfs_vnops.c	2001/01/24 12:35:50	1.107
+++ vfs_vnops.c	2001/02/10 12:57:00
@@ -479,25 +479,25 @@
 		break;
 	case VBLK:
 		mode |= S_IFBLK;
 		break;
 	case VCHR:
 		mode |= S_IFCHR;
 		break;
 	case VLNK:
 		mode |= S_IFLNK;
 		/* This is a cosmetic change, symlinks do not have a mode. */
 		if (vp->v_mount->mnt_flag & MNT_NOSYMFOLLOW)
-			sb->st_mode &= ~ACCESSPERMS;	/* 0000 */
+			mode &= ~ACCESSPERMS;	/* 0000 */
 		else
-			sb->st_mode |= ACCESSPERMS;	/* 0777 */
+			mode |= ACCESSPERMS;	/* 0777 */
 		break;
 	case VSOCK:
 		mode |= S_IFSOCK;
 		break;
 	case VFIFO:
 		mode |= S_IFIFO;
 		break;
 	default:
 		return (EBADF);
 	};
 	sb->st_mode = mode;

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102101844.f1AIisA11912>