linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: bfields@fieldses.org (J. Bruce Fields)
To: Olga Kornievskaia <kolga@netapp.com>
Cc: bfields@redhat.com, linux-nfs@vger.kernel.org
Subject: Re: [PATCH v6 05/10] NFSD first draft of async copy
Date: Thu, 25 Jan 2018 17:04:40 -0500	[thread overview]
Message-ID: <20180125220440.GA21492@fieldses.org> (raw)
In-Reply-To: <20171024174752.74910-6-kolga@netapp.com>

Nit: this could use a better subject line.

On Tue, Oct 24, 2017 at 01:47:47PM -0400, Olga Kornievskaia wrote:
...
> +	if (!copy->cp_synchronous) {
> +		status = nfsd4_init_copy_res(copy, 0);
> +		async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
> +		if (!async_copy) {
> +			status = nfserrno(-ENOMEM);
> +			goto out;
> +		}
> +		dup_copy_fields(copy, async_copy);
> +		memcpy(&copy->cp_res.cb_stateid, &copy->cp_dst_stateid,
> +			sizeof(copy->cp_dst_stateid));
> +		spin_lock(&async_copy->cp_clp->async_lock);
> +		list_add(&async_copy->copies,
> +				&async_copy->cp_clp->async_copies);
> +		spin_unlock(&async_copy->cp_clp->async_lock);

At this point other threads could in theory look up this async_copy, but
its copy_task field is not yet initialized.  I don't *think* that's a
problem for nfsd4_shutdown_copy, because I don't think the server could
be processing rpc's for this client any more at that point.  But I think
a malicious client might be able to trigger a NULL dereference in
nfsd4_offload_cancel.

Is there any reason not to assign copy_task before adding it to this
list?

--b.

> +		async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
> +				async_copy, "%s", "copy thread");
> +		if (IS_ERR(async_copy->copy_task)) {
> +			status = PTR_ERR(async_copy->copy_task);
> +			goto out_err_dec;
> +		}
> +		wake_up_process(async_copy->copy_task);
> +	} else {
> +		status = nfsd4_do_copy(copy, 1);
>  	}
> -
> -	fput(src);
> -	fput(dst);
>  out:
>  	return status;
> +out_err_dec:
> +	cleanup_async_copy(async_copy);
> +	goto out;
>  }
>  
>  static __be32
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 0c04f81..d7767a1 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -1774,6 +1774,8 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>  #ifdef CONFIG_NFSD_PNFS
>  	INIT_LIST_HEAD(&clp->cl_lo_states);
>  #endif
> +	INIT_LIST_HEAD(&clp->async_copies);
> +	spin_lock_init(&clp->async_lock);
>  	spin_lock_init(&clp->cl_lock);
>  	rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>  	return clp;
> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> index f8b0210..9189062 100644
> --- a/fs/nfsd/state.h
> +++ b/fs/nfsd/state.h
> @@ -352,6 +352,8 @@ struct nfs4_client {
>  	struct rpc_wait_queue	cl_cb_waitq;	/* backchannel callers may */
>  						/* wait here for slots */
>  	struct net		*net;
> +	struct list_head	async_copies;	/* list of async copies */
> +	spinlock_t		async_lock;	/* lock for async copies */
>  };
>  
>  /* struct nfs4_client_reset
> diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
> index 9b0c099..0a19954 100644
> --- a/fs/nfsd/xdr4.h
> +++ b/fs/nfsd/xdr4.h
> @@ -529,6 +529,15 @@ struct nfsd4_copy {
>  	struct nfsd4_callback	cp_cb;
>  	__be32			nfserr;
>  	struct knfsd_fh		fh;
> +
> +	struct nfs4_client      *cp_clp;
> +
> +	struct file             *fh_src;
> +	struct file             *fh_dst;
> +	struct net              *net;
> +
> +	struct list_head	copies;
> +	struct task_struct	*copy_task;
>  };
>  
>  struct nfsd4_seek {
> -- 
> 1.8.3.1

  reply	other threads:[~2018-01-25 22:04 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24 17:47 [PATCH v6 00/10] NFSD support for asynchronous COPY Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 01/10] NFSD CB_OFFLOAD xdr Olga Kornievskaia
2018-01-25 16:43   ` J. Bruce Fields
2018-01-26 15:16     ` Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 02/10] NFSD OFFLOAD_STATUS xdr Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 03/10] NFSD OFFLOAD_CANCEL xdr Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 04/10] NFSD xdr callback stateid in async COPY reply Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 05/10] NFSD first draft of async copy Olga Kornievskaia
2018-01-25 22:04   ` J. Bruce Fields [this message]
2018-01-26 15:17     ` Olga Kornievskaia
2018-02-15 19:59     ` Olga Kornievskaia
2018-02-15 20:06       ` J. Bruce Fields
2018-01-25 22:29   ` J. Bruce Fields
2018-01-26 15:17     ` Olga Kornievskaia
2018-01-26 21:34   ` J. Bruce Fields
2018-02-02 19:50     ` Olga Kornievskaia
2018-02-02 19:55       ` J. Bruce Fields
2017-10-24 17:47 ` [PATCH v6 06/10] NFSD return nfs4_stid in nfs4_preprocess_stateid_op Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 07/10] NFSD create new stateid for async copy Olga Kornievskaia
2018-01-26 21:37   ` J. Bruce Fields
2018-01-26 21:59   ` J. Bruce Fields
2018-02-02 20:45     ` Olga Kornievskaia
2018-02-02 21:45       ` J. Bruce Fields
2018-02-15 22:18         ` Olga Kornievskaia
2018-02-16  1:43           ` J. Bruce Fields
2018-02-16 16:06             ` Olga Kornievskaia
2018-02-16 18:12               ` J. Bruce Fields
2018-02-16 20:53                 ` Olga Kornievskaia
2018-02-20 18:48                   ` J. Bruce Fields
2018-03-06 17:15                     ` Olga Kornievskaia
2018-03-06 19:33                       ` J. Bruce Fields
2017-10-24 17:47 ` [PATCH v6 08/10] NFSD handle OFFLOAD_CANCEL op Olga Kornievskaia
2018-02-16 17:28   ` Olga Kornievskaia
2018-02-16 18:10     ` J. Bruce Fields
2017-10-24 17:47 ` [PATCH v6 09/10] NFSD support OFFLOAD_STATUS Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 10/10] NFSD stop queued async copies on client shutdown Olga Kornievskaia
2018-01-25 22:22   ` J. Bruce Fields
2018-01-26 15:17     ` Olga Kornievskaia
2017-11-03 19:57 ` [PATCH v6 00/10] NFSD support for asynchronous COPY Olga Kornievskaia
2017-11-10 15:01   ` Olga Kornievskaia
2017-11-14  0:48     ` J. Bruce Fields
2017-11-28 20:28       ` Olga Kornievskaia
2017-11-30 20:18         ` J. Bruce Fields
2017-11-30 23:03           ` Olga Kornievskaia
2017-12-04 21:32             ` J. Bruce Fields
     [not found]               ` <CAN-5tyEVSwBmPMtUBJYDdLi7FK2MNMGuDQrrsvp776zD3Jcw0w@mail.gmail.com>
2018-01-22 16:51                 ` Olga Kornievskaia
2018-01-25 22:33                   ` J. Bruce Fields
2018-01-26 15:16                     ` Olga Kornievskaia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180125220440.GA21492@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=bfields@redhat.com \
    --cc=kolga@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).