Module Name:    src
Committed By:   jdolecek
Date:           Wed Jun 24 10:28:17 UTC 2020

Modified Files:
        src/sys/compat/common: vfs_syscalls_43.c
        src/sys/compat/sunos32: sunos32_misc.c

Log Message:
remove special handling for symbolic links for COMPAT_43 lstat, it's
not necessary; this removes the only places in kernel which did namei
LOOKUP with LOCKPARENT

fixes diagnostic KASSERT() in namei() code

Reported-by: syzbot+628382ecf1438e53d...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/compat/common/vfs_syscalls_43.c
cvs rdiff -u -r1.83 -r1.84 src/sys/compat/sunos32/sunos32_misc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/common/vfs_syscalls_43.c
diff -u src/sys/compat/common/vfs_syscalls_43.c:1.65 src/sys/compat/common/vfs_syscalls_43.c:1.66
--- src/sys/compat/common/vfs_syscalls_43.c:1.65	Thu Feb 27 18:19:16 2020
+++ src/sys/compat/common/vfs_syscalls_43.c	Wed Jun 24 10:28:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls_43.c,v 1.65 2020/02/27 18:19:16 pgoyette Exp $	*/
+/*	$NetBSD: vfs_syscalls_43.c,v 1.66 2020/06/24 10:28:16 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.65 2020/02/27 18:19:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.66 2020/06/24 10:28:16 jdolecek Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -179,69 +179,19 @@ compat_43_sys_lstat(struct lwp *l, const
 		syscallarg(char *) path;
 		syscallarg(struct ostat *) ub;
 	} */
-	struct vnode *vp, *dvp;
-	struct stat sb, sb1;
+	struct stat sb;
 	struct stat43 osb;
 	int error;
-	struct pathbuf *pb;
-	struct nameidata nd;
-	int ndflags;
 
-	error = pathbuf_copyin(SCARG(uap, path), &pb);
-	if (error) {
+	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
+	if (error)
 		return error;
-	}
 
-	ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT | TRYEMULROOT;
-again:
-	NDINIT(&nd, LOOKUP, ndflags, pb);
-	if ((error = namei(&nd))) {
-		if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
-			/*
-			 * Should only happen on '/'. Retry without LOCKPARENT;
-			 * this is safe since the vnode won't be a VLNK.
-			 */
-			ndflags &= ~LOCKPARENT;
-			goto again;
-		}
-		pathbuf_destroy(pb);
-		return (error);
-	}
 	/*
-	 * For symbolic links, always return the attributes of its
+	 * For symbolic links, BSD4.3 returned the attributes of its
 	 * containing directory, except for mode, size, and links.
+	 * This is no longer emulated, the parent directory is not consulted.
 	 */
-	vp = nd.ni_vp;
-	dvp = nd.ni_dvp;
-	pathbuf_destroy(pb);
-	if (vp->v_type != VLNK) {
-		if ((ndflags & LOCKPARENT) != 0) {
-			if (dvp == vp)
-				vrele(dvp);
-			else
-				vput(dvp);
-		}
-		error = vn_stat(vp, &sb);
-		vput(vp);
-		if (error)
-			return (error);
-	} else {
-		error = vn_stat(dvp, &sb);
-		vput(dvp);
-		if (error) {
-			vput(vp);
-			return (error);
-		}
-		error = vn_stat(vp, &sb1);
-		vput(vp);
-		if (error)
-			return (error);
-		sb.st_mode &= ~S_IFDIR;
-		sb.st_mode |= S_IFLNK;
-		sb.st_nlink = sb1.st_nlink;
-		sb.st_size = sb1.st_size;
-		sb.st_blocks = sb1.st_blocks;
-	}
 	cvtstat(&sb, &osb);
 	error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
 	return (error);

Index: src/sys/compat/sunos32/sunos32_misc.c
diff -u src/sys/compat/sunos32/sunos32_misc.c:1.83 src/sys/compat/sunos32/sunos32_misc.c:1.84
--- src/sys/compat/sunos32/sunos32_misc.c:1.83	Sat Oct 26 11:34:48 2019
+++ src/sys/compat/sunos32/sunos32_misc.c	Wed Jun 24 10:28:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos32_misc.c,v 1.83 2019/10/26 11:34:48 christos Exp $	*/
+/*	$NetBSD: sunos32_misc.c,v 1.84 2020/06/24 10:28:17 jdolecek Exp $	*/
 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp	*/
 
 /*
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.83 2019/10/26 11:34:48 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.84 2020/06/24 10:28:17 jdolecek Exp $");
 
 #define COMPAT_SUNOS 1
 
@@ -294,72 +294,19 @@ sunos32_sys_lstat(struct lwp *l, const s
 		syscallarg(const netbsd32_charp) path;
 		syscallarg(netbsd32_stat43p_t) ub;
 	} */
-	struct vnode *vp, *dvp;
-	struct stat sb, sb1;
+	struct stat sb;
 	struct netbsd32_stat43 sb32;
 	int error;
-	struct pathbuf *pb;
-	struct nameidata nd;
-	int ndflags;
-	const char *path;
 
-	path = SCARG_P32(uap, path);
-
-	ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT | TRYEMULROOT;
-again:
-	error = pathbuf_copyin(path, &pb);
-	if (error) {
+	error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &sb);
+	if (error)
 		return error;
-	}
 
-	NDINIT(&nd, LOOKUP, ndflags, pb);
-	if ((error = namei(&nd))) {
-		pathbuf_destroy(pb);
-		if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
-			/*
-			 * Should only happen on '/'. Retry without LOCKPARENT;
-			 * this is safe since the vnode won't be a VLNK.
-			 */
-			ndflags &= ~LOCKPARENT;
-			goto again;
-		}
-		return (error);
-	}
 	/*
-	 * For symbolic links, always return the attributes of its
+	 * For symbolic links, SunOS returned the attributes of its
 	 * containing directory, except for mode, size, and links.
+	 * This is no longer emulated, the parent directory is not consulted.
 	 */
-	vp = nd.ni_vp;
-	dvp = nd.ni_dvp;
-	pathbuf_destroy(pb);
-	if (vp->v_type != VLNK) {
-		if ((ndflags & LOCKPARENT) != 0) {
-			if (dvp == vp)
-				vrele(dvp);
-			else
-				vput(dvp);
-		}
-		error = vn_stat(vp, &sb);
-		vput(vp);
-		if (error)
-			return (error);
-	} else {
-		error = vn_stat(dvp, &sb);
-		vput(dvp);
-		if (error) {
-			vput(vp);
-			return (error);
-		}
-		error = vn_stat(vp, &sb1);
-		vput(vp);
-		if (error)
-			return (error);
-		sb.st_mode &= ~S_IFDIR;
-		sb.st_mode |= S_IFLNK;
-		sb.st_nlink = sb1.st_nlink;
-		sb.st_size = sb1.st_size;
-		sb.st_blocks = sb1.st_blocks;
-	}
 	sunos32_from___stat13(&sb, &sb32);
 	error = copyout((void *)&sb32, SCARG_P32(uap, ub), sizeof (sb32));
 	return (error);

Reply via email to