git: b09b120818a8 - stable/14 - vn_lock_pair(): allow lkflags1/lkflags2 to be 0 if vp1/vp2 is NULL

From: Jason A. Harmening <jah_at_FreeBSD.org>
Date: Sun, 24 Mar 2024 03:04:40 UTC
The branch stable/14 has been updated by jah:

URL: https://cgit.FreeBSD.org/src/commit/?id=b09b120818a81b83a3e3201b4c301335d0c48fac

commit b09b120818a81b83a3e3201b4c301335d0c48fac
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2024-02-23 17:31:08 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2024-03-24 02:55:37 +0000

    vn_lock_pair(): allow lkflags1/lkflags2 to be 0 if vp1/vp2 is NULL
    
    It's a bit strange to require the caller to pass contrived lock flags
    if the corresponding vnode is NULL, simply to appease the assertion
    that exactly one of LK_SHARED or LK_EXCLUSIVE must be set.  On the
    other hand, we still want to catch cases in which completely bogus
    or corrupt flags are passed even if the corresponding vnode is NULL.
    Therefore, specifically allow empty flags for lkflags1/lkflags2 iff
    the respective vp1/vp2 param is NULL.
    
    Reviewed by:            kib, olce
    Differential Revision:  https://reviews.freebsd.org/D44046
    
    (cherry picked from commit fa26f46dc29f5ee1ac8e7b10fc12aa1f93cce702)
---
 sys/kern/vfs_vnops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 62339387d7d0..a16e137755b1 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -4103,9 +4103,11 @@ vn_lock_pair(struct vnode *vp1, bool vp1_locked, int lkflags1,
 {
 	int error, locked1;
 
-	MPASS(((lkflags1 & LK_SHARED) != 0) ^ ((lkflags1 & LK_EXCLUSIVE) != 0));
+	MPASS((((lkflags1 & LK_SHARED) != 0) ^ ((lkflags1 & LK_EXCLUSIVE) != 0)) ||
+	    (vp1 == NULL && lkflags1 == 0));
 	MPASS((lkflags1 & ~(LK_SHARED | LK_EXCLUSIVE | LK_NODDLKTREAT)) == 0);
-	MPASS(((lkflags2 & LK_SHARED) != 0) ^ ((lkflags2 & LK_EXCLUSIVE) != 0));
+	MPASS((((lkflags2 & LK_SHARED) != 0) ^ ((lkflags2 & LK_EXCLUSIVE) != 0)) ||
+	    (vp2 == NULL && lkflags2 == 0));
 	MPASS((lkflags2 & ~(LK_SHARED | LK_EXCLUSIVE | LK_NODDLKTREAT)) == 0);
 
 	if (vp1 == NULL && vp2 == NULL)