From patchwork Mon Nov 18 21:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879069 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 671E31E7676; Mon, 18 Nov 2024 21:14:17 +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=1731964457; cv=none; b=CBU7FFZLzFPBMTTU5bFzu0KqzualAxqXHaRWydsYQhujREV8H8QEDH+iF6XQ5LMjFcjxMcjqXg42M3Vco+7WaUwxNLiDL89ziLKC+ZbINdOYKwWrMNb696aZ3oSda0y34Xjo0ikTgJd1tRHbJexOu2aYeNg5R/P9mc6DCkMRsgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964457; c=relaxed/simple; bh=mXnmYI3CEGwEX003uQzZKukhDWAt/2Snk6B8E/IGtEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CTefHLNznAdA+0Lj1JJjTyoM4CU0M+GK+6I7WL0gQs4sqNGA4AZzmzSs9SxwejU2OB/4ZTTAY/OMIdyz4K0lxLEkf1om+FC19A2FcTRLTpSUWeX0kQz0PPhX8P9b5CmOHpW8XD0nWX3p9xGHYiNNNYFswEiqlzXjl1Le8Oh5UOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cvqAileT; 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="cvqAileT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B861AC4CED6; Mon, 18 Nov 2024 21:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964457; bh=mXnmYI3CEGwEX003uQzZKukhDWAt/2Snk6B8E/IGtEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvqAileTHgsznwrT48LnAYOaiFPdLKA4KzHhJkHWUT61bKbK25mfbPwj7INITh6Fy 3Urkh2NvyWvWsHArWIvvSySCh35Joh5C4mVx0EHH5Ir+Hh1Y5GbUFTNFIl9LLSnLGC UzM344IYhbjww4SNWXvnaG4Q0M6PEZY5c9feWxp3bGtzR/eCtPEs66xhfTpONJMWwX PSgGIe9uQu8vTOu8tUGccINTJFdmPoIjCDsIRkIpE0O1B6GewzmnnLDh76ic7eNvZr giwQyHEqLa32Rs3/8ifBJ78xgsnxjo217uuDUgDXkn3RETW1pmearYp6Xt/7yDnywP aU2P/tRPktPvQ== From: cel@kernel.org To: Cc: , Jeff Layton , Dai Ngo , Chen Hanxiao Subject: [PATCH 6.6 1/5] NFSD: initialize copy->cp_clp early in nfsd4_copy for use by trace point Date: Mon, 18 Nov 2024 16:14:09 -0500 Message-ID: <20241118211413.3756-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211413.3756-1-cel@kernel.org> References: <20241118211413.3756-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 ae0057c54ef4..a378dcb2ceb2 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1798,6 +1798,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; @@ -1812,7 +1813,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:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879070 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 1327D1E7676; Mon, 18 Nov 2024 21:14:18 +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=1731964458; cv=none; b=hKMXX2b4USkXtthlB2FpuJZw1nkmyI2nAT0uQcDalmMxajd1Eo81r1D9PBlVQp8aLhN2kv5LnPGuc93wqtVjuFihJJxCwdsMAvOwwRCUkRVzvBH/6QdL/iUu8Tb2eB9LEjrNPbpSZCRVh52pZiLsKpXM1P+ykKWMJNjCGEDLuoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964458; c=relaxed/simple; bh=1+cKXlrxG78idpFwYOPnLVoKqMYbOO+bQajpAJsA1V4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X/HZxjkTf+YAgORoj0wqLBIrgZbCldNK8kCcQhszQ8RbUa6OjwRJfxIbZyocDnquYiXmmoGMF4HSf/hfBPOpN58mbTj423FiZ2W7cxmBMePHqXxVA0XxOlyU7Mt3tHKe1AqKu6ETH9/weyHdVBIEaB+fOStvVGUkH7UyF3JGASU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X+vaeMoS; 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="X+vaeMoS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78CC6C4CED0; Mon, 18 Nov 2024 21:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964457; bh=1+cKXlrxG78idpFwYOPnLVoKqMYbOO+bQajpAJsA1V4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X+vaeMoSy55AOIFBJLqmyr4VXlfEq/fUkS1Bag7I5nm+PSxL0yN0eykXw3ugnSQza 9QVJ3IdgBqBhZ8p+oyVLI3Kap0wOxvL/KQ+SEg3E3JTBisC1afnQu+fCP6sneN1Qtk BvVNrubE5frdYqwa8m5xtcYM69GQJ+TWicfmGcD7tr9eMQkdKoeCELeZcfX8Yzek8j P8RWzoEcpjJLyY/OUVc9tBCxb4J9rBvLLGnPvM0ZkKnlPIElyft9WYTEgwIERAcyfj GmEWRHFP6PehmM+92FgvKMhNdZb8bou1cyP22Jxp473umE8ce8ut8f6NjwYL4qKENG hGmmzQe38WETw== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 6.6 2/5] NFSD: Async COPY result needs to return a write verifier Date: Mon, 18 Nov 2024 16:14:10 -0500 Message-ID: <20241118211413.3756-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211413.3756-1-cel@kernel.org> References: <20241118211413.3756-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.6.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 a378dcb2ceb2..3e35f8688426 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -751,15 +751,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) @@ -1623,7 +1614,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, @@ -1794,9 +1784,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)) { @@ -1816,8 +1811,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) @@ -1829,8 +1822,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:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879071 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 AA7AC17BA3; Mon, 18 Nov 2024 21:14:18 +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=1731964459; cv=none; b=WDNBjpNEoKtH3bb4Oj2G7Dn1RL2ZInzSUNbnb6cVhOrDb1evO3TxmCgVX6DnoayY0UeB+JAd9hzx8wXNCN748NmWnXhdMgMv8umqQ+ZAjVJ99fh/XdT+d4wT3UhMrAokkmRZ+qD6DTYpv6jHgnbIuu76UEOjdlnHVsGEKioUqWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964459; c=relaxed/simple; bh=fjth7eJ85x+57Dt8eoiP4qsUJ5JgoZqFh3BE5VLR67k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbBruIvVEncVRh/fRnvPrN9nIjXGBQJRTNsFMzYHxPhErcnusr0y8DLnVA1QMW8y7GllsiI0NKUKlfe/rYATtkqJ/U/mGmpwULtQXILP5OA3hXrayqHzp+tgBSc+5Hiq0wJWQvlaQm5HEOKXS0Xofsgl1iXVhZ4MMUtHO/wR8Pc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LjtGb1Tt; 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="LjtGb1Tt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26D49C4CED7; Mon, 18 Nov 2024 21:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964458; bh=fjth7eJ85x+57Dt8eoiP4qsUJ5JgoZqFh3BE5VLR67k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjtGb1TtlI8Ne/e4k1+XSNz7R4/NmS7D4CPoMfU55bobeorDyf/t7wslTdxQZ6hHx yxcECg2uLQu0LEOT7S9yh+IDqVlK7st3mUTGD8LAUTWZqsOmdvKtX3vpYWNuOV4oAi D43BdY5zGlY55q8s5u3/WDarXHYtNOm6YT9qGZ8zEOtgzJndzFcWmolwgI8fgLJNrL Iy3iG2+AHjfuN4I+DLB53FsgpmWZfZ85kXmD73a4wC2J2CYZeSjN5hfVtm613MbPi2 sr2Ti/+lQrtiQwpT9OLPMo1/Gf9hoYyOt44zHXAtT19+mTWdnHb45bN6CYQoR7iT8K YWV3fugFIcjrw== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever Subject: [PATCH 6.6 3/5] NFSD: Limit the number of concurrent async COPY operations Date: Mon, 18 Nov 2024 16:14:11 -0500 Message-ID: <20241118211413.3756-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211413.3756-1-cel@kernel.org> References: <20241118211413.3756-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 9bfca3dda63d..77d4f82096c9 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -153,6 +153,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 3e35f8688426..e74462fb480f 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1273,6 +1273,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); } @@ -1811,10 +1812,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); @@ -1853,7 +1860,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 975dd74a7a4d..901fc68636cd 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8142,6 +8142,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 9d918a79dc16..144e05efd14c 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:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879072 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 AA8141E7C1A; Mon, 18 Nov 2024 21:14:19 +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=1731964459; cv=none; b=aKsoH8PIffnuDPMYXK+QDbQO/FSgB8onMogVJWxz13nHOOoL3OgripFR2qc6pcD7xAHzlRylmTWR6T1CJaadTgVlOf4NfDwvNW6qFJF6izt30DzmpJG5xqJmXTAuWTuCavfW2o0yD1usfzWC+csoa7AORSeHdO9mysDt20KBhSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964459; c=relaxed/simple; bh=kudmYckbgBJUAUmnlP964NvQden0S9yrCfqiiDIoS9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tdh6M2QvJOWYSTm+qP2qR7V/d7UX0H5kwqIzBxtewv4Obno7gxjgHzvfoZ2aaDVc3wkUdUDRs8Ok/x0cp4XYMTpDdnATDRvFF7qt8ZtGtGRYbsHNBTaowlI1RjxBqT5p3zMl0Lv++9nweiBqYdrnBrYkH0Vamc9YDujrqqG8fAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LIFy81ov; 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="LIFy81ov" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9177C4CED9; Mon, 18 Nov 2024 21:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964459; bh=kudmYckbgBJUAUmnlP964NvQden0S9yrCfqiiDIoS9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIFy81ovTS+9sC0ine8sg8oP5UmoFjHgdc0YbZ5Vq2fUDVtcGZY9Td+eV/2eAVUV8 seGTggAFZhoPVkwUghmBHxEXMOwVIKRXhcbr4zaZ3I9DRWmLFUkxyF3VAOA5XtIPxt /fAiN8nMSm08nggYMUkDxX1sF3caA11YJKAOltxuNHg9Wqugc/IhDj6Nr4rNsABFft eI0cYY8v+6ridDCOX9NdDqihI16mx8q9iUsF5PIZmQBfSk8f1YDfkKWR+cZxu0+nXL SAFlACF4eawgR3gxJnIOzwzI94b2/wp+5+Oo+mMKUnX2gqIJZEUEhE6U2o+HEuVQ9v 2PTQgvuXgXIjQ== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 6.6 4/5] NFSD: Initialize struct nfsd4_copy earlier Date: Mon, 18 Nov 2024 16:14:12 -0500 Message-ID: <20241118211413.3756-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211413.3756-1-cel@kernel.org> References: <20241118211413.3756-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 e74462fb480f..444f68ade80c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1816,14 +1816,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:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13879073 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 81CE617BA3; Mon, 18 Nov 2024 21:14:20 +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=1731964460; cv=none; b=D7o6n6L7QvylmI476NHPaDp8Y1HAjBtRC8eiyBVRLJOuCTRfm/y0LPE89z8W7O2JIpo3Cg+84v51a7gk7JVXF8a04th+UmcnIZMPYpNZBOXbUXMFjjO53r5VIZV/FLqPPSZ45Ne2F3h3pqNUVZdS2FFKiAT3zP8lDEhsevQ844I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731964460; c=relaxed/simple; bh=ZWZJ0ABGP0mdbLIUchEG7glZC0kVTlkhV5EGD/OI6mY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uyG8mq2jt3TB/EhtHDHBtVrvFGp4PjeKbBE5kf2ezWUUp0AAvpqUs7ESPd1FgrNsIuILma4SS5sCgSKiI0/864Lx7ImPV3eq4CPKCXWWzgeFRrOqTj/AWtkRap/oOBsfd6qi39thmJGYRbBVpxonDKM7Qo4uNcCRiXXHnbeYjtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KZB7+L6g; 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="KZB7+L6g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B6D8C4CED6; Mon, 18 Nov 2024 21:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731964460; bh=ZWZJ0ABGP0mdbLIUchEG7glZC0kVTlkhV5EGD/OI6mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZB7+L6gWFUzgpfNfNAsr3rlM9Z7SHp5a+SHQ4vnoB+Z33smoZtyLfn+DjKnssWoE KhQ5dUrIKqPkuNN8dUm4Uc3q3R9aCVCcXj0g4jxkR4LIXNOvz0kw8HC8RxUd+E5tV9 mOvvWhbH3Glq7tK0GNcLQGboVjAaVUrug4k3Ar9p8T5SkwEWl9XiBSWjw3mZUYWD5B dS/nmyrDwScKSn6m8aeo0q18OHNo59B8ppP/fSapQd2C6bC9arqxcg+9nk2784/POG /0fI+HNk2i+IwnwqgvCVscMmUo+c5XtEyUTzMGANIFHoq0kFH8EomEGXuezILvPeqk FAXJXey3+/L/g== From: cel@kernel.org To: Cc: , Jeff Layton , Chuck Lever , Olga Kornievskaia Subject: [PATCH 6.6 5/5] NFSD: Never decrement pending_async_copies on error Date: Mon, 18 Nov 2024 16:14:13 -0500 Message-ID: <20241118211413.3756-6-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241118211413.3756-1-cel@kernel.org> References: <20241118211413.3756-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 444f68ade80c..d64f792964e1 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1820,10 +1820,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;