From nobody Thu Oct 19 19:36:49 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 4SBHz56Vnvz4xnmZ; Thu, 19 Oct 2023 19:36:49 +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 4SBHz561fqz3f3S; Thu, 19 Oct 2023 19:36:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697744209; 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=i1C9BNi73wMUFG+Mx/bYQffdMvV6xvlfJItwosyT2l8=; b=FxD0pgsTvKz/rCA2mYEiQeeU8e/kzXJ+1SWa7LCxcspVRIODFn13QQ182T0gHDhGufGZb/ Y8GcnifMxbKE4QOXCo50VAYHyJCKk305B3+ImUisJko6CZi1yB9HpcjRqqqSngzioOJwJq WqO9AXKDtCzv2H7BGjX/E5fjJQTMrwr2fk1SSSxR3nFhYbGFCnQvIppgF73Myn+/7iu4JJ 77Ko9HX8ix1qT+UzquytmM6SaOmTGotjYMZZHBHqXVOZ8tzSLGZuEPnaQiTiqsjLltSxow a9X2jH8OHA0QAazhDWgzplcEfJgNh5f5cKOMNkZwHObcFndNU24dnvY6UEb+gg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697744209; a=rsa-sha256; cv=none; b=oYz9T9sjc6yvzrdiohshtZsJd8dTgCZkoBVk5Kw0YDRyC6RfkevQdLVawWBozUpDuSKvSL W3aGEG8owCwVAIvy+PscYaTMk1SAhdPOeZcFHuExwArDA38n2Kdr2no560vQmqd49OeCgx 5TUehd4fnDlUAIWZ5xMRDxd768Nzb2JRCzhiE2myXyQEnv3xNqpAHAfVyBpN0dLNqkD7Ji uLsR5INVJ3XnIn6i2CgS0R6Y//xQ3sRM88YyK72fEpZmVq1qLZTAFRC0x5Sht2ETDe4BTZ gHi7//UYMvEWR6+FJZ2y1MEUXxBP2i4ArbbcQo5s/qhkFVZB91A8W+CAjBb0YQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697744209; 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=i1C9BNi73wMUFG+Mx/bYQffdMvV6xvlfJItwosyT2l8=; b=rdwNMuQI6+UyWNVFD/Io3wqUjICDduuAmCLVNrAXVl0E9aSLLS5NLAe2HIHlRMsQ6Bb52X IbtX+jvHYDY8Jncu5IcX76U0o0osFPaOvBzhD7vJPZpBo+A7zJTjmIBOFfD89bM+flbwrZ 6Buxf0Wz0Xq62aYyvvQI1g7ea6pLq6+EhAY5tFD4BfP0PR47NAC0vbi5mihBOXJ/ebwOUh +nay8ry4PFHBvhgI0BIp10qCS5iL0Li/68yuK+kG60N89bfV/fTsg4xx2CU/5v9K4aIdNo jojtjPkje8gWSd7z/Es6HhqosKLxeGb/fcLFOyEFQ+yp/+Ju5IHX8P132qU9ng== 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 4SBHz5545Lz134H; Thu, 19 Oct 2023 19:36:49 +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 39JJanw9094349; Thu, 19 Oct 2023 19:36:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39JJaniG094346; Thu, 19 Oct 2023 19:36:49 GMT (envelope-from git) Date: Thu, 19 Oct 2023 19:36:49 GMT Message-Id: <202310191936.39JJaniG094346@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: f300335d9aeb - main - nfsd: Fix NFSv4.1/4.2 Claim_Deleg_Cur_FH 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: f300335d9aebf2e99862bf783978bd44ede23550 Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=f300335d9aebf2e99862bf783978bd44ede23550 commit f300335d9aebf2e99862bf783978bd44ede23550 Author: Rick Macklem AuthorDate: 2023-10-19 19:35:35 +0000 Commit: Rick Macklem CommitDate: 2023-10-19 19:35:35 +0000 nfsd: Fix NFSv4.1/4.2 Claim_Deleg_Cur_FH When I implemented a test patch using Open Claim_Deleg_Cur_FH I discovered that the NFSv4.1/4.2 server was broken for this Open option. Fortunately it is never used by the FreeBSD client and never used by other clients unless delegations are enabled. (The FreeBSD NFSv4 server does not have delegations enabled by default.) Claim_Deleg_Cur_FH was broken because the code mistakenly assumed a stateID argument, which is not the case. This patch fixes the bug by changing the XDR parser to not expect a stateID and to fill most of the stateID in from the clientID. The clientID is the first two elements of the "other" array for the stateID and is sufficient to identify which client the delegation is issued to. Since there is only one delegation issued to a client per file, this is sufficient to locate the correct delegation. If you are running non-FreeBSD NFSv4.1/4.2 mounts against the FreeBSD server, you need this patch if you have delegations enabled. PR: 274574 MFC after: 2 weeks --- sys/fs/nfsserver/nfs_nfsdserv.c | 10 ++++++++-- sys/fs/nfsserver/nfs_nfsdstate.c | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index 7d3ebc683d16..3daee65ab83a 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -3000,12 +3000,18 @@ nfsrvd_open(struct nfsrv_descript *nd, __unused int isdgram, */ NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); claim = fxdr_unsigned(int, *tl); - if (claim == NFSV4OPEN_CLAIMDELEGATECUR || claim == - NFSV4OPEN_CLAIMDELEGATECURFH) { + if (claim == NFSV4OPEN_CLAIMDELEGATECUR) { NFSM_DISSECT(tl, u_int32_t *, NFSX_STATEID); stateid.seqid = fxdr_unsigned(u_int32_t, *tl++); NFSBCOPY((caddr_t)tl,(caddr_t)stateid.other,NFSX_STATEIDOTHER); stp->ls_flags |= NFSLCK_DELEGCUR; + } else if (claim == NFSV4OPEN_CLAIMDELEGATECURFH) { + /* Fill in most of the stateid from the clientid. */ + stateid.seqid = 0; + stateid.other[0] = clientid.lval[0]; + stateid.other[1] = clientid.lval[1]; + stateid.other[2] = 0; + stp->ls_flags |= NFSLCK_DELEGCUR; } else if (claim == NFSV4OPEN_CLAIMDELEGATEPREV || claim == NFSV4OPEN_CLAIMDELEGATEPREVFH) { stp->ls_flags |= NFSLCK_DELEGPREV; diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c index c73840277022..da57ebde7a52 100644 --- a/sys/fs/nfsserver/nfs_nfsdstate.c +++ b/sys/fs/nfsserver/nfs_nfsdstate.c @@ -2568,6 +2568,10 @@ tryagain: /* * For Delegate_Cur, search for the matching Delegation, * which indicates no conflict. + * For NFSv4.1/4.2 Claim_Deleg_Cur_FH only provides + * the clientid, which is the first two "other" elements + * for the stateid. This should be sufficient, since there + * is only one delegation per client and file. * An old delegation should have been recovered by the * client doing a Claim_DELEGATE_Prev, so I won't let * it match and return NFSERR_EXPIRED. Should I let it @@ -2578,8 +2582,8 @@ tryagain: (((nd->nd_flag & ND_NFSV41) != 0 && stateidp->seqid == 0) || stateidp->seqid == stp->ls_stateid.seqid) && - !NFSBCMP(stateidp->other, stp->ls_stateid.other, - NFSX_STATEIDOTHER)) + stateidp->other[0] == stp->ls_stateid.other[0] && + stateidp->other[1] == stp->ls_stateid.other[1]) break; } if (stp == LIST_END(&lfp->lf_deleg) || @@ -2830,6 +2834,10 @@ tryagain: /* * For Delegate_Cur, search for the matching Delegation, * which indicates no conflict. + * For NFSv4.1/4.2 Claim_Deleg_Cur_FH only provides + * the clientid, which is the first two "other" elements + * for the stateid. This should be sufficient, since there + * is only one delegation per client and file. * An old delegation should have been recovered by the * client doing a Claim_DELEGATE_Prev, so I won't let * it match and return NFSERR_EXPIRED. Should I let it @@ -2840,8 +2848,8 @@ tryagain: (((nd->nd_flag & ND_NFSV41) != 0 && stateidp->seqid == 0) || stateidp->seqid == stp->ls_stateid.seqid) && - !NFSBCMP(stateidp->other, stp->ls_stateid.other, - NFSX_STATEIDOTHER)) + stateidp->other[0] == stp->ls_stateid.other[0] && + stateidp->other[1] == stp->ls_stateid.other[1]) break; } if (stp == LIST_END(&lfp->lf_deleg) ||