kernel/fs: Add assertions to acquire_vnode and put_vnode.

* panic under KDEBUG if the node does not exist.

 * panic always if the node reference count was 0.
   We don't handle 0 -> 1 transitions here, and it doesn't make
   sense to acquire "another" reference to a node you
   haven't referenced.

Would have caught the ext2 use-after-free fixed in an earlier
commit.
This commit is contained in:
Augustin Cavalier
2025-08-28 13:57:11 -04:00
parent 4390b6b5c2
commit 6818591003
+12 -3
View File
@@ -3864,10 +3864,17 @@ acquire_vnode(fs_volume* volume, ino_t vnodeID)
ReadLocker nodeLocker(sVnodeLock);
struct vnode* vnode = lookup_vnode(volume->id, vnodeID);
if (vnode == NULL)
if (vnode == NULL) {
KDEBUG_ONLY(panic("acquire_vnode(%p, %" B_PRIdINO "): not found!", volume, vnodeID));
return B_BAD_VALUE;
}
if (inc_vnode_ref_count(vnode) == 0) {
// It isn't valid to acquire another reference to a vnode that
// you don't already have a reference to, so this should never happen.
panic("acquire_vnode(%p, %" B_PRIdINO "): node wasn't used!", volume, vnodeID);
}
inc_vnode_ref_count(vnode);
return B_OK;
}
@@ -3881,8 +3888,10 @@ put_vnode(fs_volume* volume, ino_t vnodeID)
vnode = lookup_vnode(volume->id, vnodeID);
rw_lock_read_unlock(&sVnodeLock);
if (vnode == NULL)
if (vnode == NULL) {
KDEBUG_ONLY(panic("put_vnode(%p, %" B_PRIdINO "): not found!", volume, vnodeID));
return B_BAD_VALUE;
}
dec_vnode_ref_count(vnode, false, true);
return B_OK;