Module Name:    src
Committed By:   riastradh
Date:           Mon Mar 13 18:13:19 UTC 2023

Modified Files:
        src/sys/kern: vfs_vnops.c

Log Message:
vn_open(9): Add assertion that vp is locked on return.

Null out vp internally out of paranoia so we'll crash in evaluating
the assertion if we ever reach it via one of the vput paths.


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/kern/vfs_vnops.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/kern/vfs_vnops.c
diff -u src/sys/kern/vfs_vnops.c:1.236 src/sys/kern/vfs_vnops.c:1.237
--- src/sys/kern/vfs_vnops.c:1.236	Mon Mar 13 18:12:52 2023
+++ src/sys/kern/vfs_vnops.c	Mon Mar 13 18:13:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnops.c,v 1.236 2023/03/13 18:12:52 riastradh Exp $	*/
+/*	$NetBSD: vfs_vnops.c,v 1.237 2023/03/13 18:13:18 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.236 2023/03/13 18:12:52 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.237 2023/03/13 18:13:18 riastradh Exp $");
 
 #include "veriexec.h"
 
@@ -242,9 +242,11 @@ vn_open(struct vnode *at_dvp, struct pat
 					vput(nd.ni_dvp);
 				nd.ni_dvp = NULL;
 				vput(vp);
+				vp = NULL;
 			}
 		} else {
 			vput(vp);
+			vp = NULL;
 		}
 		goto out;
 	}
@@ -329,8 +331,10 @@ vn_open(struct vnode *at_dvp, struct pat
 	}
 
 bad:
-	if (error)
+	if (error) {
 		vput(vp);
+		vp = NULL;
+	}
 out:
 	pathbuf_stringcopy_put(nd.ni_pathbuf, pathstring);
 
@@ -348,6 +352,7 @@ out:
 		error = 0;
 		break;
 	case 0:
+		KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
 		*ret_vp = vp;
 		break;
 	}

Reply via email to