Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern vn_open(9): Add assertion that vp is locked on return.



details:   https://anonhg.NetBSD.org/src/rev/9ba0e5a7a0c4
branches:  trunk
changeset: 373874:9ba0e5a7a0c4
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 13 18:13:18 2023 +0000

description:
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.

diffstat:

 sys/kern/vfs_vnops.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r c7a0affab378 -r 9ba0e5a7a0c4 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Mon Mar 13 18:12:52 2023 +0000
+++ b/sys/kern/vfs_vnops.c      Mon Mar 13 18:13:18 2023 +0000
@@ -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 @@
                                        vput(nd.ni_dvp);
                                nd.ni_dvp = NULL;
                                vput(vp);
+                               vp = NULL;
                        }
                } else {
                        vput(vp);
+                       vp = NULL;
                }
                goto out;
        }
@@ -329,8 +331,10 @@
        }
 
 bad:
-       if (error)
+       if (error) {
                vput(vp);
+               vp = NULL;
+       }
 out:
        pathbuf_stringcopy_put(nd.ni_pathbuf, pathstring);
 
@@ -348,6 +352,7 @@
                error = 0;
                break;
        case 0:
+               KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
                *ret_vp = vp;
                break;
        }



Home | Main Index | Thread Index | Old Index