FYI Lighttpd 1.4.23 /kernel (trailing '/' on regular file symlink) vulnerability

Dag-Erling Smørgrav des at des.no
Fri May 29 16:58:09 UTC 2009


How's this?

Index: sys/kern/vfs_lookup.c
===================================================================
--- sys/kern/vfs_lookup.c	(revision 193028)
+++ sys/kern/vfs_lookup.c	(working copy)
@@ -454,7 +454,6 @@
 	int docache;			/* == 0 do not cache last component */
 	int wantparent;			/* 1 => wantparent or lockparent flag */
 	int rdonly;			/* lookup read-only flag bit */
-	int trailing_slash;
 	int error = 0;
 	int dpunlocked = 0;		/* dp has already been unlocked */
 	struct componentname *cnp = &ndp->ni_cnd;
@@ -529,12 +528,10 @@
 	 * trailing slashes to handle symlinks, existing non-directories
 	 * and non-existing files that won't be directories specially later.
 	 */
-	trailing_slash = 0;
 	while (*cp == '/' && (cp[1] == '/' || cp[1] == '\0')) {
 		cp++;
 		ndp->ni_pathlen--;
 		if (*cp == '\0') {
-			trailing_slash = 1;
 			*ndp->ni_next = '\0';	/* XXX for direnter() ... */
 			cnp->cn_flags |= TRAILINGSLASH;
 		}
@@ -711,7 +708,7 @@
 			error = EROFS;
 			goto bad;
 		}
-		if (*cp == '\0' && trailing_slash &&
+		if (*cp == '\0' && (cnp->cn_flags & TRAILINGSLASH) &&
 		     !(cnp->cn_flags & WILLBEDIR)) {
 			error = ENOENT;
 			goto bad;
@@ -788,7 +785,7 @@
 	 * Check for symbolic link
 	 */
 	if ((dp->v_type == VLNK) &&
-	    ((cnp->cn_flags & FOLLOW) || trailing_slash ||
+	    ((cnp->cn_flags & FOLLOW) || (cnp->cn_flags & TRAILINGSLASH) ||
 	     *ndp->ni_next == '/')) {
 		cnp->cn_flags |= ISSYMLINK;
 		if (dp->v_iflag & VI_DOOMED) {

BTW, what does the "XXX for direnter()" comment mean?

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list