nfscl: newnfs_copycred() cannot be called when a mutex is held

Since newnfs_copycred() calls crsetgroups() which in turn calls
crextend() which might do a malloc(M_WAITOK), newnfs_copycred()
cannot be called with a mutex held.  Fortunately, the malloc()
call is rarely done, since XU_GROUPS is 16 and the NFS client
uses a maximum of 17 (only 17 groups will cause the malloc() to
be called).  Further, it is only a problem if the malloc() tries
to sleep().  As such, this bug does not seem to have caused
problems in practice.

This patch fixes the one place in the NFS client where
newnfs_copycred() is called while a mutex is held by moving the
call to after where the mutex is released.

Found by inspection while working on an experimental patch.

MFC after:	2 weeks
This commit is contained in:
Rick Macklem 2023-11-06 14:25:30 -08:00
parent a6173e9463
commit 501bdf3001

View file

@ -526,6 +526,7 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
struct nfscldeleg *dp;
struct nfsnode *np;
struct nfsmount *nmp;
struct nfscred ncr;
u_int8_t own[NFSV4CL_LOCKNAMELEN], lockown[NFSV4CL_LOCKNAMELEN];
int error;
bool done;
@ -683,7 +684,7 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
* A read ahead or write behind is indicated by p == NULL.
*/
if (p == NULL)
newnfs_copycred(&op->nfso_cred, cred);
memcpy(&ncr, &op->nfso_cred, sizeof(ncr));
}
/*
@ -697,6 +698,8 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
stateidp->other[1] = op->nfso_stateid.other[1];
stateidp->other[2] = op->nfso_stateid.other[2];
NFSUNLOCKCLSTATE();
if (p == NULL)
newnfs_copycred(&ncr, cred);
return (0);
}