From patchwork Mon Nov 18 21:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879108 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DA0E155C94; Mon, 18 Nov 2024 21:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965027; cv=none; b=DIDHKIUqBScn0aZjFdc/vCF3j4SoBMYL1Cr5GHGfpXVsehq22Ewk4RRQFxsADdsQtuZqTS8bkuowE373Q/BHFraCBtCHI/cYVeqvmfI2Gk5on4zSv6lHUbpyaidIXiXytE7T3pM13nnqSS8ddmVXz5ytRSeTDt1cfbkOq4lM8r8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965027; c=relaxed/simple; bh=ytUBqDm/ZNlD24zTNRBFChXh1eKV2k05IMXuHZRh6IU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+ELI++xskOkv1i8LzdWowduQRKj8d0fEjvmxrGbuRix8rXE6yX3ohW1BuWUavSslNzlROkO7ZwOSVbSTI4JmZqnnGV+EscjChKTo/8Hp+J+eKFSr+IlHShObpqrs7hiicpxoRtxg4hK30pLWXTfQeSJQeD96aw6bwm1t3aLnXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=meb+PPfK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="meb+PPfK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 777CBC4CED7; Mon, 18 Nov 2024 21:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731965027; bh=ytUBqDm/ZNlD24zTNRBFChXh1eKV2k05IMXuHZRh6IU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=meb+PPfK6rFfeIyv44mJokHHz9XmKggHw3gBbabBKyrdNz5R6QLPWyVlWrt02pA1A CIIyaHx0PUr1nhQcvoxvfS636UMTH9W5gv806CEiyCwju8ukCkO0dJYqo3dKpYoioc 7crHMZxz7ghq05e1gYrKivUo55CznnlvNvcezPoFssVPX85rbsh+Q6fID7sNcZmvVU wrXGGJkSWqKTFhwkAyg+8b+Bk3lSxCXRMlESvfvht0XY+m88Owjr+Wxm3J5rK8K74T N7XSrewwrZVghCWN1QsrDre6GOS/yGcfCpxNnAV4jzP1RBZBjC2LMde8XUs+xwPZtj i5SI3YBEE/PMQ== From: cel@kernel.org To: Cc: , Jeff Layton , Dai Ngo , Chen Hanxiao Subject: [PATCH 5.15 1/5] NFSD: initialize copy->cp_clp early in nfsd4_copy for use by trace point Date: Mon, 18 Nov 2024 16:23:39 -0500 Message-ID: <20241118212343.3935-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118212343.3935-1-cel@kernel.org> References: <20241118212343.3935-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Dai Ngo [ Upstream commit 15d1975b7279693d6f09398e0e2e31aca2310275 ] Prepare for adding server copy trace points. Signed-off-by: Dai Ngo Tested-by: Chen Hanxiao Stable-dep-of: 9ed666eba4e0 ("NFSD: Async COPY result needs to return a write verifier") Signed-off-by: Chuck Lever --- fs/nfsd/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 11dcf3debb1d..2b1fcf5b6bf8 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1769,6 +1769,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, __be32 status; struct nfsd4_copy *async_copy = NULL; + copy->cp_clp = cstate->clp; if (nfsd4_ssc_is_inter(copy)) { if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) { status = nfserr_notsupp; @@ -1783,7 +1784,6 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, return status; } - copy->cp_clp = cstate->clp; memcpy(©->fh, &cstate->current_fh.fh_handle, sizeof(struct knfsd_fh)); if (nfsd4_copy_is_async(copy)) { From patchwork Mon Nov 18 21:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879109 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3639155C94; Mon, 18 Nov 2024 21:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965027; cv=none; b=bPFIhX/TLoc+oeBqJZFpIbhWH76OfHuANm3v2FeJt4WZO+YC4sxjQd9v2etx+xv6GobARfEAbHUqjAZlvL+QwFpnYq0C0UFLVxF6pMaDUdjpAcVDBs9bs7X23ZD2X48UDrN7IzNW/9KoGdcRetlQvtkASLq6KyQCro5VP0CL190= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965027; c=relaxed/simple; bh=WlN6EyvwzLWfTLJxsOJCYPugmd+8BLbDPYS8E698i5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MnapmXirF8hPjITlvJF1EML50ZG77ijWenXC2W6lvWbV79Zh2h3Qhbvv1CESNCesQ8fnvzp56muHYjr68LrTy13AtxJm3xSxQ86vz9cFZcIeDGtejL1GGvYHtDBiPTAYzYCroYQl5eXDz+UdqLVAw3NyKovyzYFe4zZbOFopEWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SAz+gWIa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SAz+gWIa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39A00C4CEDA; Mon, 18 Nov 2024 21:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731965027; bh=WlN6EyvwzLWfTLJxsOJCYPugmd+8BLbDPYS8E698i5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SAz+gWIa4SlEod9OvXez9gXzl90+rAoTHW/1flYmnO4tTqXuo8PzNBqE0v9iJEZmS 8MbEOtK/J3QGZVexk8kx9YlnCzBX+CWj8m/QXH8ZfL3iBGAg+yEadmB4uPta6hoNjj bcVeMjnq62knXb/uDU/wPJZNZbjEljtZPLmdvcpifHAWRqztA8o14cnTZXopj2l5MZ XlOgBRzFSX4Xk+O5Jc6lFC95gOekc+Fn5cf2deozU39fvOcydB+BbNedabd7MKWALf D5zmit3MyQyc9zjqwHRFxTvfECfVndtXbI6HXMx2G7kkV7k1Ubto25QzOdtPOSZ0+v FhPix/RoXqKAg== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 5.15 2/5] NFSD: Async COPY result needs to return a write verifier Date: Mon, 18 Nov 2024 16:23:40 -0500 Message-ID: <20241118212343.3935-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118212343.3935-1-cel@kernel.org> References: <20241118212343.3935-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever [ Upstream commit 9ed666eba4e0a2bb8ffaa3739d830b64d4f2aaad ] Currently, when NFSD handles an asynchronous COPY, it returns a zero write verifier, relying on the subsequent CB_OFFLOAD callback to pass the write verifier and a stable_how4 value to the client. However, if the CB_OFFLOAD never arrives at the client (for example, if a network partition occurs just as the server sends the CB_OFFLOAD operation), the client will never receive this verifier. Thus, if the client sends a follow-up COMMIT, there is no way for the client to assess the COMMIT result. The usual recovery for a missing CB_OFFLOAD is for the client to send an OFFLOAD_STATUS operation, but that operation does not carry a write verifier in its result. Neither does it carry a stable_how4 value, so the client /must/ send a COMMIT in this case -- which will always fail because currently there's still no write verifier in the COPY result. Thus the server needs to return a normal write verifier in its COPY result even if the COPY operation is to be performed asynchronously. If the server recognizes the callback stateid in subsequent OFFLOAD_STATUS operations, then obviously it has not restarted, and the write verifier the client received in the COPY result is still valid and can be used to assess a COMMIT of the copied data, if one is needed. Reviewed-by: Jeff Layton [ cel: adjusted to apply to origin/linux-5.15.y ] Signed-off-by: Chuck Lever --- fs/nfsd/nfs4proc.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 2b1fcf5b6bf8..08d90e0e8fae 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -718,15 +718,6 @@ nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, &access->ac_supported); } -static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) -{ - __be32 *verf = (__be32 *)verifier->data; - - BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data)); - - nfsd_copy_write_verifier(verf, net_generic(net, nfsd_net_id)); -} - static __be32 nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) @@ -1594,7 +1585,6 @@ static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) test_bit(NFSD4_COPY_F_COMMITTED, ©->cp_flags) ? NFS_FILE_SYNC : NFS_UNSTABLE; nfsd4_copy_set_sync(copy, sync); - gen_boot_verifier(©->cp_res.wr_verifier, copy->cp_clp->net); } static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy, @@ -1765,9 +1755,14 @@ static __be32 nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { - struct nfsd4_copy *copy = &u->copy; - __be32 status; + struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); struct nfsd4_copy *async_copy = NULL; + struct nfsd4_copy *copy = &u->copy; + struct nfsd42_write_res *result; + __be32 status; + + result = ©->cp_res; + nfsd_copy_write_verifier((__be32 *)&result->wr_verifier.data, nn); copy->cp_clp = cstate->clp; if (nfsd4_ssc_is_inter(copy)) { @@ -1787,8 +1782,6 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, memcpy(©->fh, &cstate->current_fh.fh_handle, sizeof(struct knfsd_fh)); if (nfsd4_copy_is_async(copy)) { - struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); - status = nfserrno(-ENOMEM); async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); if (!async_copy) @@ -1800,8 +1793,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out_err; if (!nfs4_init_copy_state(nn, copy)) goto out_err; - memcpy(©->cp_res.cb_stateid, ©->cp_stateid.cs_stid, - sizeof(copy->cp_res.cb_stateid)); + memcpy(&result->cb_stateid, ©->cp_stateid.cs_stid, + sizeof(result->cb_stateid)); dup_copy_fields(copy, async_copy); async_copy->copy_task = kthread_create(nfsd4_do_async_copy, async_copy, "%s", "copy thread"); From patchwork Mon Nov 18 21:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879110 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 728D7155C94; Mon, 18 Nov 2024 21:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965028; cv=none; b=M8N2f8wyXot4snnk3c+MPmfuC8Pen9kr0DE6+YrU/tfXPbabGBvMGhlQgQQC0XmZ51Z5rxxK+SQ/rf0JUQ8mxzVddkQoz/o97Ly0jVWMx3XMuju+eOWjFIV8LiocImzRZ7jWNp2SnBXXjzhYtaoZxLoH31iaufCzgjGb56+EFMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965028; c=relaxed/simple; bh=+7sm/tQdvitSOS6l7ydW5R5PAUM8zvgonJY0FUU0fnw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SbOuGYTZ7yMZJb6JMXfrTCCUXwfyGfjh6fd+OZuGOcexV/CgRF7MkLdwTTKmz9jrfBOr93kh+LEuMLJLYLKVB2yg5j/zFa5SHtWrtHlmFJHvwcgPKSJ5ehuIvd90MKWtpJF6s2Y1+XSz4u3FLKI9EutGcUUwer9a1VEaNJbHVIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DKR2Zm5V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DKR2Zm5V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE795C4CECF; Mon, 18 Nov 2024 21:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731965028; bh=+7sm/tQdvitSOS6l7ydW5R5PAUM8zvgonJY0FUU0fnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DKR2Zm5VfXRi98heetYcqC1KC77UeYn4ws0Uy7X2BUhmvGCzpOU7u6fHHgyKVdRqj iEk9UgULs/0keTeiTzoff8/K3nZnu0agJgax4RnzQKpk35BiSlPOB4gmBiPoA7pa5U JmzbLul8xahl7yDo7T9YY5Au8MooWjNnSLOh1NWKIlkspI+2/DllcGvMDvdcNlLEcT bY/b5br+ODQA6Djh4kL32YL4s+wTk+2cPVp3wkRDfarZxkKlh5cTy3DExzRgZj8rF/ qychgW+E+JDwIw6xWOOdup90PcpF7dzaTPDERHHUZBtjhuShkuNer51dDbmx+Uwmz3 kv5rQbfHy++tQ== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 5.15 3/5] NFSD: Limit the number of concurrent async COPY operations Date: Mon, 18 Nov 2024 16:23:41 -0500 Message-ID: <20241118212343.3935-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118212343.3935-1-cel@kernel.org> References: <20241118212343.3935-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever [ Upstream commit aadc3bbea163b6caaaebfdd2b6c4667fbc726752 ] Nothing appears to limit the number of concurrent async COPY operations that clients can start. In addition, AFAICT each async COPY can copy an unlimited number of 4MB chunks, so can run for a long time. Thus IMO async COPY can become a DoS vector. Add a restriction mechanism that bounds the number of concurrent background COPY operations. Start simple and try to be fair -- this patch implements a per-namespace limit. An async COPY request that occurs while this limit is exceeded gets NFS4ERR_DELAY. The requesting client can choose to send the request again after a delay or fall back to a traditional read/write style copy. If there is need to make the mechanism more sophisticated, we can visit that in future patches. Cc: stable@vger.kernel.org Reviewed-by: Jeff Layton Link: https://nvd.nist.gov/vuln/detail/CVE-2024-49974 Signed-off-by: Chuck Lever --- fs/nfsd/netns.h | 1 + fs/nfsd/nfs4proc.c | 11 +++++++++-- fs/nfsd/nfs4state.c | 1 + fs/nfsd/xdr4.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index 548422b24a7d..41c750f34473 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -152,6 +152,7 @@ struct nfsd_net { u32 s2s_cp_cl_id; struct idr s2s_cp_stateids; spinlock_t s2s_cp_lock; + atomic_t pending_async_copies; /* * Version information diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 08d90e0e8fae..54f43501fed9 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1244,6 +1244,7 @@ static void nfs4_put_copy(struct nfsd4_copy *copy) { if (!refcount_dec_and_test(©->refcount)) return; + atomic_dec(©->cp_nn->pending_async_copies); kfree(copy->cp_src); kfree(copy); } @@ -1782,10 +1783,16 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, memcpy(©->fh, &cstate->current_fh.fh_handle, sizeof(struct knfsd_fh)); if (nfsd4_copy_is_async(copy)) { - status = nfserrno(-ENOMEM); async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); if (!async_copy) goto out_err; + async_copy->cp_nn = nn; + /* Arbitrary cap on number of pending async copy operations */ + if (atomic_inc_return(&nn->pending_async_copies) > + (int)rqstp->rq_pool->sp_nrthreads) { + atomic_dec(&nn->pending_async_copies); + goto out_err; + } INIT_LIST_HEAD(&async_copy->copies); refcount_set(&async_copy->refcount, 1); async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL); @@ -1824,7 +1831,7 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } if (async_copy) cleanup_async_copy(async_copy); - status = nfserrno(-ENOMEM); + status = nfserr_jukebox; goto out; } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 5ab3045c649f..a7016f738647 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8079,6 +8079,7 @@ static int nfs4_state_create_net(struct net *net) spin_lock_init(&nn->client_lock); spin_lock_init(&nn->s2s_cp_lock); idr_init(&nn->s2s_cp_stateids); + atomic_set(&nn->pending_async_copies, 0); spin_lock_init(&nn->blocked_locks_lock); INIT_LIST_HEAD(&nn->blocked_locks_lru); diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 510978e602da..9bd1ade6ba54 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -574,6 +574,7 @@ struct nfsd4_copy { struct nfsd4_ssc_umount_item *ss_nsui; struct nfs_fh c_fh; nfs4_stateid stateid; + struct nfsd_net *cp_nn; }; static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync) From patchwork Mon Nov 18 21:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879111 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35EA0155C94; Mon, 18 Nov 2024 21:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965029; cv=none; b=nkcMTjYxxeV5yZWsYb9R88yGExGTHrEn7y3AXhcctPuKMf+3YlwkNZOZL2M4SmQ38zPwsLprE4iS4fwOnfFrxD7+p82rA4IV8ENNTsDAmGwTXxB0Sx/knZPB5P1ZrqEiQ2J/u2k3+hk7yk6dialrZKZfc+a4oE3ite2YrYk1V0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965029; c=relaxed/simple; bh=L/5WbSn0Hcf4WWyoyklgYacsCyDIHh4RMBF1geAQ6hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cKC/oIzC2QtUygD2uLJnSQ7sLTdID9/nRXrCjh9C5EEmu43fkBut33GRORbH2vHI3UDOYA5uUgSmJdNPRkLimo77w5cDHvxMZG62fa5NNqHjj/xFPeseFDiWZC9Aq0zfIY4dC89igm59FAHR3gRAyl2jlGloF2aIfb8uBMo46IY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FFG9dEM8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FFG9dEM8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ECB8C4CEDB; Mon, 18 Nov 2024 21:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731965029; bh=L/5WbSn0Hcf4WWyoyklgYacsCyDIHh4RMBF1geAQ6hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFG9dEM8I5f5nL7aEdgzMEQzAHCJJtDvomGrLk2w8xdtQbfHVSx187l7gyKPnJmaW sZkbSmofYBv/pbGf+UKgiTiOZ5VOzkufCIjbhH0IR8uDoD/S3BMsgnwCniU8N+2wIK ReyAZ7N+aPRX03xxqPumuhxdWyFeJ8DuIKb6yxxgE3j+sZc8yQ0P7UKFA25OHnE+75 exHiMH7hiSvao/2rzvHBAy/Wv9wg37M9ldTl43gefo1xVSQ6rhOETl4/QoPqIFER6Z lm7fYCi8W0fid8guwyyUcn2+JXrTA202/AFewjvbNvzS5Ny+679NdVLMfgARaHZXus 86q8t1vLwIp+Q== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 5.15 4/5] NFSD: Initialize struct nfsd4_copy earlier Date: Mon, 18 Nov 2024 16:23:42 -0500 Message-ID: <20241118212343.3935-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118212343.3935-1-cel@kernel.org> References: <20241118212343.3935-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever [ Upstream commit 63fab04cbd0f96191b6e5beedc3b643b01c15889 ] Ensure the refcount and async_copies fields are initialized early. cleanup_async_copy() will reference these fields if an error occurs in nfsd4_copy(). If they are not correctly initialized, at the very least, a refcount underflow occurs. Reported-by: Olga Kornievskaia Fixes: aadc3bbea163 ("NFSD: Limit the number of concurrent async COPY operations") Reviewed-by: Jeff Layton Tested-by: Olga Kornievskaia Signed-off-by: Chuck Lever --- fs/nfsd/nfs4proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 54f43501fed9..6267a41092ae 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1787,14 +1787,14 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (!async_copy) goto out_err; async_copy->cp_nn = nn; + INIT_LIST_HEAD(&async_copy->copies); + refcount_set(&async_copy->refcount, 1); /* Arbitrary cap on number of pending async copy operations */ if (atomic_inc_return(&nn->pending_async_copies) > (int)rqstp->rq_pool->sp_nrthreads) { atomic_dec(&nn->pending_async_copies); goto out_err; } - INIT_LIST_HEAD(&async_copy->copies); - refcount_set(&async_copy->refcount, 1); async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL); if (!async_copy->cp_src) goto out_err; From patchwork Mon Nov 18 21:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879112 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 375F61E5722; Mon, 18 Nov 2024 21:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965030; cv=none; b=FypkAYIQ1cCFXq6afbNTmoj9uDAwrQff7timhxXvwqR14x8yI4O+f/i0QWod0p6Z5r4Iv9nfIcHSRrnpDvUwDn1s/6M7qT1z4hiE92wvvCY6GgtDccjdvg77PbSQLFLrUTEatmHEScm4KrmwAOBH2ZuaUURWrNvvyOrNaHRnhbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731965030; c=relaxed/simple; bh=MmNZW2BO6/hZLJY2y2H8eprKc3nS4nEdDPVPe3ok95Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dUCuWITOZX+K4PB7LazHlBDY2sifRXuz+XML5SOoc/TXDDDFom0GFvNv9N6Je1D1b0GbqC4aAnmVHvmi0MB+TciApERxSIam0w5r+9HgCX1I/zdvMIsyKIvL9VFmrHvW+oR0Y8J5O5Hdb73WcqEBRkHPTqHfJGys505sgxfOYlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VarhFoo+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VarhFoo+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52FAEC4CECF; Mon, 18 Nov 2024 21:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731965029; bh=MmNZW2BO6/hZLJY2y2H8eprKc3nS4nEdDPVPe3ok95Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VarhFoo+bD8EV4vtfjsTHb0hnuw4tCK+DmR3lb9c/HeiGKg6BWpsdPbFJtWY94LOP F5z6NYHv7PtcxG2QcP7Dw3C/eK9thRLNkmGC3TR+V1IpjmL6czqFU3xaNcESMVLk8z V8OIrSheu4sAvxM+yJjhsx4laFjvwZFwo04Y5yVbEKwmHaxrTtyfE1LyqnFToGUzqs O5dtXpFO8mnOljyQegW4eZvIfBMWDoLAtXvwAMc/Psp7T/O6AaTHFF/bn8ovakHfE1 JragYNmIxGHKhVlFW35C0G1nnlfguHYQHyimhVMuwin4o8y/YyEHNtNZB3DVdGIfQP BFVpIA/VWyhZA== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 5.15 5/5] NFSD: Never decrement pending_async_copies on error Date: Mon, 18 Nov 2024 16:23:43 -0500 Message-ID: <20241118212343.3935-6-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118212343.3935-1-cel@kernel.org> References: <20241118212343.3935-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever [ Upstream commit 8286f8b622990194207df9ab852e0f87c60d35e9 ] The error flow in nfsd4_copy() calls cleanup_async_copy(), which already decrements nn->pending_async_copies. Reported-by: Olga Kornievskaia Fixes: aadc3bbea163 ("NFSD: Limit the number of concurrent async COPY operations") Signed-off-by: Chuck Lever --- fs/nfsd/nfs4proc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 6267a41092ae..0b698e25826f 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1791,10 +1791,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, refcount_set(&async_copy->refcount, 1); /* Arbitrary cap on number of pending async copy operations */ if (atomic_inc_return(&nn->pending_async_copies) > - (int)rqstp->rq_pool->sp_nrthreads) { - atomic_dec(&nn->pending_async_copies); + (int)rqstp->rq_pool->sp_nrthreads) goto out_err; - } async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL); if (!async_copy->cp_src) goto out_err;