From patchwork Mon Nov 18 21:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879075 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 0D9DF154BF0; Mon, 18 Nov 2024 21:19:07 +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=1731964747; cv=none; b=HzWFoPmXJmOLnxdV5lpwjQGgBty6TFZM/Gpg9Yv59V27TVvFNffONMzoTo/vL7TSY7pp2Ss+kX9+2wx/yL6qXbpU3pYgVDZ5/E8yxsJ310NQnfWV19D6J7lDyVvZff6+K1bweHPjJDP/X2eBSwNTi9AR5gCw9rjlX7Qe+dB5xmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964747; c=relaxed/simple; bh=jfdx65p7Fv7dUHacMnQ8f9wuz98vapBGuGj22cg29NA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hssGZWWGp8z3aOyfS9edBu3E2oK4BWwTVmbYZWsUw6NVNZMZqMpsQrWdFU1Zmjyf19joolMDmdgJfIwWMgVB7utV0Ux5MZNicjehTsGm2n2BBcSrra37Tva+zg8AMOblP6qp29dci5+811pv0Ioj+TFRx+d6OHHhRgivGUFEsrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MTRFlxyc; 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="MTRFlxyc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58AACC4CED9; Mon, 18 Nov 2024 21:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964746; bh=jfdx65p7Fv7dUHacMnQ8f9wuz98vapBGuGj22cg29NA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MTRFlxycNLBhqMhX+0pxDrKXLK0GD/XIlQ/AKyRJ+tjHDZc4ViviJSMVintUcxn87 ARl2ejVEWzL0SaQ+3bkcfWzcOMkZLKz3nFOKr7r5XbNwwokR/i8jSjjYrH5fsDQ9ke EAY2e1x3ZdYaM4zJEg1pQsuZ6rqvfcl6hrgGXa5CjKmna/oI8qcsCppWqsFCJaHRuB 7eBAHjLpkyJrh/wuwwWJGWrjExin4OSu+JPFrIRG/CiS6jt8lRT9UAea+m9c3Ez6ZT TeyBZ0/1cTg39ftcjauuBeRmPDiOl2LpGBsOneRHMgBwkLyVAsnY5m9hZbhQXvCbZs Y6m5dtQENhG4Q== From: cel@kernel.org To: Cc: , Jeff Layton , Dai Ngo , Chen Hanxiao Subject: [PATCH 6.1 1/5] NFSD: initialize copy->cp_clp early in nfsd4_copy for use by trace point Date: Mon, 18 Nov 2024 16:18:56 -0500 Message-ID: <20241118211900.3808-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211900.3808-1-cel@kernel.org> References: <20241118211900.3808-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 df9dbd93663e..50f17cee8bcf 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1768,6 +1768,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; @@ -1782,7 +1783,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:18:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879076 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 102F1154BF0; Mon, 18 Nov 2024 21:19:07 +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=1731964748; cv=none; b=ptXGpzJ6W+Fb4UGNvXvHG09B2tec5iEJIVIoVl+HjQOBEhnemHRcX7F+pMktBGl0aLZE1A+/sTMqhYpYosRTWyJlU9yzgEKRKSg57KtdKozPNs0Mkt4vH6svRKnVeGQxF3RML0+rgs2/RB2txzror42C9LRORARPrKGaYJ/GriM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964748; c=relaxed/simple; bh=x+ZlJ9WAnrggxSnSnHZz4wUcD0sX0yp4+zH+mfS8b8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNLm2ztRBsfqa1q50hGR/lGKO0ZS4KKzjhxX/bl36ycYN5QXClsoVG/g393KEtX2i/suFwqQv1OdKgoO16QK2iBbn4GIUALt/vcsi6SKllPbHT0qPeIlBKHUNEkAfKfnMBUOhrStB5S3dZmGIAi7TLD5iGxCixECnbo/rAdXFNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wb+CcC8H; 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="Wb+CcC8H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22599C4CECF; Mon, 18 Nov 2024 21:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964747; bh=x+ZlJ9WAnrggxSnSnHZz4wUcD0sX0yp4+zH+mfS8b8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wb+CcC8Hmm76YFlpWqcRbvfVIBCrEwlhN7LOQUTJEQyJ5nb+McyQapDOekb1949/b XE4URKQRk8Gh6J2wgSQ1OiIjHAhKx8uqZekUuJmXcT1wPIhKhplunCTcQQ7OqC5G32 YTZxJhU0TWGYlgdCvznXc0Ee5hTrHyMQlhVBzT/AXHlT0iC6owuhOWCZix/eKX9o4S D4gASKT5NCatXyMzw2NRc/2zoeuYacXQXHJvrD2kF6ya/G0X4QyIdyKnF03u2B1gaA nrFnWqus0RpVSSAK/J0MHq72MUw8kRIWoqZ7GRIVhva0d5kjQt2sOPgPKiD81/1yD8 yQwq5kwoMqhhA== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 6.1 2/5] NFSD: Async COPY result needs to return a write verifier Date: Mon, 18 Nov 2024 16:18:57 -0500 Message-ID: <20241118211900.3808-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211900.3808-1-cel@kernel.org> References: <20241118211900.3808-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-6.1.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 50f17cee8bcf..b8fb37cc59c4 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -717,15 +717,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) @@ -1593,7 +1584,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, @@ -1764,9 +1754,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)) { @@ -1786,8 +1781,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) @@ -1799,8 +1792,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:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879077 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 A9FCC154BF0; Mon, 18 Nov 2024 21:19:08 +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=1731964748; cv=none; b=AF0x/BD0U9lwpoKI3NJT9ZQMhkBZ+T39rTwB/RwKptZ/1KWbXE9GWoWDOHHG3D/wyoocSe7FtOpqA2Ad0OM0+jFTWWTU6/8Ean/9KyEID1NhZGRDEfhAv+CwNC8GMn8rMTYsUEInnHrAskopVuCBIlrIbcD9GddspAaHyyFySi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964748; c=relaxed/simple; bh=ItwqzqsjETC47W9U0Pcv8HL3d66AO8IYKlWyoLrn0H4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cPXjAzrJNRYOcC5f5I5ur3mNoV0WLgcpy4H3qYMxzJXkPp1pQTVDYTKVRry0oD427SDpz+ck7Gs2s94mUoTQk025ta/C4Ja6S44aEfV79zpVNQ8nSoPfp5h2Te9UqKEN3Qn2s/JV0O/YWcUhv+Urn6E77HNBgby126LdyMKT6R0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ik3MI2rX; 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="Ik3MI2rX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C70B3C4CED7; Mon, 18 Nov 2024 21:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964748; bh=ItwqzqsjETC47W9U0Pcv8HL3d66AO8IYKlWyoLrn0H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ik3MI2rXaxvX4w+sRB/B6HHl1dB6m9mBPhnm3vypFRFkA/n4ogzB2z3Mn1g5u/tG4 yXofY4Z2yHQbWa8vh1DqSURgQmdy+MpmWMYqcr8UGT2NDvghzKMr0c+6JXdJm/oKIN 86RWmBASwEyQv1cUsxSy7MCPoBzlse75Koiup0Yb3zmOOaeRt/ZJbLXAROIQIeumJb Qc8EBEKl0Vgetc6twqFvKOZSdSOKL2ADBxi7lc02SLvLJsFJsbglIPyn8aSfoRTXFb 66aG71tKFU7CjM6dlpZKhCqY3G9gYv+miRQc47gD7PkxvXM7/MNrpp+Yen/1WHa0Ur a9o+ww6PEr2fQ== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 6.1 3/5] NFSD: Limit the number of concurrent async COPY operations Date: Mon, 18 Nov 2024 16:18:58 -0500 Message-ID: <20241118211900.3808-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211900.3808-1-cel@kernel.org> References: <20241118211900.3808-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 b8fb37cc59c4..6637a7ef974b 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1243,6 +1243,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); } @@ -1781,10 +1782,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); @@ -1823,7 +1830,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 893d099e0099..e195012db48e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8076,6 +8076,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:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879078 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 6F080154BF0; Mon, 18 Nov 2024 21:19:09 +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=1731964749; cv=none; b=NQQAK+OHeuxbQThiqD0BKvu6LomLAXbUr3mDSCl3VdsXV/qlOoIIOAZ21BpKXhip0EXOsk8Yli4dgebltToxkqqs/oojOPkZ+1lH7o6NlTX3SPbOLFJGH0ZIwjgzms8PZaAyanPs0uyVz1NWXGOrNZid8UYkLOlddOA4aRHbEAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964749; c=relaxed/simple; bh=3eaJq0tUJXwU7juddQdOjpKHZ4TZ6rOQUlaYChzYvak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tIYWPf7uSfci3SVsNSonKTsYhlJWxx2MSyXOGVpR86BA3SPPAumZ9MsRef6QQXo2CTa0I20zShtwrJFVmOLXXE4GcOk8IkJFby1APSMGJ4kxk8NapBi7gxDjSwo88elD8u7EDANnHj3hpohVkae8W0RHfMwigTod2wDfNWm+vM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fE2h3vt6; 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="fE2h3vt6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79EF0C4AF0B; Mon, 18 Nov 2024 21:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964749; bh=3eaJq0tUJXwU7juddQdOjpKHZ4TZ6rOQUlaYChzYvak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fE2h3vt6isYgn0WS1NdXMmqC8semEr+vx4echXpr6QNkQBzWwbUdtupnD2Rmc25tn 0mn067FE4ut1OqxyBpicxrVcnoA6s5RRMInmZLYqhko4fTvJXkNXRLCHVKw9o1gOPf 3VlmOQGtKTlT1Px4QVbM0MUs6T+b86eSjsgmJaKsfUEMnC5Tariry1FTSb3TVemM3M aSgvpf7zW91uh8Q/0eheaBFfV+LFP2r3FtMoi1NS1MLCVQ54g8MfxX4qutPr6FdA8u gBG42iOGEHzVR+x4d3elwKQ6DBIx8+nbq5gmmMQfhMpaqocSf24PJq4rloz2Pttvsy iLYeas4LRVCPQ== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 6.1 4/5] NFSD: Initialize struct nfsd4_copy earlier Date: Mon, 18 Nov 2024 16:18:59 -0500 Message-ID: <20241118211900.3808-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211900.3808-1-cel@kernel.org> References: <20241118211900.3808-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 6637a7ef974b..c0f13989bd24 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1786,14 +1786,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:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879079 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 26805154BF0; Mon, 18 Nov 2024 21:19:09 +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=1731964750; cv=none; b=gx81gTMFpJWRFCXuVdwQi2wNyDa83C2zzJN+FeNjppl7EMN2NQOkJ7MMq4wfeZ0ixo6gypLANzBZSMwW28+Gyycyq1WjvhK97Pe+0oRsA09hXpqyPjn10xTUITwnhGqSsbQMbCq8mDeaZY3qisL4JGRY96akX8LIljyTBbew8i0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964750; c=relaxed/simple; bh=orkCVnDzF+xiTY+kNNPi5W+1mEpUW/y9zbnJ6oIcvog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m57tuqRXetDtCYmzsjRAb2M39KgBKlKZ9mXI1QRc23feayLu0MnRsPzqrVoEhtIxvU1vDZF3d/n/n+k1BacTtbSBYpKkRJ61wYRRkAz6LO3GatiALMcHGRu79d75wAIr+qHpZosOKpiXjM36FJoVk6cXbjuP1/gm1pQw4YcJ5w4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=azCnNcSd; 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="azCnNcSd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CC6DC4CEDA; Mon, 18 Nov 2024 21:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964749; bh=orkCVnDzF+xiTY+kNNPi5W+1mEpUW/y9zbnJ6oIcvog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azCnNcSd9HbuoCNGsk6FrqlbSCAafaa+G9ySCu6bLC5wYb+p5OuQw905gpYWKxIDM AcmBlBeMri4j17d2DPWObjat9Ch9vZj1KfotlBlWF8yqtgq1wpafLkI+pbcrQSwTOX AmafCyMGrvSFz7NPkvQIGtBfwIBIdx5bTP4M/p7akWjYeTdxE8ovvGN+k/3DQID1ID Pxamb26ca6mT/rqbHqq6FOFxhnW0Jw5KpgzDznNg+3o7k6Wjg1JdFTQaXKD6z467T+ zgf4J0WNl2/uCaqEYe5L8Iu7ss91QFfvd/rB89t6pYFdVI2QSjIwFmf0tXlheFjc4j nZxAasyuUo8XA== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 6.1 5/5] NFSD: Never decrement pending_async_copies on error Date: Mon, 18 Nov 2024 16:19:00 -0500 Message-ID: <20241118211900.3808-6-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211900.3808-1-cel@kernel.org> References: <20241118211900.3808-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 c0f13989bd24..0aebb2dc5776 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1790,10 +1790,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;