git: 2a22edfc70ad - stable/13 - ncl_bioread(): check for vp->v_object before accessing it

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 17 Jan 2024 10:05:26 UTC
The branch stable/13 has been updated by kib:

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

commit 2a22edfc70ad442bdf5060f48ea673faebfaa386
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-01-15 11:49:14 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-01-17 10:04:48 +0000

    ncl_bioread(): check for vp->v_object before accessing it
    
    (cherry picked from commit 503f72a828c7d0d938ec73ffbf62406038c69d47)
---
 sys/fs/nfsclient/nfs_clbio.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index 7b9b68782d53..f6b8cc0a70a4 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -417,6 +417,18 @@ out:
 	return (error);
 }
 
+static bool
+ncl_bioread_dora(struct vnode *vp)
+{
+	vm_object_t obj;
+
+	obj = vp->v_object;
+	if (obj == NULL)
+		return (true);
+	return (!vm_object_mightbedirty(vp->v_object) &&
+	    vp->v_object->un_pager.vnp.writemappings == 0);
+}
+
 /*
  * Vnode op for read using bio
  */
@@ -489,9 +501,7 @@ ncl_bioread(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred)
 		 * unlocked read by nfsiod could obliterate changes
 		 * done by userspace.
 		 */
-		if (nmp->nm_readahead > 0 &&
-		    !vm_object_mightbedirty(vp->v_object) &&
-		    vp->v_object->un_pager.vnp.writemappings == 0) {
+		if (nmp->nm_readahead > 0 && ncl_bioread_dora(vp)) {
 		    for (nra = 0; nra < nmp->nm_readahead && nra < seqcount &&
 			(off_t)(lbn + 1 + nra) * biosize < nsize; nra++) {
 			rabn = lbn + 1 + nra;
@@ -678,9 +688,7 @@ ncl_bioread(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred)
 		 *  directory offset cookie of the next block.)
 		 */
 		NFSLOCKNODE(np);
-		if (nmp->nm_readahead > 0 &&
-		    !vm_object_mightbedirty(vp->v_object) &&
-		    vp->v_object->un_pager.vnp.writemappings == 0 &&
+		if (nmp->nm_readahead > 0 && ncl_bioread_dora(vp) &&
 		    (bp->b_flags & B_INVAL) == 0 &&
 		    (np->n_direofoffset == 0 ||
 		    (lbn + 1) * NFS_DIRBLKSIZ < np->n_direofoffset) &&