diff mbox series

NFSD: Initialize struct nfsd4_copy earlier

Message ID 20241026160237.4304-2-cel@kernel.org (mailing list archive)
State New
Headers show
Series NFSD: Initialize struct nfsd4_copy earlier | expand

Commit Message

Chuck Lever Oct. 26, 2024, 4:02 p.m. UTC
From: Chuck Lever <chuck.lever@oracle.com>

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 <okorniev@redhat.com>
Fixes: aadc3bbea163 ("NFSD: Limit the number of concurrent async COPY operations")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4proc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jeff Layton Oct. 27, 2024, 11:48 a.m. UTC | #1
On Sat, 2024-10-26 at 12:02 -0400, cel@kernel.org wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
> 
> 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 <okorniev@redhat.com>
> Fixes: aadc3bbea163 ("NFSD: Limit the number of concurrent async COPY operations")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  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 b5a6bf4f459f..5fd1ce3fc8fb 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -1841,14 +1841,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;

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Olga Kornievskaia Oct. 29, 2024, 7:02 p.m. UTC | #2
On Sat, Oct 26, 2024 at 12:02 PM <cel@kernel.org> wrote:
>
> From: Chuck Lever <chuck.lever@oracle.com>
>
> 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 <okorniev@redhat.com>
> Fixes: aadc3bbea163 ("NFSD: Limit the number of concurrent async COPY operations")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  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 b5a6bf4f459f..5fd1ce3fc8fb 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -1841,14 +1841,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;
> --

No more warning after this patch when we hit the copy limit.

Tested-by: Olga Kornievskaia <okorniev@redhat.com>

> 2.47.0
>
>
diff mbox series

Patch

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index b5a6bf4f459f..5fd1ce3fc8fb 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1841,14 +1841,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;