From nobody Mon Nov 06 22:26:30 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SPQtZ70Vtz50Qpr; Mon, 6 Nov 2023 22:26:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SPQtZ4yBrz4GPk; Mon, 6 Nov 2023 22:26:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699309590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cFlAh0QqAS0pGF5WU0arVXuZgrVWw9pxRhNjB8Zg4S4=; b=DYZmSP7lVXxd+k6GLQnq+bs91PDOrG6+/zxWURYFW0xm+j6FlaKqxwRAEB6dPrX0U4IMdz X6+uvYDp1KrXsY9Sof6snWePhKyRqvx5JJRS9Ctf66gVoLVWyGOJijcnOwlrmskCgH1N9D 14LDu2goNNpwq2y+bEBB1mW+y8go/fqDAXVOcmp0YU4RMSI+QbNVUQ8iquYqHGoLAXB6y0 o8LssL6Q2ivvXogsIiknSd6UfYQ3SX0AW4NDs1+9Cye01nfV0Eyxvl2B8jFUKAqaTtJ8jM kuh6WRkGDLy+vsdHo7ciTZaxmdvdNdXYUkGJO2CRXAaMri1ZikNZbFJZRUPZ9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699309590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cFlAh0QqAS0pGF5WU0arVXuZgrVWw9pxRhNjB8Zg4S4=; b=h15p7KgIbZtrR5PcKkgL1kK/L3wyCQyfxoI0XDrSdVPMIJZTJ66od/QAFpxQ/gxzESzyMs ek4AZOo0X+doktWtAOXmMhfH+9kI1JzfBiQtjHs99Lyg6UdirUk8y/0IPMR5ASX6tgiwq4 CFTcFDvT5H989GzJwzUa30DvokpHSMJlwwLmEsL2Dda+gQYGKh1ygDq9nz6QZqaqPjeVai Z/rsMvp4jqDCm9hHR7G1s47nnzo8c+VIwYJzfNOGIxCAnL5qlcIFw866n8AtodcZUsHBRn 0iTsWNrAi19cXKh2r9xhGo+3p8Wl8BqF/MVRZCSFZIRyLSbvxnKrZgqUqanBkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699309590; a=rsa-sha256; cv=none; b=r5mLXfyxLryr2j8lK/VC7zJdPG8SeoC2fvgfHs8qxCihABPquldFLR/yDBh6wrMaY/5P1p NdGT3o2INJ+XIGNPi1Co6KfMoximcvvM70zVcqGsOPPZkUHIITmMyQbu7awCfUrmZ2ofxL 5b/hRmEEMVrfW8CQFKxuwoaBTK1kOIWdR+5vMbn6hQKfUOxNVw2LwJ+/d/UZxq9e/s+/Jh jOEEoLBkujw9Z6Nr48pERRjIdMomexNtJ07krJjqs++GUuhCFcSPAMWTlmU8k++nDvJq60 zfF07hkV6T9sfsjFvV5MutnMm9HgfoE4DkdVx6eAd1HsxvCeyvxP58Ugaw90Dw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SPQtZ42Tnz9Wc; Mon, 6 Nov 2023 22:26:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3A6MQU56028450; Mon, 6 Nov 2023 22:26:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A6MQU0o028447; Mon, 6 Nov 2023 22:26:30 GMT (envelope-from git) Date: Mon, 6 Nov 2023 22:26:30 GMT Message-Id: <202311062226.3A6MQU0o028447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 501bdf300119 - main - nfscl: newnfs_copycred() cannot be called when a mutex is held List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 501bdf3001190686bf55d9d333cb533858c2cf2f Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=501bdf3001190686bf55d9d333cb533858c2cf2f commit 501bdf3001190686bf55d9d333cb533858c2cf2f Author: Rick Macklem AuthorDate: 2023-11-06 22:25:30 +0000 Commit: Rick Macklem CommitDate: 2023-11-06 22:25:30 +0000 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 --- sys/fs/nfsclient/nfs_clstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index 579210941802..ebc11efea637 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -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); }