From patchwork Tue Nov 19 00:47:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879321 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 64F41196; Tue, 19 Nov 2024 00:47:36 +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=1731977256; cv=none; b=DwvX9pxnNpqU4kkR3pUK6ZvE+J1RlrYDA/79mDSyRAKKX/Q7f3JGfZlmO9QG9dnbqNjZAHebov2ioxK0rOfCi1P1luUgzVBdDNXwCoXUj9Vfn2i7FiwpGRQA67hQEEODokntPX5+UnrwmSKjNrKeJJmCkA7WP5fl4SxTNcYxS/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731977256; c=relaxed/simple; bh=Y/t9DqFLgpHIwTerHxr91KCR8QJ6dvKYi6drrUFjCLs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtPiK9UrZ3QE3rd/oyUhnteUBnHmvt8wJYKOmi16qpH5i8TtVUUQpT2Ot7frbs9hnacqWbtvcCfcWBVON9Mwy9VOhonstmAh0DY24/VqEMfMcdlXTYo/0SwB6p+0xSTpeSEcN4VJE7+41e6LLwu6luyef/yksTwmA7WS8E8bB4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F+XjMk7s; 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="F+XjMk7s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EE1DC4CECF; Tue, 19 Nov 2024 00:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731977255; bh=Y/t9DqFLgpHIwTerHxr91KCR8QJ6dvKYi6drrUFjCLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+XjMk7s+DEsPoivKYX41ALsdEoHrVVhsTnXNwHNVTS9Welsgr1yD6cTwAW9e8KX8 9s9spKgzzP8vJiXHz5xteBuH7BKm46fHABY9WKEyuYJFf4G+sp6HJSNnILLQmiEVny 0Pv8suFTwZ5TTbASVvOa8lO86+YUoqksyyk7A2B0jHW8QA3ZK/SWX8AsmuYJ4kRVxc BvEUtW2/ve/DRvAFyweRE+F4jQ4iMV63i6B6Gb6+5/j/KPrWMwc+apz4qe65FGdTqc RM2VZB+e8vzeY6ENOSz+y7vwxcmjq3htrCovnsC5UnGEHZenqZXQcFuc5nuYm8PaPb smVMKRSc9S4QA== From: cel@kernel.org To: Cc: , Jeff Layton , Dai Ngo , Chen Hanxiao Subject: [PATCH 5.10 1/5] NFSD: initialize copy->cp_clp early in nfsd4_copy for use by trace point Date: Mon, 18 Nov 2024 19:47:28 -0500 Message-ID: <20241119004732.4703-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119004732.4703-1-cel@kernel.org> References: <20241119004732.4703-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 f10e70f37285..fbd42c1a3fcd 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 Tue Nov 19 00:47:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879322 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 1860A196; Tue, 19 Nov 2024 00:47:36 +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=1731977257; cv=none; b=Lj1DVgDaaHk6fO7vZYxsvmtQamNUips2+2a1lS2vtNjO1B61iTWTRNOPltAwQETpAokT2aw9GDSZxERJ9JAxoqgWnQT+XAaIsWQc6Zy0R7aJBOSQsQZi6rydK5S9Jf5NfUxt4bInYwx9ZeaQ6gpXk8oohUzjmi2aVwQKHBOfJy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731977257; c=relaxed/simple; bh=HfJjDxVHH7DeLmy5LOX0yFADowwiC4wUFP0XtIYNC84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=borvOeCuXR/q3s3EyknpH3tcS5se7tS2KBz1Pug5OPZLD/G7amlPYLPnUSnZZ6fxfJEifwGfMIQSMBvlMevqbge/Bws/CbdxjWBOytvrkPpFsf0Sck0QY/laczhkkYOvn6AKnPSI42TRPBEdbDwwb2YNja4RWBICTtOhGfDAwG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dY+Q7Bip; 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="dY+Q7Bip" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 223D2C4CED0; Tue, 19 Nov 2024 00:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731977256; bh=HfJjDxVHH7DeLmy5LOX0yFADowwiC4wUFP0XtIYNC84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dY+Q7BipWBP+B2rUxKXt/GCgHqZmUOnKp6eRyPZ4/eMRuOwqk/aS1gu5dLBUTRoY3 kMNrEopCgNnBbtUkwwHO2ItVMI+TJkjJdXDW3/WsMFB8HHe40SOXlwmYZay2M30iya YNtBaZLt62RuzyDN85dV3MG8aKtjtWghs/87t4fPFG0o/aOuuq3uM82x7KXpaaQyfM WmXornVmAs3aOcrlHzYmLiOS6tvPToCofOnKZ18A/Nfyf1JLu6dyFcq4Ja+Z+QPUXa 1oHcM2k7dp736ADEJYjIyPHrl72DQ1Xp18MOLmUJlvs499w201E5Urx+glmp82q/pm g9lHakFvnFmqA== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 5.10 2/5] NFSD: Async COPY result needs to return a write verifier Date: Mon, 18 Nov 2024 19:47:29 -0500 Message-ID: <20241119004732.4703-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119004732.4703-1-cel@kernel.org> References: <20241119004732.4703-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.10.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 fbd42c1a3fcd..3a445b78edd5 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 Tue Nov 19 00:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879323 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 6502E25634; Tue, 19 Nov 2024 00:47:37 +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=1731977257; cv=none; b=MXa70MVnDuMJr9UtxK9uOMbZtHWc6Y79p8tmCM2cz0PV5jPNrvxOmOAOtPNv/HzHPmCFAT1MmDwljf+9/rZgHLgQRmQoIE8c502aXJ93fJNiOoiIcqTM5t8IkcDQcRlFvgg3U6eGB/yx/BH8N1iM7kVxq/C4NB/iNu6dpJ3eOc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731977257; c=relaxed/simple; bh=azDb3efhWoEbDpj2uvsfbeMcNcSSybcxGfwNnl/LbgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tD3jCw/BZw4js3FXTnIrXSrJhndKSfogS5QudpN2LK56jXRVZM2rlQHp40YkKrkXmgjDAZkoouhxhW5goiONDQ0x9WA5Jot7iRj8R0fbFT5s9180bRmHD364rDtiTeHzZftvGxStPjDe36Lg4oxFl8OCdJo5eISNRK5ieAQYSfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oT6QTF75; 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="oT6QTF75" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC2BCC4CECF; Tue, 19 Nov 2024 00:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731977257; bh=azDb3efhWoEbDpj2uvsfbeMcNcSSybcxGfwNnl/LbgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oT6QTF75J7yUrZ80RndjWF2m5lRkP+XwYOyKfPhGpBaEOnl1H38c5T903jS9DNOg7 PHBfbx1ZK9VG4PjJc3RXMOybDg6iRV5VAJn02CzuH4HkNL5yNHZlOlVBE4zEV5SD3e MbnP9PhPC4NqXKIeTzaKnOabaN/G1BRA4oogp25hqVoGmr0CWtf4T+8b2M8ZUkgzom x8XcbogiCKcii+om81pz2jlLazqUuWMebNvqVjxnM3AczdgHgQTm87EvOqU0qvwvtK E1iga99kOCx1c/BICmcIIKfwXglN3skO07oPvi2m3Rs+5qxv6sUao9oiCic5YUWYI4 QOwU+RADuDLrg== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 5.10 3/5] NFSD: Limit the number of concurrent async COPY operations Date: Mon, 18 Nov 2024 19:47:30 -0500 Message-ID: <20241119004732.4703-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119004732.4703-1-cel@kernel.org> References: <20241119004732.4703-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 3a445b78edd5..9718af3c2611 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 18d64a9312a7..5547db4db8e6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8088,6 +8088,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 a034b9b62137..15a617bece00 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 Tue Nov 19 00:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879324 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 2E3C725634; Tue, 19 Nov 2024 00:47:38 +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=1731977258; cv=none; b=XQLZaLzOnuTO6Urek9n2yY9Mi0LT7X3pO7EMrgG4pAZdkHZzGVRXhzl5+Fr9WYWc/WCfQSApOyqPH/c1bLO5Oz+ltBRld4PRuCCFvfwkS8Sy8pE09IIKa3IdVlX+yTRwIUBrUfz6a74oCkq8hzNMcwngVbJ6nA7sX7r44RaSdYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731977258; c=relaxed/simple; bh=JXoxCMjJrfAmsPpSItXNsxwRH/VrwdTEd6ottbb37KQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g/iXHtvQW3uxOTky1fk43S+RSnx7ZFiHfD51iyAay1Qy/PBxw8u9qBqXS4dq253mGikgrrcB7/cRbIoVMC+aackJLm69rjCqka7BfXKyamBd3DO4hr1+9u9/Eld0j7Mtw7GWTCqhhYYG8aep+x9lxGJJISx9WG9OPqaIfSqkTPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ax9mrnaK; 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="Ax9mrnaK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80061C4CED6; Tue, 19 Nov 2024 00:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731977258; bh=JXoxCMjJrfAmsPpSItXNsxwRH/VrwdTEd6ottbb37KQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ax9mrnaKrGv9PineldMGz3M427ui1HIE68DaN85tk43VW1RWAOrFIGK7swWDkGyj2 zToEU4mUaMud2ftC3Q+zvhNnIjPz5/Hvkg9ne2e5otg7QQR3ToonpGe2nQvOcDyAqK LXiNIoRT6pchzIx4eBV3OIzx+HDChM2cZUqLCTr0JnYrL/yu7wbqGlPxFIKVRA4vaB 9hI7JjHo0vSiporQ8LmdUFfOiw2TBSIwPdRGuHTl27TmVQ6B/n8x6qWVYq6gYOvZh5 PRd5dhfxPS5yzLd12iBN9G+7Wq5rMMgdHpbb2jl6kQpmCMtLJczrHBK4T+CLazL0ae OhF11NeDosVAw== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 5.10 4/5] NFSD: Initialize struct nfsd4_copy earlier Date: Mon, 18 Nov 2024 19:47:31 -0500 Message-ID: <20241119004732.4703-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119004732.4703-1-cel@kernel.org> References: <20241119004732.4703-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 9718af3c2611..b439351510d2 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 Tue Nov 19 00:47:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879325 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 3E95225634; Tue, 19 Nov 2024 00:47:38 +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=1731977259; cv=none; b=aZhmqIkFRmIN3h0Czx8DAkM4JaEE5m+HVcclAGB1sdlOCLZQshlMeF41BT1Ry74IHrYXPkG9TNoCBn+W8TqucAB8UYVlgizzXY6Nle+nsqbtOOBfFLHbyzVcx5Pz/5Ghb7nwQaT1TSHLR1OlQcdeHGzjo3fWXR8b3CbetP+4Xvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731977259; c=relaxed/simple; bh=MhMkh7nubvJ3BXZAouaiBI1ZVRU/V3tNdTtRFQi+vAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fVNhQHRJ03eX+k18B8yHpVWSoWF/lQM1RZAiusgyHAXOoirAVKVyiXK+S6mlm+SAYJ1B6zUl7MF0fTN6aAQ7eJY4JHwriY+7UlidTcWIL2armZqq+gRsjHtW7B2QrvXI9IzUSfsKfjxJ8W7DStVbtF/yT0Km+eUAU8/athMIJpk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gbNhzbkc; 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="gbNhzbkc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49873C4CED0; Tue, 19 Nov 2024 00:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731977258; bh=MhMkh7nubvJ3BXZAouaiBI1ZVRU/V3tNdTtRFQi+vAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gbNhzbkct+GMxWsqr9eK0UuPpccdSz7igrL/E0UHlFlj7AAKkRHqpc+/ystMGQoI4 jCNpMSGbeS02lKSMjdY2mKYQfVWE1/GNdDOU5mq+M0pAwy0i88iLWF0aLornjN6XlU XL8HVKWE45o5Y3RqjuEC8yvtSJClYnVmXCan2+C4C/S34zgpkucBniXiyRpEHLK9aB IZaVoicXIFZrxei+mvXTtKfmgpj5z47Dm0XGDMGtd0TA1Mo2JaFidkBiON/JYzf6fK k/1iSFgVq5hoSZbTMUw7bpJC9hibJSDIPW6bIgmJQM7KQBllt4WUQOqabUfTPzj2Wi Dx2ZHQdeo2Faw== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 5.10 5/5] NFSD: Never decrement pending_async_copies on error Date: Mon, 18 Nov 2024 19:47:32 -0500 Message-ID: <20241119004732.4703-6-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119004732.4703-1-cel@kernel.org> References: <20241119004732.4703-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 b439351510d2..237e47896af8 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;