linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Josef Bacik <josef@toxicpanda.com>,
	trond.myklebust@hammerspace.com,  anna@kernel.org,
	linux-nfs@vger.kernel.org
Subject: Re: [PATCH 1/2] nfs: properly protect nfs_direct_req fields
Date: Mon, 04 Mar 2024 08:14:10 -0500	[thread overview]
Message-ID: <95c71a1d5b22bd395e8a3feb2b02831d602f9a19.camel@kernel.org> (raw)
In-Reply-To: <ca2f5e31d321b19fdb033f10ce6aec79c337a648.1709311699.git.josef@toxicpanda.com>

On Fri, 2024-03-01 at 11:49 -0500, Josef Bacik wrote:
> We protect accesses to the nfs_direct_req fields with the dreq->lock
> ever where except nfs_direct_commit_complete.  This isn't a huge deal,
> but it does lead to confusion, and we could potentially end up setting
> NFS_ODIRECT_RESCHED_WRITES in one thread where we've had an error in
> another.  Clean this up to properly protect ->error and ->flags in the
> commit completion path.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/nfs/direct.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
> index c03926a1cc73..befcc167e25f 100644
> --- a/fs/nfs/direct.c
> +++ b/fs/nfs/direct.c
> @@ -606,6 +606,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
>  
>  	trace_nfs_direct_commit_complete(dreq);
>  
> +	spin_lock(&dreq->lock);
>  	if (status < 0) {
>  		/* Errors in commit are fatal */
>  		dreq->error = status;
> @@ -613,6 +614,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
>  	} else {
>  		status = dreq->error;
>  	}
> +	spin_unlock(&dreq->lock);
>  
>  	nfs_init_cinfo_from_dreq(&cinfo, dreq);
>  
> @@ -625,7 +627,10 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
>  			spin_unlock(&dreq->lock);
>  			nfs_release_request(req);
>  		} else if (!nfs_write_match_verf(verf, req)) {
> -			dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
> +			spin_lock(&dreq->lock);
> +			if (dreq->flags == 0)
> +				dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
> +			spin_unlock(&dreq->lock);
>  			/*
>  			 * Despite the reboot, the write was successful,
>  			 * so reset wb_nio.

Seems reasonable, even if just for consistency's sake:

Reviewed-by: Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2024-03-04 13:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 16:49 [PATCH 0/2] nfs: fix UAF in direct writes Josef Bacik
2024-03-01 16:49 ` [PATCH 1/2] nfs: properly protect nfs_direct_req fields Josef Bacik
2024-03-04 13:14   ` Jeff Layton [this message]
2024-03-01 16:49 ` [PATCH 2/2] nfs: fix UAF in direct writes Josef Bacik
2024-03-04 13:30   ` Jeff Layton
2024-03-04 17:57   ` Trond Myklebust

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=95c71a1d5b22bd395e8a3feb2b02831d602f9a19.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=anna@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    /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).